Skip to content

Commit c0fc38e

Browse files
committed
Update erlang-cargo for partial compiles and take release flag into account
1 parent 5c25411 commit c0fc38e

File tree

3 files changed

+22
-48
lines changed

3 files changed

+22
-48
lines changed

rustler_mix/lib/rustler/compiler.ex

+21-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ defmodule Rustler.Compiler do
1212
crate = ensure_string(Keyword.fetch!(opts, :crate))
1313
config = Config.from(otp_app, module, opts)
1414

15-
artifacts = Server.build()
15+
is_release = config.mode == :release
16+
artifacts = do_compile(crate, is_release)
1617

17-
is_release = Mix.env() in [:prod, :bench]
1818
entry = artifacts[crate]
1919

2020
is_lib = :cargo_artifact.kind(entry) == :cdylib
@@ -77,4 +77,23 @@ defmodule Rustler.Compiler do
7777
defp ensure_string(str) when is_binary(str) do
7878
str
7979
end
80+
81+
defp do_compile(crate, is_release) do
82+
is_release = Mix.env() in [:prod, :bench]
83+
84+
cargo_opts = %{
85+
release: is_release
86+
}
87+
88+
Mix.shell().info("Starting build in #{File.cwd!()}")
89+
90+
cargo = :cargo.init(File.cwd!(), cargo_opts)
91+
92+
artifacts = :cargo.build(cargo, crate)
93+
94+
# This drops the unique key in favour of the crate name
95+
artifacts =
96+
artifacts
97+
|> Map.new(&{:cargo_artifact.name(&1), &1})
98+
end
8099
end

rustler_mix/lib/rustler/compiler/server.ex

-45
This file was deleted.

rustler_mix/mix.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%{
2-
"cargo": {:git, "https://github.com/rusterlium/erlang-cargo.git", "0e612bf1e321c6ae062b98f9079f24b6bedfba01", []},
2+
"cargo": {:git, "https://github.com/rusterlium/erlang-cargo.git", "7992e2c159255a421d83c2a693b544c20979c841", []},
33
"earmark": {:hex, :earmark, "1.4.4", "4821b8d05cda507189d51f2caeef370cf1e18ca5d7dfb7d31e9cafe6688106a4", [:mix], [], "hexpm", "1f93aba7340574847c0f609da787f0d79efcab51b044bb6e242cae5aca9d264d"},
44
"ex_doc": {:hex, :ex_doc, "0.21.3", "857ec876b35a587c5d9148a2512e952e24c24345552259464b98bfbb883c7b42", [:mix], [{:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "0db1ee8d1547ab4877c5b5dffc6604ef9454e189928d5ba8967d4a58a801f161"},
55
"jsx": {:hex, :jsx, "2.10.0", "77760560d6ac2b8c51fd4c980e9e19b784016aa70be354ce746472c33beb0b1c", [:rebar3], [], "hexpm", "9a83e3704807298016968db506f9fad0f027de37546eb838b3ae1064c3a0ad62"},

0 commit comments

Comments
 (0)