Skip to content

Commit d006d45

Browse files
committed
rust: kbuild: set bindgen's Rust target version
Each `bindgen` release may upgrade the list of Rust targets. For instance, currently, in their master branch [1], the latest ones are: Nightly => { vectorcall_abi: #124485, ptr_metadata: #81513, layout_for_ptr: #69835, }, Stable_1_77(77) => { offset_of: #106655 }, Stable_1_73(73) => { thiscall_abi: #42202 }, Stable_1_71(71) => { c_unwind_abi: #106075 }, Stable_1_68(68) => { abi_efiapi: #105795 }, By default, the highest stable release in their list is used, and users are expected to set one if they need to support older Rust versions (e.g. see [2]). Thus, over time, new Rust features are used by default, and at some point, it is likely that `bindgen` will emit Rust code that requires a Rust version higher than our minimum (or perhaps enabling an unstable feature). Currently, there is no problem because the maximum they have, as seen above, is Rust 1.77.0, and our current minimum is Rust 1.78.0. Therefore, set a Rust target explicitly now to prevent going forward in time too much and thus getting potential build failures at some point. Since we also support a minimum `bindgen` version, and since `bindgen` does not support passing unknown Rust target versions, we need to use the list of our minimum `bindgen` version, rather than the latest. So, since `bindgen` 0.65.1 had this list [3], we need to use Rust 1.68.0: /// Rust stable 1.64 /// * `core_ffi_c` ([Tracking issue](rust-lang/rust#94501)) => Stable_1_64 => 1.64; /// Rust stable 1.68 /// * `abi_efiapi` calling convention ([Tracking issue](rust-lang/rust#65815)) => Stable_1_68 => 1.68; /// Nightly rust /// * `thiscall` calling convention ([Tracking issue](rust-lang/rust#42202)) /// * `vectorcall` calling convention (no tracking issue) /// * `c_unwind` calling convention ([Tracking issue](rust-lang/rust#74990)) => Nightly => nightly; ... /// Latest stable release of Rust pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_68; Thus add the `--rust-target 1.68` parameter. Add a comment as well explaining this. An alternative would be to use the currently running (i.e. actual) `rustc` and `bindgen` versions to pick a "better" Rust target version. However, that would introduce more moving parts depending on the user setup and is also more complex to implement. Cc: Christian Poveda <git@pvdrz.com> Cc: Emilio Cobos Álvarez <emilio@crisal.io> Link: https://github.com/rust-lang/rust-bindgen/blob/21c60f473f4e824d4aa9b2b508056320d474b110/bindgen/features.rs#L97-L105 [1] Link: rust-lang/rust-bindgen#2960 [2] Link: https://github.com/rust-lang/rust-bindgen/blob/7d243056d335fdc4537f7bca73c06d01aae24ddc/bindgen/features.rs#L131-L150 [3] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent b2603f8 commit d006d45

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

rust/Makefile

+11-1
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,19 @@ endif
278278
# architecture instead of generating `usize`.
279279
bindgen_c_flags_final = $(bindgen_c_flags_lto) -fno-builtin -D__BINDGEN__
280280

281+
# Each `bindgen` release may upgrade the list of Rust target versions. By
282+
# default, the highest stable release in their list is used. Thus we need to set
283+
# a `--rust-target` to avoid future `bindgen` releases emitting code that
284+
# `rustc` may not understand. On top of that, `bindgen` does not support passing
285+
# an unknown Rust target version.
286+
#
287+
# Therefore, the Rust target for `bindgen` can be only as high as the minimum
288+
# Rust version the kernel supports and only as high as the greatest stable Rust
289+
# target supported by the minimum `bindgen` version the kernel supports (that
290+
# is, if we do not test the actual `rustc`/`bindgen` versions running).
281291
quiet_cmd_bindgen = BINDGEN $@
282292
cmd_bindgen = \
283-
$(BINDGEN) $< $(bindgen_target_flags) \
293+
$(BINDGEN) $< $(bindgen_target_flags) --rust-target 1.68 \
284294
--use-core --with-derive-default --ctypes-prefix ffi --no-layout-tests \
285295
--no-debug '.*' --enable-function-attribute-detection \
286296
-o $@ -- $(bindgen_c_flags_final) -DMODULE \

0 commit comments

Comments
 (0)