Skip to content

Commit

Permalink
Simplify preferred_libgfortran_version and preferred_cxxstring_abi (
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano authored and staticfloat committed Jan 22, 2020
1 parent c12e784 commit 0ac7808
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
56 changes: 34 additions & 22 deletions src/Rootfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,20 @@ LLVMBuild(v::VersionNumber) = LLVMBuild(v, CompilerABI())
getversion(c::CompilerBuild) = c.version
getabi(c::CompilerBuild) = c.abi

const available_gcc_builds = [GCCBuild(v"4.8.5", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.19", cxxstring_abi = :cxx03)),
GCCBuild(v"5.2.0", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.21", cxxstring_abi = :cxx11)),
GCCBuild(v"6.1.0", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.22", cxxstring_abi = :cxx11)),
GCCBuild(v"7.1.0", CompilerABI(libgfortran_version = v"4", libstdcxx_version = v"3.4.23", cxxstring_abi = :cxx11)),
GCCBuild(v"8.1.0", CompilerABI(libgfortran_version = v"5", libstdcxx_version = v"3.4.25", cxxstring_abi = :cxx11)),
GCCBuild(v"9.1.0", CompilerABI(libgfortran_version = v"5", libstdcxx_version = v"3.4.26", cxxstring_abi = :cxx11))]
const available_llvm_builds = [LLVMBuild(v"6.0.1"),
LLVMBuild(v"7.1.0"),
LLVMBuild(v"8.0.1"),
LLVMBuild(v"9.0.1")]
const available_gcc_builds = [
GCCBuild(v"4.8.5", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.19", cxxstring_abi = :cxx03)),
GCCBuild(v"5.2.0", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.21", cxxstring_abi = :cxx11)),
GCCBuild(v"6.1.0", CompilerABI(libgfortran_version = v"3", libstdcxx_version = v"3.4.22", cxxstring_abi = :cxx11)),
GCCBuild(v"7.1.0", CompilerABI(libgfortran_version = v"4", libstdcxx_version = v"3.4.23", cxxstring_abi = :cxx11)),
GCCBuild(v"8.1.0", CompilerABI(libgfortran_version = v"5", libstdcxx_version = v"3.4.25", cxxstring_abi = :cxx11)),
GCCBuild(v"9.1.0", CompilerABI(libgfortran_version = v"5", libstdcxx_version = v"3.4.26", cxxstring_abi = :cxx11)),
]
const available_llvm_builds = [
LLVMBuild(v"6.0.1"),
LLVMBuild(v"7.1.0"),
LLVMBuild(v"8.0.1"),
LLVMBuild(v"9.0.1"),
]

"""
gcc_version(cabi::CompilerABI, GCC_builds::Vector{GCCBuild})
Expand Down Expand Up @@ -598,11 +602,13 @@ function expand_cxxstring_abis(ps::Vector{<:Platform})
end

"""
preferred_libgfortran_version(platform::Platform, shard::CompilerShard)
preferred_libgfortran_version(platform::Platform, shard::CompilerShard;
gcc_builds::Vector{GCCBuild} = available_gcc_builds)
Return the libgfortran version preferred by the given platform or GCCBootstrap shard.
"""
function preferred_libgfortran_version(platform::Platform, shard::CompilerShard)
function preferred_libgfortran_version(platform::Platform, shard::CompilerShard;
gcc_builds::Vector{GCCBuild} = available_gcc_builds)
# Some input validation
if shard.name != "GCCBootstrap"
error("Shard must be `GCCBootstrap`")
Expand All @@ -615,21 +621,24 @@ function preferred_libgfortran_version(platform::Platform, shard::CompilerShard)
# Here we can't use `shard.target` because the shard always has the
# target as ABI-agnostic, thus we have also to ask for the platform.
return compiler_abi(platform).libgfortran_version
elseif shard.version < v"7"
return v"3"
elseif v"7" <= shard.version < v"8"
return v"4"
else
return v"5"
idx = findfirst(b -> getversion(b) == shard.version, available_gcc_builds)
if isnothing(idx)
error("The shard doesn't match any version of the avaiable GCC builds")
else
return getabi(gcc_builds[idx]).libgfortran_version
end
end
end

"""
preferred_cxxstring_abi(platform::Platform, shard::CompilerShard)
preferred_cxxstring_abi(platform::Platform, shard::CompilerShard;
gcc_builds::Vector{GCCBuild} = available_gcc_builds)
Return the C++ string ABI preferred by the given platform or GCCBootstrap shard.
"""
function preferred_cxxstring_abi(platform::Platform, shard::CompilerShard)
function preferred_cxxstring_abi(platform::Platform, shard::CompilerShard;
gcc_builds::Vector{GCCBuild} = available_gcc_builds)
# Some input validation
if shard.name != "GCCBootstrap"
error("Shard must be `GCCBootstrap`")
Expand All @@ -642,10 +651,13 @@ function preferred_cxxstring_abi(platform::Platform, shard::CompilerShard)
# Here we can't use `shard.target` because the shard always has the
# target as ABI-agnostic, thus we have also to ask for the platform.
return compiler_abi(platform).cxxstring_abi
elseif shard.version < v"5"
return :cxx03
else
return :cxx11
idx = findfirst(b -> getversion(b) == shard.version, available_gcc_builds)
if isnothing(idx)
error("The shard doesn't match any version of the avaiable GCC builds")
else
return getabi(gcc_builds[idx]).cxxstring_abi
end
end
end

Expand Down
7 changes: 5 additions & 2 deletions test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ end
shard = CompilerShard("GCCBootstrap", v"5.2.0", Linux(:x86_64, libc=:musl), :squashfs, target = platform)
@test preferred_libgfortran_version(platform, shard) == v"3"
@test preferred_cxxstring_abi(platform, shard) == :cxx11
shard = CompilerShard("GCCBootstrap", v"7.10.0", Linux(:x86_64, libc=:musl), :squashfs, target = platform)
shard = CompilerShard("GCCBootstrap", v"7.1.0", Linux(:x86_64, libc=:musl), :squashfs, target = platform)
@test preferred_libgfortran_version(platform, shard) == v"4"
@test preferred_cxxstring_abi(platform, shard) == :cxx11
shard = CompilerShard("GCCBootstrap", v"9.10.0", Linux(:x86_64, libc=:musl), :squashfs, target = platform)
shard = CompilerShard("GCCBootstrap", v"9.1.0", Linux(:x86_64, libc=:musl), :squashfs, target = platform)
@test preferred_libgfortran_version(platform, shard) == v"5"
@test preferred_cxxstring_abi(platform, shard) == :cxx11
shard = CompilerShard("LLVMBootstrap", v"4.8.5", Linux(:x86_64, libc=:musl), :squashfs)
Expand All @@ -336,6 +336,9 @@ end
@test_throws ErrorException preferred_libgfortran_version(platform, shard)
shard = CompilerShard("GCCBootstrap", v"4.8.5", Linux(:x86_64, libc=:musl), :squashfs, target = Linux(:x86_64, libc=:glibc))
@test_throws ErrorException preferred_cxxstring_abi(platform, shard)
shard = CompilerShard("GCCBootstrap", v"1.2.3", Linux(:x86_64, libc=:musl), :squashfs, target = Windows(:x86_64))
@test_throws ErrorException preferred_cxxstring_abi(platform, shard)
@test_throws ErrorException preferred_libgfortran_version(platform, shard)

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

0 comments on commit 0ac7808

Please sign in to comment.