{"id":17313109,"url":"https://github.com/tatsuya6502/elixir_rust_interop_demo","last_synced_at":"2025-04-14T14:33:42.844Z","repository":{"id":138123599,"uuid":"49512712","full_name":"tatsuya6502/elixir_rust_interop_demo","owner":"tatsuya6502","description":"Demonstrate calling Rust functions from Elixir using Erlang NIF interface","archived":false,"fork":false,"pushed_at":"2016-01-18T06:16:12.000Z","size":11,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T03:32:34.420Z","etag":null,"topics":["demo-apps","elixir","erlang","examples","rust"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tatsuya6502.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-12T16:23:00.000Z","updated_at":"2023-03-27T02:19:42.000Z","dependencies_parsed_at":"2023-03-15T22:45:36.931Z","dependency_job_id":null,"html_url":"https://github.com/tatsuya6502/elixir_rust_interop_demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tatsuya6502%2Felixir_rust_interop_demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tatsuya6502%2Felixir_rust_interop_demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tatsuya6502%2Felixir_rust_interop_demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tatsuya6502%2Felixir_rust_interop_demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tatsuya6502","download_url":"https://codeload.github.com/tatsuya6502/elixir_rust_interop_demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248897634,"owners_count":21179620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["demo-apps","elixir","erlang","examples","rust"],"created_at":"2024-10-15T12:45:48.425Z","updated_at":"2025-04-14T14:33:42.808Z","avatar_url":"https://github.com/tatsuya6502.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elixir Rust Interop Demo\n\nThis project demonstrates calling Rust functions from Elixir using\nErlang NIF interface. It depends on\n[ruster_unsafe](https://crates.io/crates/ruster_unsafe/) crate,\na low level bindings to Erlang NIF API for Rust.\n\n\n## Recently Tested With\n\n- Elixir 1.2.0 on Erlang/OTP 18.2.1 with dirty schedulers and HiPE\n  enabled\n- Rust 1.5\n\n\n## Requirements\n\n- Elixir 1.2.0 or newer is recommended.\n- Erlang/OTP 17.0 or newer. 18.0 or newer is recommended because\n  Elixir 1.2.0 requires 18.0.\n- Rust 1.5 or newer is recommended.\n\n\n### Erlang/OTP Build Options\n\nThese Rust functions take advantage of experimental \"dirty schedulers\"\nin Erlang/OTP 17.0 or newer, so please enable this feature.\n\n- Erlang/OTP must be built with `--enable-dirty-schedulers`\n- Optionally, Erlang/OTP can be build with `--enable-hipe`, or\n  with both `--enable-hipe --enable-native-libs`\n\n\n## Running the Program\n\nFirst of all, clone and build the project. This will build both Rust\nand Elixir stuffs.\n\n```shell-session\ngit clone https://github.com/tatsuya6502/elixir_rust_interop_demo.git\ncd elixir_rust_interop_demo\niex -S mix\n```\n\n\n### Calling a Regular Elixir Function\n\nTry to call an Elixir function to calculate an approximate number of\nPi in parallel (10 concurrent processes).\n\n```iex\niex\u003e :timer.tc(fn() -\u003e Pi.calc_pi_parallel(1_000_000_000, 10) end)\n{29319387, {:ok, 3.141592655589816}}\n```\n\n\n### Enable HiPE\n\nYou may also try HiPE. From another terminal window, compile Pi module\nwith hipe option.\n\n```shell-session\ncd elixir_rust_interop_demo\nERL_COMPILER_OPTIONS=\"[native, {hipe, [o3]}]\" elixirc -o _build/dev/lib/elixir_rust_interop_demo/ebin/ lib/pi.ex\n```\n\nThen run it.\n\n```iex\niex\u003e l Pi\niex\u003e :code.is_module_native(Pi)\ntrue\niex\u003e :timer.tc(fn() -\u003e Pi.calc_pi_parallel(1_000_000_000, 10) end)\n{15226457, {:ok, 3.141592655589816}}\n```\n\n\n### Calling a Rust Function from Elixir via Erlang NIF interface\n\nCalling a Rust function from an Elixir function to calculate an\napproximate number of Pi in parallel (10 concurrent threads).\n\n```iex\niex\u003e :timer.tc(fn() -\u003e PiNif.calc_pi_parallel(1_000_000_000, 10) end)\n{1209160, {:ok, 3.141592655589816}}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftatsuya6502%2Felixir_rust_interop_demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftatsuya6502%2Felixir_rust_interop_demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftatsuya6502%2Felixir_rust_interop_demo/lists"}