-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathrootfs.jl
297 lines (275 loc) · 17.8 KB
/
rootfs.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
using Test
using Base.BinaryPlatforms
using BinaryBuilderBase
using BinaryBuilderBase: RustBuild, CompilerShard
@testset "Expand platforms" begin
# expand_gfortran_versions
@test expand_gfortran_versions(Platform("i686", "windows")) == [
Platform("i686", "windows"; libgfortran_version=v"3"),
Platform("i686", "windows"; libgfortran_version=v"4"),
Platform("i686", "windows"; libgfortran_version=v"5"),
]
@test expand_gfortran_versions([Platform("i686", "windows"), Platform("x86_64", "windows")]) == [
Platform("i686", "windows"; libgfortran_version=v"3"),
Platform("i686", "windows"; libgfortran_version=v"4"),
Platform("i686", "windows"; libgfortran_version=v"5"),
Platform("x86_64", "windows"; libgfortran_version=v"3"),
Platform("x86_64", "windows"; libgfortran_version=v"4"),
Platform("x86_64", "windows"; libgfortran_version=v"5"),
]
@test expand_gfortran_versions([Platform("x86_64", "freebsd"; libgfortran_version=v"3")]) ==
[Platform("x86_64", "freebsd"; libgfortran_version=v"3")]
@test expand_gfortran_versions([Platform("x86_64", "macos"), Platform("aarch64", "macos")]) == [
Platform("x86_64", "macos"; libgfortran_version=v"3"),
Platform("x86_64", "macos"; libgfortran_version=v"4"),
Platform("x86_64", "macos"; libgfortran_version=v"5"),
Platform("aarch64", "macos"; libgfortran_version=v"5"),
]
@test expand_gfortran_versions(Platform("aarch64", "freebsd")) == [
Platform("aarch64", "freebsd"; libgfortran_version=v"4"),
Platform("aarch64", "freebsd"; libgfortran_version=v"5"),
]
@test expand_gfortran_versions([Platform("x86_64", "linux"; sanitize="memory")]) ==
[Platform("x86_64", "linux"; sanitize="memory")]
@test expand_gfortran_versions(Platform[]) isa Vector{Platform}
# expand_cxxstring_abis
@test expand_cxxstring_abis(Platform("x86_64", "linux"; libc="musl")) == [
Platform("x86_64", "linux", libc="musl", cxxstring_abi="cxx03"),
Platform("x86_64", "linux", libc="musl", cxxstring_abi="cxx11"),
]
@test expand_cxxstring_abis([Platform("x86_64", "freebsd"), Platform("x86_64", "macos")]) == [
Platform("x86_64", "freebsd"),
Platform("x86_64", "macos"),
]
@test expand_cxxstring_abis([Platform("x86_64", "freebsd"), Platform("x86_64", "macos")]; skip=_->false) == [
Platform("x86_64", "freebsd"; cxxstring_abi="cxx03"),
Platform("x86_64", "freebsd"; cxxstring_abi="cxx11"),
Platform("x86_64", "macos"; cxxstring_abi="cxx03"),
Platform("x86_64", "macos"; cxxstring_abi="cxx11"),
]
@test expand_cxxstring_abis([Platform("x86_64", "freebsd"), Platform("x86_64", "linux")]; skip=Sys.islinux) == [
Platform("x86_64", "freebsd"; cxxstring_abi="cxx03"),
Platform("x86_64", "freebsd"; cxxstring_abi="cxx11"),
Platform("x86_64", "linux"),
]
@test expand_cxxstring_abis([Platform("i686", "linux"; cxxstring_abi="cxx11")]) ==
[Platform("i686", "linux"; cxxstring_abi="cxx11")]
@test expand_cxxstring_abis([Platform("x86_64", "linux"; sanitize="memory")]) ==
[Platform("x86_64", "linux"; sanitize="memory", cxxstring_abi="cxx11")]
@test expand_cxxstring_abis(Platform[]) isa Vector{Platform}
# expand_microarchitectures
@test expand_microarchitectures([AnyPlatform()]) == [AnyPlatform()]
@test sort(expand_microarchitectures(Platform("x86_64", "linux"; cuda="10.1")), by=triplet) == [
Platform("x86_64", "linux"; libc="glibc", march="avx", cuda="10.1"),
Platform("x86_64", "linux"; libc="glibc", march="avx2", cuda="10.1"),
Platform("x86_64", "linux"; libc="glibc", march="avx512", cuda="10.1"),
Platform("x86_64", "linux"; libc="glibc", march="x86_64", cuda="10.1"),
]
@test sort(expand_microarchitectures(Platform("x86_64", "linux"), ["x86_64", "avx512"]), by=triplet) == [
Platform("x86_64", "linux"; libc="glibc", march="avx512"),
Platform("x86_64", "linux"; libc="glibc", march="x86_64"),
]
@test expand_microarchitectures(Platform("i686", "linux"), ["x86_64", "avx512"]) == [Platform("i686", "linux")]
@test expand_microarchitectures(Platform("aarch64", "linux"; libc="musl"), ["a64fx", "apple_m1"]) == [Platform("aarch64", "linux"; libc="musl")]
@test expand_microarchitectures(Platform("aarch64", "macos"), ["a64fx"]) == [Platform("aarch64", "macos")]
@test sort(expand_microarchitectures(filter!(p -> Sys.islinux(p) && libc(p) == "glibc", supported_platforms())), by=triplet) == [
Platform("aarch64", "linux"; libc="glibc", march="a64fx"),
Platform("aarch64", "linux"; libc="glibc", march="armv8_0"),
Platform("aarch64", "linux"; libc="glibc", march="armv8_1"),
Platform("aarch64", "linux"; libc="glibc", march="armv8_2_crypto"),
Platform("armv6l", "linux"; libc="glibc", call_abi="eabihf", march="arm1176jzfs"),
Platform("armv7l", "linux"; libc="glibc", call_abi="eabihf", march="armv7l"),
Platform("armv7l", "linux"; libc="glibc", call_abi="eabihf", march="neonvfpv4"),
Platform("i686", "linux"; libc="glibc", march="pentium4"),
Platform("i686", "linux"; libc="glibc", march="prescott"),
Platform("powerpc64le", "linux"; libc="glibc", march="power8"),
Platform("riscv64", "linux"; libc="glibc", march="riscv64"),
Platform("x86_64", "linux"; libc="glibc", march="avx"),
Platform("x86_64", "linux"; libc="glibc", march="avx2"),
Platform("x86_64", "linux"; libc="glibc", march="avx512"),
Platform("x86_64", "linux"; libc="glibc", march="x86_64"),
]
@test sort(expand_microarchitectures(filter!(p -> Sys.islinux(p) && libc(p) == "musl", supported_platforms()); filter=p->arch(p) == "aarch64"), by=triplet) == [
Platform("aarch64", "linux"; libc="musl", march="armv8_0"),
Platform("aarch64", "linux"; libc="musl", march="armv8_1"),
Platform("aarch64", "linux"; libc="musl", march="armv8_2_crypto"),
Platform("armv6l", "linux"; call_abi="eabihf", libc="musl"),
Platform("armv7l", "linux"; call_abi="eabihf", libc="musl"),
Platform("i686", "linux"; libc="musl"),
Platform("x86_64", "linux"; libc="musl"),
]
@test sort(expand_microarchitectures(filter!(p -> Sys.isapple(p), supported_platforms()), ["a64fx", "apple_m1", "x86_64", "avx2"]), by=triplet) == [
Platform("aarch64", "macos"; march="apple_m1"),
Platform("x86_64", "macos"; march="avx2"),
Platform("x86_64", "macos"; march="x86_64"),
]
@test expand_microarchitectures([Platform("x86_64", "windows"; march="avx", cuda="10.1")]) ==
[Platform("x86_64", "windows"; march="avx", cuda="10.1")]
# All of them together!
@test all(in(expand_microarchitectures(expand_gfortran_versions(expand_cxxstring_abis(supported_platforms())))),
expand_cxxstring_abis(expand_gfortran_versions(expand_microarchitectures(supported_platforms()))))
end
@testset "Compiler Shards" begin
@test_throws ErrorException CompilerShard("GCCBootstrap", v"4", Platform("x86_64", "linux"), :invalid_archive_type)
@testset "Rust toolchain selection" begin
platform = Platform("x86_64", "linux")
common_opts = (preferred_gcc_version=v"9", compilers=[:c, :rust])
shards = choose_shards(platform; preferred_rust_version = v"1.73", (common_opts)... )
@test filter(s-> s.name == "RustBase", shards)[end].version == v"1.73"
@test filter(s-> s.name == "RustToolchain", shards)[end].version == v"1.73"
@test_throws ErrorException choose_shards(platform; preferred_rust_version = v"1.78", (common_opts)...)
end
@testset "Go toolchain selection" begin
platform = Platform("x86_64", "linux")
common_opts = (preferred_gcc_version=v"9", compilers=[:c, :go])
shards = choose_shards(platform; preferred_go_version = v"1.13", (common_opts)... )
@test filter(s-> s.name == "Go", shards)[end].version == v"1.13"
# 1.14 was never added, so use that as the testcase here
@test_throws ErrorException choose_shards(platform; preferred_go_version = v"1.14", (common_opts)...)
end
@testset "GCC ABI matching" begin
# Preferred libgfortran version and C++ string ABI
platform = Platform("x86_64", "freebsd")
shard = CompilerShard("GCCBootstrap", v"4.8.5", Platform("x86_64", "linux"; libc="musl"), :squashfs, target = platform)
@test preferred_libgfortran_version(platform, shard) == v"3"
@test preferred_cxxstring_abi(platform, shard) == "cxx03"
shard = CompilerShard("GCCBootstrap", v"5.2.0", Platform("x86_64", "linux"; 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.1.0", Platform("x86_64", "linux"; 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.1.0", Platform("x86_64", "linux"; 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", Platform("x86_64", "linux"; libc="musl"), :squashfs)
@test_throws ErrorException preferred_libgfortran_version(platform, shard)
@test_throws ErrorException preferred_cxxstring_abi(platform, shard)
platform = Platform("x86_64", "linux"; libc="musl")
shard = CompilerShard("GCCBootstrap", v"4.8.5", Platform("x86_64", "linux"; libc="musl"), :squashfs, target = Platform("x86_64", "macos"))
@test_throws ErrorException preferred_libgfortran_version(platform, shard)
shard = CompilerShard("GCCBootstrap", v"4.8.5", Platform("x86_64", "linux"; libc="musl"), :squashfs, target = Platform("x86_64", "linux"; libc="glibc"))
@test_throws ErrorException preferred_cxxstring_abi(platform, shard)
shard = CompilerShard("GCCBootstrap", v"1.2.3", Platform("x86_64", "linux"; libc="musl"), :squashfs, target = Platform("x86_64", "windows"))
@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(Platform("x86_64", "linux"), available_gcc_builds) == getversion.(available_gcc_builds)
# Filter for FreeBSD. No version of LLVM is specified, all versions
# should be available
@test gcc_version(Platform("x86_64", "freebsd"), available_gcc_builds) == getversion.(available_gcc_builds)
# With LLVM 11 all versions of GCC are still allowed
@test gcc_version(Platform("x86_64", "freebsd"), available_gcc_builds; llvm_version=v"11") == getversion.(available_gcc_builds)
# With LLVM 12 we can only use GCC 6+
@test gcc_version(Platform("x86_64", "freebsd"), available_gcc_builds; llvm_version=v"12") ==
filter(≥(v"6"), getversion.(available_gcc_builds))
# We can only use GCC 7+ on AArch64
@test gcc_version(Platform("aarch64", "freebsd"), available_gcc_builds) ==
filter(≥(v"7"), getversion.(available_gcc_builds))
# libgfortran v3 and libstdcxx 22 restrict us to only v4.8, v5.2 and v6.1
p = Platform("x86_64", "linux"; libgfortran_version=v"3", libstdcxx_version=v"3.4.22")
@test gcc_version(p, available_gcc_builds) == [v"4.8.5", v"5.2.0", v"6.1.0"]
p["march"] = "avx"
@test gcc_version(p, available_gcc_builds) == [v"5.2.0", v"6.1.0"]
# Adding `"cxx11"` eliminates `v"4.X"`:
p = Platform("x86_64", "linux"; libgfortran_version=v"3", cxxstring_abi="cxx11")
@test gcc_version(p, available_gcc_builds) == [v"5.2.0", v"6.1.0"]
# AVX-512 requires GCC 7
p = Platform("x86_64", "linux"; cxxstring_abi="cxx11", march = "avx512")
@test first(sort!(gcc_version(p, available_gcc_builds))) == v"7.1.0"
# Just libgfortran v3 allows GCC 6 as well though
p = Platform("x86_64", "linux"; libgfortran_version=v"3")
@test gcc_version(p, available_gcc_builds) == [v"4.8.5", v"5.2.0", v"6.1.0"]
# Test libgfortran version v4, then splitting on libstdcxx_version:
p = Platform("x86_64", "linux"; libgfortran_version=v"4")
@test gcc_version(p, available_gcc_builds) == [v"7.1.0"]
p = Platform("x86_64", "linux"; libgfortran_version=v"4", libstdcxx_version=v"3.4.23")
@test gcc_version(p, available_gcc_builds) == [v"7.1.0"]
p = Platform("aarch64", "linux"; libgfortran_version=v"4", libstdcxx_version=v"3.4.23", march="thunderx2")
@test gcc_version(p, available_gcc_builds) == [v"7.1.0"]
p = Platform("armv7l", "linux"; march="neonvfpv4")
@test gcc_version(p, available_gcc_builds) == [v"5.2.0", v"6.1.0", v"7.1.0", v"8.1.0", v"9.1.0", v"10.2.0", v"11.1.0", v"12.1.0", v"13.2.0", v"12.0.1-iains"]
# When Rust is used on x86_64 Windows, we have to use at least binutils
# 2.25, which we bundle with at least GCC 5.
p = Platform("x86_64", "windows"; libgfortran_version=v"3")
@test gcc_version(p, available_gcc_builds, [:c, :go]) == [v"4.8.5", v"5.2.0", v"6.1.0"]
@test gcc_version(p, available_gcc_builds, [:c, :rust]) == [v"5.2.0", v"6.1.0"]
end
@testset "Compiler wrappers" begin
platform = Platform("x86_64", "linux"; libc="musl")
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path)
# Make sure the C++ string ABI is not set
@test !occursin("-D_GLIBCXX_USE_CXX11_ABI", read(joinpath(platform_bin_dir, "gcc"), String))
# Make sure gfortran doesn't uses ccache when BinaryBuilderBase.use_ccache is true
BinaryBuilderBase.use_ccache[] && @test !occursin("ccache", read(joinpath(platform_bin_dir, "gfortran"), String))
end
end
platform = Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx03")
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path)
gcc = read(joinpath(platform_bin_dir, "gcc"), String)
# Make sure the C++ string ABI is set as expected
@test occursin("-D_GLIBCXX_USE_CXX11_ABI=0", gcc)
# Make sure the unsafe flags check is there
@test occursin("You used one or more of the unsafe flags", gcc)
end
end
platform = Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx11")
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, allow_unsafe_flags = true)
gcc = read(joinpath(platform_bin_dir, "gcc"), String)
# Make sure the C++ string ABI is set as expected
@test occursin("-D_GLIBCXX_USE_CXX11_ABI=1", gcc)
# Make sure the unsafe flags check is not there in this case
@test !occursin("You used one or more of the unsafe flags", gcc)
end
end
platform = Platform("aarch64", "macos")
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, gcc_version = v"4")
if Sys.isunix()
cd(platform_bin_dir) do
@test readchomp(`./xcrun echo foo`) == "foo"
withenv("SDKROOT" => "/bar") do
@test readchomp(`./xcrun --show-sdk-path`) == "/bar"
@test readchomp(`./xcrun --show-sdk-path echo foo`) == "/bar\nfoo"
@test readchomp(`./xcrun --sdk /baz --show-sdk-path echo foo`) == "/baz\nfoo"
end
end
end
end
end
platform = Platform("x86_64", "freebsd")
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c, :rust, :go])
clang = read(joinpath(platform_bin_dir, "clang"), String)
# Check link flags
@test occursin("-L/opt/$(triplet(platform))/$(triplet(platform))/lib", clang)
# Other compilers
@test occursin("GOOS=\"freebsd\"", read(joinpath(platform_bin_dir, "go"), String))
@test occursin("--target=x86_64-unknown-freebsd", read(joinpath(platform_bin_dir, "rustc"), String))
end
end
platform = Platform("x86_64", "linux"; libc="glibc", cxxstring_abi="cxx11")
@testset "$(triplet(platform))" begin
mktempdir() do bin_path
platform_bin_dir = joinpath(bin_path, triplet(platform))
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c], gcc_version=v"5")
clang = read(joinpath(platform_bin_dir, "clang"), String)
# Check link flags
@test occursin("-L/opt/$(aatriplet(platform))/lib/gcc/opt/$(aatriplet(platform))/lib/gcc", clang)
end
end
end
end