diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f15e74c..54a65d8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ See [`UPGRADE.md`](./UPGRADE.md) for additional help when upgrading to newer ver * Deprecated `:rustler_crates` project configuration * Mark `use Rustler` module configuration as compile-time * Bump Rust edition to 2021 +* Make `:rustler` a compile-time-only dependency (#516, #559) ## [0.29.1] - 2023-06-30 diff --git a/prepare_release.sh b/prepare_release.sh index ba5c5a00..c25b5e52 100755 --- a/prepare_release.sh +++ b/prepare_release.sh @@ -41,7 +41,7 @@ sed -i "s/^version = \"[^\"]*\" # rustler_codegen version$/version = \"$VERSION\ sed -i "s/^rustler.*$/rustler = {path = \"..\/rustler\", version = \"$VERSION\"}/" rustler_bigint/Cargo.toml sed -i "s/def rustler_version, do: \"[^\"]*\"$/def rustler_version, do: \"$VERSION\"/" rustler_mix/mix.exs rustler_mix/lib/rustler.ex sed -i "s/@version .*$/@version \"$VERSION\"/" rustler_mix/mix.exs -sed -i "s/{:rustler, \".*\"}/{:rustler, \"~> $VERSION\"}/" rustler_mix/README.md +sed -i "s/{:rustler, \".*\"/{:rustler, \"~> $VERSION\"/" rustler_mix/README.md echo "Committing version.." git commit -m "(release) $VERSION" \ diff --git a/rustler_benchmarks/mix.exs b/rustler_benchmarks/mix.exs index 356fc152..ff8a3173 100644 --- a/rustler_benchmarks/mix.exs +++ b/rustler_benchmarks/mix.exs @@ -22,7 +22,7 @@ defmodule RustlerBenchmarks.MixProject do defp deps do [ {:benchee, "~> 1.0"}, - {:rustler, path: "../rustler_mix"} + {:rustler, path: "../rustler_mix", runtime: false} ] end end diff --git a/rustler_mix/README.md b/rustler_mix/README.md index 704a58e2..381db96d 100644 --- a/rustler_mix/README.md +++ b/rustler_mix/README.md @@ -15,7 +15,7 @@ This package is available on [Hex.pm](https://hex.pm/packages/rustler). To insta ```elixir def deps do [ - {:rustler, "~> 0.29.1"} + {:rustler, "~> 0.29.1", runtime: false} ] end ``` diff --git a/rustler_mix/lib/rustler.ex b/rustler_mix/lib/rustler.ex index c985e3f8..9a473512 100644 --- a/rustler_mix/lib/rustler.ex +++ b/rustler_mix/lib/rustler.ex @@ -114,6 +114,9 @@ defmodule Rustler do end defmacro __before_compile__(_env) do + default_load_data_value = %Rustler.Compiler.Config{}.load_data + default_fun_value = %Rustler.Compiler.Config{}.load_data_fun + quote do @on_load :rustler_init @@ -130,37 +133,37 @@ defmodule Rustler do |> Application.app_dir(path) |> to_charlist() - load_data = Rustler.construct_load_data(@load_data, @load_data_fun) + load_data = _construct_load_data(@load_data, @load_data_fun) :erlang.load_nif(load_path, load_data) end - end - end - def construct_load_data(load_data, load_data_fun) do - default_load_data_value = %Rustler.Compiler.Config{}.load_data - default_fun_value = %Rustler.Compiler.Config{}.load_data_fun - - case {load_data, load_data_fun} do - {load_data, ^default_fun_value} -> - load_data - - {^default_load_data_value, {module, function}} - when is_atom(module) and is_atom(function) -> - apply(module, function, []) - - {^default_load_data_value, provided_value} -> - raise """ - `load_data` has to be `{Module, :function}`. - Instead received: #{inspect(provided_value)} - """ - - {load_data, load_data_fun} -> - raise """ - Only `load_data` or `load_data_fun` can be provided. Instead received: - >>> load_data: #{inspect(load_data)} - >>> load_data_fun: #{inspect(load_data_fun)} - """ + defp _construct_load_data(load_data, load_data_fun) do + default_load_data_value = unquote(default_load_data_value) + default_fun_value = unquote(default_fun_value) + + case {load_data, load_data_fun} do + {load_data, ^default_fun_value} -> + load_data + + {^default_load_data_value, {module, function}} + when is_atom(module) and is_atom(function) -> + apply(module, function, []) + + {^default_load_data_value, provided_value} -> + raise """ + `load_data` has to be `{Module, :function}`. + Instead received: #{inspect(provided_value)} + """ + + {load_data, load_data_fun} -> + raise """ + Only `load_data` or `load_data_fun` can be provided. Instead received: + >>> load_data: #{inspect(load_data)} + >>> load_data_fun: #{inspect(load_data_fun)} + """ + end + end end end diff --git a/rustler_mix/test.sh b/rustler_mix/test.sh index cb890685..9101b211 100755 --- a/rustler_mix/test.sh +++ b/rustler_mix/test.sh @@ -47,7 +47,7 @@ defmodule TestRustlerMix.MixProject do def application, do: [ ] - defp deps, do: [ {:rustler, path: "$rustler_mix"} ] + defp deps, do: [ {:rustler, path: "$rustler_mix", runtime: false} ] end EOF @@ -90,5 +90,10 @@ EOF mix test +# See https://github.com/rusterlium/rustler/issues/516, we also need to verify that everything +# we need is part of a release. +mix release +_build/dev/rel/test_rustler_mix/bin/test_rustler_mix eval 'RustlerMixTest.add(1, 2)' + echo "Done; cleaning up" rm -r $tmp