Skip to content

Commit

Permalink
[Runners] JIT-generate Cargo config file
Browse files Browse the repository at this point in the history
This will replace the file we currently hard-code in the Rust compiler shard.
  • Loading branch information
giordano committed Dec 1, 2021
1 parent dea18f2 commit 93eb65b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
30 changes: 28 additions & 2 deletions src/BuildToolchains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ function toolchain_file(bt::Meson, p::AbstractPlatform, envs::Dict{String,String
"""
end

function generate_toolchain_files!(platform::AbstractPlatform, envs::Dict{String,String};
toolchains_path::AbstractString,
function generate_toolchain_files!(platform::AbstractPlatform, envs::Dict{String,String},
toolchains_path::AbstractString;
host_platform::AbstractPlatform = default_host_platform,
)

Expand Down Expand Up @@ -253,3 +253,29 @@ function generate_toolchain_files!(platform::AbstractPlatform, envs::Dict{String
end
end
end

function cargo_config_file!(dir::AbstractString)
# Generate "${CARGO_HOME}/config.toml" file for Cargo where we give it the
# linkers for all our targets
open(joinpath(dir, "config.toml"), "w") do io
write(io, """
# Configuration file for `cargo`
""")
for platform in supported_platforms()
# Use `aatriplet` for the linker to match how the wrappers are
# written in
# https://github.com/JuliaPackaging/BinaryBuilderBase.jl/blob/30d056ef68f81dca9cb91ededcce6b68c6466b37/src/Runner.jl#L599.
write(io, """
[target.$(map_rust_target(platform))]
linker = "$(aatriplet(platform))-gcc"
""")
if platforms_match(platform, Platform("aarch64", "linux"; libc="musl"))
# Work around bug for this platform:
# https://github.com/rust-lang/rust/issues/46651#issuecomment-433611633
write(io, """
rustflags = ["-C", "link-arg=-lgcc"]
""")
end
end
end
end
12 changes: 11 additions & 1 deletion src/DockerRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,19 @@ function DockerRunner(workspace_root::String;
push!(workspaces, compiler_wrapper_path => "/opt/bin")

# Generate CMake and Meson files
generate_toolchain_files!(platform, envs; toolchains_path=toolchains_path)
generate_toolchain_files!(platform, envs, toolchains_path)
push!(workspaces, toolchains_path => "/opt/toolchains")

# Generate directory where to write Cargo config files
compilers = collect(extract_kwargs(kwargs, (:compilers,)))
if isone(length(compilers)) && :rust in compilers[1].second
cargo_dir = mktempdir()
cargo_config_file!(cargo_dir)
# Add to the list of mappings a subdirectory of ${CARGO_HOME}, whose content
# will be put in ${CARGO_HOME}.
push!(workspaces, cargo_dir => envs["CARGO_HOME"] * "/" * randstring())
end

# the workspace_root is always a workspace, and we always mount it first
insert!(workspaces, 1, workspace_root => "/workspace")

Expand Down
12 changes: 11 additions & 1 deletion src/UserNSRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@ function UserNSRunner(workspace_root::String;
push!(workspaces, compiler_wrapper_path => "/opt/bin")

# Generate CMake and Meson files
generate_toolchain_files!(platform, envs; toolchains_path=toolchains_path)
generate_toolchain_files!(platform, envs, toolchains_path)
push!(workspaces, toolchains_path => "/opt/toolchains")

# Generate directory where to write Cargo config files
compilers = collect(extract_kwargs(kwargs, (:compilers,)))
if isone(length(compilers)) && :rust in compilers[1].second
cargo_dir = mktempdir()
cargo_config_file!(cargo_dir)
# Add to the list of mappings a subdirectory of ${CARGO_HOME}, whose content
# will be put in ${CARGO_HOME}.
push!(mappings, cargo_dir => envs["CARGO_HOME"] * "/" * randstring())
end

# the workspace_root is always a workspace, and we always mount it first
insert!(workspaces, 1, workspace_root => "/workspace")

Expand Down

0 comments on commit 93eb65b

Please sign in to comment.