Skip to content

Commit

Permalink
Add workspace and remove linkage override from 'mix rustler.new' temp…
Browse files Browse the repository at this point in the history
…lates (#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
  • Loading branch information
filmor authored Jan 8, 2025
1 parent 47ce1af commit 7edf2ac
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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")]
Expand Down
15 changes: 10 additions & 5 deletions rustler_mix/lib/mix/tasks/rustler.new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions rustler_mix/priv/templates/basic/.cargo/config.toml

This file was deleted.

1 change: 0 additions & 1 deletion rustler_mix/priv/templates/basic/Cargo.toml.eex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"

[lib]
name = "<%= library_name %>"
path = "src/lib.rs"
crate-type = ["cdylib"]

[dependencies]
Expand Down
4 changes: 4 additions & 0 deletions rustler_mix/priv/templates/root/Cargo.toml.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[workspace]
resolver = "2"

members = ["native/<%= library_name %>"]

0 comments on commit 7edf2ac

Please sign in to comment.