Skip to content

Commit 4503002

Browse files
committed
Allow specifying a Rust toolchain version for the build
1 parent d7b9ffa commit 4503002

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Rootfs.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ function choose_shards(p::AbstractPlatform;
576576
ps_build::VersionNumber=v"2024.08.10",
577577
GCC_builds::Vector{GCCBuild}=available_gcc_builds,
578578
LLVM_builds::Vector{LLVMBuild}=available_llvm_builds,
579-
Rust_build::VersionNumber=maximum(getversion.(available_rust_builds)),
579+
Rust_builds::Vector{RustBuild}=available_rust_builds,
580580
Go_build::VersionNumber=maximum(getversion.(available_go_builds)),
581581
archive_type::Symbol = (use_squashfs[] ? :squashfs : :unpacked),
582582
bootstrap_list::Vector{Symbol} = bootstrap_list,
@@ -586,6 +586,9 @@ function choose_shards(p::AbstractPlatform;
586586
# Because LLVM doesn't have compatibility issues, we always default
587587
# to the newest version possible.
588588
preferred_llvm_version::VersionNumber = getversion(LLVM_builds[end]),
589+
# Rust can have compatibility issues between versions, but by default choose
590+
# the newest one.
591+
preferred_rust_version::VersionNumber = maximum(getversion.(Rust_builds)),
589592
)
590593

591594
function find_shard(name, version, archive_type; target = nothing)
@@ -654,6 +657,13 @@ function choose_shards(p::AbstractPlatform;
654657
end
655658

656659
if :rust in compilers
660+
# Make sure the selected Rust toolchain version is available
661+
if preferred_rust_version in getversion.(Rust_builds)
662+
Rust_build = preferred_rust_version
663+
else
664+
error("Requested Rust toolchain $(preferred_rust_version) not available in $(Rust_builds)")
665+
end
666+
657667
append!(shards, [
658668
find_shard("RustBase", Rust_build, archive_type),
659669
find_shard("RustToolchain", Rust_build, archive_type; target=p),

test/rootfs.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Test
22
using Base.BinaryPlatforms
33
using BinaryBuilderBase
4+
using BinaryBuilderBase: RustBuild, CompilerShard
45

56
@testset "Expand platforms" begin
67
# expand_gfortran_versions
@@ -117,6 +118,17 @@ end
117118
@testset "Compiler Shards" begin
118119
@test_throws ErrorException CompilerShard("GCCBootstrap", v"4", Platform("x86_64", "linux"), :invalid_archive_type)
119120

121+
@testset "Rust toolchain selection" begin
122+
platform = Platform("x86_64", "linux")
123+
common_opts = (preferred_gcc_version=v"9", compilers=[:c, :rust])
124+
125+
shards = choose_shards(platform; preferred_rust_version = v"1.73", (common_opts)... )
126+
@test filter(s-> s.name == "RustBase", shards)[end].version == v"1.73"
127+
@test filter(s-> s.name == "RustToolchain", shards)[end].version == v"1.73"
128+
129+
@test_throws ErrorException choose_shards(platform; preferred_rust_version = v"1.78", (common_opts)...)
130+
end
131+
120132
@testset "GCC ABI matching" begin
121133
# Preferred libgfortran version and C++ string ABI
122134
platform = Platform("x86_64", "freebsd")

0 commit comments

Comments
 (0)