Skip to content

Commit

Permalink
Merge pull request #670 from rusterlium/elixir-1.18
Browse files Browse the repository at this point in the history
Elixir 1.18 tweaks and CI
  • Loading branch information
filmor authored Dec 17, 2024
2 parents 9522518 + b3c0354 commit bbb4676
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ jobs:
strategy:
matrix:
pair:
- { erlang: "27", elixir: "1.18.0-rc.0" }
- { erlang: "26", elixir: "1.18.0-rc.0" }
- { erlang: "27", elixir: "1.17", latest: true }
- { erlang: "26", elixir: "1.17" }
- { erlang: "26", elixir: "1.16" }
Expand Down
4 changes: 2 additions & 2 deletions rustler_mix/lib/mix/tasks/rustler.new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Mix.Tasks.Rustler.New do
root = Path.join(:code.priv_dir(:rustler), "templates/")

for {format, source, _} <- @basic do
unless format == :keep do
if format != :keep do
@external_resource Path.join(root, source)
defp render(unquote(source)), do: unquote(File.read!(Path.join(root, source)))
end
Expand Down Expand Up @@ -90,7 +90,7 @@ defmodule Mix.Tasks.Rustler.New do
end

defp check_module_name_validity!(name) do
unless name =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/ do
if !(name =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/) do
Mix.raise(
"Module name must be a valid Elixir alias (for example: Foo.Bar), got: #{inspect(name)}"
)
Expand Down
63 changes: 32 additions & 31 deletions rustler_mix/lib/rustler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,44 +113,43 @@ defmodule Rustler do
end
end

defmacro __before_compile__(_env) do
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

defmacrop _construct_load_data do
default_load_data_value = unquote(default_load_data_value)
default_fun_value = unquote(default_fun_value)
load_data = Module.get_attribute(env.module, :load_data)
load_data_fun = Module.get_attribute(env.module, :load_data_fun)

case {@load_data, @load_data_fun} do
{load_data, ^default_fun_value} ->
quote do
unquote(load_data)
end
load_data =
case {load_data, load_data_fun} do
{load_data, ^default_fun_value} ->
quote do
unquote(load_data)
end

{^default_load_data_value, {module, function}}
when is_atom(module) and is_atom(function) ->
quote do
apply(unquote(module), unquote(function), [])
end
{^default_load_data_value, {module, function}}
when is_atom(module) and is_atom(function) ->
quote do
apply(unquote(module), unquote(function), [])
end

{^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
{^default_load_data_value, provided_value} ->
raise """
`load_data_fun` 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

quote do
@on_load :rustler_init

@doc false
def rustler_init do
# Remove any old modules that may be loaded so we don't get
Expand All @@ -164,7 +163,9 @@ defmodule Rustler do
|> Application.app_dir(path)
|> to_charlist()

:erlang.load_nif(load_path, _construct_load_data())
load_data = unquote(load_data)

:erlang.load_nif(load_path, load_data)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions rustler_mix/lib/rustler/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Rustler.Compiler do
def compile_crate(otp_app, config, opts) do
config = Config.from(otp_app, config, opts)

unless config.skip_compilation? do
if !config.skip_compilation? do
crate_full_path = Path.expand(config.path, File.cwd!())

File.mkdir_p!(priv_dir())
Expand Down Expand Up @@ -54,7 +54,7 @@ defmodule Rustler.Compiler do
throw_error(:rustup_not_installed)
end

unless Rustup.version_installed?(version) do
if !Rustup.version_installed?(version) do
throw_error({:rust_version_not_installed, version})
end

Expand Down Expand Up @@ -176,7 +176,7 @@ defmodule Rustler.Compiler do
end

defp toml_data(path) do
unless File.dir?(path) do
if !File.dir?(path) do
throw_error({:nonexistent_crate_directory, path})
end

Expand Down
2 changes: 1 addition & 1 deletion rustler_tests/test/serde_rustler_tests_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ defmodule SerdeRustlerTests.NifTest do
Helpers.run_ser(test_name, expected_term)
Helpers.run_de(test_name, expected_term)

unless ctx[:skip] == :transcode do
if ctx[:skip] != :transcode do
Helpers.run_transcode(test_name, expected_term)
end
end
Expand Down

0 comments on commit bbb4676

Please sign in to comment.