Skip to content

Commit

Permalink
Make sure :nif_versions option is respect (#60)
Browse files Browse the repository at this point in the history
This is a small bug fix that was blocking the usage of a more
restrict list of "NIF versions". For example, if my system is
using NIF version 2.16, but I want to be compatible with only
version 2.15, this was being ignored, since the algorithm for
finding compatible versions was not taking into account this
restriction.
  • Loading branch information
philss authored Aug 28, 2023
1 parent 94b2b75 commit 3138af8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.6.3] - 2023-08-28

### Fixed

- Make sure `:nif_versions` option is respected.

This is a small bug fix that was blocking the usage of a more
restrict list of "NIF versions". For example, if my system is
using NIF version 2.16, but I want to be compatible with only
version 2.15, this was being ignored, since the algorithm for
finding compatible versions was not taking into account this
restriction.

## [0.6.2] - 2023-07-05

### Added
Expand Down Expand Up @@ -151,7 +164,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add basic features to download and use the precompiled NIFs in a safe way.

[Unreleased]: https://github.com/philss/rustler_precompiled/compare/v0.6.2...HEAD
[Unreleased]: https://github.com/philss/rustler_precompiled/compare/v0.6.3...HEAD
[0.6.3]: https://github.com/philss/rustler_precompiled/compare/v0.6.2...v0.6.3
[0.6.2]: https://github.com/philss/rustler_precompiled/compare/v0.6.1...v0.6.2
[0.6.1]: https://github.com/philss/rustler_precompiled/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/philss/rustler_precompiled/compare/v0.5.5...v0.6.0
Expand Down
6 changes: 3 additions & 3 deletions lib/rustler_precompiled.ex
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ defmodule RustlerPrecompiled do
end
end

defp target_config do
defp target_config(available_nif_versions \\ Config.available_nif_versions()) do
current_nif_version = :erlang.system_info(:nif_version) |> List.to_string()

nif_version =
case find_compatible_nif_version(current_nif_version, Config.available_nif_versions()) do
case find_compatible_nif_version(current_nif_version, available_nif_versions) do
{:ok, vsn} ->
vsn

Expand Down Expand Up @@ -505,7 +505,7 @@ defmodule RustlerPrecompiled do
version: config.version
}

case target(target_config(), config.targets, config.nif_versions) do
case target(target_config(config.nif_versions), config.targets, config.nif_versions) do
{:ok, target} ->
basename = config.crate || config.otp_app
lib_name = "#{lib_prefix(target)}#{basename}-v#{config.version}-#{target}"
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule RustlerPrecompiled.MixProject do
use Mix.Project

@version "0.6.2"
@version "0.6.3"
@repo "https://github.com/philss/rustler_precompiled"

def project do
Expand Down
25 changes: 21 additions & 4 deletions test/rustler_precompiled_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,12 @@ defmodule RustlerPrecompiledTest do
version: "0.2.0",
crate: "example",
targets: @available_targets,
nif_versions: ["future_nif_version"]
nif_versions: ["4.2"]
}

assert {:error, error} = RustlerPrecompiled.build_metadata(config)
assert error =~ "precompiled NIF is not available for this NIF version: "
assert error =~ ".\nThe available NIF versions are:\n - future_nif_version"
assert error =~ ".\nThe available NIF versions are:\n - 4.2"
end

test "returns a base metadata when nif_version is not available but force build is enabled" do
Expand All @@ -672,7 +672,7 @@ defmodule RustlerPrecompiledTest do
version: "0.2.0",
crate: "example",
targets: @available_targets,
nif_versions: ["future_nif_version"],
nif_versions: ["4.2"],
force_build?: true
}

Expand All @@ -681,10 +681,27 @@ defmodule RustlerPrecompiledTest do
assert base_metadata[:otp_app] == :rustler_precompiled
assert base_metadata[:crate] == "example"
assert base_metadata[:targets] == @available_targets
assert base_metadata[:nif_versions] == ["future_nif_version"]
assert base_metadata[:nif_versions] == ["4.2"]
assert base_metadata[:version] == "0.2.0"
assert base_metadata[:base_url] == config.base_url
end

test "builds a valid metadata with a restrict NIF versions list" do
config = %RustlerPrecompiled.Config{
otp_app: :rustler_precompiled,
module: RustlerPrecompilationExample.Native,
base_url:
"https://github.com/philss/rustler_precompilation_example/releases/download/v0.2.0",
version: "0.2.0",
crate: "example",
targets: @available_targets,
nif_versions: ["2.15"]
}

assert {:ok, metadata} = RustlerPrecompiled.build_metadata(config)

assert metadata.nif_versions == ["2.15"]
end
end

def in_tmp(tmp_path, function) do
Expand Down

0 comments on commit 3138af8

Please sign in to comment.