Skip to content

findrust: Simplify - #11328

Merged
faho merged 4 commits into
fish-shell:masterfrom
faho:cmakeectomy
Mar 30, 2025
Merged

faho merged 4 commits into
fish-shell:masterfrom
faho:cmakeectomy

Conversation

@faho

@faho faho commented Mar 27, 2025 •

Copy link
Copy Markdown
Member

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.

TODOs:

  • [N/A] Changes to fish usage are reflected in user documentation/manpages.
  • [N/A] Tests have been added for regressions fixed
  • [N/A] User-visible changes noted in CHANGELOG.rst
  • Update README with the config variables?

@faho faho added the cmake label Mar 27, 2025
@faho faho added this to the fish 4.1 milestone Mar 27, 2025
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 zanchey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I think this is a good idea. We don't need all the complexity of the toolchain handling from Corrosion.

Comment thread cmake/FindRust.cmake Outdated
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."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an error?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cmake/Rust.cmake Outdated
set(Rust_RESOLVE_RUSTUP_TOOLCHAINS Off)

include(FindRust)
find_package(Rust 1.70 REQUIRED)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably drop the version number here again, cargo will do this for us I guess?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

faho added 3 commits March 30, 2025 18:40
We pass everything to cargo, that needs to know about the target.

I don't believe cmake does.
@faho
faho merged commit 205d80c into fish-shell:master Mar 30, 2025
@faho
faho deleted the cmakeectomy branch April 6, 2025 19:06
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.
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants