Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Generate .cargo/config #192

Merged
merged 1 commit into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
members = [
"rustler",
"rustler_codegen",
"rustler_tests"
"rustler_tests/native/rustler_test",
]
44 changes: 39 additions & 5 deletions rustler_mix/lib/mix/tasks/compile.rustler.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Mix.Tasks.Compile.Rustler do
use Mix.Task
require Logger

alias Rustler.Compiler.{Messages, Rustup}

Expand Down Expand Up @@ -51,7 +52,7 @@ defmodule Mix.Tasks.Compile.Rustler do
|> make_no_default_features_flag(Keyword.get(config, :default_features, true))
|> make_features_flag(Keyword.get(config, :features, []))
|> make_build_mode_flag(build_mode)
|> make_platform_hacks(output_type, :os.type())
|> make_platform_hacks(crate_full_path, output_type, :os.type())

[cmd_bin | args] = compile_command

Expand Down Expand Up @@ -93,11 +94,44 @@ defmodule Mix.Tasks.Compile.Rustler do
["rustup", "run", version, "cargo", "rustc"]
end

defp make_platform_hacks(args, :lib, {:unix, :darwin}) do
# Fix for https://github.com/hansihe/Rustler/issues/12
args ++ ["--", "--codegen", "link-args=-flat_namespace -undefined suppress"]
defp make_platform_hacks(args, crate_path, :lib, {:unix, :darwin}) do
path = Path.join([crate_path, ".cargo", "config"])

if 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
end
defp make_platform_hacks(args, _, _), do: args
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"]
Expand Down
1 change: 1 addition & 0 deletions rustler_mix/lib/mix/tasks/rustler.new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Mix.Tasks.Rustler.New do
"""

@basic [
{:eex, "basic/.cargo/config", ".cargo/config"},
{:eex, "basic/README.md", "README.md"},
{:eex, "basic/Cargo.toml.eex", "Cargo.toml"},
{:eex, "basic/src/lib.rs", "src/lib.rs"},
Expand Down
5 changes: 5 additions & 0 deletions rustler_mix/priv/templates/basic/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
8 changes: 0 additions & 8 deletions rustler_mix/test/rustler_mix_test.exs

This file was deleted.

15 changes: 4 additions & 11 deletions rustler_tests/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ defmodule RustlerTest.Mixfile do
[app: :rustler_test,
version: "0.0.1",
elixir: "~> 1.2",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
compilers: [:rustler] ++ Mix.compilers,
rustler_crates: rustler_crates(),
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
compilers: [:rustler] ++ Mix.compilers(),
rustler_crates: [rustler_test: [mode: :debug]],
deps: deps()]
end

Expand All @@ -19,11 +19,4 @@ defmodule RustlerTest.Mixfile do
defp deps do
[{:rustler, path: "../rustler_mix"}]
end

defp rustler_crates do
[rustler_test: [
path: ".",
mode: :debug,
]]
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ path = "src/lib.rs"
crate-type = ["cdylib"]

[dependencies]
lazy_static = "1.0"
rustler = { path = "../rustler" }
rustler_codegen = { path = "../rustler_codegen" }
lazy_static = "1.2"
rustler = { path = "../../../rustler" }
rustler_codegen = { path = "../../../rustler_codegen" }
File renamed without changes.