Skip to content

Commit

Permalink
[Runners] Generate Go and Rust env vars only if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Dec 2, 2021
1 parent 4551f07 commit 06718ae
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 33 deletions.
12 changes: 7 additions & 5 deletions src/DockerRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@ function DockerRunner(workspace_root::String;
# encrypted directory, as that can trigger kernel bugs
check_encryption(workspace_root; verbose=verbose)

# Extract compilers argument
compilers = collect(extract_kwargs(kwargs, (:compilers,)))

# Construct environment variables we'll use from here on out
platform = get_concrete_platform(platform; extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:compilers))...)
platform = get_concrete_platform(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version))...)
envs = merge(platform_envs(platform, src_name; verbose=verbose), extra_env)

# JIT out some compiler wrappers, add it to our mounts
generate_compiler_wrappers!(platform; bin_path=compiler_wrapper_path, extract_kwargs(kwargs, (:compilers,:allow_unsafe_flags,:lock_microarchitecture))...)
generate_compiler_wrappers!(platform; bin_path=compiler_wrapper_path, compilers..., extract_kwargs(kwargs, (:allow_unsafe_flags,:lock_microarchitecture))...)
push!(workspaces, compiler_wrapper_path => "/opt/bin")

if isempty(bootstrap_list)
Expand All @@ -99,8 +102,7 @@ function DockerRunner(workspace_root::String;
end

# Generate directory where to write Cargo config files
compilers = collect(extract_kwargs(kwargs, (:compilers,)))
if isone(length(compilers)) && :rust in compilers[1].second
if isone(length(collect(compilers))) && :rust in collect(compilers)[1].second
cargo_dir = mktempdir()
cargo_config_file!(cargo_dir)
# Add to the list of mappings a subdirectory of ${CARGO_HOME}, whose content
Expand All @@ -121,7 +123,7 @@ function DockerRunner(workspace_root::String;

if isnothing(shards)
# Choose the shards we're going to mount
shards = choose_shards(platform; extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:bootstrap_list,:compilers))...)
shards = choose_shards(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:bootstrap_list))...)
end

# Import docker image
Expand Down
68 changes: 46 additions & 22 deletions src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -836,17 +836,32 @@ function map_rust_target(p::AbstractPlatform)
end

"""
platform_envs(platform::AbstractPlatform)
Given a `platform`, generate a `Dict` mapping representing all the environment
variables to be set within the build environment to force compiles toward the
defined target architecture. Examples of things set are `PATH`, `CC`,
`RANLIB`, as well as nonstandard things like `target`.
platform_envs(platform::AbstractPlatform, src_name::AbstractString;
host_platform = default_host_platform,
bootstrap::Bool=!isempty(bootstrap_list),
compilers::Vector{Symbol}=[:c],
verbose::Bool = false,
)
Given a `platform` and a `src_name`, generate a `Dict` mapping representing all
the environment variables to be set within the build environment to force
compiles toward the defined target architecture. Examples of things set are
`PATH`, `CC`, `RANLIB`, as well as nonstandard things like `target`.
Accepted keyword arguments are:
* `host_platform`: the platform of the host system,
* `bootstraop`: if `true`, only basic environment variables will be generated,
* `compilers`: list of compilers, some environment variables will be generated
only if the relevant compilers are used (e.g., for Go and Rust)
* `verbose`: holds the value of the `V` and `VERBOSE` environment variables.
"""
function platform_envs(platform::AbstractPlatform, src_name::AbstractString;
host_platform = default_host_platform,
bootstrap::Bool=!isempty(bootstrap_list),
verbose::Bool = false)
compilers::Vector{Symbol}=[:c],
verbose::Bool = false,
)
global use_ccache

