1# SPDX-License-Identifier: GPL-2.0
2
3# Where to place rustdoc generated documentation
4rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
5
6obj-$(CONFIG_RUST) += core.o compiler_builtins.o
7always-$(CONFIG_RUST) += exports_core_generated.h
8
9# Missing prototypes are expected in the helpers since these are exported
10# for Rust only, thus there is no header nor prototypes.
11obj-$(CONFIG_RUST) += helpers.o
12CFLAGS_REMOVE_helpers.o = -Wmissing-prototypes -Wmissing-declarations
13
14always-$(CONFIG_RUST) += libmacros.so
15no-clean-files += libmacros.so
16
17always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs
18obj-$(CONFIG_RUST) += alloc.o bindings.o kernel.o
19always-$(CONFIG_RUST) += exports_alloc_generated.h exports_bindings_generated.h \
20    exports_kernel_generated.h
21
22always-$(CONFIG_RUST) += uapi/uapi_generated.rs
23obj-$(CONFIG_RUST) += uapi.o
24
25ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW
26obj-$(CONFIG_RUST) += build_error.o
27else
28always-$(CONFIG_RUST) += build_error.o
29endif
30
31obj-$(CONFIG_RUST) += exports.o
32
33always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
34always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
35
36obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.o
37obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.o
38
39# Avoids running `$(RUSTC)` for the sysroot when it may not be available.
40ifdef CONFIG_RUST
41
42# `$(rust_flags)` is passed in case the user added `--sysroot`.
43rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot)
44rustc_host_target := $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cut -d' ' -f2)
45RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/src/rust/library
46
47ifeq ($(quiet),silent_)
48cargo_quiet=-q
49rust_test_quiet=-q
50rustdoc_test_quiet=--test-args -q
51rustdoc_test_kernel_quiet=>/dev/null
52else ifeq ($(quiet),quiet_)
53rust_test_quiet=-q
54rustdoc_test_quiet=--test-args -q
55rustdoc_test_kernel_quiet=>/dev/null
56else
57cargo_quiet=--verbose
58endif
59
60core-cfgs = \
61    --cfg no_fp_fmt_parse
62
63alloc-cfgs = \
64    --cfg no_global_oom_handling \
65    --cfg no_rc \
66    --cfg no_sync
67
68quiet_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.
89rustdoc: 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
101rustdoc-macros: private rustdoc_host = yes
102rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
103    --extern proc_macro
104rustdoc-macros: $(src)/macros/lib.rs FORCE
105	+$(call if_changed,rustdoc)
106
107rustdoc-core: private rustc_target_flags = $(core-cfgs)
108rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
109	+$(call if_changed,rustdoc)
110
111rustdoc-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.
118rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \
119    -Arustdoc::broken_intra_doc_links
120rustdoc-alloc: $(RUST_LIB_SRC)/alloc/src/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE
121	+$(call if_changed,rustdoc)
122
123rustdoc-kernel: private rustc_target_flags = --extern alloc \
124    --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
125    --extern bindings --extern uapi
126rustdoc-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
131quiet_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
142rusttestlib-build_error: $(src)/build_error.rs rusttest-prepare FORCE
143	+$(call if_changed,rustc_test_library)
144
145rusttestlib-macros: private rustc_target_flags = --extern proc_macro
146rusttestlib-macros: private rustc_test_library_proc = yes
147rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
148	+$(call if_changed,rustc_test_library)
149
150rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE
151	+$(call if_changed,rustc_test_library)
152
153rusttestlib-uapi: $(src)/uapi/lib.rs rusttest-prepare FORCE
154	+$(call if_changed,rustc_test_library)
155
156quiet_cmd_rustdoc_test = RUSTDOC T $<
157      cmd_rustdoc_test = \
158	OBJTREE=$(abspath $(objtree)) \
159	$(RUSTDOC) --test $(rust_common_flags) \
160		@$(objtree)/include/generated/rustc_cfg \
161		$(rustc_target_flags) $(rustdoc_test_target_flags) \
162		--sysroot $(objtree)/$(obj)/test/sysroot $(rustdoc_test_quiet) \
163		-L$(objtree)/$(obj)/test --output $(rustdoc_output) \
164		--crate-name $(subst rusttest-,,$@) $<
165
166quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
167      cmd_rustdoc_test_kernel = \
168	rm -rf $(objtree)/$(obj)/test/doctests/kernel; \
169	mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \
170	OBJTREE=$(abspath $(objtree)) \
171	$(RUSTDOC) --test $(rust_flags) \
172		-L$(objtree)/$(obj) --extern alloc --extern kernel \
173		--extern build_error --extern macros \
174		--extern bindings --extern uapi \
175		--no-run --crate-name kernel -Zunstable-options \
176		--sysroot=/dev/null \
177		--test-builder $(objtree)/scripts/rustdoc_test_builder \
178		$< $(rustdoc_test_kernel_quiet); \
179	$(objtree)/scripts/rustdoc_test_gen
180
181%/doctests_kernel_generated.rs %/doctests_kernel_generated_kunit.c: \
182    $(src)/kernel/lib.rs $(obj)/kernel.o \
183    $(objtree)/scripts/rustdoc_test_builder \
184    $(objtree)/scripts/rustdoc_test_gen FORCE
185	+$(call if_changed,rustdoc_test_kernel)
186
187# We cannot use `-Zpanic-abort-tests` because some tests are dynamic,
188# so for the moment we skip `-Cpanic=abort`.
189quiet_cmd_rustc_test = RUSTC T  $<
190      cmd_rustc_test = \
191	OBJTREE=$(abspath $(objtree)) \
192	$(RUSTC) --test $(rust_common_flags) \
193		@$(objtree)/include/generated/rustc_cfg \
194		$(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \
195		--sysroot $(objtree)/$(obj)/test/sysroot \
196		-L$(objtree)/$(obj)/test \
197		--crate-name $(subst rusttest-,,$@) $<; \
198	$(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \
199		$(rustc_test_run_flags)
200
201rusttest: rusttest-macros rusttest-kernel
202
203# This prepares a custom sysroot with our custom `alloc` instead of
204# the standard one.
205#
206# This requires several hacks:
207#   - Unlike `core` and `alloc`, `std` depends on more than a dozen crates,
208#     including third-party crates that need to be downloaded, plus custom
209#     `build.rs` steps. Thus hardcoding things here is not maintainable.
210#   - `cargo` knows how to build the standard library, but it is an unstable
211#     feature so far (`-Zbuild-std`).
212#   - `cargo` only considers the use case of building the standard library
213#     to use it in a given package. Thus we need to create a dummy package
214#     and pick the generated libraries from there.
215#   - The usual ways of modifying the dependency graph in `cargo` do not seem
216#     to apply for the `-Zbuild-std` steps, thus we have to mislead it
217#     by modifying the sources in the sysroot.
218#   - To avoid messing with the user's Rust installation, we create a clone
219#     of the sysroot. However, `cargo` ignores `RUSTFLAGS` in the `-Zbuild-std`
220#     steps, thus we use a wrapper binary passed via `RUSTC` to pass the flag.
221#
222# In the future, we hope to avoid the whole ordeal by either:
223#   - Making the `test` crate not depend on `std` (either improving upstream
224#     or having our own custom crate).
225#   - Making the tests run in kernel space (requires the previous point).
226#   - Making `std` and friends be more like a "normal" crate, so that
227#     `-Zbuild-std` and related hacks are not needed.
228quiet_cmd_rustsysroot = RUSTSYSROOT
229      cmd_rustsysroot = \
230	rm -rf $(objtree)/$(obj)/test; \
231	mkdir -p $(objtree)/$(obj)/test; \
232	cp -a $(rustc_sysroot) $(objtree)/$(obj)/test/sysroot; \
233	echo '\#!/bin/sh' > $(objtree)/$(obj)/test/rustc_sysroot; \
234	echo "$(RUSTC) --sysroot=$(abspath $(objtree)/$(obj)/test/sysroot) \"\$$@\"" \
235		>> $(objtree)/$(obj)/test/rustc_sysroot; \
236	chmod u+x $(objtree)/$(obj)/test/rustc_sysroot; \
237	$(CARGO) -q new $(objtree)/$(obj)/test/dummy; \
238	RUSTC=$(objtree)/$(obj)/test/rustc_sysroot $(CARGO) $(cargo_quiet) \
239		test -Zbuild-std --target $(rustc_host_target) \
240		--manifest-path $(objtree)/$(obj)/test/dummy/Cargo.toml; \
241	rm $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib/*; \
242	cp $(objtree)/$(obj)/test/dummy/target/$(rustc_host_target)/debug/deps/* \
243		$(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib
244
245rusttest-prepare: FORCE
246	+$(call if_changed,rustsysroot)
247
248rusttest-macros: private rustc_target_flags = --extern proc_macro
249rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
250rusttest-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
251	+$(call if_changed,rustc_test)
252	+$(call if_changed,rustdoc_test)
253
254rusttest-kernel: private rustc_target_flags = --extern alloc \
255    --extern build_error --extern macros --extern bindings --extern uapi
256rusttest-kernel: $(src)/kernel/lib.rs rusttest-prepare \
257    rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \
258    rusttestlib-uapi FORCE
259	+$(call if_changed,rustc_test)
260	+$(call if_changed,rustc_test_library)
261
262ifdef CONFIG_CC_IS_CLANG
263bindgen_c_flags = $(c_flags)
264else
265# bindgen relies on libclang to parse C. Ideally, bindgen would support a GCC
266# plugin backend and/or the Clang driver would be perfectly compatible with GCC.
267#
268# For the moment, here we are tweaking the flags on the fly. This is a hack,
269# and some kernel configurations may not work (e.g. `GCC_PLUGIN_RANDSTRUCT`
270# if we end up using one of those structs).
271bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
272	-mskip-rax-setup -mgeneral-regs-only -msign-return-address=% \
273	-mindirect-branch=thunk-extern -mindirect-branch-register \
274	-mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \
275	-mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \
276	-mno-pointers-to-nested-functions -mno-string \
277	-mno-strict-align -mstrict-align \
278	-fconserve-stack -falign-jumps=% -falign-loops=% \
279	-femit-struct-debug-baseonly -fno-ipa-cp-clone -fno-ipa-sra \
280	-fno-partial-inlining -fplugin-arg-arm_ssp_per_task_plugin-% \
281	-fno-reorder-blocks -fno-allow-store-data-races -fasan-shadow-offset=% \
282	-fzero-call-used-regs=% -fno-stack-clash-protection \
283	-fno-inline-functions-called-once -fsanitize=bounds-strict \
284	-fstrict-flex-arrays=% \
285	--param=% --param asan-%
286
287# Derived from `scripts/Makefile.clang`.
288BINDGEN_TARGET_x86	:= x86_64-linux-gnu
289BINDGEN_TARGET_arm64	:= aarch64-linux-gnu
290BINDGEN_TARGET		:= $(BINDGEN_TARGET_$(SRCARCH))
291
292# All warnings are inhibited since GCC builds are very experimental,
293# many GCC warnings are not supported by Clang, they may only appear in
294# some configurations, with new GCC versions, etc.
295bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET)
296
297# Auto variable zero-initialization requires an additional special option with
298# clang that is going to be removed sometime in the future (likely in
299# clang-18), so make sure to pass this option only if clang supports it
300# (libclang major version < 16).
301#
302# https://github.com/llvm/llvm-project/issues/44842
303# https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags
304ifdef CONFIG_INIT_STACK_ALL_ZERO
305libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p')
306ifeq ($(shell expr $(libclang_maj_ver) \< 16), 1)
307bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
308endif
309endif
310
311bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
312	$(bindgen_extra_c_flags)
313endif
314
315ifdef CONFIG_LTO
316bindgen_c_flags_lto = $(filter-out $(CC_FLAGS_LTO), $(bindgen_c_flags))
317else
318bindgen_c_flags_lto = $(bindgen_c_flags)
319endif
320
321bindgen_c_flags_final = $(bindgen_c_flags_lto) -D__BINDGEN__
322
323quiet_cmd_bindgen = BINDGEN $@
324      cmd_bindgen = \
325	$(BINDGEN) $< $(bindgen_target_flags) \
326		--use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
327		--no-debug '.*' \
328		-o $@ -- $(bindgen_c_flags_final) -DMODULE \
329		$(bindgen_target_cflags) $(bindgen_target_extra)
330
331$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
332    $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
333$(obj)/bindings/bindings_generated.rs: private bindgen_target_extra = ; \
334    sed -Ei 's/pub const RUST_CONST_HELPER_([a-zA-Z0-9_]*)/pub const \1/g' $@
335$(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
336    $(src)/bindgen_parameters FORCE
337	$(call if_changed_dep,bindgen)
338
339$(obj)/uapi/uapi_generated.rs: private bindgen_target_flags = \
340    $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
341$(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \
342    $(src)/bindgen_parameters FORCE
343	$(call if_changed_dep,bindgen)
344
345# See `CFLAGS_REMOVE_helpers.o` above. In addition, Clang on C does not warn
346# with `-Wmissing-declarations` (unlike GCC), so it is not strictly needed here
347# given it is `libclang`; but for consistency, future Clang changes and/or
348# a potential future GCC backend for `bindgen`, we disable it too.
349$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \
350    --blocklist-type '.*' --allowlist-var '' \
351    --allowlist-function 'rust_helper_.*'
352$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_cflags = \
353    -I$(objtree)/$(obj) -Wno-missing-prototypes -Wno-missing-declarations
354$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; \
355    sed -Ei 's/pub fn rust_helper_([a-zA-Z0-9_]*)/#[link_name="rust_helper_\1"]\n    pub fn \1/g' $@
356$(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers.c FORCE
357	$(call if_changed_dep,bindgen)
358
359quiet_cmd_exports = EXPORTS $@
360      cmd_exports = \
361	$(NM) -p --defined-only $< \
362		| awk '/ (T|R|D) / {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@
363
364$(obj)/exports_core_generated.h: $(obj)/core.o FORCE
365	$(call if_changed,exports)
366
367$(obj)/exports_alloc_generated.h: $(obj)/alloc.o FORCE
368	$(call if_changed,exports)
369
370$(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
371	$(call if_changed,exports)
372
373$(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
374	$(call if_changed,exports)
375
376quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
377      cmd_rustc_procmacro = \
378	$(RUSTC_OR_CLIPPY) $(rust_common_flags) \
379		-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
380		-Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
381		--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
382		--crate-type proc-macro \
383		--crate-name $(patsubst lib%.so,%,$(notdir $@)) $<
384
385# Procedural macros can only be used with the `rustc` that compiled it.
386# Therefore, to get `libmacros.so` automatically recompiled when the compiler
387# version changes, we add `core.o` as a dependency (even if it is not needed).
388$(obj)/libmacros.so: $(src)/macros/lib.rs $(obj)/core.o FORCE
389	+$(call if_changed_dep,rustc_procmacro)
390
391quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
392      cmd_rustc_library = \
393	OBJTREE=$(abspath $(objtree)) \
394	$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
395		$(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
396		--emit=dep-info=$(depfile) --emit=obj=$@ \
397		--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
398		--crate-type rlib -L$(objtree)/$(obj) \
399		--crate-name $(patsubst %.o,%,$(notdir $@)) $< \
400		--sysroot=/dev/null \
401	$(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)
402
403rust-analyzer:
404	$(Q)$(srctree)/scripts/generate_rust_analyzer.py \
405		--cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \
406		$(realpath $(srctree)) $(realpath $(objtree)) \
407		$(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \
408		$(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json
409
410redirect-intrinsics = \
411	__addsf3 __eqsf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __unordsf2 \
412	__adddf3 __ledf2 __ltdf2 __muldf3 __unorddf2 \
413	__muloti4 __multi3 \
414	__udivmodti4 __udivti3 __umodti3
415
416ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
417	# These intrinsics are defined for ARM64 and RISCV64
418	redirect-intrinsics += \
419		__ashrti3 \
420		__ashlti3 __lshrti3
421endif
422
423$(obj)/core.o: private skip_clippy = 1
424$(obj)/core.o: private skip_flags = -Dunreachable_pub
425$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
426$(obj)/core.o: private rustc_target_flags = $(core-cfgs)
427$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
428	+$(call if_changed_dep,rustc_library)
429ifneq ($(or $(CONFIG_X86_64),$(CONFIG_LOONGARCH)),)
430$(obj)/core.o: scripts/target.json
431endif
432
433$(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
434$(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
435	+$(call if_changed_dep,rustc_library)
436
437$(obj)/alloc.o: private skip_clippy = 1
438$(obj)/alloc.o: private skip_flags = -Dunreachable_pub
439$(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
440$(obj)/alloc.o: $(RUST_LIB_SRC)/alloc/src/lib.rs $(obj)/compiler_builtins.o FORCE
441	+$(call if_changed_dep,rustc_library)
442
443$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
444	+$(call if_changed_dep,rustc_library)
445
446$(obj)/bindings.o: $(src)/bindings/lib.rs \
447    $(obj)/compiler_builtins.o \
448    $(obj)/bindings/bindings_generated.rs \
449    $(obj)/bindings/bindings_helpers_generated.rs FORCE
450	+$(call if_changed_dep,rustc_library)
451
452$(obj)/uapi.o: $(src)/uapi/lib.rs \
453    $(obj)/compiler_builtins.o \
454    $(obj)/uapi/uapi_generated.rs FORCE
455	+$(call if_changed_dep,rustc_library)
456
457$(obj)/kernel.o: private rustc_target_flags = --extern alloc \
458    --extern build_error --extern macros --extern bindings --extern uapi
459$(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \
460    $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE
461	+$(call if_changed_dep,rustc_library)
462
463endif # CONFIG_RUST
464