Skip to content

Commit 2f9ebab

Browse files
committed
Toolchains: Add macOS GCC toolchain
This was so much more work than I expected, and it all basically boils down to the fact that my strategth for easily building GCC versions (providing `build -> host` and `build -> target` bootstrap GCC compilers, to then build all `host -> target` combinations) requires a *GCC*, not a `*clang*`, so our LLVMBootstrap is somewhat useless for this. Indeed, I needed to create the `GCCBootstrapMacOS` where I build my own `host -> target` compiler for macOS, tweaking the `GCC` build process slightly in order to make it all work. Sigh. Part of medoesn't care aobut this and says "just get the bootstrapping process done by hook or by crook, it doesn't need to be pretty, you just need to get the actual compilers (e.g. `GCC`) working!" but the wiser part of my brain knows that I'm going to be doing this bootstrapping a few more times in the next decade, and it's better to have a more streamlined process if at all possible.
1 parent a7d092f commit 2f9ebab

11 files changed

+6293
-46
lines changed

BinaryBuilderToolchains.jl/src/toolchains/CToolchain.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -341,21 +341,21 @@ function jll_source_selection(vendor::Symbol, platform::CrossPlatform,
341341
platform.target;
342342
uuid=Base.UUID("465c4c53-7f13-5720-b733-07d6cbd50c3b"),
343343
repo=Pkg.Types.GitRepo(
344-
rev="bb2/GCC",
344+
rev="main",
345345
source="https://github.com/staticfloat/GCC_support_libraries_jll.jl",
346346
),
347-
version=v"9.4.0",
347+
version=v"14.2.0",
348348
target=get_simple_vendor(vendor),
349349
),
350350
JLLSource(
351351
"GCC_crt_objects_jll",
352352
platform.target;
353353
uuid=Base.UUID("7bc14925-bf4e-535d-80f2-90698dc22d13"),
354354
repo=Pkg.Types.GitRepo(
355-
rev="bb2/GCC",
355+
rev="main",
356356
source="https://github.com/staticfloat/GCC_crt_objects_jll.jl",
357357
),
358-
version=v"9.4.0",
358+
version=v"14.2.0",
359359
target=get_simple_vendor(vendor),
360360
),
361361
]
@@ -380,10 +380,10 @@ function jll_source_selection(vendor::Symbol, platform::CrossPlatform,
380380
platform.target;
381381
uuid=Base.UUID("3ba1ab17-c18f-5d2d-9d5a-db37f286de95"),
382382
repo=Pkg.Types.GitRepo(
383-
rev="bb2/GCC",
383+
rev="main",
384384
source="https://github.com/staticfloat/libstdcxx_jll.jl",
385385
),
386-
version=v"9.4.0",
386+
version=v"14.2.0",
387387
target=get_simple_vendor(vendor),
388388
),
389389
]
@@ -476,7 +476,7 @@ function jll_source_selection(vendor::Symbol, platform::CrossPlatform,
476476
rev="bb2/GCCBootstrap-$(triplet(platform.host))",
477477
source="https://github.com/staticfloat/GCCBootstrap_jll.jl"
478478
),
479-
version=v"9.4.0",
479+
version=v"14.2.0",
480480
target="gcc",
481481
))
482482
end
@@ -511,12 +511,12 @@ function jll_source_selection(vendor::Symbol, platform::CrossPlatform,
511511
platform;
512512
uuid=Base.UUID("ec15993a-68c6-5861-8652-ef539d7ffb0b"),
513513
repo=Pkg.Types.GitRepo(
514-
rev="bb2/GCC",
514+
rev="main",
515515
source="https://github.com/staticfloat/GCC_jll.jl",
516516
),
517517
# eventually, include a resolved version
518518
# but for now, we're locked to this specific version
519-
version=v"9.4.0",
519+
version=v"14.2.0",
520520
target="gcc",
521521
),
522522
gcc_support_libs...,

