Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: add pin-init crate build infrastructure

Add infrastructure for moving the initialization API to its own crate.
Covers all make targets such as `rust-analyzer` and `rustdoc`. The tests
of pin-init are not added to `rusttest`, as they are already tested in
the user-space repository [1].

Link: https://github.com/Rust-for-Linux/pin-init [1]
Co-developed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Link: https://lore.kernel.org/r/20250308110339.2997091-15-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

+86 -20
+57 -18
rust/Makefile
··· 12 12 CFLAGS_REMOVE_helpers/helpers.o = -Wmissing-prototypes -Wmissing-declarations 13 13 14 14 always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs 15 - obj-$(CONFIG_RUST) += bindings.o kernel.o 15 + obj-$(CONFIG_RUST) += bindings.o pin_init.o kernel.o 16 16 always-$(CONFIG_RUST) += exports_helpers_generated.h \ 17 17 exports_bindings_generated.h exports_kernel_generated.h 18 18 ··· 41 41 libmacros_name := $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name macros --crate-type proc-macro - </dev/null) 42 42 libmacros_extension := $(patsubst libmacros.%,%,$(libmacros_name)) 43 43 44 - always-$(CONFIG_RUST) += $(libmacros_name) 44 + libpin_init_internal_name := $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name pin_init_internal --crate-type proc-macro - </dev/null) 45 + libpin_init_internal_extension := $(patsubst libpin_init_internal.%,%,$(libpin_init_internal_name)) 46 + 47 + always-$(CONFIG_RUST) += $(libmacros_name) $(libpin_init_internal_name) 45 48 46 49 # `$(rust_flags)` is passed in case the user added `--sysroot`. 47 50 rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot) ··· 83 80 # command-like flags to solve the issue. Meanwhile, we use the non-custom case 84 81 # and then retouch the generated files. 85 82 rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \ 86 - rustdoc-kernel 83 + rustdoc-kernel rustdoc-pin_init 87 84 $(Q)cp $(srctree)/Documentation/images/logo.svg $(rustdoc_output)/static.files/ 88 85 $(Q)cp $(srctree)/Documentation/images/COPYING-logo $(rustdoc_output)/static.files/ 89 86 $(Q)find $(rustdoc_output) -name '*.html' -type f -print0 | xargs -0 sed -Ei \ ··· 113 110 rustdoc-ffi: $(src)/ffi.rs rustdoc-core FORCE 114 111 +$(call if_changed,rustdoc) 115 112 116 - rustdoc-kernel: private rustc_target_flags = --extern ffi \ 113 + rustdoc-pin_init_internal: private rustdoc_host = yes 114 + rustdoc-pin_init_internal: private rustc_target_flags = --cfg kernel \ 115 + --extern proc_macro --crate-type proc-macro 116 + rustdoc-pin_init_internal: $(src)/pin-init/internal/src/_lib.rs FORCE 117 + +$(call if_changed,rustdoc) 118 + 119 + rustdoc-pin_init: private rustdoc_host = yes 120 + rustdoc-pin_init: private rustc_target_flags = --extern pin_init_internal \ 121 + --extern macros --extern alloc --cfg kernel --cfg feature=\"alloc\" 122 + rustdoc-pin_init: $(src)/pin-init/src/_lib.rs rustdoc-pin_init_internal \ 123 + rustdoc-macros FORCE 124 + +$(call if_changed,rustdoc) 125 + 126 + rustdoc-kernel: private rustc_target_flags = --extern ffi --extern pin_init \ 117 127 --extern build_error --extern macros \ 118 128 --extern bindings --extern uapi 119 129 rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-ffi rustdoc-macros \ 120 - rustdoc-compiler_builtins $(obj)/$(libmacros_name) \ 130 + rustdoc-pin_init rustdoc-compiler_builtins $(obj)/$(libmacros_name) \ 121 131 $(obj)/bindings.o FORCE 122 132 +$(call if_changed,rustdoc) 123 133 ··· 155 139 rusttestlib-macros: $(src)/macros/lib.rs FORCE 156 140 +$(call if_changed,rustc_test_library) 157 141 142 + rusttestlib-pin_init_internal: private rustc_target_flags = --cfg kernel \ 143 + --extern proc_macro 144 + rusttestlib-pin_init_internal: private rustc_test_library_proc = yes 145 + rusttestlib-pin_init_internal: $(src)/pin-init/internal/src/_lib.rs FORCE 146 + +$(call if_changed,rustc_test_library) 147 + 148 + rusttestlib-pin_init: private rustc_target_flags = --extern pin_init_internal \ 149 + --extern macros --cfg kernel 150 + rusttestlib-pin_init: $(src)/pin-init/src/_lib.rs rusttestlib-macros \ 151 + rusttestlib-pin_init_internal $(obj)/$(libpin_init_internal_name) FORCE 152 + +$(call if_changed,rustc_test_library) 153 + 158 154 rusttestlib-kernel: private rustc_target_flags = --extern ffi \ 159 - --extern build_error --extern macros \ 155 + --extern build_error --extern macros --extern pin_init \ 160 156 --extern bindings --extern uapi 161 - rusttestlib-kernel: $(src)/kernel/lib.rs \ 162 - rusttestlib-bindings rusttestlib-uapi rusttestlib-build_error \ 163 - $(obj)/$(libmacros_name) $(obj)/bindings.o FORCE 157 + rusttestlib-kernel: $(src)/kernel/lib.rs rusttestlib-bindings rusttestlib-uapi \ 158 + rusttestlib-build_error rusttestlib-pin_init $(obj)/$(libmacros_name) \ 159 + $(obj)/bindings.o FORCE 164 160 +$(call if_changed,rustc_test_library) 165 161 166 162 rusttestlib-bindings: private rustc_target_flags = --extern ffi ··· 200 172 mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \ 201 173 OBJTREE=$(abspath $(objtree)) \ 202 174 $(RUSTDOC) --test $(rust_flags) \ 203 - -L$(objtree)/$(obj) --extern ffi --extern kernel \ 204 - --extern build_error --extern macros \ 175 + -L$(objtree)/$(obj) --extern ffi --extern pin_init \ 176 + --extern kernel --extern build_error --extern macros \ 205 177 --extern bindings --extern uapi \ 206 178 --no-run --crate-name kernel -Zunstable-options \ 207 179 --sysroot=/dev/null \ ··· 231 203 rusttest: rusttest-macros rusttest-kernel 232 204 233 205 rusttest-macros: private rustc_target_flags = --extern proc_macro \ 234 - --extern macros --extern kernel 206 + --extern macros --extern kernel --extern pin_init 235 207 rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro 236 208 rusttest-macros: $(src)/macros/lib.rs \ 237 - rusttestlib-macros rusttestlib-kernel FORCE 209 + rusttestlib-macros rusttestlib-kernel rusttestlib-pin_init FORCE 238 210 +$(call if_changed,rustc_test) 239 211 +$(call if_changed,rustdoc_test) 240 212 241 - rusttest-kernel: private rustc_target_flags = --extern ffi \ 213 + rusttest-kernel: private rustc_target_flags = --extern ffi --extern pin_init \ 242 214 --extern build_error --extern macros --extern bindings --extern uapi 243 215 rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-ffi rusttestlib-kernel \ 244 216 rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \ 245 - rusttestlib-uapi FORCE 217 + rusttestlib-uapi rusttestlib-pin_init FORCE 246 218 +$(call if_changed,rustc_test) 247 219 248 220 ifdef CONFIG_CC_IS_CLANG ··· 389 361 390 362 quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ 391 363 cmd_rustc_procmacro = \ 392 - $(RUSTC_OR_CLIPPY) $(rust_common_flags) \ 364 + $(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \ 393 365 -Clinker-flavor=gcc -Clinker=$(HOSTCC) \ 394 366 -Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \ 395 367 --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \ ··· 398 370 399 371 # Procedural macros can only be used with the `rustc` that compiled it. 400 372 $(obj)/$(libmacros_name): $(src)/macros/lib.rs FORCE 373 + +$(call if_changed_dep,rustc_procmacro) 374 + 375 + $(obj)/$(libpin_init_internal_name): private rustc_target_flags = --cfg kernel 376 + $(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/_lib.rs FORCE 401 377 +$(call if_changed_dep,rustc_procmacro) 402 378 403 379 quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@ ··· 483 451 $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE 484 452 +$(call if_changed_rule,rustc_library) 485 453 454 + $(obj)/pin_init.o: private skip_gendwarfksyms = 1 455 + $(obj)/pin_init.o: private rustc_target_flags = --extern pin_init_internal \ 456 + --extern macros --cfg kernel 457 + $(obj)/pin_init.o: $(src)/pin-init/src/_lib.rs $(obj)/compiler_builtins.o \ 458 + $(obj)/$(libpin_init_internal_name) $(obj)/$(libmacros_name) FORCE 459 + +$(call if_changed_rule,rustc_library) 460 + 486 461 $(obj)/build_error.o: private skip_gendwarfksyms = 1 487 462 $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE 488 463 +$(call if_changed_rule,rustc_library) ··· 512 473 $(obj)/uapi/uapi_generated.rs FORCE 513 474 +$(call if_changed_rule,rustc_library) 514 475 515 - $(obj)/kernel.o: private rustc_target_flags = --extern ffi \ 476 + $(obj)/kernel.o: private rustc_target_flags = --extern ffi --extern pin_init \ 516 477 --extern build_error --extern macros --extern bindings --extern uapi 517 - $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/build_error.o \ 478 + $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/build_error.o $(obj)/pin_init.o \ 518 479 $(obj)/$(libmacros_name) $(obj)/bindings.o $(obj)/uapi.o FORCE 519 480 +$(call if_changed_rule,rustc_library) 520 481
+3
rust/pin-init/internal/src/_lib.rs
··· 1 + // SPDX-License-Identifier: Apache-2.0 OR MIT 2 + 3 + //! Will be removed in a future commit, only exists to prevent compilation errors.
+4
rust/pin-init/internal/src/lib.rs
··· 1 1 // SPDX-License-Identifier: Apache-2.0 OR MIT 2 2 3 + // When fixdep scans this, it will find this string `CONFIG_RUSTC_VERSION_TEXT` 4 + // and thus add a dependency on `include/config/RUSTC_VERSION_TEXT`, which is 5 + // touched by Kconfig when the version string from the compiler changes. 6 + 3 7 #[allow(missing_docs)] 4 8 #[proc_macro_attribute] 5 9 pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
+5
rust/pin-init/src/_lib.rs
··· 1 + // SPDX-License-Identifier: Apache-2.0 OR MIT 2 + 3 + //! Will be removed in a future commit, only exists to prevent compilation errors. 4 + 5 + #![no_std]
+1 -1
scripts/Makefile.build
··· 237 237 -Zallow-features=$(rust_allowed_features) \ 238 238 -Zcrate-attr=no_std \ 239 239 -Zcrate-attr='feature($(rust_allowed_features))' \ 240 - -Zunstable-options --extern kernel \ 240 + -Zunstable-options --extern pin_init --extern kernel \ 241 241 --crate-type rlib -L $(objtree)/rust/ \ 242 242 --crate-name $(basename $(notdir $@)) \ 243 243 --sysroot=/dev/null \
+16 -1
scripts/generate_rust_analyzer.py
··· 94 94 crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True)) 95 95 96 96 append_crate( 97 + "pin_init_internal", 98 + srctree / "rust" / "pin-init" / "internal" / "src" / "_lib.rs", 99 + [], 100 + cfg=["kernel"], 101 + is_proc_macro=True, 102 + ) 103 + 104 + append_crate( 105 + "pin_init", 106 + srctree / "rust" / "pin-init" / "src" / "_lib.rs", 107 + ["core", "pin_init_internal", "macros"], 108 + cfg=["kernel"], 109 + ) 110 + 111 + append_crate( 97 112 "kernel", 98 113 srctree / "rust" / "kernel" / "lib.rs", 99 - ["core", "macros", "build_error", "bindings"], 114 + ["core", "macros", "build_error", "bindings", "pin_init"], 100 115 cfg=cfg, 101 116 ) 102 117 crates[-1]["source"] = {