Skip to content

Commit c25f6ed

Browse files
authored
[Runner] Set linker min macos version flag only when linking (#429)
This was causing errors when compiling with `-Werror=unused-command-line-argument`.
1 parent 2a3691f commit c25f6ed

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/Runner.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,12 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
382382
return flags
383383
end
384384

385-
function min_macos_version_flags()
386-
# Ask compilers to compile for a minimum macOS version, targeting that SDK.
387-
return ("-mmacosx-version-min=\${MACOSX_DEPLOYMENT_TARGET}", "-Wl,-sdk_version,\${MACOSX_DEPLOYMENT_TARGET}")
385+
# Ask compilers to compile for a minimum macOS version, targeting that SDK.
386+
function min_macos_version_compiler_flags()
387+
return ("-mmacosx-version-min=\${MACOSX_DEPLOYMENT_TARGET}",)
388+
end
389+
function min_macos_version_linker_flags()
390+
return ("-Wl,-sdk_version,\${MACOSX_DEPLOYMENT_TARGET}",)
388391
end
389392

390393
function add_system_includedir(flags::Vector{String})
@@ -455,9 +458,8 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
455458
])
456459

457460
if Sys.isapple(p)
458-
macos_version_flags = clang_use_lld ? (min_macos_version_flags()[1],) : min_macos_version_flags()
459461
append!(flags, String[
460-
macos_version_flags...,
462+
min_macos_version_compiler_flags()...,
461463
])
462464
end
463465

@@ -529,10 +531,14 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
529531
end
530532
sanitize_link_flags!(p, flags)
531533

532-
# On macos, we need to pass `-headerpad_max_install_names` so that we have lots of space
533-
# for `install_name_tool` shenanigans during audit fixups.
534534
if Sys.isapple(p)
535+
# On macos, we need to pass `-headerpad_max_install_names` so that we have lots
536+
# of space for `install_name_tool` shenanigans during audit fixups.
535537
push!(flags, "-headerpad_max_install_names")
538+
if !clang_use_lld
539+
# The `-sdk_version` flag is not implemented in lld yet.
540+
append!(flags, min_macos_version_linker_flags())
541+
end
536542
end
537543
return flags
538544
end
@@ -544,7 +550,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
544550
if gcc_version.major in (4, 5)
545551
push!(flags, "-Wl,-syslibroot,/opt/$(aatriplet(p))/$(aatriplet(p))/sys-root")
546552
end
547-
append!(flags, min_macos_version_flags())
553+
append!(flags, min_macos_version_compiler_flags())
548554
return flags
549555
end
550556

@@ -617,6 +623,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
617623
])
618624
elseif Sys.isapple(p)
619625
push!(flags, "-headerpad_max_install_names")
626+
append!(flags, min_macos_version_linker_flags())
620627
elseif Sys.iswindows(p) && gcc_version v"5"
621628
# Do not embed timestamps, for reproducibility:
622629
# https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/1232

test/runners.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,14 @@ end
458458
platform = Platform("x86_64", "macos")
459459
test_script = raw"""
460460
set -e
461-
prog='int main(void) { return 0; }'
462-
echo "${prog}" | clang -x c - -o test-clang
461+
echo 'int main(void) { return 0; }' > test.c
462+
clang -Wall -Werror -Werror=unused-command-line-argument test.c -c -o test-clang.o
463+
clang -Wall -Werror -Werror=unused-command-line-argument test-clang.o -o test-clang
463464
otool -lV test-clang | grep sdk
464465
# Set `MACOSX_DEPLOYMENT_TARGET` to override the value of the SDK
465466
export MACOSX_DEPLOYMENT_TARGET=10.14
466-
echo "${prog}" | gcc -x c - -o test-gcc
467+
gcc -Wall -Werror test.c -c -o test-gcc.o
468+
gcc -Wall -Werror test-gcc.o -o test-gcc
467469
otool -lV test-gcc | grep sdk
468470
"""
469471
cmd = `/bin/bash -c "$(test_script)"`

0 commit comments

Comments
 (0)