From 024b8a7c64544c14500dc6b02632278b4ad14ded Mon Sep 17 00:00:00 2001 From: SphericalKat Date: Mon, 16 Aug 2021 13:58:58 +0530 Subject: [PATCH] chore: generate a rustler project Signed-off-by: SphericalKat --- mix.exs | 1 + mix.lock | 2 ++ native/ketbin_utils_syntax/.cargo/config | 5 +++++ native/ketbin_utils_syntax/.gitignore | 1 + native/ketbin_utils_syntax/Cargo.toml | 13 +++++++++++++ native/ketbin_utils_syntax/README.md | 20 ++++++++++++++++++++ native/ketbin_utils_syntax/src/lib.rs | 6 ++++++ 7 files changed, 48 insertions(+) create mode 100644 native/ketbin_utils_syntax/.cargo/config create mode 100644 native/ketbin_utils_syntax/.gitignore create mode 100644 native/ketbin_utils_syntax/Cargo.toml create mode 100644 native/ketbin_utils_syntax/README.md create mode 100644 native/ketbin_utils_syntax/src/lib.rs diff --git a/mix.exs b/mix.exs index bce50e1..bbbecdf 100644 --- a/mix.exs +++ b/mix.exs @@ -47,6 +47,7 @@ defmodule Ketbin.MixProject do {:jason, "~> 1.0"}, {:plug_cowboy, "~> 2.0"}, {:phx_gen_auth, "~> 0.7", only: [:dev], runtime: false}, + {:rustler, "~> 0.22-rc"} ] end diff --git a/mix.lock b/mix.lock index b98c782..c0c34ee 100644 --- a/mix.lock +++ b/mix.lock @@ -27,7 +27,9 @@ "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"}, "postgrex": {:hex, :postgrex, "0.15.10", "2809dee1b1d76f7cbabe570b2a9285c2e7b41be60cf792f5f2804a54b838a067", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "1560ca427542f6b213f8e281633ae1a3b31cdbcd84ebd7f50628765b8f6132be"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, + "rustler": {:hex, :rustler, "0.22.0", "e2930f9d6933e910f87526bb0a7f904e32b62a7e838a3ca4a884ee7fdfb957ed", [:mix], [{:toml, "~> 0.5.2", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "01f5989dd511ebec09be481e07d3c59773d5373c5061e09d3ebc3ef61811b49d"}, "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"}, "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, "telemetry_poller": {:hex, :telemetry_poller, "0.5.1", "21071cc2e536810bac5628b935521ff3e28f0303e770951158c73eaaa01e962a", [:rebar3], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4cab72069210bc6e7a080cec9afffad1b33370149ed5d379b81c7c5f0c663fd4"}, + "toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm", "f1e3dabef71fb510d015fad18c0e05e7c57281001141504c6b69d94e99750a07"}, } diff --git a/native/ketbin_utils_syntax/.cargo/config b/native/ketbin_utils_syntax/.cargo/config new file mode 100644 index 0000000..a125291 --- /dev/null +++ b/native/ketbin_utils_syntax/.cargo/config @@ -0,0 +1,5 @@ +[target.x86_64-apple-darwin] +rustflags = [ + "-C", "link-arg=-undefined", + "-C", "link-arg=dynamic_lookup", +] diff --git a/native/ketbin_utils_syntax/.gitignore b/native/ketbin_utils_syntax/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/native/ketbin_utils_syntax/.gitignore @@ -0,0 +1 @@ +/target diff --git a/native/ketbin_utils_syntax/Cargo.toml b/native/ketbin_utils_syntax/Cargo.toml new file mode 100644 index 0000000..cfb57ec --- /dev/null +++ b/native/ketbin_utils_syntax/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "ketbin_utils_syntax" +version = "0.1.0" +authors = [] +edition = "2018" + +[lib] +name = "ketbin_utils_syntax" +path = "src/lib.rs" +crate-type = ["cdylib"] + +[dependencies] +rustler = "0.22.0" diff --git a/native/ketbin_utils_syntax/README.md b/native/ketbin_utils_syntax/README.md new file mode 100644 index 0000000..98ebe0c --- /dev/null +++ b/native/ketbin_utils_syntax/README.md @@ -0,0 +1,20 @@ +# NIF for Elixir.Ketbin.Utils.Syntax + +## To build the NIF module: + +- Your NIF will now build along with your project. + +## To load the NIF: + +```elixir +defmodule Ketbin.Utils.Syntax do + use Rustler, otp_app: :ketbin, crate: "ketbin_utils_syntax" + + # When your NIF is loaded, it will override this function. + def add(_a, _b), do: :erlang.nif_error(:nif_not_loaded) +end +``` + +## Examples + +[This](https://github.com/hansihe/NifIo) is a complete example of a NIF written in Rust. diff --git a/native/ketbin_utils_syntax/src/lib.rs b/native/ketbin_utils_syntax/src/lib.rs new file mode 100644 index 0000000..ee4c00f --- /dev/null +++ b/native/ketbin_utils_syntax/src/lib.rs @@ -0,0 +1,6 @@ +#[rustler::nif] +fn add(a: i64, b: i64) -> i64 { + a + b +} + +rustler::init!("Elixir.Ketbin.Utils.Syntax", [add]);