Skip to content

Commit e72aa2f

Browse files
authored
[Runner] Set also minimum SDK version when targeting macOS (#284)
* [Runner] Set also minimum SDK version when targeting macOS * Add test for macOS SDK version set correctly * [Runner] Get value of minimum macOS version and SDK from `MACOSX_DEPLOYMENT_TARGET`
1 parent 43ba740 commit e72aa2f

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/Runner.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
336336
return flags
337337
end
338338

339-
function min_macos_version_flag(p::AbstractPlatform)
340-
# Ask compilers to compile for a minimum macOS version
341-
return "-mmacosx-version-min=$(macos_version(p))"
339+
function min_macos_version_flags()
340+
# Ask compilers to compile for a minimum macOS version, targeting that SDK.
341+
return ("-mmacosx-version-min=\${MACOSX_DEPLOYMENT_TARGET}", "-Wl,-sdk_version,\${MACOSX_DEPLOYMENT_TARGET}")
342342
end
343343

344344
function add_system_includedir(flags::Vector{String})
@@ -405,7 +405,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
405405
# `clang` as a linker (and we have no real way to detect that in the wrapper), which will
406406
# cause `clang` to complain about compiler flags being passed in.
407407
"-Wno-unused-command-line-argument",
408-
min_macos_version_flag(p),
408+
min_macos_version_flags()...,
409409
])
410410
end
411411
sanitize_compile_flags!(p, flags)
@@ -454,7 +454,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
454454
if gcc_version.major in (4, 5)
455455
push!(flags, "-Wl,-syslibroot,/opt/$(aatriplet(p))/$(aatriplet(p))/sys-root")
456456
end
457-
push!(flags, min_macos_version_flag(p))
457+
append!(flags, min_macos_version_flags())
458458
return flags
459459
end
460460

test/runners.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,32 @@ end
398398
@test split(String(read(iobuff)), "\n")[2] == ""
399399
end
400400
end
401+
402+
@testset "macOS SDK setting" begin
403+
mktempdir() do dir
404+
platform = Platform("x86_64", "macos")
405+
test_script = raw"""
406+
set -e
407+
prog='int main(void) { return 0; }'
408+
echo "${prog}" | clang -x c - -o test-clang
409+
otool -lV test-clang | grep sdk
410+
# Set `MACOSX_DEPLOYMENT_TARGET` to override the value of the SDK
411+
export MACOSX_DEPLOYMENT_TARGET=10.14
412+
echo "${prog}" | gcc -x c - -o test-gcc
413+
otool -lV test-gcc | grep sdk
414+
"""
415+
cmd = `/bin/bash -c "$(test_script)"`
416+
ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false)
417+
iobuff = IOBuffer()
418+
@test run(ur, cmd, iobuff; tee_stream=devnull)
419+
seekstart(iobuff)
420+
lines = readlines(iobuff)
421+
# Make sure the SDK for this platform is set to 10.10, instead of other wrong
422+
# values, and that we can set `MACOSX_DEPLOYMENT_TARGET` to control the value.
423+
@test contains(lines[end - 1], r"^ +sdk 10\.10$")
424+
@test contains(lines[end], r"^ +sdk 10\.14$")
425+
end
426+
end
401427
end
402428

403429
@testset "Shards" begin

0 commit comments

Comments
 (0)