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 ...
Showing the changes to scripts (3 of 25 files). Show all
Unified · Split
| @@ -117,20 +117,16 @@ if [ "$rust_compiler_cversion" -lt "$rust_compiler_min_cversion" ]; then · 116 unmodified lines | |||
| 117 | echo >&2 "***" | 117 | echo >&2 "***" |
| 118 | exit 1 | 118 | exit 1 |
| 119 | fi | 119 | 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 | ||
| 128 | 120 | ||
| 129 | # Check that the Rust bindings generator is suitable. | 121 | # Check that the Rust bindings generator is suitable. |
| 130 | # | 122 | # |
| 131 | # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. | 123 | # 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). | ||
| 132 | rust_bindings_generator_output=$( \ | 128 | 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 |
| 134 | ) || rust_bindings_generator_code=$? | 130 | ) || rust_bindings_generator_code=$? |
| 135 | if [ -n "$rust_bindings_generator_code" ]; then | 131 | if [ -n "$rust_bindings_generator_code" ]; then |
| 136 | echo >&2 "***" | 132 | echo >&2 "***" |
| @@ -165,13 +161,18 @@ if [ "$rust_bindings_generator_cversion" -lt "$rust_bindings_generator_min_cvers · 28 unmodified lines | |||
| 165 | echo >&2 "***" | 161 | echo >&2 "***" |
| 166 | exit 1 | 162 | exit 1 |
| 167 | fi | 163 | fi |
| 168 | if [ "$rust_bindings_generator_cversion" -gt "$rust_bindings_generator_min_cversion" ]; then | 164 | if [ "$rust_bindings_generator_cversion" -eq 6600 ] || |
| 169 | echo >&2 "***" | 165 | [ "$rust_bindings_generator_cversion" -eq 6601 ]; then |
| 170 | echo >&2 "*** Rust bindings generator '$BINDGEN' is too new. This may or may not work." | 166 | # Distributions may have patched the issue (e.g. Debian did). |
| 171 | echo >&2 "*** Your version: $rust_bindings_generator_version" | 167 | if ! "$BINDGEN" $(dirname $0)/rust_is_available_bindgen_0_66.h >/dev/null; then |
| 172 | echo >&2 "*** Expected version: $rust_bindings_generator_min_version" | 168 | echo >&2 "***" |
| 173 | echo >&2 "***" | 169 | echo >&2 "*** Rust bindings generator '$BINDGEN' versions 0.66.0 and 0.66.1 may not" |
| 174 | warning=1 | 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 | ||
| 175 | fi | 176 | fi |
| 176 | 177 | ||
| 177 | # Check that the `libclang` used by the Rust bindings generator is suitable. | 178 | # Check that the `libclang` used by the Rust bindings generator is suitable. |
| @@ -0,0 +1,2 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | #define A "\0" | ||
| @@ -54,18 +54,34 @@ else: · 53 unmodified lines | |||
| 54 | """) | 54 | """) |
| 55 | 55 | ||
| 56 | @classmethod | 56 | @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 | |||
| 58 | return cls.generate_executable(f"""#!/usr/bin/env python3 | 68 | return cls.generate_executable(f"""#!/usr/bin/env python3 |
| 59 | import sys | 69 | import sys |
| 60 | if "rust_is_available_bindgen_libclang.h" in " ".join(sys.argv): | 70 | 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} | ||
| 62 | else: | 74 | else: |
| 63 | print({repr(version_stdout)}) | 75 | print({repr(version_stdout)}) |
| 64 | """) | 76 | """) |
| 65 | 77 | ||
| 66 | @classmethod | 78 | @classmethod |
| 67 | def generate_bindgen_version(cls, stdout): | 79 | def generate_bindgen_version(cls, stdout, version_0_66_patched=False): |
| 68 | return cls.generate_bindgen(stdout, cls.bindgen_default_bindgen_libclang_stderr) | 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) | ||
| 69 | 85 | ||
| 70 | @classmethod | 86 | @classmethod |
| 71 | def generate_bindgen_libclang(cls, stderr): | 87 | def generate_bindgen_libclang(cls, stderr): |
| @@ -89,6 +105,7 @@ else: · 17 unmodified lines | |||
| 89 | cls.rust_default_sysroot = subprocess.check_output(("rustc", "--print", "sysroot")).decode().strip() | 105 | cls.rust_default_sysroot = subprocess.check_output(("rustc", "--print", "sysroot")).decode().strip() |
| 90 | 106 | ||
| 91 | cls.bindgen_default_bindgen_version_stdout = f"bindgen {cls.bindgen_default_version}" | 107 | cls.bindgen_default_bindgen_version_stdout = f"bindgen {cls.bindgen_default_version}" |
| 108 | cls.bindgen_default_bindgen_libclang_failure_exit_code = 42 | ||
| 92 | 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" | 109 | 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" |
| 93 | 110 | ||
| 94 | cls.default_rustc = cls.generate_rustc(f"rustc {cls.rustc_default_version}") | 111 | cls.default_rustc = cls.generate_rustc(f"rustc {cls.rustc_default_version}") |
| @@ -193,11 +210,6 @@ else: · 98 unmodified lines | |||
| 193 | result = self.run_script(self.Expected.FAILURE, { "RUSTC": rustc }) | 210 | result = self.run_script(self.Expected.FAILURE, { "RUSTC": rustc }) |
| 194 | self.assertIn(f"Rust compiler '{rustc}' is too old.", result.stderr) | 211 | self.assertIn(f"Rust compiler '{rustc}' is too old.", result.stderr) |
| 195 | 212 | ||
| 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 | |||
| 201 | def test_bindgen_nonexecutable(self): | 213 | def test_bindgen_nonexecutable(self): |
| 202 | result = self.run_script(self.Expected.FAILURE, { "BINDGEN": self.nonexecutable }) | 214 | result = self.run_script(self.Expected.FAILURE, { "BINDGEN": self.nonexecutable }) |
| 203 | self.assertIn(f"Running '{self.nonexecutable}' to check the Rust bindings generator version failed with", result.stderr) | 215 | 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 | |||
| 226 | result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen }) | 238 | result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen }) |
| 227 | self.assertIn(f"Rust bindings generator '{bindgen}' is too old.", result.stderr) | 239 | self.assertIn(f"Rust bindings generator '{bindgen}' is too old.", result.stderr) |
| 228 | 240 | ||
| 229 | def test_bindgen_new_version(self): | 241 | def test_bindgen_bad_version_0_66_0_and_0_66_1(self): |
| 230 | bindgen = self.generate_bindgen_version("bindgen 0.999.0") | 242 | for version in ("0.66.0", "0.66.1"): |
| 231 | result = self.run_script(self.Expected.SUCCESS_WITH_WARNINGS, { "BINDGEN": bindgen }) | 243 | with self.subTest(version=version): |
| 232 | self.assertIn(f"Rust bindings generator '{bindgen}' is too new. This may or may not work.", result.stderr) | 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 }) | ||
| 233 | 253 | ||
| 234 | def test_bindgen_libclang_failure(self): | 254 | def test_bindgen_libclang_failure(self): |
| 235 | for env in ( | 255 | bindgen = self.generate_bindgen_libclang_failure() |
| 236 | { "LLVM_CONFIG_PATH": self.missing }, | 256 | result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen }) |
| 237 | { "LIBCLANG_PATH": self.missing }, | 257 | self.assertIn(f"Running '{bindgen}' to check the libclang version (used by the Rust", result.stderr) |
| 238 | { "CLANG_PATH": self.missing }, | 258 | self.assertIn(f"bindings generator) failed with code {self.bindgen_default_bindgen_libclang_failure_exit_code}. This may be caused by", result.stderr) |
| 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) | ||
| 244 | 259 | ||
| 245 | def test_bindgen_libclang_unexpected_version(self): | 260 | def test_bindgen_libclang_unexpected_version(self): |
| 246 | bindgen = self.generate_bindgen_libclang("scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version unexpected [-W#pragma-messages], err: false") | 261 | bindgen = self.generate_bindgen_libclang("scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version unexpected [-W#pragma-messages], err: false") |