[PATCH 1/4] kbuild: rust: Expand rusttest target for macros

Ethan D. Twardy posted 4 patches 1 year, 5 months ago
There is a newer version of this series
[PATCH 1/4] kbuild: rust: Expand rusttest target for macros
Posted by Ethan D. Twardy 1 year, 5 months ago
Previously, the rusttest target for the macros crate did not specify
the dependencies necessary to run the rustdoc tests. These test rely on
the kernel crate, so add a specialized rustdoc tests command for this
particular crate.

Signed-off-by: Ethan D. Twardy <ethan.twardy@gmail.com>

diff --git a/rust/Makefile b/rust/Makefile
index f70d5e244fee..de58f0cae23b 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -147,6 +147,23 @@ rusttestlib-macros: private rustc_test_library_proc = yes
 rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
 	+$(call if_changed,rustc_test_library)
 
+rusttestlib-build_error: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
+	+$(call if_changed,rustc_test_library)
+
+rusttestlib-uapi: $(src)/uapi/lib.rs \
+    $(obj)/compiler_builtins.o \
+    $(obj)/uapi/uapi_generated.rs FORCE
+	+$(call if_changed,rustc_test_library)
+
+rusttestlib-kernel: private rustc_target_flags = --extern alloc \
+    --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
+    --extern bindings --extern uapi
+rusttestlib-kernel: $(src)/kernel/lib.rs rustdoc-compiler_builtins \
+    rustdoc-alloc rusttestlib-bindings rusttestlib-uapi rusttestlib-build_error \
+    $(obj)/libmacros.so \
+    $(obj)/bindings.o FORCE
+	+$(call if_changed,rustc_test_library)
+
 rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE
 	+$(call if_changed,rustc_test_library)
 
@@ -245,11 +262,24 @@ quiet_cmd_rustsysroot = RUSTSYSROOT
 rusttest-prepare: FORCE
 	+$(call if_changed,rustsysroot)
 
-rusttest-macros: private rustc_target_flags = --extern proc_macro
+quiet_cmd_rustdoc_test_macros = RUSTDOC T $<
+      cmd_rustdoc_test_macros = \
+	OBJTREE=$(abspath $(objtree)) \
+	$(RUSTDOC) --test $(rust_common_flags) \
+		@$(objtree)/include/generated/rustc_cfg \
+		$(rustc_target_flags) $(rustdoc_test_target_flags) \
+		--sysroot $(objtree)/$(obj)/test/sysroot $(rustdoc_test_quiet) \
+		-L$(objtree)/$(obj)/test --output $(rustdoc_output) \
+		-Zproc-macro-backtrace \
+		--crate-name $(subst rusttest-,,$@) $<
+
+rusttest-macros: private rustc_target_flags = --extern proc_macro \
+	--extern macros=$(objtree)/$(obj)/libmacros.so --extern kernel
 rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
-rusttest-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
+rusttest-macros: $(src)/macros/lib.rs rusttest-prepare \
+    rusttestlib-macros rusttestlib-kernel FORCE
 	+$(call if_changed,rustc_test)
-	+$(call if_changed,rustdoc_test)
+	+$(call if_changed,rustdoc_test_macros)
 
 rusttest-kernel: private rustc_target_flags = --extern alloc \
     --extern build_error --extern macros --extern bindings --extern uapi
-- 
2.44.2
Re: [PATCH 1/4] kbuild: rust: Expand rusttest target for macros
Posted by kernel test robot 1 year, 5 months ago
Hi Ethan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on a126eca844353360ebafa9088d22865cb8e022e3]

url:    https://github.com/intel-lab-lkp/linux/commits/Ethan-D-Twardy/kbuild-rust-Expand-rusttest-target-for-macros/20240625-230535
base:   a126eca844353360ebafa9088d22865cb8e022e3
patch link:    https://lore.kernel.org/r/20240624030327.90301-2-ethan.twardy%40gmail.com
patch subject: [PATCH 1/4] kbuild: rust: Expand rusttest target for macros
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20240626/202406261127.VzakF8rL-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240626/202406261127.VzakF8rL-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202406261127.VzakF8rL-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> rust/Makefile:151: warning: overriding recipe for target 'rusttestlib-build_error'
>> rust/Makefile:143: warning: ignoring old recipe for target 'rusttestlib-build_error'
>> rust/Makefile:171: warning: overriding recipe for target 'rusttestlib-uapi'
>> rust/Makefile:156: warning: ignoring old recipe for target 'rusttestlib-uapi'


