Skip to content

Commit 45acaa5

Browse files
stemanngiordano
andauthored
[Runner] Updated xcrun executable to handle a few arguments (#392)
* [Runner] Updated xcrun executable to handle `--sdk`, `--show-sdk-path` and `--show-sdk-version`. Also, added SDKROOT env. var. * Using plistutil to handle conversion of binary format plist files * Fixed a few bugs * Added tests running xcrun (on host) * Apply suggestions from code review Co-authored-by: Mosè Giordano <[email protected]> * Fixed bash/sh syntax --------- Co-authored-by: Mosè Giordano <[email protected]>
1 parent 55272a7 commit 45acaa5

File tree

2 files changed

+104
-39
lines changed

2 files changed

+104
-39
lines changed

src/Runner.jl

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,10 +1037,47 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
10371037
# `xcrun` is another macOS-specific tool, which is occasionally needed to run some
10381038
# commands, for example for the CGO linker. Ref:
10391039
# <https://github.com/JuliaPackaging/Yggdrasil/pull/2962>.
1040+
# Cf. <https://www.unix.com/man-page/osx/1/xcrun/>
10401041
xcrun_path = joinpath(bin_path, triplet(platform), "xcrun")
10411042
write(xcrun_path, """
10421043
#!/bin/sh
1043-
exec "\${@}"
1044+
1045+
sdk_path="\${SDKROOT}"
1046+
1047+
show_sdk_path() {
1048+
echo "\${1}"
1049+
}
1050+
1051+
show_sdk_version() {
1052+
plistutil -f xml -i "\${1}"/SDKSettings.plist \\
1053+
| grep -A1 '<key>Version</key>' \\
1054+
| tail -n1 \\
1055+
| sed -E -e 's/\\s*<string>([^<]+)<\\/string>\\s*/\\1/'
1056+
}
1057+
1058+
while [ "\${#}" -gt 0 ]; do
1059+
case "\${1}" in
1060+
--sdk)
1061+
sdk_path="\${2}"
1062+
shift 2
1063+
;;
1064+
--show-sdk-path)
1065+
show_sdk_path "\${sdk_path}"
1066+
shift
1067+
;;
1068+
--show-sdk-version)
1069+
show_sdk_version "\${sdk_path}"
1070+
shift
1071+
;;
1072+
*)
1073+
break
1074+
;;
1075+
esac
1076+
done
1077+
1078+
if [ "\${#}" -gt 0 ]; then
1079+
exec "\${@}"
1080+
fi
10441081
""")
10451082
chmod(xcrun_path, 0o775)
10461083
end
@@ -1294,6 +1331,7 @@ function platform_envs(platform::AbstractPlatform, src_name::AbstractString;
12941331
if Sys.isapple(platform)
12951332
mapping["LD"] = "/opt/bin/$(triplet(platform))/ld"
12961333
mapping["MACOSX_DEPLOYMENT_TARGET"] = macos_version(platform)
1334+
mapping["SDKROOT"] = "/opt/$(aatriplet(platform))/$(aatriplet(platform))/sys-root"
12971335
end
12981336

12991337
# There is no broad agreement on what host compilers should be called,

test/rootfs.jl

Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -217,52 +217,79 @@ end
217217

218218
@testset "Compiler wrappers" begin
219219
platform = Platform("x86_64", "linux"; libc="musl")
220-
mktempdir() do bin_path
221-
platform_bin_dir = joinpath(bin_path, triplet(platform))
222-
generate_compiler_wrappers!(platform; bin_path = bin_path)
223-
# Make sure the C++ string ABI is not set
224-
@test !occursin("-D_GLIBCXX_USE_CXX11_ABI", read(joinpath(platform_bin_dir, "gcc"), String))
225-
# Make sure gfortran doesn't uses ccache when BinaryBuilderBase.use_ccache is true
226-
BinaryBuilderBase.use_ccache[] && @test !occursin("ccache", read(joinpath(platform_bin_dir, "gfortran"), String))
220+
@testset "$(triplet(platform))" begin
221+
mktempdir() do bin_path
222+
platform_bin_dir = joinpath(bin_path, triplet(platform))
223+
generate_compiler_wrappers!(platform; bin_path = bin_path)
224+
# Make sure the C++ string ABI is not set
225+
@test !occursin("-D_GLIBCXX_USE_CXX11_ABI", read(joinpath(platform_bin_dir, "gcc"), String))
226+
# Make sure gfortran doesn't uses ccache when BinaryBuilderBase.use_ccache is true
227+
BinaryBuilderBase.use_ccache[] && @test !occursin("ccache", read(joinpath(platform_bin_dir, "gfortran"), String))
228+
end
227229
end
228230
platform = Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx03")
229-
mktempdir() do bin_path
230-
platform_bin_dir = joinpath(bin_path, triplet(platform))
231-
generate_compiler_wrappers!(platform; bin_path = bin_path)
232-
gcc = read(joinpath(platform_bin_dir, "gcc"), String)
233-
# Make sure the C++ string ABI is set as expected
234-
@test occursin("-D_GLIBCXX_USE_CXX11_ABI=0", gcc)
235-
# Make sure the unsafe flags check is there
236-
@test occursin("You used one or more of the unsafe flags", gcc)
231+
@testset "$(triplet(platform))" begin
232+
mktempdir() do bin_path
233+
platform_bin_dir = joinpath(bin_path, triplet(platform))
234+
generate_compiler_wrappers!(platform; bin_path = bin_path)
235+
gcc = read(joinpath(platform_bin_dir, "gcc"), String)
236+
# Make sure the C++ string ABI is set as expected
237+
@test occursin("-D_GLIBCXX_USE_CXX11_ABI=0", gcc)
238+
# Make sure the unsafe flags check is there
239+
@test occursin("You used one or more of the unsafe flags", gcc)
240+
end
237241
end
238242
platform = Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx11")
239-
mktempdir() do bin_path
240-
platform_bin_dir = joinpath(bin_path, triplet(platform))
241-
generate_compiler_wrappers!(platform; bin_path = bin_path, allow_unsafe_flags = true)
242-
gcc = read(joinpath(platform_bin_dir, "gcc"), String)
243-
# Make sure the C++ string ABI is set as expected
244-
@test occursin("-D_GLIBCXX_USE_CXX11_ABI=1", gcc)
245-
# Make sure the unsafe flags check is not there in this case
246-
@test !occursin("You used one or more of the unsafe flags", gcc)
243+
@testset "$(triplet(platform))" begin
244+
mktempdir() do bin_path
245+
platform_bin_dir = joinpath(bin_path, triplet(platform))
246+
generate_compiler_wrappers!(platform; bin_path = bin_path, allow_unsafe_flags = true)
247+
gcc = read(joinpath(platform_bin_dir, "gcc"), String)
248+
# Make sure the C++ string ABI is set as expected
249+
@test occursin("-D_GLIBCXX_USE_CXX11_ABI=1", gcc)
250+
# Make sure the unsafe flags check is not there in this case
251+
@test !occursin("You used one or more of the unsafe flags", gcc)
252+
end
253+
end
254+
platform = Platform("aarch64", "macos")
255+
@testset "$(triplet(platform))" begin
256+
mktempdir() do bin_path
257+
platform_bin_dir = joinpath(bin_path, triplet(platform))
258+
generate_compiler_wrappers!(platform; bin_path = bin_path, gcc_version = v"4")
259+
if Sys.isunix()
260+
cd(platform_bin_dir) do
261+
@test readchomp(`./xcrun echo foo`) == "foo"
262+
withenv("SDKROOT" => "/bar") do
263+
@test readchomp(`./xcrun --show-sdk-path`) == "/bar"
264+
@test readchomp(`./xcrun --show-sdk-path echo foo`) == "/bar\nfoo"
265+
@test readchomp(`./xcrun --sdk /baz --show-sdk-path echo foo`) == "/baz\nfoo"
266+
end
267+
end
268+
end
269+
end
247270
end
248271
platform = Platform("x86_64", "freebsd")
249-
mktempdir() do bin_path
250-
platform_bin_dir = joinpath(bin_path, triplet(platform))
251-
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c, :rust, :go])
252-
clang = read(joinpath(platform_bin_dir, "clang"), String)
253-
# Check link flags
254-
@test occursin("-L/opt/$(triplet(platform))/$(triplet(platform))/lib", clang)
255-
# Other compilers
256-
@test occursin("GOOS=\"freebsd\"", read(joinpath(platform_bin_dir, "go"), String))
257-
@test occursin("--target=x86_64-unknown-freebsd", read(joinpath(platform_bin_dir, "rustc"), String))
272+
@testset "$(triplet(platform))" begin
273+
mktempdir() do bin_path
274+
platform_bin_dir = joinpath(bin_path, triplet(platform))
275+
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c, :rust, :go])
276+
clang = read(joinpath(platform_bin_dir, "clang"), String)
277+
# Check link flags
278+
@test occursin("-L/opt/$(triplet(platform))/$(triplet(platform))/lib", clang)
279+
# Other compilers
280+
@test occursin("GOOS=\"freebsd\"", read(joinpath(platform_bin_dir, "go"), String))
281+
@test occursin("--target=x86_64-unknown-freebsd", read(joinpath(platform_bin_dir, "rustc"), String))
282+
end
258283
end
259284
platform = Platform("x86_64", "linux"; libc="glibc", cxxstring_abi="cxx11")
260-
mktempdir() do bin_path
261-
platform_bin_dir = joinpath(bin_path, triplet(platform))
262-
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c], gcc_version=v"5")
263-
clang = read(joinpath(platform_bin_dir, "clang"), String)
264-
# Check link flags
265-
@test occursin("-L/opt/$(aatriplet(platform))/lib/gcc/opt/$(aatriplet(platform))/lib/gcc", clang)
285+
@testset "$(triplet(platform))" begin
286+
mktempdir() do bin_path
287+
platform_bin_dir = joinpath(bin_path, triplet(platform))
288+
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c], gcc_version=v"5")
289+
clang = read(joinpath(platform_bin_dir, "clang"), String)
290+
# Check link flags
291+
@test occursin("-L/opt/$(aatriplet(platform))/lib/gcc/opt/$(aatriplet(platform))/lib/gcc", clang)
292+
end
266293
end
267294
end
268295
end

0 commit comments

Comments
 (0)