# Convert platform to a triplet, but strip out the ABI parts
Expand Down Expand Up @@ -951,6 +966,30 @@ function platform_envs(platform::AbstractPlatform, src_name::AbstractString;
end
end


# Go stuff
if :go in compilers
merge!(mapping, Dict(
"GO" => "go",
"GOCACHE" => "/workspace/.gocache",
"GOPATH" => "/workspace/.gopath",
"GOARM" => GOARM(platform),
))
end

# Rust stuff
if :rust in compilers
merge!(mapping, Dict(
"RUSTC" => "rustc",
"CARGO" => "cargo",
"CARGO_BUILD_TARGET" => map_rust_target(platform),
"CARGO_HOME" => "/opt/$(host_target)",
"RUSTUP_HOME" => "/opt/$(host_target)",
# TODO: we'll need a way to parameterize this toolchain number
"RUSTUP_TOOLCHAIN" => "1.56.1-$(map_rust_target(host_platform))",
))
end

merge!(mapping, Dict(
"PATH" => join((
# First things first, our compiler wrappers trump all
Expand All @@ -974,21 +1013,6 @@ function platform_envs(platform::AbstractPlatform, src_name::AbstractString;
"CC" => "cc",
"CXX" => "c++",
"FC" => "gfortran",
"GO" => "go",
"RUSTC" => "rustc",
"CARGO" => "cargo",

# Go stuff
"GOCACHE" => "/workspace/.gocache",
"GOPATH" => "/workspace/.gopath",
"GOARM" => GOARM(platform),

# Rust stuff
"CARGO_BUILD_TARGET" => map_rust_target(platform),
"CARGO_HOME" => "/opt/$(host_target)",
"RUSTUP_HOME" => "/opt/$(host_target)",
# TODO: we'll need a way to parameterize this toolchain number
"RUSTUP_TOOLCHAIN" => "1.56.1-$(map_rust_target(host_platform))",

# We conditionally add on some compiler flags; we'll cull empty ones at the end
"USE_CCACHE" => "$(use_ccache)",
Expand Down
14 changes: 8 additions & 6 deletions src/UserNSRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ function UserNSRunner(workspace_root::String;
# encrypted directory, as that triggers kernel bugs
check_encryption(workspace_root; verbose=verbose)

# Extract compilers argument
compilers = extract_kwargs(kwargs, (:compilers,))

# Construct environment variables we'll use from here on out
platform = get_concrete_platform(platform; extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:compilers))...)
envs = merge(platform_envs(platform, src_name; verbose=verbose), extra_env)
platform = get_concrete_platform(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version))...)
envs = merge(platform_envs(platform, src_name; verbose, compilers...), extra_env)

# JIT out some compiler wrappers, add it to our mounts
generate_compiler_wrappers!(platform; bin_path=compiler_wrapper_path, extract_kwargs(kwargs, (:compilers,:allow_unsafe_flags,:lock_microarchitecture))...)
generate_compiler_wrappers!(platform; bin_path=compiler_wrapper_path, compilers..., extract_kwargs(kwargs, (:allow_unsafe_flags,:lock_microarchitecture))...)
push!(workspaces, compiler_wrapper_path => "/opt/bin")

if isempty(bootstrap_list)
Expand All @@ -54,8 +57,7 @@ function UserNSRunner(workspace_root::String;
end

# Generate directory where to write Cargo config files
compilers = collect(extract_kwargs(kwargs, (:compilers,)))
if isone(length(compilers)) && :rust in compilers[1].second
if isone(length(collect(compilers))) && :rust in collect(compilers)[1].second
cargo_dir = mktempdir()
cargo_config_file!(cargo_dir)
# Add to the list of mappings a subdirectory of ${CARGO_HOME}, whose content
Expand Down Expand Up @@ -91,7 +93,7 @@ function UserNSRunner(workspace_root::String;

if isnothing(shards)
# Choose the shards we're going to mount
shards = choose_shards(platform; extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:bootstrap_list,:compilers))...)
shards = choose_shards(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:bootstrap_list))...)
end

# Construct sandbox command to look at the location it'll be mounted under
Expand Down

0 comments on commit 06718ae

Please sign in to comment.