Skip to content

Commit

Permalink
Fix Nif* macros requiring an encoder (#676)
Browse files Browse the repository at this point in the history
* Fix Nif* macros requiring an encoder
* Add note and changelog entry
  • Loading branch information
filmor committed Jan 8, 2025
1 parent 47ce1af commit 389af62
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 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
9 changes: 7 additions & 2 deletions rustler_mix/lib/mix/tasks/rustler.new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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"},
Expand Down Expand Up @@ -68,8 +67,14 @@ 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)

# Create a Cargo workspace
File.write(
Path.join(path, "Cargo.toml"),
"[workspace]\nresolver = \"2\"\nmembers = [\"native/#{name}\"]\n"
)
end

defp new(otp_app, path, module, name, _opts) 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

0 comments on commit 389af62

Please sign in to comment.