]>
Commit | Line | Data |
---|---|---|
2f7ab126 MO |
1 | # SPDX-License-Identifier: GPL-2.0 |
2 | ||
48fadf44 CB |
3 | # Where to place rustdoc generated documentation |
4 | rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc | |
5 | ||
2f7ab126 MO |
6 | obj-$(CONFIG_RUST) += core.o compiler_builtins.o |
7 | always-$(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. | |
11 | obj-$(CONFIG_RUST) += helpers.o | |
12 | CFLAGS_REMOVE_helpers.o = -Wmissing-prototypes -Wmissing-declarations | |
13 | ||
14 | always-$(CONFIG_RUST) += libmacros.so | |
15 | no-clean-files += libmacros.so | |
16 | ||
17 | always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs | |
18 | obj-$(CONFIG_RUST) += alloc.o bindings.o kernel.o | |
19 | always-$(CONFIG_RUST) += exports_alloc_generated.h exports_bindings_generated.h \ | |
20 | exports_kernel_generated.h | |
21 | ||
4e174665 AL |
22 | always-$(CONFIG_RUST) += uapi/uapi_generated.rs |
23 | obj-$(CONFIG_RUST) += uapi.o | |
24 | ||
ecaa6ddf GG |
25 | ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW |
26 | obj-$(CONFIG_RUST) += build_error.o | |
27 | else | |
28 | always-$(CONFIG_RUST) += build_error.o | |
29 | endif | |
30 | ||
2f7ab126 MO |
31 | obj-$(CONFIG_RUST) += exports.o |
32 | ||
a66d733d MO |
33 | always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs |
34 | always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c | |
35 | ||
36 | obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.o | |
37 | obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.o | |
38 | ||
2f7ab126 MO |
39 | # Avoids running `$(RUSTC)` for the sysroot when it may not be available. |
40 | ifdef CONFIG_RUST | |
41 | ||
42 | # `$(rust_flags)` is passed in case the user added `--sysroot`. | |
ecab4115 | 43 | rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot) |
2f7ab126 MO |
44 | rustc_host_target := $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cut -d' ' -f2) |
45 | RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/src/rust/library | |
46 | ||
9ffc80c8 | 47 | ifneq ($(quiet),) |
2f7ab126 MO |
48 | rust_test_quiet=-q |
49 | rustdoc_test_quiet=--test-args -q | |
a66d733d | 50 | rustdoc_test_kernel_quiet=>/dev/null |
2f7ab126 MO |
51 | endif |
52 | ||
53 | core-cfgs = \ | |
54 | --cfg no_fp_fmt_parse | |
55 | ||
56 | alloc-cfgs = \ | |
2f7ab126 | 57 | --cfg no_global_oom_handling \ |
2f7ab126 | 58 | --cfg no_rc \ |
11795ae4 | 59 | --cfg no_sync |
2f7ab126 MO |
60 | |
61 | quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $< | |
62 | cmd_rustdoc = \ | |
63 | OBJTREE=$(abspath $(objtree)) \ | |
64 | $(RUSTDOC) $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags)) \ | |
65 | $(rustc_target_flags) -L$(objtree)/$(obj) \ | |
48fadf44 | 66 | --output $(rustdoc_output) \ |
2f7ab126 | 67 | --crate-name $(subst rustdoc-,,$@) \ |
71479eee | 68 | $(if $(rustdoc_host),,--sysroot=/dev/null) \ |
2f7ab126 MO |
69 | @$(objtree)/include/generated/rustc_cfg $< |
70 | ||
71 | # The `html_logo_url` and `html_favicon_url` forms of the `doc` attribute | |
72 | # can be used to specify a custom logo. However: | |
73 | # - The given value is used as-is, thus it cannot be relative or a local file | |
74 | # (unlike the non-custom case) since the generated docs have subfolders. | |
75 | # - It requires adding it to every crate. | |
76 | # - It requires changing `core` which comes from the sysroot. | |
77 | # | |
78 | # Using `-Zcrate-attr` would solve the last two points, but not the first. | |
79 | # The https://github.com/rust-lang/rfcs/pull/3226 RFC suggests two new | |
80 | # command-like flags to solve the issue. Meanwhile, we use the non-custom case | |
81 | # and then retouch the generated files. | |
82 | rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \ | |
83 | rustdoc-alloc rustdoc-kernel | |
cfd96726 MO |
84 | $(Q)cp $(srctree)/Documentation/images/logo.svg $(rustdoc_output)/static.files/ |
85 | $(Q)cp $(srctree)/Documentation/images/COPYING-logo $(rustdoc_output)/static.files/ | |
48fadf44 | 86 | $(Q)find $(rustdoc_output) -name '*.html' -type f -print0 | xargs -0 sed -Ei \ |
cfd96726 MO |
87 | -e 's:rust-logo-[0-9a-f]+\.svg:logo.svg:g' \ |
88 | -e 's:favicon-[0-9a-f]+\.svg:logo.svg:g' \ | |
bc2e7d5c | 89 | -e 's:<link rel="alternate icon" type="image/png" href="[/.]+/static\.files/favicon-(16x16|32x32)-[0-9a-f]+\.png">::g' \ |
e2bad142 | 90 | -e 's:<a href="srctree/([^"]+)">:<a href="$(realpath $(srctree))/\1">:g' |
cfd96726 MO |
91 | $(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \ |
92 | echo ".logo-container > img { object-fit: contain; }" >> $$f; done | |
2f7ab126 MO |
93 | |
94 | rustdoc-macros: private rustdoc_host = yes | |
95 | rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \ | |
96 | --extern proc_macro | |
97 | rustdoc-macros: $(src)/macros/lib.rs FORCE | |
ecab4115 | 98 | +$(call if_changed,rustdoc) |
2f7ab126 MO |
99 | |
100 | rustdoc-core: private rustc_target_flags = $(core-cfgs) | |
101 | rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE | |
ecab4115 | 102 | +$(call if_changed,rustdoc) |
2f7ab126 MO |
103 | |
104 | rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE | |
ecab4115 | 105 | +$(call if_changed,rustdoc) |
2f7ab126 MO |
106 | |
107 | # We need to allow `rustdoc::broken_intra_doc_links` because some | |
108 | # `no_global_oom_handling` functions refer to non-`no_global_oom_handling` | |
109 | # functions. Ideally `rustdoc` would have a way to distinguish broken links | |
110 | # due to things that are "configured out" vs. entirely non-existing ones. | |
111 | rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \ | |
112 | -Arustdoc::broken_intra_doc_links | |
11795ae4 | 113 | rustdoc-alloc: $(RUST_LIB_SRC)/alloc/src/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE |
ecab4115 | 114 | +$(call if_changed,rustdoc) |
2f7ab126 MO |
115 | |
116 | rustdoc-kernel: private rustc_target_flags = --extern alloc \ | |
ecaa6ddf | 117 | --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \ |
4e174665 | 118 | --extern bindings --extern uapi |
2f7ab126 MO |
119 | rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \ |
120 | rustdoc-compiler_builtins rustdoc-alloc $(obj)/libmacros.so \ | |
121 | $(obj)/bindings.o FORCE | |
ecab4115 | 122 | +$(call if_changed,rustdoc) |
2f7ab126 MO |
123 | |
124 | quiet_cmd_rustc_test_library = RUSTC TL $< | |
125 | cmd_rustc_test_library = \ | |
126 | OBJTREE=$(abspath $(objtree)) \ | |
127 | $(RUSTC) $(rust_common_flags) \ | |
128 | @$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \ | |
129 | --crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \ | |
130 | --out-dir $(objtree)/$(obj)/test --cfg testlib \ | |
2f7ab126 MO |
131 | -L$(objtree)/$(obj)/test \ |
132 | --crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $< | |
133 | ||
9ffc80c8 | 134 | rusttestlib-build_error: $(src)/build_error.rs FORCE |
ecab4115 | 135 | +$(call if_changed,rustc_test_library) |
ecaa6ddf | 136 | |
2f7ab126 MO |
137 | rusttestlib-macros: private rustc_target_flags = --extern proc_macro |
138 | rusttestlib-macros: private rustc_test_library_proc = yes | |
9ffc80c8 | 139 | rusttestlib-macros: $(src)/macros/lib.rs FORCE |
ecab4115 | 140 | +$(call if_changed,rustc_test_library) |
2f7ab126 | 141 | |
9ffc80c8 | 142 | rusttestlib-bindings: $(src)/bindings/lib.rs FORCE |
ecab4115 | 143 | +$(call if_changed,rustc_test_library) |
2f7ab126 | 144 | |
9ffc80c8 | 145 | rusttestlib-uapi: $(src)/uapi/lib.rs FORCE |
ecab4115 | 146 | +$(call if_changed,rustc_test_library) |
4e174665 | 147 | |
2f7ab126 MO |
148 | quiet_cmd_rustdoc_test = RUSTDOC T $< |
149 | cmd_rustdoc_test = \ | |
150 | OBJTREE=$(abspath $(objtree)) \ | |
151 | $(RUSTDOC) --test $(rust_common_flags) \ | |
152 | @$(objtree)/include/generated/rustc_cfg \ | |
153 | $(rustc_target_flags) $(rustdoc_test_target_flags) \ | |
9ffc80c8 | 154 | $(rustdoc_test_quiet) \ |
48fadf44 | 155 | -L$(objtree)/$(obj)/test --output $(rustdoc_output) \ |
2f7ab126 MO |
156 | --crate-name $(subst rusttest-,,$@) $< |
157 | ||
a66d733d MO |
158 | quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $< |
159 | cmd_rustdoc_test_kernel = \ | |
160 | rm -rf $(objtree)/$(obj)/test/doctests/kernel; \ | |
161 | mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \ | |
162 | OBJTREE=$(abspath $(objtree)) \ | |
163 | $(RUSTDOC) --test $(rust_flags) \ | |
a66d733d MO |
164 | -L$(objtree)/$(obj) --extern alloc --extern kernel \ |
165 | --extern build_error --extern macros \ | |
166 | --extern bindings --extern uapi \ | |
167 | --no-run --crate-name kernel -Zunstable-options \ | |
71479eee | 168 | --sysroot=/dev/null \ |
a66d733d MO |
169 | --test-builder $(objtree)/scripts/rustdoc_test_builder \ |
170 | $< $(rustdoc_test_kernel_quiet); \ | |
171 | $(objtree)/scripts/rustdoc_test_gen | |
172 | ||
173 | %/doctests_kernel_generated.rs %/doctests_kernel_generated_kunit.c: \ | |
174 | $(src)/kernel/lib.rs $(obj)/kernel.o \ | |
175 | $(objtree)/scripts/rustdoc_test_builder \ | |
176 | $(objtree)/scripts/rustdoc_test_gen FORCE | |
ecab4115 | 177 | +$(call if_changed,rustdoc_test_kernel) |
a66d733d | 178 | |
2f7ab126 MO |
179 | # We cannot use `-Zpanic-abort-tests` because some tests are dynamic, |
180 | # so for the moment we skip `-Cpanic=abort`. | |
181 | quiet_cmd_rustc_test = RUSTC T $< | |
182 | cmd_rustc_test = \ | |
183 | OBJTREE=$(abspath $(objtree)) \ | |
184 | $(RUSTC) --test $(rust_common_flags) \ | |
185 | @$(objtree)/include/generated/rustc_cfg \ | |
186 | $(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \ | |
2f7ab126 MO |
187 | -L$(objtree)/$(obj)/test \ |
188 | --crate-name $(subst rusttest-,,$@) $<; \ | |
189 | $(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \ | |
190 | $(rustc_test_run_flags) | |
191 | ||
192 | rusttest: rusttest-macros rusttest-kernel | |
193 | ||
2f7ab126 MO |
194 | rusttest-macros: private rustc_target_flags = --extern proc_macro |
195 | rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro | |
9ffc80c8 | 196 | rusttest-macros: $(src)/macros/lib.rs FORCE |
ecab4115 MO |
197 | +$(call if_changed,rustc_test) |
198 | +$(call if_changed,rustdoc_test) | |
2f7ab126 MO |
199 | |
200 | rusttest-kernel: private rustc_target_flags = --extern alloc \ | |
4e174665 | 201 | --extern build_error --extern macros --extern bindings --extern uapi |
9ffc80c8 | 202 | rusttest-kernel: $(src)/kernel/lib.rs \ |
4e174665 AL |
203 | rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \ |
204 | rusttestlib-uapi FORCE | |
ecab4115 MO |
205 | +$(call if_changed,rustc_test) |
206 | +$(call if_changed,rustc_test_library) | |
2f7ab126 | 207 | |
2f7ab126 MO |
208 | ifdef CONFIG_CC_IS_CLANG |
209 | bindgen_c_flags = $(c_flags) | |
210 | else | |
211 | # bindgen relies on libclang to parse C. Ideally, bindgen would support a GCC | |
212 | # plugin backend and/or the Clang driver would be perfectly compatible with GCC. | |
213 | # | |
214 | # For the moment, here we are tweaking the flags on the fly. This is a hack, | |
215 | # and some kernel configurations may not work (e.g. `GCC_PLUGIN_RANDSTRUCT` | |
216 | # if we end up using one of those structs). | |
217 | bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \ | |
218 | -mskip-rax-setup -mgeneral-regs-only -msign-return-address=% \ | |
219 | -mindirect-branch=thunk-extern -mindirect-branch-register \ | |
220 | -mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \ | |
221 | -mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \ | |
222 | -mno-pointers-to-nested-functions -mno-string \ | |
223 | -mno-strict-align -mstrict-align \ | |
224 | -fconserve-stack -falign-jumps=% -falign-loops=% \ | |
225 | -femit-struct-debug-baseonly -fno-ipa-cp-clone -fno-ipa-sra \ | |
226 | -fno-partial-inlining -fplugin-arg-arm_ssp_per_task_plugin-% \ | |
227 | -fno-reorder-blocks -fno-allow-store-data-races -fasan-shadow-offset=% \ | |
228 | -fzero-call-used-regs=% -fno-stack-clash-protection \ | |
b0554488 | 229 | -fno-inline-functions-called-once -fsanitize=bounds-strict \ |
869b5016 | 230 | -fstrict-flex-arrays=% -fmin-function-alignment=% \ |
2f7ab126 MO |
231 | --param=% --param asan-% |
232 | ||
233 | # Derived from `scripts/Makefile.clang`. | |
234 | BINDGEN_TARGET_x86 := x86_64-linux-gnu | |
724a75ac | 235 | BINDGEN_TARGET_arm64 := aarch64-linux-gnu |
2f7ab126 MO |
236 | BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) |
237 | ||
238 | # All warnings are inhibited since GCC builds are very experimental, | |
239 | # many GCC warnings are not supported by Clang, they may only appear in | |
240 | # some configurations, with new GCC versions, etc. | |
241 | bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET) | |
242 | ||
d966c3ca AR |
243 | # Auto variable zero-initialization requires an additional special option with |
244 | # clang that is going to be removed sometime in the future (likely in | |
245 | # clang-18), so make sure to pass this option only if clang supports it | |
246 | # (libclang major version < 16). | |
247 | # | |
248 | # https://github.com/llvm/llvm-project/issues/44842 | |
249 | # https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags | |
250 | ifdef CONFIG_INIT_STACK_ALL_ZERO | |
251 | libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p') | |
252 | ifeq ($(shell expr $(libclang_maj_ver) \< 16), 1) | |
253 | bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang | |
254 | endif | |
255 | endif | |
256 | ||
2f7ab126 MO |
257 | bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \ |
258 | $(bindgen_extra_c_flags) | |
259 | endif | |
260 | ||
261 | ifdef CONFIG_LTO | |
262 | bindgen_c_flags_lto = $(filter-out $(CC_FLAGS_LTO), $(bindgen_c_flags)) | |
263 | else | |
264 | bindgen_c_flags_lto = $(bindgen_c_flags) | |
265 | endif | |
266 | ||
267 | bindgen_c_flags_final = $(bindgen_c_flags_lto) -D__BINDGEN__ | |
268 | ||
269 | quiet_cmd_bindgen = BINDGEN $@ | |
270 | cmd_bindgen = \ | |
271 | $(BINDGEN) $< $(bindgen_target_flags) \ | |
272 | --use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \ | |
273 | --no-debug '.*' \ | |
08ab7865 | 274 | -o $@ -- $(bindgen_c_flags_final) -DMODULE \ |
2f7ab126 MO |
275 | $(bindgen_target_cflags) $(bindgen_target_extra) |
276 | ||
277 | $(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \ | |
b1992c37 | 278 | $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters) |
74376656 GG |
279 | $(obj)/bindings/bindings_generated.rs: private bindgen_target_extra = ; \ |
280 | sed -Ei 's/pub const RUST_CONST_HELPER_([a-zA-Z0-9_]*)/pub const \1/g' $@ | |
2f7ab126 MO |
281 | $(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \ |
282 | $(src)/bindgen_parameters FORCE | |
283 | $(call if_changed_dep,bindgen) | |
284 | ||
4e174665 | 285 | $(obj)/uapi/uapi_generated.rs: private bindgen_target_flags = \ |
b1992c37 | 286 | $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters) |
4e174665 AL |
287 | $(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \ |
288 | $(src)/bindgen_parameters FORCE | |
289 | $(call if_changed_dep,bindgen) | |
290 | ||
2f7ab126 MO |
291 | # See `CFLAGS_REMOVE_helpers.o` above. In addition, Clang on C does not warn |
292 | # with `-Wmissing-declarations` (unlike GCC), so it is not strictly needed here | |
293 | # given it is `libclang`; but for consistency, future Clang changes and/or | |
294 | # a potential future GCC backend for `bindgen`, we disable it too. | |
295 | $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \ | |
08ab7865 ASS |
296 | --blocklist-type '.*' --allowlist-var '' \ |
297 | --allowlist-function 'rust_helper_.*' | |
2f7ab126 MO |
298 | $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_cflags = \ |
299 | -I$(objtree)/$(obj) -Wno-missing-prototypes -Wno-missing-declarations | |
300 | $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; \ | |
301 | sed -Ei 's/pub fn rust_helper_([a-zA-Z0-9_]*)/#[link_name="rust_helper_\1"]\n pub fn \1/g' $@ | |
302 | $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers.c FORCE | |
303 | $(call if_changed_dep,bindgen) | |
304 | ||
305 | quiet_cmd_exports = EXPORTS $@ | |
306 | cmd_exports = \ | |
307 | $(NM) -p --defined-only $< \ | |
45f97e63 | 308 | | awk '/ (T|R|D) / {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@ |
2f7ab126 MO |
309 | |
310 | $(obj)/exports_core_generated.h: $(obj)/core.o FORCE | |
311 | $(call if_changed,exports) | |
312 | ||
313 | $(obj)/exports_alloc_generated.h: $(obj)/alloc.o FORCE | |
314 | $(call if_changed,exports) | |
315 | ||
316 | $(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE | |
317 | $(call if_changed,exports) | |
318 | ||
319 | $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE | |
320 | $(call if_changed,exports) | |
321 | ||
322 | quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ | |
323 | cmd_rustc_procmacro = \ | |
324 | $(RUSTC_OR_CLIPPY) $(rust_common_flags) \ | |
80bac83a MM |
325 | -Clinker-flavor=gcc -Clinker=$(HOSTCC) \ |
326 | -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \ | |
295d8398 MY |
327 | --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \ |
328 | --crate-type proc-macro \ | |
2185242f | 329 | --crate-name $(patsubst lib%.so,%,$(notdir $@)) $< |
2f7ab126 MO |
330 | |
331 | # Procedural macros can only be used with the `rustc` that compiled it. | |
332 | # Therefore, to get `libmacros.so` automatically recompiled when the compiler | |
333 | # version changes, we add `core.o` as a dependency (even if it is not needed). | |
334 | $(obj)/libmacros.so: $(src)/macros/lib.rs $(obj)/core.o FORCE | |
ecab4115 | 335 | +$(call if_changed_dep,rustc_procmacro) |
2f7ab126 MO |
336 | |
337 | quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@ | |
338 | cmd_rustc_library = \ | |
339 | OBJTREE=$(abspath $(objtree)) \ | |
340 | $(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \ | |
341 | $(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \ | |
295d8398 MY |
342 | --emit=dep-info=$(depfile) --emit=obj=$@ \ |
343 | --emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \ | |
344 | --crate-type rlib -L$(objtree)/$(obj) \ | |
2185242f | 345 | --crate-name $(patsubst %.o,%,$(notdir $@)) $< \ |
71479eee | 346 | --sysroot=/dev/null \ |
2f7ab126 MO |
347 | $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) |
348 | ||
349 | rust-analyzer: | |
49a9ef76 | 350 | $(Q)$(srctree)/scripts/generate_rust_analyzer.py \ |
4f353e0d | 351 | --cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \ |
e2bad142 | 352 | $(realpath $(srctree)) $(realpath $(objtree)) \ |
fe992163 | 353 | $(rustc_sysroot) $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \ |
49a9ef76 | 354 | $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json |
2f7ab126 | 355 | |
cb7d9def | 356 | redirect-intrinsics = \ |
02dfd63a MO |
357 | __addsf3 __eqsf2 __extendsfdf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __truncdfsf2 __unordsf2 \ |
358 | __adddf3 __eqdf2 __ledf2 __ltdf2 __muldf3 __unorddf2 \ | |
cb7d9def GG |
359 | __muloti4 __multi3 \ |
360 | __udivmodti4 __udivti3 __umodti3 | |
361 | ||
362 | ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),) | |
363 | # These intrinsics are defined for ARM64 and RISCV64 | |
364 | redirect-intrinsics += \ | |
365 | __ashrti3 \ | |
366 | __ashlti3 __lshrti3 | |
367 | endif | |
368 | ||
2f7ab126 | 369 | $(obj)/core.o: private skip_clippy = 1 |
f8f88aa2 | 370 | $(obj)/core.o: private skip_flags = -Wunreachable_pub |
cb7d9def | 371 | $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym)) |
2f7ab126 | 372 | $(obj)/core.o: private rustc_target_flags = $(core-cfgs) |
f82811e2 | 373 | $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE |
ecab4115 | 374 | +$(call if_changed_dep,rustc_library) |
ab0f4ced | 375 | ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) |
f82811e2 JC |
376 | $(obj)/core.o: scripts/target.json |
377 | endif | |
2f7ab126 MO |
378 | |
379 | $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*' | |
380 | $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE | |
ecab4115 | 381 | +$(call if_changed_dep,rustc_library) |
2f7ab126 MO |
382 | |
383 | $(obj)/alloc.o: private skip_clippy = 1 | |
f8f88aa2 | 384 | $(obj)/alloc.o: private skip_flags = -Wunreachable_pub |
2f7ab126 | 385 | $(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs) |
11795ae4 | 386 | $(obj)/alloc.o: $(RUST_LIB_SRC)/alloc/src/lib.rs $(obj)/compiler_builtins.o FORCE |
ecab4115 | 387 | +$(call if_changed_dep,rustc_library) |
2f7ab126 | 388 | |
ecaa6ddf | 389 | $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE |
ecab4115 | 390 | +$(call if_changed_dep,rustc_library) |
ecaa6ddf | 391 | |
2f7ab126 MO |
392 | $(obj)/bindings.o: $(src)/bindings/lib.rs \ |
393 | $(obj)/compiler_builtins.o \ | |
394 | $(obj)/bindings/bindings_generated.rs \ | |
395 | $(obj)/bindings/bindings_helpers_generated.rs FORCE | |
ecab4115 | 396 | +$(call if_changed_dep,rustc_library) |
2f7ab126 | 397 | |
4e174665 AL |
398 | $(obj)/uapi.o: $(src)/uapi/lib.rs \ |
399 | $(obj)/compiler_builtins.o \ | |
400 | $(obj)/uapi/uapi_generated.rs FORCE | |
ecab4115 | 401 | +$(call if_changed_dep,rustc_library) |
4e174665 | 402 | |
2f7ab126 | 403 | $(obj)/kernel.o: private rustc_target_flags = --extern alloc \ |
4e174665 | 404 | --extern build_error --extern macros --extern bindings --extern uapi |
ecaa6ddf | 405 | $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \ |
4e174665 | 406 | $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE |
ecab4115 | 407 | +$(call if_changed_dep,rustc_library) |
2f7ab126 MO |
408 | |
409 | endif # CONFIG_RUST |