]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: zerocopy: enable support in kbuild
authorMiguel Ojeda <ojeda@kernel.org>
Mon, 8 Jun 2026 14:14:31 +0000 (16:14 +0200)
committerMiguel Ojeda <ojeda@kernel.org>
Tue, 9 Jun 2026 02:13:22 +0000 (04:13 +0200)
With all the new files in place and ready from the new crate, enable
the support for it in the build system.

In addition, skip formatting for this vendored crate.

Finally, there are no generated symbols expected from `zerocopy`, thus
skip adding the `exports` generation.

Link: https://patch.msgid.link/20260608141439.182634-13-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Makefile
rust/Makefile
scripts/Makefile.build
scripts/generate_rust_analyzer.py

index 3a265e7e33477313785f70876afb5c59c8f04f17..33135f39bbeea8301315e29d337b0776e02b14ca 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1956,6 +1956,7 @@ rustfmt:
                        -path $(srctree)/rust/proc-macro2 \
                        -o -path $(srctree)/rust/quote \
                        -o -path $(srctree)/rust/syn \
+                       -o -path $(srctree)/rust/zerocopy \
                \) -prune -o \
                -type f -a -name '*.rs' -a ! -name '*generated*' -print \
                | xargs $(RUSTFMT) $(rustfmt_flags)
index 7b1db0d5d4233e621e828052f7070eb6e8589d37..a87b33926cdfa85ca371b83b8c7c5b44163d57e6 100644 (file)
@@ -6,6 +6,8 @@ rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
 obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o
 always-$(CONFIG_RUST) += exports_core_generated.h
 
+obj-$(CONFIG_RUST) += zerocopy.o
+
 ifdef CONFIG_RUST_INLINE_HELPERS
 always-$(CONFIG_RUST) += helpers/helpers.bc helpers/helpers_module.bc
 else
@@ -81,6 +83,12 @@ core-flags := \
     --edition=$(core-edition) \
     $(call cfgs-to-flags,$(core-cfgs))
 
+zerocopy-flags := \
+    --cap-lints=allow
+
+zerocopy-envs := \
+    CARGO_PKG_VERSION=0.8.50
+
 proc_macro2-cfgs := \
     feature="proc-macro" \
     wrap_proc_macro \
@@ -167,7 +175,7 @@ quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
 # command-like flags to solve the issue. Meanwhile, we use the non-custom case
 # and then retouch the generated files.
 rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
-    rustdoc-kernel rustdoc-pin_init
+    rustdoc-kernel rustdoc-pin_init rustdoc-zerocopy
        $(Q)grep -Ehro '<a href="srctree/([^"]+)"' $(rustdoc_output) | \
                cut -d'"' -f2 | cut -d/ -f2- | while read f; do \
                        if [ ! -e "$(srctree)/$$f" ]; then \
@@ -219,6 +227,13 @@ rustdoc-compiler_builtins: private is-kernel-object := y
 rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
        +$(call if_changed,rustdoc)
 
+rustdoc-zerocopy: private rustc_target_envs := $(zerocopy-envs)
+rustdoc-zerocopy: private is-kernel-object := y
+rustdoc-zerocopy: private rustc_target_flags = $(zerocopy-flags) \
+    --extend-css $(src)/zerocopy/rustdoc/style.css
+rustdoc-zerocopy: $(src)/zerocopy/src/lib.rs rustdoc-clean rustdoc-core FORCE
+       +$(call if_changed,rustdoc)
+
 rustdoc-ffi: private is-kernel-object := y
 rustdoc-ffi: $(src)/ffi.rs rustdoc-core FORCE
        +$(call if_changed,rustdoc)
@@ -240,7 +255,8 @@ rustdoc-pin_init: $(src)/pin-init/src/lib.rs rustdoc-pin_init_internal \
 rustdoc-kernel: private is-kernel-object := y
 rustdoc-kernel: private rustc_target_flags = --extern ffi --extern pin_init \
     --extern build_error --extern macros \
-    --extern bindings --extern uapi
+    --extern bindings --extern uapi \
+    --extern zerocopy
 rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-ffi rustdoc-macros \
     rustdoc-pin_init rustdoc-compiler_builtins $(obj)/$(libmacros_name) \
     $(obj)/bindings.o FORCE
@@ -260,6 +276,11 @@ quiet_cmd_rustc_test_library = $(RUSTC_OR_CLIPPY_QUIET) TL $<
                -L$(objtree)/$(obj)/test \
                --crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $<
 
+rusttestlib-zerocopy: private rustc_target_envs := $(zerocopy-envs)
+rusttestlib-zerocopy: private rustc_target_flags = $(zerocopy-flags)
+rusttestlib-zerocopy: $(src)/zerocopy/src/lib.rs FORCE
+       +$(call if_changed,rustc_test_library)
+
 rusttestlib-build_error: $(src)/build_error.rs FORCE
        +$(call if_changed,rustc_test_library)
 
