From 8b2839f8e892065dd85bfd521c0425b1ed32bdc8 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Mon, 16 Dec 2024 10:19:35 +0100 Subject: [PATCH 1/3] Run mix format --migrate to drop usage of 'unless' --- rustler_mix/lib/mix/tasks/rustler.new.ex | 4 ++-- rustler_mix/lib/rustler/compiler.ex | 6 +++--- rustler_tests/test/serde_rustler_tests_test.exs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rustler_mix/lib/mix/tasks/rustler.new.ex b/rustler_mix/lib/mix/tasks/rustler.new.ex index a1cb7222..5eb37fc4 100644 --- a/rustler_mix/lib/mix/tasks/rustler.new.ex +++ b/rustler_mix/lib/mix/tasks/rustler.new.ex @@ -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 @@ -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)}" ) diff --git a/rustler_mix/lib/rustler/compiler.ex b/rustler_mix/lib/rustler/compiler.ex index 56982544..88d2bb10 100644 --- a/rustler_mix/lib/rustler/compiler.ex +++ b/rustler_mix/lib/rustler/compiler.ex @@ -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()) @@ -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 @@ -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 diff --git a/rustler_tests/test/serde_rustler_tests_test.exs b/rustler_tests/test/serde_rustler_tests_test.exs index 0fd6bf09..5bc5672a 100644 --- a/rustler_tests/test/serde_rustler_tests_test.exs +++ b/rustler_tests/test/serde_rustler_tests_test.exs @@ -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 From 3c62340cbeb87147381312c1cf302de56a9e596b Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 17 Dec 2024 12:41:35 +0100 Subject: [PATCH 2/3] Flatten __before_compile__ macro to make the new type check happy --- rustler_mix/lib/rustler.ex | 63 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/rustler_mix/lib/rustler.ex b/rustler_mix/lib/rustler.ex index 487d8b4d..32d0a024 100644 --- a/rustler_mix/lib/rustler.ex +++ b/rustler_mix/lib/rustler.ex @@ -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 @@ -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 From b3c035413b52568024c9a769f0fd7b98cf45955b Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 17 Dec 2024 12:42:35 +0100 Subject: [PATCH 3/3] Add Elixir 1.18 release candidate to CI --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c2263157..5c5bda10 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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" }