History

Merge tag 'rust-6.11' of https://github.com/Rust-for-Linux/linux

Pull Rust updates from Miguel Ojeda: "The highlight is the establishment of a minimum version for the Rust toolchain, including 'rustc' (and bundled tools) and 'bindgen'. The initial minimum will be the pinned version we currently have, i.e. we are just widening the allowed versions. That covers three stable Rust releases: 1.78.0, 1.79.0, 1.80.0 (getting released tomorrow), plus beta, plus nightly. This should already be enough for kernel developers in distributions that provide recent Rust compiler versions routinely, such as Arch Linux, Debian Unstable (outside the freeze period), Fedora Linux, Gentoo Linux (especially the testing channel), Nix (unstable) and openSUSE Slowroll and Tumbleweed. In addition, the kernel is now being built-tested by Rust's pre-merge CI. That is, every change that is attempting to land into the Rust compiler is tested against the kernel, and it is merged only if it passes. Similarly, the bindgen tool has agreed to build the kernel in their CI too. Thus, with the pre-merge CI in place, both projects hope to avoid unintentional changes to Rust that break the kernel. This means that, in general, apart from intentional changes on their side (that we will need to workaround conditionally on our side), the upcoming Rust compiler versions should generally work. In addition, the Rust project has proposed getting the kernel into stable Rust (at least solving the main blockers) as one of its three flagship goals for 2024H2 [1]. I would like to thank Niko, Sid, Emilio et al. for their help promoting the collaboration between Rust and the kernel. Toolchain and infrastructure: - Support several Rust toolchain versions. - Support several bindgen versions. - Remove 'cargo' requirement and simplify 'rusttest', thanks to 'alloc' having been dropped last cycle. - Provide proper error reporting for the 'rust-analyzer' target. 'kernel' crate: - Add 'uaccess' module with a safe userspace pointers abstraction. - Add 'page' module with a 'struct page' abstraction. - Support more complex generics in workqueue's 'impl_has_work!' macro. 'macros' crate: - Add 'firmware' field support to the 'module!' macro. - Improve 'module!' macro documentation. Documentation: - Provide instructions on what packages should be installed to build the kernel in some popular Linux distributions. - Introduce the new kernel.org LLVM+Rust toolchains. - Explain '#[no_std]'. And a few other small bits" Link: https://rust-lang.github.io/rust-project-goals/2024h2/index.html#flagship-goals [1] * tag 'rust-6.11' of https://github.com/Rust-for-Linux/linux: (26 commits) docs: rust: quick-start: add section on Linux distributions rust: warn about `bindgen` versions 0.66.0 and 0.66.1 rust: start supporting several `bindgen` versions rust: work around `bindgen` 0.69.0 issue rust: avoid assuming a particular `bindgen` build rust: start supporting several compiler versions rust: simplify Clippy warning flags set rust: relax most deny-level lints to warnings rust: allow `dead_code` for never constructed bindings rust: init: simplify from `map_err` to `inspect_err` rust: macros: indent list item in `paste!`'s docs rust: add abstraction for `struct page` rust: uaccess: add typed accessors for userspace pointers uaccess: always export _copy_[from|to]_user with CONFIG_RUST rust: uaccess: add userspace pointers kbuild: rust-analyzer: improve comment documentation kbuild: rust-analyzer: better error handling docs: rust: no_std is used rust: alloc: add __GFP_HIGHMEM flag rust: alloc: fix typo in docs for GFP_NOWAIT ...

Linus Torvalds committed 2 years ago

Commit 910bfc22 parents ff30564 b12634125 files · +1058 −236Browse files

Showing the changes to scripts (3 of 25 files). Show all

Unified · Split

3 files
  1. scripts/rust_is_available.sh +17 −16
  2. scripts/rust_is_available_bindgen_0_66.h +2 −0
  3. scripts/rust_is_available_test.py +37 −22