@@ -300,10 +321,11 @@ rusttestlib-pin_init: $(src)/pin-init/src/lib.rs rusttestlib-macros \
 
 rusttestlib-kernel: private rustc_target_flags = --extern ffi \
     --extern build_error --extern macros --extern pin_init \
-    --extern bindings --extern uapi
+    --extern bindings --extern uapi \
+    --extern zerocopy
 rusttestlib-kernel: $(src)/kernel/lib.rs rusttestlib-bindings rusttestlib-uapi \
     rusttestlib-build_error rusttestlib-pin_init $(obj)/$(libmacros_name) \
-    $(obj)/bindings.o FORCE
+    $(obj)/bindings.o rusttestlib-zerocopy FORCE
        +$(call if_changed,rustc_test_library)
 
 rusttestlib-bindings: private rustc_target_flags = --extern ffi --extern pin_init
@@ -337,6 +359,7 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
                -L$(objtree)/$(obj) --extern ffi --extern pin_init \
                --extern kernel --extern build_error --extern macros \
                --extern bindings --extern uapi \
+               --extern zerocopy \
                --no-run --crate-name kernel -Zunstable-options \
                --sysroot=/dev/null \
                $(doctests_modifiers_workaround) \
@@ -599,6 +622,7 @@ rust-analyzer:
                --cfgs='syn=$(syn-cfgs)' \
                --cfgs='pin_init_internal=$(pin_init_internal-cfgs)' \
                --cfgs='pin_init=$(pin_init-cfgs)' \
+               --envs='zerocopy=$(zerocopy-envs)' \
                $(realpath $(srctree)) $(realpath $(objtree)) \
                $(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
                > rust-project.json
@@ -670,6 +694,13 @@ $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
 $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
        +$(call if_changed_rule,rustc_library)
 
+$(obj)/zerocopy.o: private skip_clippy = 1
+$(obj)/zerocopy.o: private skip_gendwarfksyms = 1
+$(obj)/zerocopy.o: private rustc_target_envs := $(zerocopy-envs)
+$(obj)/zerocopy.o: private rustc_target_flags = $(zerocopy-flags)
+$(obj)/zerocopy.o: $(src)/zerocopy/src/lib.rs $(obj)/compiler_builtins.o FORCE
+       +$(call if_changed_rule,rustc_library)
+
 $(obj)/pin_init.o: private skip_gendwarfksyms = 1
 $(obj)/pin_init.o: private rustc_target_flags = $(pin_init-flags)
 $(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \
@@ -705,9 +736,11 @@ $(obj)/uapi.o: $(src)/uapi/lib.rs \
        +$(call if_changed_rule,rustc_library)
 
 $(obj)/kernel.o: private rustc_target_flags = --extern ffi --extern pin_init \
-    --extern build_error --extern macros --extern bindings --extern uapi
+    --extern build_error --extern macros --extern bindings --extern uapi \
+    --extern zerocopy
 $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/build_error.o $(obj)/pin_init.o \
-    $(obj)/$(libmacros_name) $(obj)/bindings.o $(obj)/uapi.o FORCE
+    $(obj)/$(libmacros_name) $(obj)/bindings.o $(obj)/uapi.o \
+    $(obj)/zerocopy.o FORCE
        +$(call if_changed_rule,rustc_library)
 
 ifdef CONFIG_JUMP_LABEL
index 3498d25b15e8532d668cd88e6039d3ad660a8f74..ddf0461dda6abaebed58f33a980a6a5d4d02580d 100644 (file)
@@ -329,6 +329,7 @@ rust_common_cmd = \
        -Zcrate-attr=no_std \
        -Zcrate-attr='feature($(rust_allowed_features))' \
        -Zunstable-options --extern pin_init --extern kernel \
+       --extern zerocopy \
        --crate-type rlib -L $(objtree)/rust/ \
        --sysroot=/dev/null \
        --out-dir $(dir $@) --emit=dep-info=$(depfile)
index 2477209e1e944172c292319b14f29ce72b3c3eb4..80f7647f633a84ae26933775567c978faf7e7a8b 100755 (executable)
@@ -276,6 +276,12 @@ def generate_crates(
         [core, compiler_builtins],
     )
 
+    zerocopy = append_crate(
+        "zerocopy",
+        srctree / "rust" / "zerocopy" / "src" / "lib.rs",
+        [core, compiler_builtins],
+    )
+
     def append_crate_with_generated(
         display_name: str,
         deps: List[Dependency],
@@ -304,7 +310,7 @@ def generate_crates(
     bindings = append_crate_with_generated("bindings", [core, ffi, pin_init])
     uapi = append_crate_with_generated("uapi", [core, ffi, pin_init])
     kernel = append_crate_with_generated(
-        "kernel", [core, macros, build_error, pin_init, ffi, bindings, uapi]
+        "kernel", [core, macros, build_error, pin_init, ffi, bindings, uapi, zerocopy]
     )
 
     scripts = srctree / "scripts"
@@ -349,7 +355,7 @@ def generate_crates(
             append_crate(
                 crate_name,
                 path,
-                [core, kernel, pin_init],
+                [core, kernel, pin_init, zerocopy],
                 cfg=generated_cfg,
             )