BinaryBuilderToolchains.jl/test/CToolchainTestJLLs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ cxx_csl_libs = [
66
BBHostPlatform();
77
uuid=Base.UUID("3ba1ab17-c18f-5d2d-9d5a-db37f286de95"),
88
repo=Pkg.Types.GitRepo(
9-
rev="bb2/GCC",
9+
rev="main",
1010
source="https://github.com/staticfloat/libstdcxx_jll.jl",
1111
),
12-
version=v"9.4.0",
12+
version=v"14.2.0",
1313
),
1414
JLLSource(
1515
"LLVMLibcxx_jll",

BinaryBuilderToolchains.jl/test/CToolchainTests.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,14 @@ const htt_toolchain = HostToolsToolchain(BBHostPlatform())
151151
end
152152

153153
# Next, run `make compile-all`
154-
cd(joinpath(@__DIR__, "testsuite", "CToolchain")) do
155-
p, output = capture_output(setenv(Cmd(["/bin/bash", "-c", "make clean-all && make compile-all"]), env))
156-
if !success(p)
157-
println(output)
154+
@testset "make compile-all" begin
155+
cd(joinpath(@__DIR__, "testsuite", "CToolchain")) do
156+
p, output = capture_output(setenv(Cmd(["/bin/bash", "-c", "make clean-all && make compile-all"]), env))
157+
if !success(p)
158+
println(output)
159+
end
160+
@test success(p)
158161
end
159-
@test success(p)
160162
end
161163
end
162164
end

bootstrap/GCC/build_tarballs.jl

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using BinaryBuilder2
22

33
include("gcc_common.jl")
44

5-
for version in (v"9.4.0",) #keys(gcc_version_sources)
5+
for version in (v"14.2.0",) #keys(gcc_version_sources)
66
build_tarballs(;
77
src_name = "GCC",
88
src_version = version,
@@ -11,7 +11,7 @@ for version in (v"9.4.0",) #keys(gcc_version_sources)
1111
DirectorySource("./patches-v$(version)"; follow_symlinks=true, target="patches"),
1212
],
1313
script,
14-
platforms,
14+
platforms = gcc_platforms(version),
1515
products = [
1616
FileProduct("bin", :bindir),
1717
ExecutableProduct("\${target}-gcc", :gcc),

bootstrap/GCC/gcc_common.jl

Lines changed: 72 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -108,34 +108,31 @@ const gcc_version_sources = Dict{VersionNumber,Vector}(
108108
ArchiveSource("https://mirrors.kernel.org/gnu/gmp/gmp-6.1.2.tar.xz",
109109
"87b565e89a9a684fe4ebeeddb8399dce2599f9c9049854ca8c0dfbdea0e21912"),
110110
],
111-
v"14.1.0" => [
112-
ArchiveSource("https://mirrors.kernel.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.xz",
113-
"e283c654987afe3de9d8080bc0bd79534b5ca0d681a73a11ff2b5d3767426840"),
111+
v"14.2.0" => [
112+
ArchiveSource("https://mirrors.kernel.org/gnu/gcc/gcc-14.2.0/gcc-14.2.0.tar.xz",
113+
"a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9"),
114114
ArchiveSource("https://mirrors.kernel.org/gnu/mpfr/mpfr-4.1.0.tar.xz",
115115
"0c98a3f1732ff6ca4ea690552079da9c597872d30e96ec28414ee23c95558a7f",
116-
target="gcc-14.1.0"),
116+
target="gcc-14.2.0"),
117117
ArchiveSource("https://mirrors.kernel.org/gnu/mpc/mpc-1.2.1.tar.gz",
118118
"17503d2c395dfcf106b622dc142683c1199431d095367c6aacba6eec30340459",
119-
target="gcc-14.1.0"),
119+
target="gcc-14.2.0"),
120120
ArchiveSource("https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.24.tar.bz2",
121121
"fcf78dd9656c10eb8cf9fbd5f59a0b6b01386205fe1934b3b287a0a1898145c0",
122-
target="gcc-14.1.0"),
122+
target="gcc-14.2.0"),
123123
ArchiveSource("https://mirrors.kernel.org/gnu/gmp/gmp-6.2.1.tar.xz",
124124
"fd4829912cddd12f84181c3451cc752be224643e87fac497b69edddadc49b4f2",
125-
target="gcc-14.1.0"),
125+
target="gcc-14.2.0"),
126126
],
127127
)
128128

129129

