rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

`--rust-target` beta and nightly suffixes

Open Kangie opened this issue 9 months ago • 1 comments

#2993 loosened --rust-target parsing to accept "any*" Rust version output.

Unfortunately, this does not include all of the possible rustc --version output varieties. The following apparently-valid version strings result in error: invalid value '...' for '--rust-target <RUST_TARGET>': "..." is not a valid Rust target:

rustc --version        
rustc 1.86.0-beta.1 (f0cb41030 2025-02-17) (gentoo)
rustc --version   
rustc 1.87.0-nightly (gentoo)

Some consumers of Rust / bindgen (e.g. Meson via the Rust module and rust.bindgen()) pass this version info into bindgen as a --rust-target: e.g. as --rust-target=1.87.0-nightly.

How should this be handled?

I see two options:

  • If a version has a suffix, drop the suffix and parse it as just the version (e.g. 1.86.0-beta* as 1.86.0
  • The above, but a -nightly suffix is special-cased to be the same as passing nightly

I'm not sure which option (if either) is desirable, however:

  • it seems better to address this at the source
  • it seems like a sane assumption that version strings as output by Rust itself should pass validation
  • not accepting Rust version strings is obviously breaking user expectations.

I'll already need to update Meson's Rust module to handle the #2993-changed "invalid Rust target" output; if you have any suggestions on how a build system should use the --rust-target option please let me know.

Downstream bug: https://bugs.gentoo.org/949593

Kangie avatar Feb 25 '25 05:02 Kangie

Meson dev here, I think this is actually our bug. We should be stripping the -nightly and -beta* suffix from the version for the check here, but we don't correctly strip that for rustc.

dcbaker avatar Feb 26 '25 17:02 dcbaker