From 7edf2ac314707a0a1cc4c5387665e2fb59e909d1 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Wed, 8 Jan 2025 19:42:23 +0100 Subject: [PATCH] Add workspace and remove linkage override from 'mix rustler.new' templates (#672) * Update 'mix.rustler.new' templates - Add a workspace `Cargo.toml`` at the root of the project to be able to `cargo build` directly - Remove now obsolete linkage override that was necessary on macOS before merging #650 (Dynamic Symbols on Unix) * Use template for the root Cargo.toml as well --- CHANGELOG.md | 16 +++++++++++++++- rustler_mix/lib/mix/tasks/rustler.new.ex | 15 ++++++++++----- .../priv/templates/basic/.cargo/config.toml | 5 ----- rustler_mix/priv/templates/basic/Cargo.toml.eex | 1 - rustler_mix/priv/templates/root/Cargo.toml.eex | 4 ++++ 5 files changed, 29 insertions(+), 12 deletions(-) delete mode 100644 rustler_mix/priv/templates/basic/.cargo/config.toml create mode 100644 rustler_mix/priv/templates/root/Cargo.toml.eex diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b762401..66dbf385 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,21 @@ versions. ## unreleased +### Added + +- Create a workplace `Cargo.toml` file with `mix rustler.new` (#672) + ### Fixed - Some derive macros failed when only `decode` was requested (#676) +### Changed + +### Removed + +- The linkage override for macOS is not needed anymore and has been removed from + the template (#672) + ## [0.35.1] - 2024-12-18 ### Fixed @@ -317,7 +328,6 @@ The `Untagged` variant is represented as the atom `:untagged` in Elixir. - `rustler_mix`: Bumped required toml dependency to 0.6 - Bumped `rustler_sys` dependency to `~2.2` - ## [0.23.0] - 2021-12-22 ### Added @@ -383,6 +393,7 @@ The `Untagged` variant is represented as the atom `:untagged` in Elixir. - `rustler_atoms!` is now `rustler::atoms!` - `resource_struct_init!` is now `rustler::resource!` - New `rustler::atoms!` macro removed the `atom` prefix from the name: + ```rust // // Before @@ -404,6 +415,7 @@ The `Untagged` variant is represented as the atom `:untagged` in Elixir. ``` - NIF functions can be initialized with a simplified syntax: + ```rust // // Before @@ -424,6 +436,7 @@ The `Untagged` variant is represented as the atom `:untagged` in Elixir. - NIFs can be derived from regular functions, if the arguments implement `Decoder` and the return type implements `Encoder`: + ```rust // // Before @@ -446,6 +459,7 @@ The `Untagged` variant is represented as the atom `:untagged` in Elixir. - `rustler::nif` exposes more options to configure a NIF were the NIF is defined: + ```rust #[rustler::nif(schedule = "DirtyCpu")] diff --git a/rustler_mix/lib/mix/tasks/rustler.new.ex b/rustler_mix/lib/mix/tasks/rustler.new.ex index 5eb37fc4..ab90cbef 100644 --- a/rustler_mix/lib/mix/tasks/rustler.new.ex +++ b/rustler_mix/lib/mix/tasks/rustler.new.ex @@ -14,16 +14,19 @@ defmodule Mix.Tasks.Rustler.New do """ @basic [ - {:eex, "basic/.cargo/config.toml", ".cargo/config.toml"}, {:eex, "basic/README.md", "README.md"}, {:eex, "basic/Cargo.toml.eex", "Cargo.toml"}, {:eex, "basic/src/lib.rs", "src/lib.rs"}, {:text, "basic/.gitignore", ".gitignore"} ] + @root [ + {:eex, "root/Cargo.toml.eex", "Cargo.toml"} + ] + root = Path.join(:code.priv_dir(:rustler), "templates/") - for {format, source, _} <- @basic do + for {format, source, _} <- @basic ++ @root do if format != :keep do @external_resource Path.join(root, source) defp render(unquote(source)), do: unquote(File.read!(Path.join(root, source))) @@ -68,8 +71,12 @@ defmodule Mix.Tasks.Rustler.New do check_module_name_validity!(module) - path = Path.join([File.cwd!(), "native/", name]) + path = Path.join([File.cwd!(), "native", name]) new(otp_app, path, module, name, opts) + + copy_from(File.cwd!(), [library_name: name], @root) + + Mix.Shell.IO.info([:green, "Ready to go! See #{path}/README.md for further instructions."]) end defp new(otp_app, path, module, name, _opts) do @@ -85,8 +92,6 @@ defmodule Mix.Tasks.Rustler.New do ] copy_from(path, binding, @basic) - - Mix.Shell.IO.info([:green, "Ready to go! See #{path}/README.md for further instructions."]) end defp check_module_name_validity!(name) do diff --git a/rustler_mix/priv/templates/basic/.cargo/config.toml b/rustler_mix/priv/templates/basic/.cargo/config.toml deleted file mode 100644 index 20f03f3d..00000000 --- a/rustler_mix/priv/templates/basic/.cargo/config.toml +++ /dev/null @@ -1,5 +0,0 @@ -[target.'cfg(target_os = "macos")'] -rustflags = [ - "-C", "link-arg=-undefined", - "-C", "link-arg=dynamic_lookup", -] diff --git a/rustler_mix/priv/templates/basic/Cargo.toml.eex b/rustler_mix/priv/templates/basic/Cargo.toml.eex index fd271cfe..bb3159e4 100644 --- a/rustler_mix/priv/templates/basic/Cargo.toml.eex +++ b/rustler_mix/priv/templates/basic/Cargo.toml.eex @@ -6,7 +6,6 @@ edition = "2021" [lib] name = "<%= library_name %>" -path = "src/lib.rs" crate-type = ["cdylib"] [dependencies] diff --git a/rustler_mix/priv/templates/root/Cargo.toml.eex b/rustler_mix/priv/templates/root/Cargo.toml.eex new file mode 100644 index 00000000..08615865 --- /dev/null +++ b/rustler_mix/priv/templates/root/Cargo.toml.eex @@ -0,0 +1,4 @@ +[workspace] +resolver = "2" + +members = ["native/<%= library_name %>"]