From 5d635f8d3d0082c474bdb3b1ed2245f2fa3a4ec2 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Thu, 23 Apr 2020 23:14:03 +0200 Subject: [PATCH] Drop debug output, add missing files --- rustler_mix/lib/rustler.ex | 2 -- rustler_mix/lib/rustler/compiler/config.ex | 2 -- rustler_mix/lib/rustler/compiler/server.ex | 39 ++++++++++++++++++++++ rustler_tests/Cargo.toml | 2 ++ 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 rustler_mix/lib/rustler/compiler/server.ex create mode 100644 rustler_tests/Cargo.toml diff --git a/rustler_mix/lib/rustler.ex b/rustler_mix/lib/rustler.ex index 6ce97b67e..1a2c1abba 100644 --- a/rustler_mix/lib/rustler.ex +++ b/rustler_mix/lib/rustler.ex @@ -88,8 +88,6 @@ defmodule Rustler do {otp_app, path} = @load_from - IO.warn("#{inspect(otp_app)}, #{path}") - load_path = Path.join(:code.priv_dir(otp_app), path) |> to_charlist() :erlang.load_nif(load_path, @load_data) diff --git a/rustler_mix/lib/rustler/compiler/config.ex b/rustler_mix/lib/rustler/compiler/config.ex index 4de8f208d..f4c4c852e 100644 --- a/rustler_mix/lib/rustler/compiler/config.ex +++ b/rustler_mix/lib/rustler/compiler/config.ex @@ -30,8 +30,6 @@ defmodule Rustler.Compiler.Config do otp_app: otp_app } - IO.inspect(defaults) - opts = defaults |> Map.from_struct() diff --git a/rustler_mix/lib/rustler/compiler/server.ex b/rustler_mix/lib/rustler/compiler/server.ex new file mode 100644 index 000000000..bbcd06fc6 --- /dev/null +++ b/rustler_mix/lib/rustler/compiler/server.ex @@ -0,0 +1,39 @@ +defmodule Rustler.Compiler.Server do + use GenServer + + defp ensure_running() do + case GenServer.start(__MODULE__, [], name: __MODULE__) do + {:ok, _pid} -> :ok + {:error, {:already_started, _pid}} -> :ok + end + end + + def build() do + ensure_running() + GenServer.call(__MODULE__, :compile, :infinity) + end + + @impl true + def init([]) do + {:ok, nil} + end + + @impl true + def handle_call(:compile, _from, nil) do + shell = Mix.shell() + _otp_app = Mix.Project.config() |> Keyword.get(:app) + is_release = Mix.env() in [:prod, :bench] + + cargo_opts = %{ + release: is_release + } + + cargo = :cargo.init(File.cwd!(), cargo_opts) + artifacts = :cargo.build_and_capture(cargo) + {:reply, artifacts, artifacts} + end + + def handle_call(:compile, _from, artifacts) do + {:reply, artifacts, artifacts} + end +end diff --git a/rustler_tests/Cargo.toml b/rustler_tests/Cargo.toml new file mode 100644 index 000000000..9daf7bd19 --- /dev/null +++ b/rustler_tests/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["native/binary_example", "native/deprecated_macros", "native/rustler_test"]