Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document to use runtime: false for rustler dependency #559

Merged
merged 7 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion prepare_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
2 changes: 1 addition & 1 deletion rustler_benchmarks/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion rustler_mix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
57 changes: 30 additions & 27 deletions rustler_mix/lib/rustler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
7 changes: 6 additions & 1 deletion rustler_mix/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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