Skip to content

[Runner] Set linker min macos version flag only when linking #429

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

Merged
merged 1 commit into from
Jun 13, 2025
Merged
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
23 changes: 15 additions & 8 deletions src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions test/runners.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`
Expand Down