Skip to content

Commit 65d6001

Browse files
authored
Add clang-16 (#324)
* Add clang-16 * Fix windows! * Readd broken test arg * Set the libstdc++ ABI define also in clang * Add some fixups and make the gcc_version detection correct
1 parent fec32a3 commit 65d6001

File tree

4 files changed

+62
-22
lines changed

4 files changed

+62
-22
lines changed

Artifacts.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,6 +3034,28 @@ os = "linux"
30343034
sha256 = "baf8f1f42219ba94d0bed5a8d2533bd4bb9f8e109691d930e0da57f2746ac02a"
30353035
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/LLVMBootstrap-v13.0.1+1/LLVMBootstrap.v13.0.1.x86_64-linux-musl.unpacked.tar.gz"
30363036

3037+
[["LLVMBootstrap.v16.0.6.x86_64-linux-musl.squashfs"]]
3038+
arch = "x86_64"
3039+
git-tree-sha1 = "69c66aef8882dafafa179cf7152fcdf825f19591"
3040+
lazy = true
3041+
libc = "musl"
3042+
os = "linux"
3043+
3044+
[["LLVMBootstrap.v16.0.6.x86_64-linux-musl.squashfs".download]]
3045+
sha256 = "e0197e2ed9f96b9e7e5c369068d54a9a85a08588739f6b84f08ad5bde825553e"
3046+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/LLVMBootstrap-v16.0.6/LLVMBootstrap.v16.0.6.x86_64-linux-musl.squashfs.tar.gz"
3047+
3048+
[["LLVMBootstrap.v16.0.6.x86_64-linux-musl.unpacked"]]
3049+
arch = "x86_64"
3050+
git-tree-sha1 = "ef7ca988b60e65d8e6dd139bc7c18864a760ffa8"
3051+
lazy = true
3052+
libc = "musl"
3053+
os = "linux"
3054+
3055+
[["LLVMBootstrap.v16.0.6.x86_64-linux-musl.unpacked".download]]
3056+
sha256 = "a4cc72616d41db70d8452b8706078800a15c7e01f20877634029ff36a5083b07"
3057+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/LLVMBootstrap-v16.0.6/LLVMBootstrap.v16.0.6.x86_64-linux-musl.unpacked.tar.gz"
3058+
30373059
[["LLVMBootstrap.v6.0.1.x86_64-linux-musl.squashfs"]]
30383060
arch = "x86_64"
30393061
git-tree-sha1 = "474b55ee699607660a7375f4e38afc9a76583c41"

src/Rootfs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ function expand_cxxstring_abis(platform::AbstractPlatform; skip=Sys.isbsd)
805805
p["cxxstring_abi"] = "cxx11" #Clang only seems to generate cxx11 abi
806806
return [p]
807807
end
808-
808+
809809
# Otherwise, generate new versions!
810810
map(["cxx03", "cxx11"]) do abi
811811
p = deepcopy(platform)

src/Runner.jl

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ end
141141
prefer_clang(p::AbstractPlatform) =
142142
Sys.isbsd(p) || sanitize(p) in ("memory", "memory_origins", "address")
143143

144+
# Add the string ABI define
145+
function add_cxx_abi(p::AbstractPlatform, flags::Vector{String})
146+
if cxxstring_abi(p) == "cxx11"
147+
push!(flags, "-D_GLIBCXX_USE_CXX11_ABI=1")
148+
elseif cxxstring_abi(p) == "cxx03"
149+
push!(flags, "-D_GLIBCXX_USE_CXX11_ABI=0")
150+
end
151+
end
152+
144153
"""
145154
generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::AbstractString,
146155
host_platform::AbstractPlatform = $(repr(default_host_platform)),
@@ -162,6 +171,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
162171
allow_unsafe_flags::Bool = false,
163172
lock_microarchitecture::Bool = true,
164173
bootstrap::Bool = !isempty(bootstrap_list),
174+
gcc_version::Union{Nothing,VersionNumber}=nothing,
165175
)
166176
# Wipe that directory out, in case it already had compiler wrappers
167177
rm(bin_path; recursive=true, force=true)
@@ -322,17 +332,17 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
322332
"--sysroot=/opt/$(aatriplet(p))/$(aatriplet(p))/sys-root",
323333
])
324334
if !Sys.isbsd(p)
325-
append!(flags, [
326-
# Find GCC toolchain here (for things like libgcc_s)
327-
"--gcc-toolchain=/opt/$(aatriplet(p))"
328-
])
335+
add_cxx_abi(p, flags)
329336
if iscxx
330337
append!(flags, [
331338
# Link with libstdc++ when compiling c++ on non-BSDs
332339
"-stdlib=libstdc++"
333340
])
334341
end
335342
end
343+
if Sys.islinux(p) && !isnothing(gcc_version)
344+
append!(flags, ["--gcc-install-dir=/opt/$(aatriplet(p))/lib/gcc/$(aatriplet(p))/$(gcc_version)"])
345+
end
336346
if Sys.iswindows(p)
337347
windows_cflags!(p, flags)
338348
end
@@ -415,6 +425,15 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
415425
if Sys.isfreebsd(p)
416426
add_system_includedir(flags)
417427
end
428+
429+
if !Sys.isbsd(p) && !isnothing(gcc_version)
430+
append!(flags, String["-isystem /opt/$(aatriplet(p))/$(aatriplet(p))/include/c++/$(gcc_version)",
431+
"-isystem /opt/$(aatriplet(p))/$(aatriplet(p))/include/c++/$(gcc_version)/$(aatriplet(p))",
432+
"-isystem /opt/$(aatriplet(p))/$(aatriplet(p))/include/c++/$(gcc_version)/backward",
433+
"-isystem /opt/$(aatriplet(p))/$(aatriplet(p))/include",
434+
"-isystem /opt/$(aatriplet(p))/$(aatriplet(p))/sys-root/include"])
435+
end
436+
418437
return flags
419438
end
420439

@@ -434,6 +453,12 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
434453
# Use libgcc as the C runtime library
435454
"-rtlib=libgcc"
436455
])
456+
if !isnothing(gcc_version)
457+
append!(flags, String["-L/opt/$(aatriplet(p))/lib/gcc/opt/$(aatriplet(p))/lib/gcc",
458+
"-L/opt/$(aatriplet(p))/$(aatriplet(p))/lib",
459+
"-L/opt/$(aatriplet(p))/lib/gcc/$(aatriplet(p))/$(gcc_version)",
460+
"-L/opt/$(aatriplet(p))/$(aatriplet(p))/sys-root/lib",])
461+
end
437462
end
438463
# we want to use a particular linker with clang. But we want to avoid warnings about unused
439464
# flags when just compiling, so we put it into "linker-only flags".
@@ -453,7 +478,6 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
453478
function macos_gcc_flags!(p::AbstractPlatform, flags::Vector{String} = String[])
454479
# On macOS, if we're on an old GCC, the default -syslibroot that gets
455480
# passed to the linker isn't calculated correctly, so we have to manually set it.
456-
gcc_version, llvm_version = select_compiler_versions(p, compilers)
457481
if gcc_version.major in (4, 5)
458482
push!(flags, "-Wl,-syslibroot,/opt/$(aatriplet(p))/$(aatriplet(p))/sys-root")
459483
end
@@ -473,11 +497,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
473497

474498
function gcc_flags!(p::AbstractPlatform, flags::Vector{String} = String[])
475499
# Force proper cxx11 string ABI usage w00t w00t!
476-
if cxxstring_abi(p) == "cxx11"
477-
push!(flags, "-D_GLIBCXX_USE_CXX11_ABI=1")
478-
elseif cxxstring_abi(p) == "cxx03"
479-
push!(flags, "-D_GLIBCXX_USE_CXX11_ABI=0")
480-
end
500+
add_cxx_abi(p, flags)
481501

482502
# Simulate some of the `__OSX_AVAILABLE()` macro usage that is broken in GCC
483503
if Sys.isapple(p) && something(os_version(p), v"14") < v"16"
@@ -513,7 +533,6 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
513533
append!(flags, get_march_flags(arch(p), march(p), "gcc"))
514534
end
515535
sanitize_compile_flags!(p, flags)
516-
gcc_version, llvm_version = select_compiler_versions(p, compilers)
517536
if libc(platform) == "musl" && gcc_version in (v"4.8.5", v"5.2.0")
518537
add_system_includedir(flags)
519538
end
@@ -523,7 +542,6 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
523542
function gcc_link_flags!(p::AbstractPlatform, flags::Vector{String} = String[])
524543
# Yes, it does seem that the inclusion of `/lib64` on `powerpc64le` was fixed
525544
# in GCC 6, broken again in GCC 7, and then fixed again for GCC 8 and 9
526-
gcc_version, llvm_version = select_compiler_versions(p, compilers)
527545
if arch(p) == "powerpc64le" && Sys.islinux(p) && gcc_version.major in (4, 5, 7)
528546
append!(flags, String[
529547
"-L/opt/$(aatriplet(p))/$(aatriplet(p))/sys-root/lib64",
@@ -1298,12 +1316,15 @@ function runner_setup!(workspaces, mappings, workspace_root, verbose, kwargs, pl
12981316
rb = filter(s -> s.name == "RustBase", shards)
12991317
rust_version = length(rb) == 1 ? only(rb).version : nothing
13001318

1319+
# Determine version of GCC toolchain.
1320+
gcc = filter(s -> s.name == "GCCBootstrap" && platforms_match(s.target, platform), shards)
1321+
gcc_version = length(gcc) == 1 ? only(gcc).version : nothing
13011322
# Construct environment variables we'll use from here on out
13021323
platform::Platform = get_concrete_platform(platform; compilers..., extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version))...)
13031324
envs::Dict{String,String} = merge(platform_envs(platform, src_name; rust_version, verbose, compilers...), extra_env)
13041325

13051326
# JIT out some compiler wrappers, add it to our mounts
1306-
generate_compiler_wrappers!(platform; bin_path=compiler_wrapper_path, compilers..., extract_kwargs(kwargs, (:allow_unsafe_flags,:lock_microarchitecture))...)
1327+
generate_compiler_wrappers!(platform; bin_path=compiler_wrapper_path, gcc_version, compilers..., extract_kwargs(kwargs, (:allow_unsafe_flags,:lock_microarchitecture))...)
13071328
push!(workspaces, compiler_wrapper_path => "/opt/bin")
13081329

13091330
if isempty(bootstrap_list)

test/runners.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,10 @@ end
126126
# This tests only that compilers for all platforms can build and link simple C code
127127
@testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("cc", "gcc", "clang")
128128
mktempdir() do dir
129-
# https://github.com/JuliaPackaging/BinaryBuilderBase.jl/issues/248
130-
is_broken = compiler == "clang" && Sys.iswindows(platform)
131129
ur = preferred_runner()(dir; platform=platform)
132130
iobuff = IOBuffer()
133131
test_c = """
132+
#include <stdlib.h>
134133
int test(void) {
135134
return 0;
136135
}
@@ -155,18 +154,16 @@ end
155154
$(compiler) -Werror -o main main.c -L. -ltest
156155
"""
157156
cmd = `/bin/bash -c "$(test_script)"`
158-
@test run(ur, cmd, iobuff; tee_stream=devnull) broken=is_broken
157+
@test run(ur, cmd, iobuff)
159158
seekstart(iobuff)
160159
# Make sure `iobuff` contains only the input command, no other text
161-
@test readchomp(iobuff) == string(cmd) broken=is_broken
160+
@test readchomp(iobuff) == string(cmd)
162161
end
163162
end
164163

165164
# This tests only that compilers for all platforms can build and link simple C++ code
166165
@testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("c++", "g++", "clang++")
167166
mktempdir() do dir
168-
# https://github.com/JuliaPackaging/BinaryBuilderBase.jl/issues/248
169-
is_broken = compiler == "clang++" && Sys.iswindows(platform)
170167
ur = preferred_runner()(dir; platform=platform)
171168
iobuff = IOBuffer()
172169
needfpic = Sys.iswindows(platform) ? "" : "-fPIC"
@@ -198,10 +195,10 @@ end
198195
$(compiler) -Werror -std=c++11 -o main main.cpp -L. -ltest
199196
"""
200197
cmd = `/bin/bash -c "$(test_script)"`
201-
@test run(ur, cmd, iobuff; tee_stream=devnull) broken=is_broken
198+
@test run(ur, cmd, iobuff; tee_stream=devnull)
202199
seekstart(iobuff)
203200
# Make sure `iobuff` contains only the input command, no other text
204-
is_broken = is_broken || (compiler == "g++" && Sys.isapple(platform) && arch(platform) == "x86_64")
201+
is_broken = (compiler == "g++" && Sys.isapple(platform) && arch(platform) == "x86_64") # This gets fixed by using GCC7 or up
205202
@test readchomp(iobuff) == string(cmd) broken=is_broken
206203
end
207204
end

0 commit comments

Comments
 (0)