diff --git a/src/Runner.jl b/src/Runner.jl index cf4f3c5d..3999de26 100644 --- a/src/Runner.jl +++ b/src/Runner.jl @@ -382,9 +382,12 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr return flags end - 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}") + # Ask compilers to compile for a minimum macOS version, targeting that SDK. + function min_macos_version_compiler_flags() + return ("-mmacosx-version-min=\${MACOSX_DEPLOYMENT_TARGET}",) + end + function min_macos_version_linker_flags() + return ("-Wl,-sdk_version,\${MACOSX_DEPLOYMENT_TARGET}",) end function add_system_includedir(flags::Vector{String}) @@ -455,9 +458,8 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr ]) if Sys.isapple(p) - macos_version_flags = clang_use_lld ? (min_macos_version_flags()[1],) : min_macos_version_flags() append!(flags, String[ - macos_version_flags..., + min_macos_version_compiler_flags()..., ]) end @@ -529,10 +531,14 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr end sanitize_link_flags!(p, flags) - # On macos, we need to pass `-headerpad_max_install_names` so that we have lots of space - # for `install_name_tool` shenanigans during audit fixups. if Sys.isapple(p) + # On macos, we need to pass `-headerpad_max_install_names` so that we have lots + # of space for `install_name_tool` shenanigans during audit fixups. push!(flags, "-headerpad_max_install_names") + if !clang_use_lld + # The `-sdk_version` flag is not implemented in lld yet. + append!(flags, min_macos_version_linker_flags()) + end end return flags end @@ -544,7 +550,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()) + append!(flags, min_macos_version_compiler_flags()) return flags end @@ -617,6 +623,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr ]) elseif Sys.isapple(p) push!(flags, "-headerpad_max_install_names") + append!(flags, min_macos_version_linker_flags()) elseif Sys.iswindows(p) && gcc_version ≥ v"5" # Do not embed timestamps, for reproducibility: # https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/1232 diff --git a/test/runners.jl b/test/runners.jl index 3d330b86..7a12eb05 100644 --- a/test/runners.jl +++ b/test/runners.jl @@ -458,12 +458,14 @@ end platform = Platform("x86_64", "macos") test_script = raw""" set -e - prog='int main(void) { return 0; }' - echo "${prog}" | clang -x c - -o test-clang + echo 'int main(void) { return 0; }' > test.c + clang -Wall -Werror -Werror=unused-command-line-argument test.c -c -o test-clang.o + clang -Wall -Werror -Werror=unused-command-line-argument test-clang.o -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 + gcc -Wall -Werror test.c -c -o test-gcc.o + gcc -Wall -Werror test-gcc.o -o test-gcc otool -lV test-gcc | grep sdk """ cmd = `/bin/bash -c "$(test_script)"`