diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ab6484ec..115449aa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -119,8 +119,10 @@ jobs: - name: Extend PATH run: echo "C:\\ProgramData\\chocolatey\\lib\\Elixir\\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - name: Hex - run: mix local.hex --force + - name: Mix tools + run: | + mix local.hex --force + mix local.rebar --force - name: Test rustler_mix working-directory: rustler_mix diff --git a/.gitignore b/.gitignore index 08e3d7b4..d9b4f43f 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,7 @@ Session.vim # Generated by Cargo **/target/* /rustler/target/ -/rustler_tests/priv/native/* +/rustler_tests/priv/crates/* /rustler_tests/target/ /rustler_tests/_build /rustler_tests/deps diff --git a/rustler_mix/lib/mix/tasks/compile.rustler.ex b/rustler_mix/lib/mix/tasks/compile.rustler.ex deleted file mode 100644 index 3e01f68f..00000000 --- a/rustler_mix/lib/mix/tasks/compile.rustler.ex +++ /dev/null @@ -1,19 +0,0 @@ -defmodule Mix.Tasks.Compile.Rustler do - @moduledoc false - - use Mix.Task - - def run(_args) do - IO.puts([ - IO.ANSI.yellow(), - """ - - The `:rustler` compiler has been deprecated since v0.22.0 and will be - removed in v1.0. - - To remove this warning, please consult the CHANGELOG for v0.22.0. - """, - IO.ANSI.default_color() - ]) - end -end diff --git a/rustler_mix/lib/mix/tasks/rustler.new.ex b/rustler_mix/lib/mix/tasks/rustler.new.ex index 465508ab..5b746396 100644 --- a/rustler_mix/lib/mix/tasks/rustler.new.ex +++ b/rustler_mix/lib/mix/tasks/rustler.new.ex @@ -25,7 +25,6 @@ defmodule Mix.Tasks.Rustler.New do for {format, source, _} <- @basic do unless format == :keep do - @external_resource Path.join(root, source) defp render(unquote(source)), do: unquote(File.read!(Path.join(root, source))) end end @@ -68,8 +67,12 @@ defmodule Mix.Tasks.Rustler.New do check_module_name_validity!(module) - path = Path.join([File.cwd!(), "native/", name]) + sub_path = Path.join("native", name) + + path = Path.join([File.cwd!(), sub_path]) new(otp_app, path, module, name, opts) + + add_to_workspace(sub_path) end defp new(otp_app, path, module, name, _opts) do @@ -89,6 +92,36 @@ defmodule Mix.Tasks.Rustler.New do Mix.Shell.IO.info([:green, "Ready to go! See #{path}/README.md for further instructions."]) end + defp add_to_workspace(sub_path) do + Mix.Shell.IO.info([:green, "Adding #{sub_path} to workspace"]) + cargo_toml_fn = Path.join(File.cwd!(), "Cargo.toml") + + cargo_toml = + case Toml.decode_file(cargo_toml_fn) do + {:ok, data} -> + data + + {:error, _} -> + %{} + end + + workspace = Map.get(cargo_toml, "workspace", %{}) + + members = + MapSet.new(Map.get(workspace, "members", [])) + |> MapSet.put(sub_path) + |> MapSet.to_list() + + workspace_section = """ + [workspace] + members = [#{members |> Enum.map(&inspect/1) |> Enum.join(", ")}] + """ + + # TODO: Only replace the existing workspace.members entry + + File.write(cargo_toml_fn, workspace_section) + end + defp check_module_name_validity!(name) do unless name =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/ do Mix.raise( diff --git a/rustler_mix/lib/rustler.ex b/rustler_mix/lib/rustler.ex index 083d1b52..ce0eb0f1 100644 --- a/rustler_mix/lib/rustler.ex +++ b/rustler_mix/lib/rustler.ex @@ -33,13 +33,8 @@ defmodule Rustler do value. If you have more than one crate in your project, you will need to be explicit about which crate you intend to use. - * `:default_features` - a boolean to specify whether the crate's default features - should be used. - * `:env` - Specify a list of environment variables when envoking the compiler. - * `:features` - a list of features to enable when compiling the crate. - * `:load_data` - Any valid term. This value is passed into the NIF when it is loaded (default: `0`) @@ -56,12 +51,6 @@ defmodule Rustler do - When `Mix.env()` is `:dev` or `:test`, the crate will be compiled in `:debug` mode. - When `Mix.env()` is `:prod` or `:bench`, the crate will be compiled in `:release` mode. - * `:path` - By default, rustler expects the crate to be found in `native/` in the - root of the project. Use this option to override this. - - * `:skip_compilation?` - This option skips envoking the rust compiler. Specify this option - in combination with `:load_from` to load a pre-compiled artifact. - * `:target` - Specify a compile [target] triple. * `:target_dir`: Override the compiler output directory. @@ -82,14 +71,12 @@ defmodule Rustler do quote bind_quoted: [opts: opts] do config = Rustler.Compiler.compile_crate(__MODULE__, opts) - for resource <- config.external_resources do - @external_resource resource - end + @load_from {config.otp_app, config.load_path} if config.lib do - @load_from config.load_from @load_data config.load_data - + @before_compile {Rustler, :__before_compile_nif__} + else @before_compile Rustler end end @@ -97,27 +84,39 @@ defmodule Rustler do defmacro __before_compile__(_env) do quote do - @on_load :rustler_init - - @doc false - def rustler_init do - # Remove any old modules that may be loaded so we don't get - # {:error, {:upgrade, 'Upgrade not supported by this NIF library.'}} - :code.purge(__MODULE__) - + def rustler_path do {otp_app, path} = @load_from - - load_path = - otp_app - |> Application.app_dir(path) - |> to_charlist() - - :erlang.load_nif(load_path, @load_data) + Path.join(:code.priv_dir(otp_app), path) end end end + defmacro __before_compile_nif__(_env) do + quoted = + quote do + def rustler_path do + # TODO: Parametrise, and keep all crates in the list + {otp_app, path} = @load_from + Path.join(:code.priv_dir(otp_app), path) + end + + @on_load :rustler_init + @doc false + def rustler_init do + # Remove any old modules that may be loaded so we don't get + # :error, {:upgrade, 'Upgrade not supported by this NIF library.'}} + :code.purge(__MODULE__) + load_path = String.to_charlist(rustler_path()) + :ok = :erlang.load_nif(load_path, @load_data) + end + end + + # quoted |> Macro.to_string |> IO.puts + quoted + end + @doc false + @spec rustler_version() :: binary() def rustler_version, do: "0.22.0" @doc """ diff --git a/rustler_mix/lib/rustler/compiler.ex b/rustler_mix/lib/rustler/compiler.ex index e991b5b6..a654fc5e 100644 --- a/rustler_mix/lib/rustler/compiler.ex +++ b/rustler_mix/lib/rustler/compiler.ex @@ -1,178 +1,94 @@ defmodule Rustler.Compiler do @moduledoc false - alias Rustler.Compiler.{Config, Messages, Rustup} + alias Rustler.Compiler.{Config} @doc false def compile_crate(module, opts) do + shell = Mix.shell() otp_app = Keyword.fetch!(opts, :otp_app) - config = Config.from(otp_app, module, opts) - - unless config.skip_compilation? do - crate_full_path = Path.expand(config.path, File.cwd!()) - File.mkdir_p!(priv_dir()) + crate = ensure_string(Keyword.fetch!(opts, :crate)) + config = Config.from(otp_app, module, opts) - Mix.shell().info("Compiling crate #{config.crate} in #{config.mode} mode (#{config.path})") + is_release = config.mode == :release + artifacts = do_compile(crate, is_release) - [cmd | args] = - make_base_command(config.cargo) - |> make_no_default_features_flag(config.default_features) - |> make_features_flag(config.features) - |> make_target_flag(config.target) - |> make_build_mode_flag(config.mode) - |> make_platform_hacks(crate_full_path, :os.type()) + entry = artifacts[crate] - compile_result = - System.cmd(cmd, args, - cd: crate_full_path, - stderr_to_stdout: true, - env: [{"CARGO_TARGET_DIR", config.target_dir} | config.env], - into: IO.stream(:stdio, :line) - ) + is_lib = :cargo_artifact.kind(entry) == :cdylib + is_bin = :cargo_artifact.kind(entry) == :bin - case compile_result do - {_, 0} -> :ok - {_, code} -> raise "Rust NIF compile error (rustc exit code #{code})" - end - - handle_artifacts(crate_full_path, config) - # See #326: Ensure that the libraries are copied into the correct subdirectory - # in `_build`. - Mix.Project.build_structure() + if !is_lib and !is_bin do + Mix.raise("Crate #{crate} is neither a 'bin' nor a 'cdylib' but #{entry[:kind]}") end - config - end + priv_dir = priv_dir(entry, is_release) + dest_root = :code.priv_dir(config.otp_app) - defp make_base_command(:system), do: ["cargo", "rustc"] - defp make_base_command({:system, channel}), do: ["cargo", channel, "rustc"] - defp make_base_command({:bin, path}), do: [path, "rustc"] + out_paths = + for filename <- :cargo_artifact.filenames(entry) do + out_path = Path.join(priv_dir, Path.basename(filename)) + dest = Path.join(dest_root, out_path) + rel_filename = Path.basename(filename) + rel_dest = Path.relative_to_cwd(dest) - defp make_base_command({:rustup, version}) do - if Rustup.version() == :none do - throw_error(:rustup_not_installed) - end + shell.info(" Copying #{rel_filename} to #{rel_dest}") + File.mkdir_p!(Path.dirname(dest)) + File.copy!(filename, dest) - unless Rustup.version_installed?(version) do - throw_error({:rust_version_not_installed, version}) - end + out_path + end - ["rustup", "run", version, "cargo", "rustc"] - end + [load_path] = + if is_lib do + out_paths |> Enum.filter(&:cargo_util.is_dylib/1) + else + exec = :cargo_artifact.executable(entry) + [Path.join(priv_dir, Path.basename(exec))] + end - defp make_platform_hacks(args, crate_path, {:unix, :darwin}) do - root = Path.join([".cargo", "config"]) - path = Path.join([crate_path, ".cargo", "config"]) - - if File.exists?(root) || File.exists?(path) do - args - else - IO.write([ - "\n", - IO.ANSI.yellow(), - """ - Compiling on macOS requires special link args in order to compile - correctly. - - Rustler is currently working around this issue in the compiler task. - This will be removed in v1.0.0 in favor of a user supplied .cargo/config - file. - - To remove this warning, please create #{path} - with the following content: - - [target.x86_64-apple-darwin] - rustflags = [ - "-C", "link-arg=-undefined", - "-C", "link-arg=dynamic_lookup", - ] - - See https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/MachOTopics/1-Articles/executing_files.html - for more details. - - """, - IO.ANSI.default_color(), - "\n" - ]) - - args ++ ["--", "-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"] - end + %Config{config | lib: is_lib, load_path: Path.rootname(load_path)} end - defp make_platform_hacks(args, _, _), do: args - - defp make_no_default_features_flag(args, true), do: args - defp make_no_default_features_flag(args, false), do: args ++ ["--no-default-features"] - - defp make_features_flag(args, []), do: args - defp make_features_flag(args, flags), do: args ++ ["--features", Enum.join(flags, ",")] - - defp make_target_flag(args, target) when is_binary(target), do: args ++ ["--target=#{target}"] - defp make_target_flag(args, _), do: args - - defp make_build_mode_flag(args, :release), do: args ++ ["--release"] - defp make_build_mode_flag(args, :debug), do: args - - defp handle_artifacts(path, config) do - toml = toml_data(path) - names = get_name(toml, :lib) ++ get_name(toml, :bin) + defp priv_dir(entry, is_release) do + type = + if is_release do + "release" + else + "debug" + end - Enum.each(names, fn {name, type} -> - {src_file, dst_file} = make_file_names(name, type) - compiled_lib = Path.join([config.target_dir, Atom.to_string(config.mode), src_file]) - destination_lib = Path.join(priv_dir(), dst_file) + name = :cargo_artifact.name(entry) + version = :cargo_artifact.version(entry) - # If the file exists already, we delete it first. This is to ensure that another - # process, which might have the library dynamically linked in, does not generate - # a segfault. By deleting it first, we ensure that the copy operation below does - # not write into the existing file. - File.rm(destination_lib) - File.cp!(compiled_lib, destination_lib) - end) + "crates/#{name}/#{version}/#{type}" end - defp get_name(toml, section) do - case toml[to_string(section)] do - nil -> [] - values when is_map(values) -> [{values["name"], section}] - values when is_list(values) -> Enum.map(values, &{&1["name"], section}) - end + defp ensure_string(atom) when is_atom(atom) do + Atom.to_string(atom) end - defp make_file_names(base_name, :lib) do - case :os.type() do - {:win32, _} -> {"#{base_name}.dll", "lib#{base_name}.dll"} - {:unix, :darwin} -> {"lib#{base_name}.dylib", "lib#{base_name}.so"} - {:unix, _} -> {"lib#{base_name}.so", "lib#{base_name}.so"} - end + defp ensure_string(list) when is_list(list) do + IO.iodata_to_binary(list) end - defp make_file_names(base_name, :bin) do - case :os.type() do - {:win32, _} -> {"#{base_name}.exe", "#{base_name}.exe"} - {:unix, _} -> {base_name, base_name} - end + defp ensure_string(str) when is_binary(str) do + str end - defp throw_error(error_descr) do - Mix.shell().error(Messages.message(error_descr)) - raise "Compilation error" - end + defp do_compile(crate, is_release) do + cargo_opts = %{ + release: is_release + } - defp toml_data(path) do - unless File.dir?(path) do - throw_error({:nonexistent_crate_directory, path}) - end + Mix.shell().info("Starting build in #{File.cwd!()}") - case File.read("#{path}/Cargo.toml") do - {:error, :enoent} -> - throw_error({:cargo_toml_not_found, path}) + cargo = :cargo.init(File.cwd!(), cargo_opts) - {:ok, text} -> - Toml.decode!(text) - end - end + artifacts = :cargo.build(cargo, crate) - defp priv_dir, do: "priv/native" + # This drops the unique key in favour of the crate name + artifacts |> Map.new(&{:cargo_artifact.name(&1), &1}) + end end diff --git a/rustler_mix/lib/rustler/compiler/config.ex b/rustler_mix/lib/rustler/compiler/config.ex index eac34784..f4c4c852 100644 --- a/rustler_mix/lib/rustler/compiler/config.ex +++ b/rustler_mix/lib/rustler/compiler/config.ex @@ -2,31 +2,20 @@ defmodule Rustler.Compiler.Config do @moduledoc false @type rust_version :: :stable | :beta | :nightly | binary() - @type cargo :: :system | {:rustup, rust_version()} | {:bin, Path.t()} @type crate :: binary() @type default_features :: boolean() @type env :: [{binary(), binary()}] @type features :: [binary()] @type mode :: :debug | :release @type load_data :: term() - @type path :: Path.t() - defstruct cargo: :system, - crate: nil, - default_features: true, - env: [], - external_resources: [], - features: [], + defstruct crate: nil, lib: true, load_data: 0, - load_from: nil, + load_path: nil, mode: :release, otp_app: nil, - path: "", - priv_dir: "", - skip_compilation?: false, - target: nil, - target_dir: "" + target: nil alias Rustler.Compiler.Config @@ -35,53 +24,22 @@ defmodule Rustler.Compiler.Config do crate = config[:crate] || opts[:crate] || otp_app - # TODO: Remove in 1.0 - rustler_crates = Mix.Project.config()[:rustler_crates] || [] - legacy_config = rustler_crates[to_atom(crate)] || [] - defaults = %Config{ crate: crate, - load_from: {otp_app, "priv/native/lib#{crate}"}, mode: build_mode(Mix.env()), - otp_app: otp_app, - path: "native/#{crate}", - target_dir: Application.app_dir(otp_app, "native/#{crate}") + otp_app: otp_app } - defaults - |> Map.from_struct() - |> Enum.into([]) - |> Keyword.merge(legacy_config) - |> Keyword.merge(opts) - |> Keyword.merge(config) - |> build() - end - - defp build(opts) do - resources = - opts - |> Keyword.get(:path) - |> external_resources() - - opts = Keyword.put(opts, :external_resources, resources) + opts = + defaults + |> Map.from_struct() + |> Enum.into([]) + |> Keyword.merge(opts) + |> Keyword.merge(config) struct!(Config, opts) end - defp external_resources(crate_path) do - "#{crate_path}/**/*" - |> Path.wildcard() - |> Enum.reject(fn path -> - String.starts_with?(path, "#{crate_path}/target/") - end) - end - defp build_mode(env) when env in [:prod, :bench], do: :release defp build_mode(_), do: :debug - - defp to_atom(name) when is_binary(name), - do: String.to_atom(name) - - defp to_atom(name) when is_atom(name), - do: name end diff --git a/rustler_mix/lib/rustler/compiler/rustup.ex b/rustler_mix/lib/rustler/compiler/rustup.ex deleted file mode 100644 index 2b48b92a..00000000 --- a/rustler_mix/lib/rustler/compiler/rustup.ex +++ /dev/null @@ -1,44 +0,0 @@ -defmodule Rustler.Compiler.Rustup do - @moduledoc false - - def rustup_binary, do: System.get_env("RUSTUP_BINARY") || "rustup" - - def version do - multirust_exec = System.find_executable(rustup_binary()) - - if multirust_exec == nil do - :none - else - {version, 0} = System.cmd(rustup_binary(), ["--version"]) - {:ok, version} - end - end - - def version_installed?(version) do - {_resp, return} = System.cmd(rustup_binary(), ["run", version, "rustc", "--version"]) - - case return do - 0 -> true - _ -> false - end - end - - # def rust_versions do - # {versions_raw, 0} = System.cmd("rustup", ["list-toolchains"]) - # versions_raw - # |> String.strip(?\n) - # |> String.split("\n") - # end - - def install_toolchain(version) do - {_resp, 0} = System.cmd(rustup_binary(), ["install", version], into: IO.stream(:stdio, :line)) - end - - def compile_with(path, version, args \\ [], env \\ [], into \\ "") do - System.cmd(rustup_binary(), ["run", version, "cargo", "build" | args], - cd: path, - into: into, - env: env - ) - end -end diff --git a/rustler_mix/mix.exs b/rustler_mix/mix.exs index e61b2401..38587133 100644 --- a/rustler_mix/mix.exs +++ b/rustler_mix/mix.exs @@ -24,8 +24,9 @@ defmodule Rustler.Mixfile do defp deps do [ - {:toml, "~> 0.5.2", runtime: false}, - {:ex_doc, ">= 0.0.0", only: :dev, runtime: false} + {:cargo, "~> 0.1"}, + {:toml, "~> 0.6"}, + {:ex_doc, "~> 0.21", only: :dev, runtime: false} ] end diff --git a/rustler_mix/mix.lock b/rustler_mix/mix.lock index 68ee4081..56e2618b 100644 --- a/rustler_mix/mix.lock +++ b/rustler_mix/mix.lock @@ -1,10 +1,11 @@ %{ - "earmark": {:hex, :earmark, "1.4.4", "4821b8d05cda507189d51f2caeef370cf1e18ca5d7dfb7d31e9cafe6688106a4", [:mix], [], "hexpm", "1f93aba7340574847c0f609da787f0d79efcab51b044bb6e242cae5aca9d264d"}, + "cargo": {:hex, :cargo, "0.1.2", "1245b5a21454ebeabacf403911d54a82a0d457a3f635511a03ad06845f5abf95", [:mix, :rebar3], [{:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm", "eb614ba74f9f5b61643e5cc607bbf7ddc8420d368661e31c04e0db7ad47e21b3"}, "earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"}, "ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"}, + "jsx": {:hex, :jsx, "2.11.0", "08154624050333919b4ac1b789667d5f4db166dc50e190c4d778d1587f102ee0", [:rebar3], [], "hexpm", "eed26a0d04d217f9eecefffb89714452556cf90eb38f290a27a4d45b9988f8c0"}, "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, "makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, - "toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm", "f1e3dabef71fb510d015fad18c0e05e7c57281001141504c6b69d94e99750a07"}, + "toml": {:hex, :toml, "0.6.2", "38f445df384a17e5d382befe30e3489112a48d3ba4c459e543f748c2f25dd4d1", [:mix], [], "hexpm", "d013e45126d74c0c26a38d31f5e8e9b83ea19fc752470feb9a86071ca5a672fa"}, } diff --git a/rustler_mix/test.sh b/rustler_mix/test.sh index 8bfd3e68..c8153351 100755 --- a/rustler_mix/test.sh +++ b/rustler_mix/test.sh @@ -91,4 +91,4 @@ EOF mix test echo "Done; cleaning up" -rm -r $tmp +rm -rf "$tmp" diff --git a/rustler_tests/lib/binary_example.ex b/rustler_tests/lib/binary_example.ex index b21f1373..5946f27c 100644 --- a/rustler_tests/lib/binary_example.ex +++ b/rustler_tests/lib/binary_example.ex @@ -1,6 +1,5 @@ defmodule BinaryExample do use Rustler, otp_app: :rustler_test, - crate: :binary_example, - lib: false + crate: :binary_example end diff --git a/rustler_tests/mix.exs b/rustler_tests/mix.exs index daa116e3..0a8fab2f 100644 --- a/rustler_tests/mix.exs +++ b/rustler_tests/mix.exs @@ -6,7 +6,6 @@ defmodule RustlerTest.Mixfile do app: :rustler_test, version: "0.0.1", elixir: "~> 1.2", - compilers: [:rustler] ++ Mix.compilers(), build_embedded: Mix.env() == :prod, start_permanent: Mix.env() == :prod, deps: deps() diff --git a/rustler_tests/native/rustler_test/Cargo.toml b/rustler_tests/native/rustler_test/Cargo.toml index 9f0b4d04..0bd0d3da 100644 --- a/rustler_tests/native/rustler_test/Cargo.toml +++ b/rustler_tests/native/rustler_test/Cargo.toml @@ -13,10 +13,6 @@ crate-type = ["cdylib"] name = "hello_rust" path = "src/main.rs" -[[bin]] -name = "hello_rust2" -path = "src/main.rs" - [dependencies] lazy_static = "1.4" rustler = { path = "../../../rustler" } diff --git a/rustler_tests/test/binary_example_test.exs b/rustler_tests/test/binary_example_test.exs index 1d3a2dc9..81154516 100644 --- a/rustler_tests/test/binary_example_test.exs +++ b/rustler_tests/test/binary_example_test.exs @@ -2,22 +2,7 @@ defmodule BinaryExampleTest do use ExUnit.Case test "binary is compiled" do - bins = ~w(binary_example hello_rust hello_rust2) - - for bin <- bins do - assert_exists(bin) - end - end - - defp assert_exists(name) do - assert_exists(name, :os.type()) - end - - defp assert_exists(name, {:win32, _} = type) do - assert File.exists?("priv/native/#{name}.exe") - end - - defp assert_exists(name, type) do - assert File.exists?("priv/native/#{name}") + path = BinaryExample.rustler_path() + File.exists?(path) end end