{"id":17964792,"url":"https://github.com/brucify/rebar3_rustler","last_synced_at":"2025-03-25T06:31:02.295Z","repository":{"id":64334923,"uuid":"573885586","full_name":"brucify/rebar3_rustler","owner":"brucify","description":"Create new Erlang NIF libs in Rust in no time","archived":false,"fork":false,"pushed_at":"2022-12-16T11:09:48.000Z","size":22,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-19T09:21:11.369Z","etag":null,"topics":["cargo","erlang","erlang-nif","nif","rebar3","rebar3-plugin","rebar3-template","rust","rustler"],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brucify.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":"2022-12-03T18:34:45.000Z","updated_at":"2024-12-06T03:57:55.000Z","dependencies_parsed_at":"2023-01-29T13:00:59.716Z","dependency_job_id":null,"html_url":"https://github.com/brucify/rebar3_rustler","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brucify%2Frebar3_rustler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brucify%2Frebar3_rustler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brucify%2Frebar3_rustler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brucify%2Frebar3_rustler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brucify","download_url":"https://codeload.github.com/brucify/rebar3_rustler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245413574,"owners_count":20611350,"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":["cargo","erlang","erlang-nif","nif","rebar3","rebar3-plugin","rebar3-template","rust","rustler"],"created_at":"2024-10-29T12:08:41.490Z","updated_at":"2025-03-25T06:31:01.957Z","avatar_url":"https://github.com/brucify.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rebar3 rustler plugin\n\n[![Hex.pm package version](https://img.shields.io/hexpm/v/rebar3_rustler.svg)](https://hex.pm/packages/rebar3_rustler)\n[![Last Updated](https://img.shields.io/github/last-commit/brucify/rebar3_rustler.svg)](https://github.com/brucify/rebar3_rustler/commits/master)\n\nA basic set of [rebar3](https://www.rebar3.org) templates to aid creating [rustler](https://github.com/rusterlium/rustler)-based Erlang NIFs (Native Implemented Functions), allowing us to call Rust from Erlang.\nThis plugin uses [rebar3_cargo](https://github.com/rusterlium/rebar3_cargo) to compile Rust crates in the crates directory and copy all binary outputs to `priv/crates/\u003ccratename\u003e/\u003cbinary\u003e`.\n\n2 templates are provided:\n\n* `rustler_lib` for generating a complete Rustler-based Erlang NIF library\n* `rustler_nif` for generating new Rustler-based NIF in an existing Erlang app\n\nStructure of the generated NIF library. An example can be found [here](https://github.com/brucify/my_nif).\n```\n├── rebar.config\n└── src\n    ├── my_nif.app.src\n    └── my_nif.erl\n├── priv\n├── native\n│   └── my_nif\n│       ├── Cargo.toml\n│       └── src\n│           └── lib.rs\n```\n\n## Usage\n\nUse the plugin by adding the following to `~/.config/rebar3/rebar.config`\n\n    {plugins, [rebar3_rustler]}.\n\nRunning `rebar3 new` should now show extra templates available:\n\n\t$ rebar3 new\n\t...\n    rustler_lib (plugin): Complete Erlang NIF library written in Rust using rustler\n    rustler_nif (plugin): A basic Erlang NIF written in Rust using rustler\n\t...\n### Creating a new Erlang NIF library\n\n\t$ rebar3 new rustler_lib my_nif # change my_nif to whatever you want to call your lib\n\t$ cd my_nif\n\t$ make\n\nCompiling the app will fetch dependencies for both Erlang and Rust:\n\n\t===\u003e Fetching rebar3_cargo v0.1.0\n    ===\u003e Fetching cargo v0.1.2\n    ===\u003e Fetching jsx v2.11.0\n    ...\n        Compiling regex v1.7.0\n        Compiling rustler_sys v2.2.0\n        Compiling rustler_codegen v0.26.0\n        Compiling my_nif v0.1.0 (/Users/bruce/git/my_nif/native/my_nif)\n        Finished dev [unoptimized + debuginfo] target(s) in 6.08s\n    ===\u003e   Copying libmy_nif...\n    ===\u003e Analyzing applications...\n    ===\u003e Compiling my_nif\n\nTo check if we can call Rust from the Erlang shell:\n\n\t1\u003e my_nif:add(2, 2).\n    4\n\n### Creating a NIF in an existing Erlang app\n\n    $ cd my_app                      # change my_app to your existing app name               \n    $ rebar3 new rustler_nif my_nif\n\nThen follow the instructions in `native/my_nif/README.md`\n\n### Testing\n\nRunning Erlang eunit tests will also invoke `cargo test` in the Rust crate, thanks to the [rebar3_cargo](https://github.com/rusterlium/rebar3_cargo) plugin.\n\n\t$ rebar3 eunit    # unit tests\n\n### Options \n\nPass options as usual to the [rebar3_cargo](https://github.com/rusterlium/rebar3_cargo) plugin.\n\n    {cargo_opts, [\n        {src_dir, \"native/my_nif\"}\n    ]}.\n\n    {provider_hooks, [\n        {pre, [\n            {compile, {cargo, build}}\n        ]},\n        {post, [\n            {clean, {cargo, clean}},\n            {eunit, {cargo, test}}\n        ]}\n    ]}.\n\n## License\n\nCopyright 2022 Bruce Yinhe\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n\n# Acknowledgment\nThis plugin is based on\n[rebar3_cargo](https://github.com/rusterlium/rebar3_cargo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrucify%2Frebar3_rustler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrucify%2Frebar3_rustler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrucify%2Frebar3_rustler/lists"}