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: proc-macro2: enable support in kbuild

With all the new files in place and ready from the new crate, enable
the support for it in the build system.

`proc_macro_byte_character` and `proc_macro_c_str_literals` were
stabilized in Rust 1.79.0 [1] and were implemented earlier than our
minimum Rust version (1.78) [2][3]. Thus just enable them instead of using
the `cfg` that `proc-macro2` uses to emulate them in older compilers.

In addition, skip formatting for this vendored crate and take the chance
to add a comment mentioning this.

Link: https://github.com/rust-lang/rust/pull/123431 [1]
Link: https://github.com/rust-lang/rust/pull/112711 [2]
Link: https://github.com/rust-lang/rust/pull/119651 [3]
Reviewed-by: Gary Guo <gary@garyguo.net>
Tested-by: Gary Guo <gary@garyguo.net>
Tested-by: Jesung Yang <y.j3ms.n@gmail.com>
Link: https://patch.msgid.link/20251124151837.2184382-11-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

+42 -2
+5
Makefile
··· 1826 1826 $(Q)$(MAKE) $(build)=rust $@ 1827 1827 1828 1828 # Formatting targets 1829 + # 1830 + # Generated files as well as vendored crates are skipped. 1829 1831 PHONY += rustfmt rustfmtcheck 1830 1832 1831 1833 rustfmt: 1832 1834 $(Q)find $(srctree) $(RCS_FIND_IGNORE) \ 1835 + \( \ 1836 + -path $(srctree)/rust/proc-macro2 \ 1837 + \) -prune -o \ 1833 1838 -type f -a -name '*.rs' -a ! -name '*generated*' -print \ 1834 1839 | xargs $(RUSTFMT) $(rustfmt_flags) 1835 1840
+30 -2
rust/Makefile
··· 27 27 28 28 obj-$(CONFIG_RUST) += exports.o 29 29 30 + always-$(CONFIG_RUST) += libproc_macro2.rlib 31 + 30 32 always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs 31 33 always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c 32 34 ··· 77 75 core-flags := \ 78 76 --edition=$(core-edition) \ 79 77 $(call cfgs-to-flags,$(core-cfgs)) 78 + 79 + proc_macro2-cfgs := \ 80 + feature="proc-macro" \ 81 + wrap_proc_macro \ 82 + $(if $(call rustc-min-version,108800),proc_macro_span_file proc_macro_span_location) 83 + 84 + # Stable since Rust 1.79.0: `feature(proc_macro_byte_character,proc_macro_c_str_literals)`. 85 + proc_macro2-flags := \ 86 + --cap-lints=allow \ 87 + -Zcrate-attr='feature(proc_macro_byte_character,proc_macro_c_str_literals)' \ 88 + $(call cfgs-to-flags,$(proc_macro2-cfgs)) 80 89 81 90 # `rustdoc` did not save the target modifiers, thus workaround for 82 91 # the time being (https://github.com/rust-lang/rust/issues/144521). ··· 138 125 $(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \ 139 126 echo ".logo-container > img { object-fit: contain; }" >> $$f; done 140 127 128 + rustdoc-proc_macro2: private rustdoc_host = yes 129 + rustdoc-proc_macro2: private rustc_target_flags = $(proc_macro2-flags) 130 + rustdoc-proc_macro2: $(src)/proc-macro2/lib.rs rustdoc-clean FORCE 131 + +$(call if_changed,rustdoc) 132 + 141 133 rustdoc-macros: private rustdoc_host = yes 142 134 rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \ 143 135 --extern proc_macro 144 - rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean FORCE 136 + rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean rustdoc-proc_macro2 FORCE 145 137 +$(call if_changed,rustdoc) 146 138 147 139 # Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should ··· 201 183 +$(call if_changed,rustc_test_library) 202 184 203 185 rusttestlib-ffi: $(src)/ffi.rs FORCE 186 + +$(call if_changed,rustc_test_library) 187 + 188 + rusttestlib-proc_macro2: private rustc_target_flags = $(proc_macro2-flags) 189 + rusttestlib-proc_macro2: $(src)/proc-macro2/lib.rs FORCE 204 190 +$(call if_changed,rustc_test_library) 205 191 206 192 rusttestlib-macros: private rustc_target_flags = --extern proc_macro ··· 453 431 mv $(objtree)/$(obj)/$(patsubst lib%.rlib,%,$(notdir $@)).d $(depfile); \ 454 432 sed -i '/^\#/d' $(depfile) 455 433 434 + $(obj)/libproc_macro2.rlib: private skip_clippy = 1 435 + $(obj)/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags) 436 + $(obj)/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE 437 + +$(call if_changed_dep,rustc_procmacrolibrary) 438 + 456 439 quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ 457 440 cmd_rustc_procmacro = \ 458 441 $(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \ ··· 469 442 @$(objtree)/include/generated/rustc_cfg $< 470 443 471 444 # Procedural macros can only be used with the `rustc` that compiled it. 472 - $(obj)/$(libmacros_name): $(src)/macros/lib.rs FORCE 445 + $(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib FORCE 473 446 +$(call if_changed_dep,rustc_procmacro) 474 447 475 448 $(obj)/$(libpin_init_internal_name): private rustc_target_flags = --cfg kernel ··· 492 465 rust-analyzer: 493 466 $(Q)MAKEFLAGS= $(srctree)/scripts/generate_rust_analyzer.py \ 494 467 --cfgs='core=$(core-cfgs)' $(core-edition) \ 468 + --cfgs='proc_macro2=$(proc_macro2-cfgs)' \ 495 469 $(realpath $(srctree)) $(realpath $(objtree)) \ 496 470 $(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \ 497 471 > rust-project.json
+7
scripts/generate_rust_analyzer.py
··· 87 87 ) 88 88 89 89 append_crate( 90 + "proc_macro2", 91 + srctree / "rust" / "proc-macro2" / "lib.rs", 92 + ["core", "alloc", "std", "proc_macro"], 93 + cfg=crates_cfgs["proc_macro2"], 94 + ) 95 + 96 + append_crate( 90 97 "macros", 91 98 srctree / "rust" / "macros" / "lib.rs", 92 99 ["std", "proc_macro"],