Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Runner] Updated xcrun executable to handle a few arguments #392

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 39 additions & 1 deletion src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,47 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
# `xcrun` is another macOS-specific tool, which is occasionally needed to run some
# commands, for example for the CGO linker. Ref:
# <https://github.com/JuliaPackaging/Yggdrasil/pull/2962>.
# Cf. <https://www.unix.com/man-page/osx/1/xcrun/>
xcrun_path = joinpath(bin_path, triplet(platform), "xcrun")
write(xcrun_path, """
#!/bin/sh
exec "\${@}"

sdk_path="\${SDKROOT}"

show_sdk_path() {
echo "\${1}"
}

show_sdk_version() {
plistutil -f xml -i "\${1}"/SDKSettings.plist \\
| grep -A1 '<key>Version</key>' \\
| tail -n1 \\
| sed -E -e 's/\\s*<string>([^<]+)<\\/string>\\s*/\\1/'
}

while [ "\${#}" -gt 0 ]; do
case "\${1}" in
--sdk)
sdk_path="\${2}"
shift 2
;;
--show-sdk-path)
show_sdk_path "\${sdk_path}"
shift
;;
--show-sdk-version)
show_sdk_version "\${sdk_path}"
shift
;;
*)
break
;;
esac
done

if [ "\${#}" -gt 0 ]; then
exec "\${@}"
fi
""")
chmod(xcrun_path, 0o775)
end
Expand Down Expand Up @@ -1255,6 +1292,7 @@ function platform_envs(platform::AbstractPlatform, src_name::AbstractString;
if Sys.isapple(platform)
mapping["LD"] = "/opt/bin/$(triplet(platform))/ld"
mapping["MACOSX_DEPLOYMENT_TARGET"] = macos_version(platform)
mapping["SDKROOT"] = "/opt/$(aatriplet(platform))/$(aatriplet(platform))/sys-root"
end

# There is no broad agreement on what host compilers should be called,
Expand Down
103 changes: 65 additions & 38 deletions test/rootfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,52 +219,79 @@ end

@testset "Compiler wrappers" begin
platform = Platform("x86_64", "linux"; libc="musl")
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path)
# Make sure the C++ string ABI is not set
@test !occursin("-D_GLIBCXX_USE_CXX11_ABI", read(joinpath(platform_bin_dir, "gcc"), String))
# Make sure gfortran doesn't uses ccache when BinaryBuilderBase.use_ccache is true
BinaryBuilderBase.use_ccache[] && @test !occursin("ccache", read(joinpath(platform_bin_dir, "gfortran"), String))
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path)
# Make sure the C++ string ABI is not set
@test !occursin("-D_GLIBCXX_USE_CXX11_ABI", read(joinpath(platform_bin_dir, "gcc"), String))
# Make sure gfortran doesn't uses ccache when BinaryBuilderBase.use_ccache is true
BinaryBuilderBase.use_ccache[] && @test !occursin("ccache", read(joinpath(platform_bin_dir, "gfortran"), String))
end
end
platform = Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx03")
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path)
gcc = read(joinpath(platform_bin_dir, "gcc"), String)
# Make sure the C++ string ABI is set as expected
@test occursin("-D_GLIBCXX_USE_CXX11_ABI=0", gcc)
# Make sure the unsafe flags check is there
@test occursin("You used one or more of the unsafe flags", gcc)
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path)
gcc = read(joinpath(platform_bin_dir, "gcc"), String)
# Make sure the C++ string ABI is set as expected
@test occursin("-D_GLIBCXX_USE_CXX11_ABI=0", gcc)
# Make sure the unsafe flags check is there
@test occursin("You used one or more of the unsafe flags", gcc)
end
end
platform = Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx11")
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, allow_unsafe_flags = true)
gcc = read(joinpath(platform_bin_dir, "gcc"), String)
# Make sure the C++ string ABI is set as expected
@test occursin("-D_GLIBCXX_USE_CXX11_ABI=1", gcc)
# Make sure the unsafe flags check is not there in this case
@test !occursin("You used one or more of the unsafe flags", gcc)
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, allow_unsafe_flags = true)
gcc = read(joinpath(platform_bin_dir, "gcc"), String)
# Make sure the C++ string ABI is set as expected
@test occursin("-D_GLIBCXX_USE_CXX11_ABI=1", gcc)
# Make sure the unsafe flags check is not there in this case
@test !occursin("You used one or more of the unsafe flags", gcc)
end
end
platform = Platform("aarch64", "macos")
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, gcc_version = v"4")
if Sys.isunix()
cd(platform_bin_dir) do
@test readchomp(`./xcrun echo foo`) == "foo"
withenv("SDKROOT" => "/bar") do
@test readchomp(`./xcrun --show-sdk-path`) == "/bar"
@test readchomp(`./xcrun --show-sdk-path echo foo`) == "/bar\nfoo"
@test readchomp(`./xcrun --sdk /baz --show-sdk-path echo foo`) == "/baz\nfoo"
end
end
end
end
end
platform = Platform("x86_64", "freebsd")
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c, :rust, :go])
clang = read(joinpath(platform_bin_dir, "clang"), String)
# Check link flags
@test occursin("-L/opt/$(triplet(platform))/$(triplet(platform))/lib", clang)
# Other compilers
@test occursin("GOOS=\"freebsd\"", read(joinpath(platform_bin_dir, "go"), String))
@test occursin("--target=x86_64-unknown-freebsd", read(joinpath(platform_bin_dir, "rustc"), String))
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c, :rust, :go])
clang = read(joinpath(platform_bin_dir, "clang"), String)
# Check link flags
@test occursin("-L/opt/$(triplet(platform))/$(triplet(platform))/lib", clang)
# Other compilers
@test occursin("GOOS=\"freebsd\"", read(joinpath(platform_bin_dir, "go"), String))
@test occursin("--target=x86_64-unknown-freebsd", read(joinpath(platform_bin_dir, "rustc"), String))
end
end
platform = Platform("x86_64", "linux"; libc="glibc", cxxstring_abi="cxx11")
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c], gcc_version=v"5")
clang = read(joinpath(platform_bin_dir, "clang"), String)
# Check link flags
@test occursin("-L/opt/$(aatriplet(platform))/lib/gcc/opt/$(aatriplet(platform))/lib/gcc", clang)
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c], gcc_version=v"5")
clang = read(joinpath(platform_bin_dir, "clang"), String)
# Check link flags
@test occursin("-L/opt/$(aatriplet(platform))/lib/gcc/opt/$(aatriplet(platform))/lib/gcc", clang)
end
end
end
end