vim +151 rust/Makefile

    59	
    60	core-cfgs = \
    61	    --cfg no_fp_fmt_parse
    62	
    63	alloc-cfgs = \
    64	    --cfg no_global_oom_handling \
    65	    --cfg no_rc \
    66	    --cfg no_sync
    67	
    68	quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
    69	      cmd_rustdoc = \
    70		OBJTREE=$(abspath $(objtree)) \
    71		$(RUSTDOC) $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags)) \
    72			$(rustc_target_flags) -L$(objtree)/$(obj) \
    73			--output $(rustdoc_output) \
    74			--crate-name $(subst rustdoc-,,$@) \
    75			$(if $(rustdoc_host),,--sysroot=/dev/null) \
    76			@$(objtree)/include/generated/rustc_cfg $<
    77	
    78	# The `html_logo_url` and `html_favicon_url` forms of the `doc` attribute
    79	# can be used to specify a custom logo. However:
    80	#   - The given value is used as-is, thus it cannot be relative or a local file
    81	#     (unlike the non-custom case) since the generated docs have subfolders.
    82	#   - It requires adding it to every crate.
    83	#   - It requires changing `core` which comes from the sysroot.
    84	#
    85	# Using `-Zcrate-attr` would solve the last two points, but not the first.
    86	# The https://github.com/rust-lang/rfcs/pull/3226 RFC suggests two new
    87	# command-like flags to solve the issue. Meanwhile, we use the non-custom case
    88	# and then retouch the generated files.
    89	rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
    90	    rustdoc-alloc rustdoc-kernel
    91		$(Q)cp $(srctree)/Documentation/images/logo.svg $(rustdoc_output)/static.files/
    92		$(Q)cp $(srctree)/Documentation/images/COPYING-logo $(rustdoc_output)/static.files/
    93		$(Q)find $(rustdoc_output) -name '*.html' -type f -print0 | xargs -0 sed -Ei \
    94			-e 's:rust-logo-[0-9a-f]+\.svg:logo.svg:g' \
    95			-e 's:favicon-[0-9a-f]+\.svg:logo.svg:g' \
    96			-e 's:<link rel="alternate icon" type="image/png" href="[/.]+/static\.files/favicon-(16x16|32x32)-[0-9a-f]+\.png">::g' \
    97			-e 's:<a href="srctree/([^"]+)">:<a href="$(realpath $(srctree))/\1">:g'
    98		$(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \
    99			echo ".logo-container > img { object-fit: contain; }" >> $$f; done
   100	
   101	rustdoc-macros: private rustdoc_host = yes
   102	rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
   103	    --extern proc_macro
   104	rustdoc-macros: $(src)/macros/lib.rs FORCE
   105		+$(call if_changed,rustdoc)
   106	
   107	rustdoc-core: private rustc_target_flags = $(core-cfgs)
   108	rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
   109		+$(call if_changed,rustdoc)
   110	
   111	rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
   112		+$(call if_changed,rustdoc)
   113	
   114	# We need to allow `rustdoc::broken_intra_doc_links` because some
   115	# `no_global_oom_handling` functions refer to non-`no_global_oom_handling`
   116	# functions. Ideally `rustdoc` would have a way to distinguish broken links
   117	# due to things that are "configured out" vs. entirely non-existing ones.
   118	rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \
   119	    -Arustdoc::broken_intra_doc_links
   120	rustdoc-alloc: $(RUST_LIB_SRC)/alloc/src/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE
   121		+$(call if_changed,rustdoc)
   122	
   123	rustdoc-kernel: private rustc_target_flags = --extern alloc \
   124	    --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
   125	    --extern bindings --extern uapi
   126	rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \
   127	    rustdoc-compiler_builtins rustdoc-alloc $(obj)/libmacros.so \
   128	    $(obj)/bindings.o FORCE
   129		+$(call if_changed,rustdoc)
   130	
   131	quiet_cmd_rustc_test_library = RUSTC TL $<
   132	      cmd_rustc_test_library = \
   133		OBJTREE=$(abspath $(objtree)) \
   134		$(RUSTC) $(rust_common_flags) \
   135			@$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \
   136			--crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \
   137			--out-dir $(objtree)/$(obj)/test --cfg testlib \
   138			--sysroot $(objtree)/$(obj)/test/sysroot \
   139			-L$(objtree)/$(obj)/test \
   140			--crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $<
   141	
   142	rusttestlib-build_error: $(src)/build_error.rs rusttest-prepare FORCE
 > 143		+$(call if_changed,rustc_test_library)
   144	
   145	rusttestlib-macros: private rustc_target_flags = --extern proc_macro
   146	rusttestlib-macros: private rustc_test_library_proc = yes
   147	rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
   148		+$(call if_changed,rustc_test_library)
   149	
   150	rusttestlib-build_error: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
 > 151		+$(call if_changed,rustc_test_library)
   152	
   153	rusttestlib-uapi: $(src)/uapi/lib.rs \
   154	    $(obj)/compiler_builtins.o \
   155	    $(obj)/uapi/uapi_generated.rs FORCE
 > 156		+$(call if_changed,rustc_test_library)
   157	
   158	rusttestlib-kernel: private rustc_target_flags = --extern alloc \
   159	    --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
   160	    --extern bindings --extern uapi
   161	rusttestlib-kernel: $(src)/kernel/lib.rs rustdoc-compiler_builtins \
   162	    rustdoc-alloc rusttestlib-bindings rusttestlib-uapi rusttestlib-build_error \
   163	    $(obj)/libmacros.so \
   164	    $(obj)/bindings.o FORCE
   165		+$(call if_changed,rustc_test_library)
   166	
   167	rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE
   168		+$(call if_changed,rustc_test_library)
   169	
   170	rusttestlib-uapi: $(src)/uapi/lib.rs rusttest-prepare FORCE
 > 171		+$(call if_changed,rustc_test_library)
   172	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki