diff --git a/src/Runner.jl b/src/Runner.jl index 9cdb3217..f42b1fee 100644 --- a/src/Runner.jl +++ b/src/Runner.jl @@ -336,9 +336,9 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr return flags end - function min_macos_version_flag(p::AbstractPlatform) - # Ask compilers to compile for a minimum macOS version - return "-mmacosx-version-min=$(macos_version(p))" + function min_macos_version_flags() + # Ask compilers to compile for a minimum macOS version, targeting that SDK. + return ("-mmacosx-version-min=\${MACOSX_DEPLOYMENT_TARGET}", "-Wl,-sdk_version,\${MACOSX_DEPLOYMENT_TARGET}") end function add_system_includedir(flags::Vector{String}) @@ -405,7 +405,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr # `clang` as a linker (and we have no real way to detect that in the wrapper), which will # cause `clang` to complain about compiler flags being passed in. "-Wno-unused-command-line-argument", - min_macos_version_flag(p), + min_macos_version_flags()..., ]) end sanitize_compile_flags!(p, flags) @@ -454,7 +454,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr if gcc_version.major in (4, 5) push!(flags, "-Wl,-syslibroot,/opt/$(aatriplet(p))/$(aatriplet(p))/sys-root") end - push!(flags, min_macos_version_flag(p)) + append!(flags, min_macos_version_flags()) return flags end diff --git a/test/runners.jl b/test/runners.jl index 609ef6b5..0d08503a 100644 --- a/test/runners.jl +++ b/test/runners.jl @@ -398,6 +398,32 @@ end @test split(String(read(iobuff)), "\n")[2] == "" end end + + @testset "macOS SDK setting" begin + mktempdir() do dir + platform = Platform("x86_64", "macos") + test_script = raw""" + set -e + prog='int main(void) { return 0; }' + echo "${prog}" | clang -x c - -o test-clang + otool -lV test-clang | grep sdk + # Set `MACOSX_DEPLOYMENT_TARGET` to override the value of the SDK + export MACOSX_DEPLOYMENT_TARGET=10.14 + echo "${prog}" | gcc -x c - -o test-gcc + otool -lV test-gcc | grep sdk + """ + cmd = `/bin/bash -c "$(test_script)"` + ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false) + iobuff = IOBuffer() + @test run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + lines = readlines(iobuff) + # Make sure the SDK for this platform is set to 10.10, instead of other wrong + # values, and that we can set `MACOSX_DEPLOYMENT_TARGET` to control the value. + @test contains(lines[end - 1], r"^ +sdk 10\.10$") + @test contains(lines[end], r"^ +sdk 10\.14$") + end + end end @testset "Shards" begin