Skip to content

Commit

Permalink
Merge pull request #543 from rusterlium/apply-current-nif-for-tests
Browse files Browse the repository at this point in the history
Apply current NIF version for tests and raise default
  • Loading branch information
filmor authored May 25, 2023
2 parents 4ea76ec + 6f6670d commit 90e4ef8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rustler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "../README.md"
edition = "2018"

[features]
default = ["derive", "nif_version_2_14"]
default = ["derive", "nif_version_2_15"]
derive = ["rustler_codegen"]
alternative_nif_init_name = []
nif_version_2_14 = ["rustler_sys/nif_version_2_14"]
Expand Down
3 changes: 1 addition & 2 deletions rustler_sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ build = "build.rs"
categories = ["external-ffi-bindings"]

[features]
# Default version: 2.14
default = ["nif_version_2_14"]
default = ["nif_version_2_15"]
nif_version_2_14 = []
nif_version_2_15 = ["nif_version_2_14"]
nif_version_2_16 = ["nif_version_2_15"]
Expand Down
14 changes: 13 additions & 1 deletion rustler_tests/lib/rustler_test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ defmodule NifNotLoadedError do
defexception message: "nif not loaded"
end

defmodule RustlerTest.Helper do
def nif_feature_from_running_version() do
[major, minor | _] =
:erlang.system_info(:nif_version)
|> to_string
|> String.split(".")

"nif_version_#{major}_#{minor}"
end
end

defmodule RustlerTest do
use Rustler,
otp_app: :rustler_test,
crate: :rustler_test
crate: :rustler_test,
features: [RustlerTest.Helper.nif_feature_from_running_version()]

defp err, do: :erlang.nif_error(:nif_not_loaded)

Expand Down
6 changes: 6 additions & 0 deletions rustler_tests/native/rustler_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ crate-type = ["cdylib"]
name = "hello_rust"
path = "src/main.rs"

[features]
nif_version_2_14 = ["rustler/nif_version_2_14"]
nif_version_2_15 = ["nif_version_2_14", "rustler/nif_version_2_15"]
nif_version_2_16 = ["nif_version_2_15", "rustler/nif_version_2_16"]
nif_version_2_17 = ["nif_version_2_16", "rustler/nif_version_2_17"]

[dependencies]
lazy_static = "1.4"
rustler = { path = "../../../rustler" }

0 comments on commit 90e4ef8

Please sign in to comment.