From 9ac8ca24b6a324f395d3e335cdac18f62aacd954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Fri, 4 Nov 2022 01:52:27 +0000 Subject: [PATCH 1/3] [Runner] Set also minimum SDK version when targeting macOS --- src/Runner.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Runner.jl b/src/Runner.jl index 9cdb3217..68afce68 100644 --- a/src/Runner.jl +++ b/src/Runner.jl @@ -336,9 +336,10 @@ 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(p::AbstractPlatform) + ver = macos_version(p) + # Ask compilers to compile for a minimum macOS version, targeting that SDK. + return ("-mmacosx-version-min=$(ver)", "-Wl,-sdk_version,$(ver)") end function add_system_includedir(flags::Vector{String}) @@ -405,7 +406,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(p)..., ]) end sanitize_compile_flags!(p, flags) @@ -454,7 +455,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(p)) return flags end From 4f2797204306f191f03b6b2c013449c00d9e2682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Fri, 4 Nov 2022 22:35:57 +0000 Subject: [PATCH 2/3] Add test for macOS SDK version set correctly --- test/runners.jl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/runners.jl b/test/runners.jl index 609ef6b5..36dd91fc 100644 --- a/test/runners.jl +++ b/test/runners.jl @@ -398,6 +398,30 @@ 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 = """ + set -e + echo 'int main(void) { return 0; }' | clang -x c - -o test-clang + otool -lV test-clang | grep sdk + echo 'int main(void) { return 0; }' | 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. + sdk = r"^ +sdk 10\.10$" + @test contains(lines[end - 1], sdk) + @test contains(lines[end], sdk) + end + end end @testset "Shards" begin From cefd3862908c5be28bbd1b38904a97f957b51550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Sat, 5 Nov 2022 12:04:31 +0000 Subject: [PATCH 3/3] [Runner] Get value of minimum macOS version and SDK from `MACOSX_DEPLOYMENT_TARGET` --- src/Runner.jl | 9 ++++----- test/runners.jl | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Runner.jl b/src/Runner.jl index 68afce68..f42b1fee 100644 --- a/src/Runner.jl +++ b/src/Runner.jl @@ -336,10 +336,9 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr return flags end - function min_macos_version_flags(p::AbstractPlatform) - ver = macos_version(p) + function min_macos_version_flags() # Ask compilers to compile for a minimum macOS version, targeting that SDK. - return ("-mmacosx-version-min=$(ver)", "-Wl,-sdk_version,$(ver)") + return ("-mmacosx-version-min=\${MACOSX_DEPLOYMENT_TARGET}", "-Wl,-sdk_version,\${MACOSX_DEPLOYMENT_TARGET}") end function add_system_includedir(flags::Vector{String}) @@ -406,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_flags(p)..., + min_macos_version_flags()..., ]) end sanitize_compile_flags!(p, flags) @@ -455,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 - append!(flags, min_macos_version_flags(p)) + append!(flags, min_macos_version_flags()) return flags end diff --git a/test/runners.jl b/test/runners.jl index 36dd91fc..0d08503a 100644 --- a/test/runners.jl +++ b/test/runners.jl @@ -402,11 +402,14 @@ end @testset "macOS SDK setting" begin mktempdir() do dir platform = Platform("x86_64", "macos") - test_script = """ + test_script = raw""" set -e - echo 'int main(void) { return 0; }' | clang -x c - -o test-clang + prog='int main(void) { return 0; }' + echo "${prog}" | clang -x c - -o test-clang otool -lV test-clang | grep sdk - echo 'int main(void) { return 0; }' | gcc -x c - -o test-gcc + # 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)"` @@ -415,11 +418,10 @@ end @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. - sdk = r"^ +sdk 10\.10$" - @test contains(lines[end - 1], sdk) - @test contains(lines[end], sdk) + # 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