diff --git a/src/Runner.jl b/src/Runner.jl index be497e02..2672f469 100644 --- a/src/Runner.jl +++ b/src/Runner.jl @@ -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: # . + # Cf. 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 'Version' \\ + | tail -n1 \\ + | sed -E -e 's/\\s*([^<]+)<\\/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 @@ -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, diff --git a/test/rootfs.jl b/test/rootfs.jl index ccdb6678..fa611279 100644 --- a/test/rootfs.jl +++ b/test/rootfs.jl @@ -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