130130
script = raw"""
131131
cd ${WORKSPACE}/srcdir
132132
133-
# Move all `target` dependencies over to the `host` prefix,
134-
# because we need those deps available in the `host` prefix
135-
136133
# Figure out the GCC version from the directory name
137134
gcc_version="$(echo gcc-* | cut -d- -f2)"
138-
if [[ "${target}" != *mingw* ]]; then
135+
if [[ "${target}" != *mingw* ]] && [[ "${target}" != *darwin* ]]; then
139136
lib64="lib${target_nbits%32}"
140137
else
141138
lib64="lib"
@@ -151,6 +148,14 @@ done
151148
# Initialize GCC_CONF_ARGS
152149
GCC_CONF_ARGS=()
153150
151+
## If we're doing a bootstrapping build (GCC does not, GCCBootstrapMacOS does)
152+
# add in the appropriate configure arguments:
153+
if [[ "${GCC_ENABLE_BOOTSTRAP:-false}" == "true" ]]; then
154+
GCC_CONF_ARGS+=( --enable-bootstrap )
155+
else
156+
GCC_CONF_ARGS+=( --disable-bootstrap )
157+
fi
158+
154159
## Architecture-dependent arguments
155160
# Choose a default arch, and on arm*hf targets, pass `--with-float=hard` explicitly
156161
if [[ "${target}" == arm*hf ]]; then
@@ -194,6 +199,16 @@ elif [[ "${target}" == *-darwin* ]]; then
194199
# that are available only starting in later macOS versions such as `clock_gettime` or `mkostemp`
195200
export ac_cv_func_clock_gettime=no
196201
export ac_cv_func_mkostemp=no
202+
203+
# Force GCC to use its own libiconv, don't use Apple's
204+
ICONV_PATHS=(
205+
/opt/target-*
206+
${target_prefix}
207+
)
208+
if [[ "${host}" == *-darwin* ]]; then
209+
ICONV_PATHS+=( /opt/host-* )
210+
fi
211+
find ${ICONV_PATHS[@]} -name iconv.h -o -name libiconv\* | xargs rm -fv
197212
fi
198213
199214
# Get rid of version numbers at the end of GCC deps
@@ -228,9 +243,12 @@ for TOOL in CC CPP CXX AS AR NM LD RANLIB; do
228243
export ${TOOL}_FOR_TARGET=${!TARGET_NAME}
229244
230245
# These target tool autodetections do not work
231-
export ac_cv_path_${TOOL}_FOR_TARGET=${!TARGET_NAME}
246+
#export ac_cv_path_${TOOL}_FOR_TARGET=${!TARGET_NAME}
232247
done
233248
249+
# libcc1 fails with an error about `-rdynamic` unless we defien this
250+
export gcc_cv_nm="${NM_FOR_TARGET}"
251+
234252
# Make sure the tools that GCC itself wants to use ("ld", "as", "dysmutil") are available
235253
# not just as "host-ld" or "host-as", etc... Otherwise, the `collect2` we generate looks
236254
# for these names. This lovely mess of bash results in `--with-ld=x86_64-linux-gnu-ld`
@@ -252,7 +270,6 @@ $WORKSPACE/srcdir/gcc-*/configure \
252270
--target="${target}" \
253271
--disable-multilib \
254272
--disable-werror \
255-
--disable-bootstrap \
256273
--enable-threads=posix \
257274
--enable-languages=c,c++ \
258275
--with-build-sysroot="${target_prefix}/${target}" \
@@ -275,6 +292,16 @@ install_license ${WORKSPACE}/srcdir/gcc-*/COPYING*
275292
"""
276293

