xref: /linux/rust/Makefile (revision 069ced2206d23e56b89ed118e17a8a71a05e0ca3)
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 $(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_borrow \
65    --cfg no_fmt \
66    --cfg no_global_oom_handling \
67    --cfg no_macros \
68    --cfg no_rc \
69    --cfg no_str \
70    --cfg no_string \
71    --cfg no_sync \
72    --cfg no_thin
73
74quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
75      cmd_rustdoc = \
76	OBJTREE=$(abspath $(objtree)) \
77	$(RUSTDOC) $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags)) \
78		$(rustc_target_flags) -L$(objtree)/$(obj) \
79		--output $(rustdoc_output) \
80		--crate-name $(subst rustdoc-,,$@) \
81		@$(objtree)/include/generated/rustc_cfg $<
82
83# The `html_logo_url` and `html_favicon_url` forms of the `doc` attribute
84# can be used to specify a custom logo. However:
85#   - The given value is used as-is, thus it cannot be relative or a local file
86#     (unlike the non-custom case) since the generated docs have subfolders.
87#   - It requires adding it to every crate.
88#   - It requires changing `core` which comes from the sysroot.
89#
90# Using `-Zcrate-attr` would solve the last two points, but not the first.
91# The https://github.com/rust-lang/rfcs/pull/3226 RFC suggests two new
92# command-like flags to solve the issue. Meanwhile, we use the non-custom case
93# and then retouch the generated files.
94rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
95    rustdoc-alloc rustdoc-kernel
96	$(Q)cp $(srctree)/Documentation/images/logo.svg $(rustdoc_output)/static.files/
97	$(Q)cp $(srctree)/Documentation/images/COPYING-logo $(rustdoc_output)/static.files/
98	$(Q)find $(rustdoc_output) -name '*.html' -type f -print0 | xargs -0 sed -Ei \
99		-e 's:rust-logo-[0-9a-f]+\.svg:logo.svg:g' \
100		-e 's:favicon-[0-9a-f]+\.svg:logo.svg:g' \
101		-e 's:<link rel="alternate icon" type="image/png" href="[/.]+/static\.files/favicon-(16x16|32x32)-[0-9a-f]+\.png">::g'
102	$(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \
103		echo ".logo-container > img { object-fit: contain; }" >> $$f; done
104
105rustdoc-macros: private rustdoc_host = yes
106rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
107    --extern proc_macro
108rustdoc-macros: $(src)/macros/lib.rs FORCE
109	$(call if_changed,rustdoc)
110
111rustdoc-core: private rustc_target_flags = $(core-cfgs)
112rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
113	$(call if_changed,rustdoc)
114
115rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
116	$(call if_changed,rustdoc)
117
118# We need to allow `rustdoc::broken_intra_doc_links` because some
119# `no_global_oom_handling` functions refer to non-`no_global_oom_handling`
120# functions. Ideally `rustdoc` would have a way to distinguish broken links
121# due to things that are "configured out" vs. entirely non-existing ones.
122rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \
123    -Arustdoc::broken_intra_doc_links
124rustdoc-alloc: $(src)/alloc/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE
125	$(call if_changed,rustdoc)
126
127rustdoc-kernel: private rustc_target_flags = --extern alloc \
128    --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
129    --extern bindings --extern uapi
130rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \
131    rustdoc-compiler_builtins rustdoc-alloc $(obj)/libmacros.so \
132    $(obj)/bindings.o FORCE
133	$(call if_changed,rustdoc)
134
135quiet_cmd_rustc_test_library = RUSTC TL $<
136      cmd_rustc_test_library = \
137	OBJTREE=$(abspath $(objtree)) \
138	$(RUSTC) $(rust_common_flags) \
139		@$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \
140		--crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \
141		--out-dir $(objtree)/$(obj)/test --cfg testlib \
142		--sysroot $(objtree)/$(obj)/test/sysroot \
143		-L$(objtree)/$(obj)/test \
144		--crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $<
145
146rusttestlib-build_error: $(src)/build_error.rs rusttest-prepare FORCE
147	$(call if_changed,rustc_test_library)
148
149rusttestlib-macros: private rustc_target_flags = --extern proc_macro
150rusttestlib-macros: private rustc_test_library_proc = yes
151rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
152	$(call if_changed,rustc_test_library)
153
154rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE
155	$(call if_changed,rustc_test_library)
156
157rusttestlib-uapi: $(src)/uapi/lib.rs rusttest-prepare FORCE
158	$(call if_changed,rustc_test_library)
159
160quiet_cmd_rustdoc_test = RUSTDOC T $<
161      cmd_rustdoc_test = \
162	OBJTREE=$(abspath $(objtree)) \
163	$(RUSTDOC) --test $(rust_common_flags) \
164		@$(objtree)/include/generated/rustc_cfg \
165		$(rustc_target_flags) $(rustdoc_test_target_flags) \
166		--sysroot $(objtree)/$(obj)/test/sysroot $(rustdoc_test_quiet) \
167		-L$(objtree)/$(obj)/test --output $(rustdoc_output) \
168		--crate-name $(subst rusttest-,,$@) $<
169
170quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
171      cmd_rustdoc_test_kernel = \
172	rm -rf $(objtree)/$(obj)/test/doctests/kernel; \
173	mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \
174	OBJTREE=$(abspath $(objtree)) \
175	$(RUSTDOC) --test $(rust_flags) \
176		@$(objtree)/include/generated/rustc_cfg \
177		-L$(objtree)/$(obj) --extern alloc --extern kernel \
178		--extern build_error --extern macros \
179		--extern bindings --extern uapi \
180		--no-run --crate-name kernel -Zunstable-options \
181		--test-builder $(objtree)/scripts/rustdoc_test_builder \
182		$< $(rustdoc_test_kernel_quiet); \
183	$(objtree)/scripts/rustdoc_test_gen
184
185%/doctests_kernel_generated.rs %/doctests_kernel_generated_kunit.c: \
186    $(src)/kernel/lib.rs $(obj)/kernel.o \
187    $(objtree)/scripts/rustdoc_test_builder \
188    $(objtree)/scripts/rustdoc_test_gen FORCE
189	$(call if_changed,rustdoc_test_kernel)
190
191# We cannot use `-Zpanic-abort-tests` because some tests are dynamic,
192# so for the moment we skip `-Cpanic=abort`.
193quiet_cmd_rustc_test = RUSTC T  $<
194      cmd_rustc_test = \
195	OBJTREE=$(abspath $(objtree)) \
196	$(RUSTC) --test $(rust_common_flags) \
197		@$(objtree)/include/generated/rustc_cfg \
198		$(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \
199		--sysroot $(objtree)/$(obj)/test/sysroot \
200		-L$(objtree)/$(obj)/test \
201		--crate-name $(subst rusttest-,,$@) $<; \
202	$(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \
203		$(rustc_test_run_flags)
204
205rusttest: rusttest-macros rusttest-kernel
206
207# This prepares a custom sysroot with our custom `alloc` instead of
208# the standard one.
209#
210# This requires several hacks:
211#   - Unlike `core` and `alloc`, `std` depends on more than a dozen crates,
212#     including third-party crates that need to be downloaded, plus custom
213#     `build.rs` steps. Thus hardcoding things here is not maintainable.
214#   - `cargo` knows how to build the standard library, but it is an unstable
215#     feature so far (`-Zbuild-std`).
216#   - `cargo` only considers the use case of building the standard library
217#     to use it in a given package. Thus we need to create a dummy package
218#     and pick the generated libraries from there.
219#   - Since we only keep a subset of upstream `alloc` in-tree, we need
220#     to recreate it on the fly by putting our sources on top.
221#   - The usual ways of modifying the dependency graph in `cargo` do not seem
222#     to apply for the `-Zbuild-std` steps, thus we have to mislead it
223#     by modifying the sources in the sysroot.
224#   - To avoid messing with the user's Rust installation, we create a clone
225#     of the sysroot. However, `cargo` ignores `RUSTFLAGS` in the `-Zbuild-std`
226#     steps, thus we use a wrapper binary passed via `RUSTC` to pass the flag.
227#
228# In the future, we hope to avoid the whole ordeal by either:
229#   - Making the `test` crate not depend on `std` (either improving upstream
230#     or having our own custom crate).
231#   - Making the tests run in kernel space (requires the previous point).
232#   - Making `std` and friends be more like a "normal" crate, so that
233#     `-Zbuild-std` and related hacks are not needed.
234quiet_cmd_rustsysroot = RUSTSYSROOT
235      cmd_rustsysroot = \
236	rm -rf $(objtree)/$(obj)/test; \
237	mkdir -p $(objtree)/$(obj)/test; \
238	cp -a $(rustc_sysroot) $(objtree)/$(obj)/test/sysroot; \
239	cp -r $(srctree)/$(src)/alloc/* \
240		$(objtree)/$(obj)/test/sysroot/lib/rustlib/src/rust/library/alloc/src; \
241	echo '\#!/bin/sh' > $(objtree)/$(obj)/test/rustc_sysroot; \
242	echo "$(RUSTC) --sysroot=$(abspath $(objtree)/$(obj)/test/sysroot) \"\$$@\"" \
243		>> $(objtree)/$(obj)/test/rustc_sysroot; \
244	chmod u+x $(objtree)/$(obj)/test/rustc_sysroot; \
245	$(CARGO) -q new $(objtree)/$(obj)/test/dummy; \
246	RUSTC=$(objtree)/$(obj)/test/rustc_sysroot $(CARGO) $(cargo_quiet) \
247		test -Zbuild-std --target $(rustc_host_target) \
248		--manifest-path $(objtree)/$(obj)/test/dummy/Cargo.toml; \
249	rm $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib/*; \
250	cp $(objtree)/$(obj)/test/dummy/target/$(rustc_host_target)/debug/deps/* \
251		$(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib
252
253rusttest-prepare: FORCE
254	$(call if_changed,rustsysroot)
255
256rusttest-macros: private rustc_target_flags = --extern proc_macro
257rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
258rusttest-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
259	$(call if_changed,rustc_test)
260	$(call if_changed,rustdoc_test)
261
262rusttest-kernel: private rustc_target_flags = --extern alloc \
263    --extern build_error --extern macros --extern bindings --extern uapi
264rusttest-kernel: $(src)/kernel/lib.rs rusttest-prepare \
265    rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \
266    rusttestlib-uapi FORCE
267	$(call if_changed,rustc_test)
268	$(call if_changed,rustc_test_library)
269
270ifdef CONFIG_CC_IS_CLANG
271bindgen_c_flags = $(c_flags)
272else
273# bindgen relies on libclang to parse C. Ideally, bindgen would support a GCC
274# plugin backend and/or the Clang driver would be perfectly compatible with GCC.
275#
276# For the moment, here we are tweaking the flags on the fly. This is a hack,
277# and some kernel configurations may not work (e.g. `GCC_PLUGIN_RANDSTRUCT`
278# if we end up using one of those structs).
279bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
280	-mskip-rax-setup -mgeneral-regs-only -msign-return-address=% \
281	-mindirect-branch=thunk-extern -mindirect-branch-register \
282	-mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \
283	-mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \
284	-mno-pointers-to-nested-functions -mno-string \
285	-mno-strict-align -mstrict-align \
286	-fconserve-stack -falign-jumps=% -falign-loops=% \
287	-femit-struct-debug-baseonly -fno-ipa-cp-clone -fno-ipa-sra \
288	-fno-partial-inlining -fplugin-arg-arm_ssp_per_task_plugin-% \
289	-fno-reorder-blocks -fno-allow-store-data-races -fasan-shadow-offset=% \
290	-fzero-call-used-regs=% -fno-stack-clash-protection \
291	-fno-inline-functions-called-once -fsanitize=bounds-strict \
292	-fstrict-flex-arrays=% \
293	--param=% --param asan-%
294
295# Derived from `scripts/Makefile.clang`.
296BINDGEN_TARGET_x86	:= x86_64-linux-gnu
297BINDGEN_TARGET		:= $(BINDGEN_TARGET_$(SRCARCH))
298
299# All warnings are inhibited since GCC builds are very experimental,
300# many GCC warnings are not supported by Clang, they may only appear in
301# some configurations, with new GCC versions, etc.
302bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET)
303
304# Auto variable zero-initialization requires an additional special option with
305# clang that is going to be removed sometime in the future (likely in
306# clang-18), so make sure to pass this option only if clang supports it
307# (libclang major version < 16).
308#
309# https://github.com/llvm/llvm-project/issues/44842
310# https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags
311ifdef CONFIG_INIT_STACK_ALL_ZERO
312libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p')
313ifeq ($(shell expr $(libclang_maj_ver) \< 16), 1)
314bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
315endif
316endif
317
318bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
319	$(bindgen_extra_c_flags)
320endif
321
322ifdef CONFIG_LTO
323bindgen_c_flags_lto = $(filter-out $(CC_FLAGS_LTO), $(bindgen_c_flags))
324else
325bindgen_c_flags_lto = $(bindgen_c_flags)
326endif
327
328bindgen_c_flags_final = $(bindgen_c_flags_lto) -D__BINDGEN__
329
330quiet_cmd_bindgen = BINDGEN $@
331      cmd_bindgen = \
332	$(BINDGEN) $< $(bindgen_target_flags) \
333		--use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
334		--no-debug '.*' \
335		-o $@ -- $(bindgen_c_flags_final) -DMODULE \
336		$(bindgen_target_cflags) $(bindgen_target_extra)
337
338$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
339    $(shell grep -Ev '^#|^$$' $(srctree)/$(src)/bindgen_parameters)
340$(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
341    $(src)/bindgen_parameters FORCE
342	$(call if_changed_dep,bindgen)
343
344$(obj)/uapi/uapi_generated.rs: private bindgen_target_flags = \
345    $(shell grep -Ev '^#|^$$' $(srctree)/$(src)/bindgen_parameters)
346$(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \
347    $(src)/bindgen_parameters FORCE
348	$(call if_changed_dep,bindgen)
349
350# See `CFLAGS_REMOVE_helpers.o` above. In addition, Clang on C does not warn
351# with `-Wmissing-declarations` (unlike GCC), so it is not strictly needed here
352# given it is `libclang`; but for consistency, future Clang changes and/or
353# a potential future GCC backend for `bindgen`, we disable it too.
354$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \
355    --blocklist-type '.*' --allowlist-var '' \
356    --allowlist-function 'rust_helper_.*'
357$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_cflags = \
358    -I$(objtree)/$(obj) -Wno-missing-prototypes -Wno-missing-declarations
359$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; \
360    sed -Ei 's/pub fn rust_helper_([a-zA-Z0-9_]*)/#[link_name="rust_helper_\1"]\n    pub fn \1/g' $@
361$(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers.c FORCE
362	$(call if_changed_dep,bindgen)
363
364quiet_cmd_exports = EXPORTS $@
365      cmd_exports = \
366	$(NM) -p --defined-only $< \
367		| awk '/ (T|R|D) / {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@
368
369$(obj)/exports_core_generated.h: $(obj)/core.o FORCE
370	$(call if_changed,exports)
371
372$(obj)/exports_alloc_generated.h: $(obj)/alloc.o FORCE
373	$(call if_changed,exports)
374
375$(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
376	$(call if_changed,exports)
377
378$(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
379	$(call if_changed,exports)
380
381quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
382      cmd_rustc_procmacro = \
383	$(RUSTC_OR_CLIPPY) $(rust_common_flags) \
384		-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
385		-Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
386		--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
387		--crate-type proc-macro \
388		--crate-name $(patsubst lib%.so,%,$(notdir $@)) $<
389
390# Procedural macros can only be used with the `rustc` that compiled it.
391# Therefore, to get `libmacros.so` automatically recompiled when the compiler
392# version changes, we add `core.o` as a dependency (even if it is not needed).
393$(obj)/libmacros.so: $(src)/macros/lib.rs $(obj)/core.o FORCE
394	$(call if_changed_dep,rustc_procmacro)
395
396quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
397      cmd_rustc_library = \
398	OBJTREE=$(abspath $(objtree)) \
399	$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
400		$(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
401		--emit=dep-info=$(depfile) --emit=obj=$@ \
402		--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
403		--crate-type rlib -L$(objtree)/$(obj) \
404		--crate-name $(patsubst %.o,%,$(notdir $@)) $< \
405	$(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)
406
407rust-analyzer:
408	$(Q)$(srctree)/scripts/generate_rust_analyzer.py \
409		--cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \
410		$(abs_srctree) $(abs_objtree) \
411		$(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \
412		$(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json
413
414redirect-intrinsics = \
415	__addsf3 __eqsf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __unordsf2 \
416	__adddf3 __ledf2 __ltdf2 __muldf3 __unorddf2 \
417	__muloti4 __multi3 \
418	__udivmodti4 __udivti3 __umodti3
419
420ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
421	# These intrinsics are defined for ARM64 and RISCV64
422	redirect-intrinsics += \
423		__ashrti3 \
424		__ashlti3 __lshrti3
425endif
426
427$(obj)/core.o: private skip_clippy = 1
428$(obj)/core.o: private skip_flags = -Dunreachable_pub
429$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
430$(obj)/core.o: private rustc_target_flags = $(core-cfgs)
431$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE
432	$(call if_changed_dep,rustc_library)
433
434$(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
435$(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
436	$(call if_changed_dep,rustc_library)
437
438$(obj)/alloc.o: private skip_clippy = 1
439$(obj)/alloc.o: private skip_flags = -Dunreachable_pub
440$(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
441$(obj)/alloc.o: $(src)/alloc/lib.rs $(obj)/compiler_builtins.o FORCE
442	$(call if_changed_dep,rustc_library)
443
444$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
445	$(call if_changed_dep,rustc_library)
446
447$(obj)/bindings.o: $(src)/bindings/lib.rs \
448    $(obj)/compiler_builtins.o \
449    $(obj)/bindings/bindings_generated.rs \
450    $(obj)/bindings/bindings_helpers_generated.rs FORCE
451	$(call if_changed_dep,rustc_library)
452
453$(obj)/uapi.o: $(src)/uapi/lib.rs \
454    $(obj)/compiler_builtins.o \
455    $(obj)/uapi/uapi_generated.rs FORCE
456	$(call if_changed_dep,rustc_library)
457
458$(obj)/kernel.o: private rustc_target_flags = --extern alloc \
459    --extern build_error --extern macros --extern bindings --extern uapi
460$(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \
461    $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE
462	$(call if_changed_dep,rustc_library)
463
464endif # CONFIG_RUST
465