From 089efe6b5a8fcfa3f000057935481ecbdf9f58e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Wed, 1 Dec 2021 01:03:04 +0000 Subject: [PATCH] [Runners] JIT-generate Cargo config file This will replace the file we currently hard-code in the Rust compiler shard. --- src/BuildToolchains.jl | 30 ++++++++++++++++++++++++++++-- src/DockerRunner.jl | 11 ++++++++++- src/UserNSRunner.jl | 11 ++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/BuildToolchains.jl b/src/BuildToolchains.jl index 7a36a7dd..7d952610 100644 --- a/src/BuildToolchains.jl +++ b/src/BuildToolchains.jl @@ -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, ) @@ -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 diff --git a/src/DockerRunner.jl b/src/DockerRunner.jl index 93feca81..f6184f14 100644 --- a/src/DockerRunner.jl +++ b/src/DockerRunner.jl @@ -93,9 +93,18 @@ 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 + if :rust in only(extract_kwargs(kwargs, (:compilers,))).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") diff --git a/src/UserNSRunner.jl b/src/UserNSRunner.jl index 79811fce..6ec46670 100644 --- a/src/UserNSRunner.jl +++ b/src/UserNSRunner.jl @@ -48,9 +48,18 @@ 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 + if :rust in only(extract_kwargs(kwargs, (:compilers,))).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")