scripts/rust_is_available.sh+17−16
@@ -117,20 +117,16 @@ if [ "$rust_compiler_cversion" -lt "$rust_compiler_min_cversion" ]; then · 116 unmodified lines
117117 echo >&2 "***"
118118 exit 1
119119 fi
120−if [ "$rust_compiler_cversion" -gt "$rust_compiler_min_cversion" ]; then
121− echo >&2 "***"
122− echo >&2 "*** Rust compiler '$RUSTC' is too new. This may or may not work."
123− echo >&2 "*** Your version: $rust_compiler_version"
124− echo >&2 "*** Expected version: $rust_compiler_min_version"
125− echo >&2 "***"
126− warning=1
127−fi
128120
129121 # Check that the Rust bindings generator is suitable.
130122 #
131123 # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`.
124+#
125+# The dummy parameter `workaround-for-0.69.0` is required to support 0.69.0
126+# (https://github.com/rust-lang/rust-bindgen/pull/2678). It can be removed when
127+# the minimum version is upgraded past that (0.69.1 already fixed the issue).
132128 rust_bindings_generator_output=$( \
133− LC_ALL=C "$BINDGEN" --version 2>/dev/null
129+ LC_ALL=C "$BINDGEN" --version workaround-for-0.69.0 2>/dev/null
134130 ) || rust_bindings_generator_code=$?
135131 if [ -n "$rust_bindings_generator_code" ]; then
136132 echo >&2 "***"
@@ -165,13 +161,18 @@ if [ "$rust_bindings_generator_cversion" -lt "$rust_bindings_generator_min_cvers · 28 unmodified lines
165161 echo >&2 "***"
166162 exit 1
167163 fi
168−if [ "$rust_bindings_generator_cversion" -gt "$rust_bindings_generator_min_cversion" ]; then
169− echo >&2 "***"
170− echo >&2 "*** Rust bindings generator '$BINDGEN' is too new. This may or may not work."
171− echo >&2 "*** Your version: $rust_bindings_generator_version"
172− echo >&2 "*** Expected version: $rust_bindings_generator_min_version"
173− echo >&2 "***"
174− warning=1
164+if [ "$rust_bindings_generator_cversion" -eq 6600 ] ||
165+ [ "$rust_bindings_generator_cversion" -eq 6601 ]; then
166+ # Distributions may have patched the issue (e.g. Debian did).
167+ if ! "$BINDGEN" $(dirname $0)/rust_is_available_bindgen_0_66.h >/dev/null; then
168+ echo >&2 "***"
169+ echo >&2 "*** Rust bindings generator '$BINDGEN' versions 0.66.0 and 0.66.1 may not"
170+ echo >&2 "*** work due to a bug (https://github.com/rust-lang/rust-bindgen/pull/2567),"
171+ echo >&2 "*** unless patched (like Debian's)."
172+ echo >&2 "*** Your version: $rust_bindings_generator_version"
173+ echo >&2 "***"
174+ warning=1
175+ fi
175176 fi
176177
177178 # Check that the `libclang` used by the Rust bindings generator is suitable.
scripts/rust_is_available_bindgen_0_66.h+2−0
@@ -0,0 +1,2 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+#define A "\0"
scripts/rust_is_available_test.py+37−22
@@ -54,18 +54,34 @@ else: · 53 unmodified lines
5454 """)
5555
5656 @classmethod
57− def generate_bindgen(cls, version_stdout, libclang_stderr):
57+ def generate_bindgen(cls, version_stdout, libclang_stderr, version_0_66_patched=False):
58+ if libclang_stderr is None:
59+ libclang_case = f"raise SystemExit({cls.bindgen_default_bindgen_libclang_failure_exit_code})"
60+ else:
61+ libclang_case = f"print({repr(libclang_stderr)}, file=sys.stderr)"
62+
63+ if version_0_66_patched:
64+ version_0_66_case = "pass"
65+ else:
66+ version_0_66_case = "raise SystemExit(1)"
67+
5868 return cls.generate_executable(f"""#!/usr/bin/env python3
5969 import sys
6070 if "rust_is_available_bindgen_libclang.h" in " ".join(sys.argv):
61− print({repr(libclang_stderr)}, file=sys.stderr)
71+ {libclang_case}
72+elif "rust_is_available_bindgen_0_66.h" in " ".join(sys.argv):
73+ {version_0_66_case}
6274 else:
6375 print({repr(version_stdout)})
6476 """)
6577
6678 @classmethod
67− def generate_bindgen_version(cls, stdout):
68− return cls.generate_bindgen(stdout, cls.bindgen_default_bindgen_libclang_stderr)
79+ def generate_bindgen_version(cls, stdout, version_0_66_patched=False):
80+ return cls.generate_bindgen(stdout, cls.bindgen_default_bindgen_libclang_stderr, version_0_66_patched)
81+
82+ @classmethod
83+ def generate_bindgen_libclang_failure(cls):
84+ return cls.generate_bindgen(cls.bindgen_default_bindgen_version_stdout, None)
6985
7086 @classmethod
7187 def generate_bindgen_libclang(cls, stderr):
@@ -89,6 +105,7 @@ else: · 17 unmodified lines
89105 cls.rust_default_sysroot = subprocess.check_output(("rustc", "--print", "sysroot")).decode().strip()
90106
91107 cls.bindgen_default_bindgen_version_stdout = f"bindgen {cls.bindgen_default_version}"
108+ cls.bindgen_default_bindgen_libclang_failure_exit_code = 42
92109 cls.bindgen_default_bindgen_libclang_stderr = f"scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version {cls.llvm_default_version} [-W#pragma-messages], err: false"
93110
94111 cls.default_rustc = cls.generate_rustc(f"rustc {cls.rustc_default_version}")
@@ -193,11 +210,6 @@ else: · 98 unmodified lines
193210 result = self.run_script(self.Expected.FAILURE, { "RUSTC": rustc })
194211 self.assertIn(f"Rust compiler '{rustc}' is too old.", result.stderr)
195212
196− def test_rustc_new_version(self):
197− rustc = self.generate_rustc("rustc 1.999.0 (a8314ef7d 2099-06-27)")
198− result = self.run_script(self.Expected.SUCCESS_WITH_WARNINGS, { "RUSTC": rustc })
199− self.assertIn(f"Rust compiler '{rustc}' is too new. This may or may not work.", result.stderr)
200−
201213 def test_bindgen_nonexecutable(self):
202214 result = self.run_script(self.Expected.FAILURE, { "BINDGEN": self.nonexecutable })
203215 self.assertIn(f"Running '{self.nonexecutable}' to check the Rust bindings generator version failed with", result.stderr)
@@ -226,21 +238,24 @@ else: · 22 unmodified lines
226238 result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen })
227239 self.assertIn(f"Rust bindings generator '{bindgen}' is too old.", result.stderr)
228240
229− def test_bindgen_new_version(self):
230− bindgen = self.generate_bindgen_version("bindgen 0.999.0")
231− result = self.run_script(self.Expected.SUCCESS_WITH_WARNINGS, { "BINDGEN": bindgen })
232− self.assertIn(f"Rust bindings generator '{bindgen}' is too new. This may or may not work.", result.stderr)
241+ def test_bindgen_bad_version_0_66_0_and_0_66_1(self):
242+ for version in ("0.66.0", "0.66.1"):
243+ with self.subTest(version=version):
244+ bindgen = self.generate_bindgen_version(f"bindgen {version}")
245+ result = self.run_script(self.Expected.SUCCESS_WITH_WARNINGS, { "BINDGEN": bindgen })
246+ self.assertIn(f"Rust bindings generator '{bindgen}' versions 0.66.0 and 0.66.1 may not", result.stderr)
247+
248+ def test_bindgen_bad_version_0_66_0_and_0_66_1_patched(self):
249+ for version in ("0.66.0", "0.66.1"):
250+ with self.subTest(version=version):
251+ bindgen = self.generate_bindgen_version(f"bindgen {version}", True)
252+ result = self.run_script(self.Expected.SUCCESS, { "BINDGEN": bindgen })
233253
234254 def test_bindgen_libclang_failure(self):
235− for env in (
236− { "LLVM_CONFIG_PATH": self.missing },
237− { "LIBCLANG_PATH": self.missing },
238− { "CLANG_PATH": self.missing },
239− ):
240− with self.subTest(env=env):
241− result = self.run_script(self.Expected.FAILURE, env | { "PATH": os.environ["PATH"], "BINDGEN": "bindgen" })
242− self.assertIn("Running 'bindgen' to check the libclang version (used by the Rust", result.stderr)
243− self.assertIn("bindings generator) failed with code ", result.stderr)
255+ bindgen = self.generate_bindgen_libclang_failure()
256+ result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen })
257+ self.assertIn(f"Running '{bindgen}' to check the libclang version (used by the Rust", result.stderr)
258+ self.assertIn(f"bindings generator) failed with code {self.bindgen_default_bindgen_libclang_failure_exit_code}. This may be caused by", result.stderr)
244259
245260 def test_bindgen_libclang_unexpected_version(self):
246261 bindgen = self.generate_bindgen_libclang("scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version unexpected [-W#pragma-messages], err: false")