Skip to content

Commit

Permalink
Update erlang-cargo for partial compiles and take release flag into a…
Browse files Browse the repository at this point in the history
…ccount
  • Loading branch information
filmor committed May 21, 2020
1 parent 5c25411 commit c0fc38e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 48 deletions.
23 changes: 21 additions & 2 deletions rustler_mix/lib/rustler/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ defmodule Rustler.Compiler do
crate = ensure_string(Keyword.fetch!(opts, :crate))
config = Config.from(otp_app, module, opts)

artifacts = Server.build()
is_release = config.mode == :release
artifacts = do_compile(crate, is_release)

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

is_lib = :cargo_artifact.kind(entry) == :cdylib
Expand Down Expand Up @@ -77,4 +77,23 @@ defmodule Rustler.Compiler do
defp ensure_string(str) when is_binary(str) do
str
end

defp do_compile(crate, is_release) do
is_release = Mix.env() in [:prod, :bench]

cargo_opts = %{
release: is_release
}

Mix.shell().info("Starting build in #{File.cwd!()}")

cargo = :cargo.init(File.cwd!(), cargo_opts)

artifacts = :cargo.build(cargo, crate)

# This drops the unique key in favour of the crate name
artifacts =
artifacts
|> Map.new(&{:cargo_artifact.name(&1), &1})
end
end
45 changes: 0 additions & 45 deletions rustler_mix/lib/rustler/compiler/server.ex

This file was deleted.

2 changes: 1 addition & 1 deletion rustler_mix/mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%{
"cargo": {:git, "https://github.com/rusterlium/erlang-cargo.git", "0e612bf1e321c6ae062b98f9079f24b6bedfba01", []},
"cargo": {:git, "https://github.com/rusterlium/erlang-cargo.git", "7992e2c159255a421d83c2a693b544c20979c841", []},
"earmark": {:hex, :earmark, "1.4.4", "4821b8d05cda507189d51f2caeef370cf1e18ca5d7dfb7d31e9cafe6688106a4", [:mix], [], "hexpm", "1f93aba7340574847c0f609da787f0d79efcab51b044bb6e242cae5aca9d264d"},
"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"},
"jsx": {:hex, :jsx, "2.10.0", "77760560d6ac2b8c51fd4c980e9e19b784016aa70be354ce746472c33beb0b1c", [:rebar3], [], "hexpm", "9a83e3704807298016968db506f9fad0f027de37546eb838b3ae1064c3a0ad62"},
Expand Down

0 comments on commit c0fc38e

Please sign in to comment.