277294
function gcc_extract_spec_generator(build::BuildConfig, platform::AbstractPlatform)
295+
gcc_crt_object_names = ["libgcc.a"]
296+
if Sys.isapple(platform.target)
297+
append!(gcc_crt_object_names, ["crttms.o", "crt3.o"])
298+
else
299+
append!(gcc_crt_object_names, ["crtbegin.o", "crtend.o"])
300+
end
301+
gcc_crt_object_products = [
302+
FileProduct([string(raw"lib/gcc/${target}/${gcc_version}/", name)],
303+
Symbol(replace(name, "." => "_"))) for name in gcc_crt_object_names
304+
]
278305
return Dict(
279306
"libstdcxx" => ExtractSpec(
280307
raw"""
@@ -312,11 +339,7 @@ function gcc_extract_spec_generator(build::BuildConfig, platform::AbstractPlatfo
312339
raw"""
313340
extract ${prefix}/lib/gcc/${target}/${gcc_version}
314341
""",
315-
[
316-
FileProduct([raw"lib/gcc/${target}/${gcc_version}/crtbegin.o"], :crtbegin_o),
317-
FileProduct([raw"lib/gcc/${target}/${gcc_version}/crtend.o"], :crtend_o),
318-
FileProduct([raw"lib/gcc/${target}/${gcc_version}/libgcc.a"], :libgcc_a),
319-
],
342+
gcc_crt_object_products,
320343
get_target_spec_by_name(build, "host");
321344
platform = platform.target,
322345
),
@@ -369,14 +392,25 @@ target_platforms = [
369392

370393
Platform("x86_64", "windows"),
371394
Platform("i686", "windows"),
395+
396+
Platform("x86_64", "macos"),
397+
Platform("aarch64", "macos"),
372398
]
373399

374-
platforms = vcat(
375-
# Build cross-gcc from `host => target`
376-
(CrossPlatform(host, target) for host in host_platforms, target in target_platforms if host != target)...,
377-
# Build native gcc for all targets as well
378-
(CrossPlatform(target, target) for target in target_platforms)...,
379-
)
400+
function gcc_platforms(version::VersionNumber)
401+
platforms = vcat(
402+
# Build cross-gcc from `host => target`
403+
(CrossPlatform(host, target) for host in host_platforms, target in target_platforms if host != target)...,
404+
# Build native gcc for all targets as well
405+
(CrossPlatform(target, target) for target in target_platforms)...,
406+
)
407+
# aarch64-apple-darwin can't be targeted by GCC versions before
408+
# Iain Sandoe's legendary porting effort.
409+
if version < v"12"
410+
filter!(p -> !(os(p) == "macos" && arch(p) == "aarch64"), platforms)
411+
end
412+
return platforms
413+
end
380414

381415
function gcc_build_spec_generator(host, platform)
382416
target_str = triplet(gcc_platform(platform.target))
@@ -436,6 +470,17 @@ function gcc_build_spec_generator(host, platform)
436470
),
437471
target=target_str,
438472
))
473+
elseif os(platform.target) == "macos"
474+
push!(target_sources, JLLSource(
475+
"macOSSDK_jll",
476+
platform.target;
477+
uuid=Base.UUID("52f8e75f-aed1-5264-b4c9-b8da5a6d5365"),
478+
repo=Pkg.Types.GitRepo(
479+
rev="main",
480+
source="https://github.com/staticfloat/macOSSDK_jll.jl"
481+
),
482+
target=target_str,
483+
))
439484
else
440485
throw(ArgumentError("Don't know how to install libc sources for $(triplet(platform.target))"))
441486
end
@@ -444,21 +489,21 @@ function gcc_build_spec_generator(host, platform)
444489
BuildTargetSpec(
445490
"build",
446491
CrossPlatform(host => host),
447-
[CToolchain(; vendor=:bootstrap, lock_microarchitecture), HostToolsToolchain()],
492+
[CToolchain(; vendor=:gcc_bootstrap, lock_microarchitecture), HostToolsToolchain()],
448493
[],
449494
Set([:host]),
450495
),
451496
BuildTargetSpec(
452497
"host",
453498
CrossPlatform(host => platform.host),
454-
[CToolchain(; vendor=:bootstrap, lock_microarchitecture)],
499+
[CToolchain(; vendor=:gcc_bootstrap, lock_microarchitecture)],
455500
[],
456501
Set([:default]),
457502
),
458503
BuildTargetSpec(
459504
"target",
460505
CrossPlatform(host => platform.target),
461-
[CToolchain(; vendor=:bootstrap, lock_microarchitecture)],
506+
[CToolchain(; vendor=:gcc_bootstrap, lock_microarchitecture)],
462507
target_sources,
463508
Set([]),
464509
),

bootstrap/GCC/patches-v14.1.0/gcc-901-gxx_include_dir.patch

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)