Repository navigation
findrust: Simplify - #11328
Merged
Merged
findrust: Simplify#11328
Conversation
FindRust is too clever by half. It tries to do rustup's job for it. See b38551d for how that can break. So we simplify it, and only let it check three things: - Where's rustc? Look in $PATH and ~/.cargo/bin - Where's cargo? Look in $PATH and ~/.cargo/bin - What is the rust target (because we pass it explicitly)? If any of these aren't that simple, we'll ask the user to tell us, by setting Rust_COMPILER, Rust_CARGO or Rust_CARGO_TARGET. None of the other things are helpful to us - we do not support windows or whatever a "unikraft" is, and if the rust version doesn't work it'll print its own error. We could add a rustc version check, but that will become less and less useful because rustc versions since 1.56 (released October 2021) will check rust-version in Cargo.toml. So even at this point it's only pretty old rust versions already.
zanchey
approved these changes
Mar 30, 2025
zanchey
left a comment
Member
There was a problem hiding this comment.
Yep, I think this is a good idea. We don't need all the complexity of the toolchain handling from Corrosion.
| WARNING | ||
| "Failed to parse rustc LLVM version. `rustc --version --verbose` evaluated to:\n${_RUSTC_VERSION_RAW}" | ||
| if(CMAKE_CROSSCOMPILING) | ||
| message(WARNING "CMake is in cross-compiling mode, but the cargo target-triple could not be inferred." |
Member
Author
There was a problem hiding this comment.
Yeah, I don't know what the cmake cross-compilation support helps us.
Cargo handles the compilation, so just telling that about the target should be fine.
E.g. if I do
cmake -DRust_CARGO_TARGET=x86_64-unknown-linux-musl ..
PATH=~/dev/toolchains/x86_64-linux-musl-cross/bin/":$PATH" make that seems to be enough to build a musl-fish.
| set(Rust_RESOLVE_RUSTUP_TOOLCHAINS Off) | ||
|
|
||
| include(FindRust) | ||
| find_package(Rust 1.70 REQUIRED) |
Member
There was a problem hiding this comment.
Probably drop the version number here again, cargo will do this for us I guess?
Member
Author
There was a problem hiding this comment.
Yeah that's fine, I wasn't sure if we wanted to add it back.
Cargo/Rust will do it from 1.56 onwards, which should barely be a concern now and won't be one at all anymore soon.
We pass everything to cargo, that needs to know about the target. I don't believe cmake does.
krobelus
added a commit
that referenced
this pull request
Sep 27, 2025
Since 205d80c (findrust: Simplify (#11328), 2025-03-30), we need to set Rust_COMPILER and Rust_CARGO instead of Rust_TOOLCHAIN (which is no longer used). Adjust macOS builds accordingly. When I set only one of the two, the error messages were pretty unintelligible. But I guess few normal users need to override the Rust version, and they can always look here. While at it, enable localization. AFAIK, the only reason why we didn't do this on macOS were problems related to the gettext shared library / dependency. We no longer need that, and it's already tested in CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FindRust is too clever by half. It tries to do rustup's job for it.
See b38551d for how that can break.
So we simplify it, and only let it check three things:
If any of these aren't that simple, we'll ask the user to tell us, by setting Rust_COMPILER, Rust_CARGO or Rust_CARGO_TARGET.
None of the other things are helpful to us - we do not support windows or whatever a "unikraft" is, and if the rust version doesn't work it'll print its own error.
We could add a rustc version check, but that will become less and less useful because rustc versions since 1.56 (released October 2021) will check rust-version in Cargo.toml. So even at this point it's only pretty old rust versions already.
TODOs: