Skip to content

Commit 0ac7808

Browse files
giordanostaticfloat
authored andcommitted
Simplify preferred_libgfortran_version and preferred_cxxstring_abi (#623)
1 parent c12e784 commit 0ac7808

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

src/Rootfs.jl

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -336,16 +336,20 @@ LLVMBuild(v::VersionNumber) = LLVMBuild(v, CompilerABI())
336336
getversion(c::CompilerBuild) = c.version
337337
getabi(c::CompilerBuild) = c.abi
338338

339-
const available_gcc_builds = [GCCBuild(v"4.8.5", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.19", cxxstring_abi = :cxx03)),
340-
GCCBuild(v"5.2.0", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.21", cxxstring_abi = :cxx11)),
341-
GCCBuild(v"6.1.0", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.22", cxxstring_abi = :cxx11)),
342-
GCCBuild(v"7.1.0", CompilerABI(libgfortran_version = v"4", libstdcxx_version = v"3.4.23", cxxstring_abi = :cxx11)),
343-
GCCBuild(v"8.1.0", CompilerABI(libgfortran_version = v"5", libstdcxx_version = v"3.4.25", cxxstring_abi = :cxx11)),
344-
GCCBuild(v"9.1.0", CompilerABI(libgfortran_version = v"5", libstdcxx_version = v"3.4.26", cxxstring_abi = :cxx11))]
345-
const available_llvm_builds = [LLVMBuild(v"6.0.1"),
346-
LLVMBuild(v"7.1.0"),
347-
LLVMBuild(v"8.0.1"),
348-
LLVMBuild(v"9.0.1")]
339+
const available_gcc_builds = [
340+
GCCBuild(v"4.8.5", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.19", cxxstring_abi = :cxx03)),
341+
GCCBuild(v"5.2.0", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.21", cxxstring_abi = :cxx11)),
342+
GCCBuild(v"6.1.0", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.22", cxxstring_abi = :cxx11)),
343+
GCCBuild(v"7.1.0", CompilerABI(libgfortran_version = v"4", libstdcxx_version = v"3.4.23", cxxstring_abi = :cxx11)),
344+
GCCBuild(v"8.1.0", CompilerABI(libgfortran_version = v"5", libstdcxx_version = v"3.4.25", cxxstring_abi = :cxx11)),
345+
GCCBuild(v"9.1.0", CompilerABI(libgfortran_version = v"5", libstdcxx_version = v"3.4.26", cxxstring_abi = :cxx11)),
346+
]
347+
const available_llvm_builds = [
348+
LLVMBuild(v"6.0.1"),
349+
LLVMBuild(v"7.1.0"),
350+
LLVMBuild(v"8.0.1"),
351+
LLVMBuild(v"9.0.1"),
352+
]
349353

350354
"""
351355
gcc_version(cabi::CompilerABI, GCC_builds::Vector{GCCBuild})
@@ -598,11 +602,13 @@ function expand_cxxstring_abis(ps::Vector{<:Platform})
598602
end
599603

600604
"""
601-
preferred_libgfortran_version(platform::Platform, shard::CompilerShard)
605+
preferred_libgfortran_version(platform::Platform, shard::CompilerShard;
606+
gcc_builds::Vector{GCCBuild} = available_gcc_builds)
602607
603608
Return the libgfortran version preferred by the given platform or GCCBootstrap shard.
604609
"""
605-
function preferred_libgfortran_version(platform::Platform, shard::CompilerShard)
610+
function preferred_libgfortran_version(platform::Platform, shard::CompilerShard;
611+
gcc_builds::Vector{GCCBuild} = available_gcc_builds)
606612
# Some input validation
607613
if shard.name != "GCCBootstrap"
608614
error("Shard must be `GCCBootstrap`")
@@ -615,21 +621,24 @@ function preferred_libgfortran_version(platform::Platform, shard::CompilerShard)
615621
# Here we can't use `shard.target` because the shard always has the
616622
# target as ABI-agnostic, thus we have also to ask for the platform.
617623
return compiler_abi(platform).libgfortran_version
618-
elseif shard.version < v"7"
619-
return v"3"
620-
elseif v"7" <= shard.version < v"8"
621-
return v"4"
622624
else
623-
return v"5"
625+
idx = findfirst(b -> getversion(b) == shard.version, available_gcc_builds)
626+
if isnothing(idx)
627+
error("The shard doesn't match any version of the avaiable GCC builds")
628+
else
629+
return getabi(gcc_builds[idx]).libgfortran_version
630+
end
624631
end
625632
end
626633

627634
"""
628-
preferred_cxxstring_abi(platform::Platform, shard::CompilerShard)
635+
preferred_cxxstring_abi(platform::Platform, shard::CompilerShard;
636+
gcc_builds::Vector{GCCBuild} = available_gcc_builds)
629637
630638
Return the C++ string ABI preferred by the given platform or GCCBootstrap shard.
631639
"""
632-
function preferred_cxxstring_abi(platform::Platform, shard::CompilerShard)
640+
function preferred_cxxstring_abi(platform::Platform, shard::CompilerShard;
641+
gcc_builds::Vector{GCCBuild} = available_gcc_builds)
633642
# Some input validation
634643
if shard.name != "GCCBootstrap"
635644
error("Shard must be `GCCBootstrap`")
@@ -642,10 +651,13 @@ function preferred_cxxstring_abi(platform::Platform, shard::CompilerShard)
642651
# Here we can't use `shard.target` because the shard always has the
643652
# target as ABI-agnostic, thus we have also to ask for the platform.
644653
return compiler_abi(platform).cxxstring_abi
645-
elseif shard.version < v"5"
646-
return :cxx03
647654
else
648-
return :cxx11
655+
idx = findfirst(b -> getversion(b) == shard.version, available_gcc_builds)
656+
if isnothing(idx)
657+
error("The shard doesn't match any version of the avaiable GCC builds")
658+
else
659+
return getabi(gcc_builds[idx]).cxxstring_abi
660+
end
649661
end
650662
end
651663

test/basic.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,10 @@ end
322322
shard = CompilerShard("GCCBootstrap", v"5.2.0", Linux(:x86_64, libc=:musl), :squashfs, target = platform)
323323
@test preferred_libgfortran_version(platform, shard) == v"3"
324324
@test preferred_cxxstring_abi(platform, shard) == :cxx11
325-
shard = CompilerShard("GCCBootstrap", v"7.10.0", Linux(:x86_64, libc=:musl), :squashfs, target = platform)
325+
shard = CompilerShard("GCCBootstrap", v"7.1.0", Linux(:x86_64, libc=:musl), :squashfs, target = platform)
326326
@test preferred_libgfortran_version(platform, shard) == v"4"
327327
@test preferred_cxxstring_abi(platform, shard) == :cxx11
328-
shard = CompilerShard("GCCBootstrap", v"9.10.0", Linux(:x86_64, libc=:musl), :squashfs, target = platform)
328+
shard = CompilerShard("GCCBootstrap", v"9.1.0", Linux(:x86_64, libc=:musl), :squashfs, target = platform)
329329
@test preferred_libgfortran_version(platform, shard) == v"5"
330330
@test preferred_cxxstring_abi(platform, shard) == :cxx11
331331
shard = CompilerShard("LLVMBootstrap", v"4.8.5", Linux(:x86_64, libc=:musl), :squashfs)
@@ -336,6 +336,9 @@ end
336336
@test_throws ErrorException preferred_libgfortran_version(platform, shard)
337337
shard = CompilerShard("GCCBootstrap", v"4.8.5", Linux(:x86_64, libc=:musl), :squashfs, target = Linux(:x86_64, libc=:glibc))
338338
@test_throws ErrorException preferred_cxxstring_abi(platform, shard)
339+
shard = CompilerShard("GCCBootstrap", v"1.2.3", Linux(:x86_64, libc=:musl), :squashfs, target = Windows(:x86_64))
340+
@test_throws ErrorException preferred_cxxstring_abi(platform, shard)
341+
@test_throws ErrorException preferred_libgfortran_version(platform, shard)
339342

340343
# With no constraints, we should get them all back
341344
@test gcc_version(CompilerABI(), available_gcc_builds) == getversion.(available_gcc_builds)

0 commit comments

Comments
 (0)