| 1 |
|
| 2 |
|
| 3 |
|
| 4 | rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
|
| 5 |
|
| 6 | obj-$(CONFIG_RUST) += core.o compiler_builtins.o
|
| 7 | always-$(CONFIG_RUST) += exports_core_generated.h
|
| 8 |
|
| 9 |
|
| 10 |
|
| 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 |
|
| 22 | always-$(CONFIG_RUST) += uapi/uapi_generated.rs
|
| 23 | obj-$(CONFIG_RUST) += uapi.o
|
| 24 |
|
| 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 |
|
| 31 | obj-$(CONFIG_RUST) += exports.o
|
| 32 |
|
| 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 |
|
| 39 |
|
| 40 | ifdef CONFIG_RUST
|
| 41 |
|
| 42 |
|
| 43 | rustc_sysroot := $(shell $(RUSTC) $(rust_flags) --print sysroot)
|
| 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 |
|
| 47 | ifeq ($(quiet),silent_)
|
| 48 | cargo_quiet=-q
|
| 49 | rust_test_quiet=-q
|
| 50 | rustdoc_test_quiet=--test-args -q
|
| 51 | rustdoc_test_kernel_quiet=>/dev/null
|
| 52 | else ifeq ($(quiet),quiet_)
|
| 53 | rust_test_quiet=-q
|
| 54 | rustdoc_test_quiet=--test-args -q
|
| 55 | rustdoc_test_kernel_quiet=>/dev/null
|
| 56 | else
|
| 57 | cargo_quiet=--verbose
|
| 58 | endif
|
| 59 |
|
| 60 | core-cfgs = \
|
| 61 | --cfg no_fp_fmt_parse
|
| 62 |
|
| 63 | alloc-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 |
|
| 74 | quiet_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 | $(if $(rustdoc_host),,--sysroot=/dev/null) \
|
| 82 | @$(objtree)/include/generated/rustc_cfg $<
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 | rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
|
| 96 | rustdoc-alloc rustdoc-kernel
|
| 97 | $(Q)cp $(srctree)/Documentation/images/logo.svg $(rustdoc_output)/static.files/
|
| 98 | $(Q)cp $(srctree)/Documentation/images/COPYING-logo $(rustdoc_output)/static.files/
|
| 99 | $(Q)find $(rustdoc_output) -name '*.html' -type f -print0 | xargs -0 sed -Ei \
|
| 100 | -e 's:rust-logo-[0-9a-f]+\.svg:logo.svg:g' \
|
| 101 | -e 's:favicon-[0-9a-f]+\.svg:logo.svg:g' \
|
| 102 | -e 's:<link rel="alternate icon" type="image/png" href="[/.]+/static\.files/favicon-(16x16|32x32)-[0-9a-f]+\.png">::g' \
|
| 103 | -e 's:<a href="srctree/([^"]+)">:<a href="$(abs_srctree)/\1">:g'
|
| 104 | $(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \
|
| 105 | echo ".logo-container > img { object-fit: contain; }" >> $$f; done
|
| 106 |
|
| 107 | rustdoc-macros: private rustdoc_host = yes
|
| 108 | rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
|
| 109 | --extern proc_macro
|
| 110 | rustdoc-macros: $(src)/macros/lib.rs FORCE
|
| 111 | $(call if_changed,rustdoc)
|
| 112 |
|
| 113 | rustdoc-core: private rustc_target_flags = $(core-cfgs)
|
| 114 | rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
|
| 115 | $(call if_changed,rustdoc)
|
| 116 |
|
| 117 | rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
|
| 118 | $(call if_changed,rustdoc)
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 | rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \
|
| 125 | -Arustdoc::broken_intra_doc_links
|
| 126 | rustdoc-alloc: $(src)/alloc/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE
|
| 127 | $(call if_changed,rustdoc)
|
| 128 |
|
| 129 | rustdoc-kernel: private rustc_target_flags = --extern alloc \
|
| 130 | --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
|
| 131 | --extern bindings --extern uapi
|
| 132 | rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \
|
| 133 | rustdoc-compiler_builtins rustdoc-alloc $(obj)/libmacros.so \
|
| 134 | $(obj)/bindings.o FORCE
|
| 135 | $(call if_changed,rustdoc)
|
| 136 |
|
| 137 | quiet_cmd_rustc_test_library = RUSTC TL $<
|
| 138 | cmd_rustc_test_library = \
|
| 139 | OBJTREE=$(abspath $(objtree)) \
|
| 140 | $(RUSTC) $(rust_common_flags) \
|
| 141 | @$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \
|
| 142 | --crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \
|
| 143 | --out-dir $(objtree)/$(obj)/test --cfg testlib \
|
| 144 | --sysroot $(objtree)/$(obj)/test/sysroot \
|
| 145 | -L$(objtree)/$(obj)/test \
|
| 146 | --crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $<
|
| 147 |
|
| 148 | rusttestlib-build_error: $(src)/build_error.rs rusttest-prepare FORCE
|
| 149 | $(call if_changed,rustc_test_library)
|
| 150 |
|
| 151 | rusttestlib-macros: private rustc_target_flags = --extern proc_macro
|
| 152 | rusttestlib-macros: private rustc_test_library_proc = yes
|
| 153 | rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
|
| 154 | $(call if_changed,rustc_test_library)
|
| 155 |
|
| 156 | rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE
|
| 157 | $(call if_changed,rustc_test_library)
|
| 158 |
|
| 159 | rusttestlib-uapi: $(src)/uapi/lib.rs rusttest-prepare FORCE
|
| 160 | $(call if_changed,rustc_test_library)
|
| 161 |
|
| 162 | quiet_cmd_rustdoc_test = RUSTDOC T $<
|
| 163 | cmd_rustdoc_test = \
|
| 164 | OBJTREE=$(abspath $(objtree)) \
|
| 165 | $(RUSTDOC) --test $(rust_common_flags) \
|
| 166 | @$(objtree)/include/generated/rustc_cfg \
|
| 167 | $(rustc_target_flags) $(rustdoc_test_target_flags) \
|
| 168 | --sysroot $(objtree)/$(obj)/test/sysroot $(rustdoc_test_quiet) \
|
| 169 | -L$(objtree)/$(obj)/test --output $(rustdoc_output) \
|
| 170 | --crate-name $(subst rusttest-,,$@) $<
|
| 171 |
|
| 172 | quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
|
| 173 | cmd_rustdoc_test_kernel = \
|
| 174 | rm -rf $(objtree)/$(obj)/test/doctests/kernel; \
|
| 175 | mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \
|
| 176 | OBJTREE=$(abspath $(objtree)) \
|
| 177 | $(RUSTDOC) --test $(rust_flags) \
|
| 178 | @$(objtree)/include/generated/rustc_cfg \
|
| 179 | -L$(objtree)/$(obj) --extern alloc --extern kernel \
|
| 180 | --extern build_error --extern macros \
|
| 181 | --extern bindings --extern uapi \
|
| 182 | --no-run --crate-name kernel -Zunstable-options \
|
| 183 | --sysroot=/dev/null \
|
| 184 | --test-builder $(objtree)/scripts/rustdoc_test_builder \
|
| 185 | $< $(rustdoc_test_kernel_quiet); \
|
| 186 | $(objtree)/scripts/rustdoc_test_gen
|
| 187 |
|
| 188 | %/doctests_kernel_generated.rs %/doctests_kernel_generated_kunit.c: \
|
| 189 | $(src)/kernel/lib.rs $(obj)/kernel.o \
|
| 190 | $(objtree)/scripts/rustdoc_test_builder \
|
| 191 | $(objtree)/scripts/rustdoc_test_gen FORCE
|
| 192 | $(call if_changed,rustdoc_test_kernel)
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 | quiet_cmd_rustc_test = RUSTC T $<
|
| 197 | cmd_rustc_test = \
|
| 198 | OBJTREE=$(abspath $(objtree)) \
|
| 199 | $(RUSTC) --test $(rust_common_flags) \
|
| 200 | @$(objtree)/include/generated/rustc_cfg \
|
| 201 | $(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \
|
| 202 | --sysroot $(objtree)/$(obj)/test/sysroot \
|
| 203 | -L$(objtree)/$(obj)/test \
|
| 204 | --crate-name $(subst rusttest-,,$@) $<; \
|
| 205 | $(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \
|
| 206 | $(rustc_test_run_flags)
|
| 207 |
|
| 208 | rusttest: rusttest-macros rusttest-kernel
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 | quiet_cmd_rustsysroot = RUSTSYSROOT
|
| 238 | cmd_rustsysroot = \
|
| 239 | rm -rf $(objtree)/$(obj)/test; \
|
| 240 | mkdir -p $(objtree)/$(obj)/test; \
|
| 241 | cp -a $(rustc_sysroot) $(objtree)/$(obj)/test/sysroot; \
|
| 242 | cp -r $(srctree)/$(src)/alloc/* \
|
| 243 | $(objtree)/$(obj)/test/sysroot/lib/rustlib/src/rust/library/alloc/src; \
|
| 244 | echo '\#!/bin/sh' > $(objtree)/$(obj)/test/rustc_sysroot; \
|
| 245 | echo "$(RUSTC) --sysroot=$(abspath $(objtree)/$(obj)/test/sysroot) \"\$$@\"" \
|
| 246 | >> $(objtree)/$(obj)/test/rustc_sysroot; \
|
| 247 | chmod u+x $(objtree)/$(obj)/test/rustc_sysroot; \
|
| 248 | $(CARGO) -q new $(objtree)/$(obj)/test/dummy; \
|
| 249 | RUSTC=$(objtree)/$(obj)/test/rustc_sysroot $(CARGO) $(cargo_quiet) \
|
| 250 | test -Zbuild-std --target $(rustc_host_target) \
|
| 251 | --manifest-path $(objtree)/$(obj)/test/dummy/Cargo.toml; \
|
| 252 | rm $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib/*; \
|
| 253 | cp $(objtree)/$(obj)/test/dummy/target/$(rustc_host_target)/debug/deps/* \
|
| 254 | $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib
|
| 255 |
|
| 256 | rusttest-prepare: FORCE
|
| 257 | $(call if_changed,rustsysroot)
|
| 258 |
|
| 259 | rusttest-macros: private rustc_target_flags = --extern proc_macro
|
| 260 | rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
|
| 261 | rusttest-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
|
| 262 | $(call if_changed,rustc_test)
|
| 263 | $(call if_changed,rustdoc_test)
|
| 264 |
|
| 265 | rusttest-kernel: private rustc_target_flags = --extern alloc \
|
| 266 | --extern build_error --extern macros --extern bindings --extern uapi
|
| 267 | rusttest-kernel: $(src)/kernel/lib.rs rusttest-prepare \
|
| 268 | rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \
|
| 269 | rusttestlib-uapi FORCE
|
| 270 | $(call if_changed,rustc_test)
|
| 271 | $(call if_changed,rustc_test_library)
|
| 272 |
|
| 273 | ifdef CONFIG_CC_IS_CLANG
|
| 274 | bindgen_c_flags = $(c_flags)
|
| 275 | else
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 | bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
|
| 283 | -mskip-rax-setup -mgeneral-regs-only -msign-return-address=% \
|
| 284 | -mindirect-branch=thunk-extern -mindirect-branch-register \
|
| 285 | -mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \
|
| 286 | -mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \
|
| 287 | -mno-pointers-to-nested-functions -mno-string \
|
| 288 | -mno-strict-align -mstrict-align \
|
| 289 | -fconserve-stack -falign-jumps=% -falign-loops=% \
|
| 290 | -femit-struct-debug-baseonly -fno-ipa-cp-clone -fno-ipa-sra \
|
| 291 | -fno-partial-inlining -fplugin-arg-arm_ssp_per_task_plugin-% \
|
| 292 | -fno-reorder-blocks -fno-allow-store-data-races -fasan-shadow-offset=% \
|
| 293 | -fzero-call-used-regs=% -fno-stack-clash-protection \
|
| 294 | -fno-inline-functions-called-once -fsanitize=bounds-strict \
|
| 295 | -fstrict-flex-arrays=% \
|
| 296 | --param=% --param asan-%
|
| 297 |
|
| 298 |
|
| 299 | BINDGEN_TARGET_x86 := x86_64-linux-gnu
|
| 300 | BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 | bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET)
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 | ifdef CONFIG_INIT_STACK_ALL_ZERO
|
| 315 | libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p')
|
| 316 | ifeq ($(shell expr $(libclang_maj_ver) \< 16), 1)
|
| 317 | bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
|
| 318 | endif
|
| 319 | endif
|
| 320 |
|
| 321 | bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
|
| 322 | $(bindgen_extra_c_flags)
|
| 323 | endif
|
| 324 |
|
| 325 | ifdef CONFIG_LTO
|
| 326 | bindgen_c_flags_lto = $(filter-out $(CC_FLAGS_LTO), $(bindgen_c_flags))
|
| 327 | else
|
| 328 | bindgen_c_flags_lto = $(bindgen_c_flags)
|
| 329 | endif
|
| 330 |
|
| 331 | bindgen_c_flags_final = $(bindgen_c_flags_lto) -D__BINDGEN__
|
| 332 |
|
| 333 | quiet_cmd_bindgen = BINDGEN $@
|
| 334 | cmd_bindgen = \
|
| 335 | $(BINDGEN) $< $(bindgen_target_flags) \
|
| 336 | --use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
|
| 337 | --no-debug '.*' \
|
| 338 | -o $@ -- $(bindgen_c_flags_final) -DMODULE \
|
| 339 | $(bindgen_target_cflags) $(bindgen_target_extra)
|
| 340 |
|
| 341 | $(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
|
| 342 | $(shell grep -Ev '^#|^$$' $(srctree)/$(src)/bindgen_parameters)
|
| 343 | $(obj)/bindings/bindings_generated.rs: private bindgen_target_extra = ; \
|
| 344 | sed -Ei 's/pub const RUST_CONST_HELPER_([a-zA-Z0-9_]*)/pub const \1/g' $@
|
| 345 | $(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
|
| 346 | $(src)/bindgen_parameters FORCE
|
| 347 | $(call if_changed_dep,bindgen)
|
| 348 |
|
| 349 | $(obj)/uapi/uapi_generated.rs: private bindgen_target_flags = \
|
| 350 | $(shell grep -Ev '^#|^$$' $(srctree)/$(src)/bindgen_parameters)
|
| 351 | $(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \
|
| 352 | $(src)/bindgen_parameters FORCE
|
| 353 | $(call if_changed_dep,bindgen)
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 | $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \
|
| 360 | --blocklist-type '.*' --allowlist-var '' \
|
| 361 | --allowlist-function 'rust_helper_.*'
|
| 362 | $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_cflags = \
|
| 363 | -I$(objtree)/$(obj) -Wno-missing-prototypes -Wno-missing-declarations
|
| 364 | $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; \
|
| 365 | sed -Ei 's/pub fn rust_helper_([a-zA-Z0-9_]*)/
|
| 366 | $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers.c FORCE
|
| 367 | $(call if_changed_dep,bindgen)
|
| 368 |
|
| 369 | quiet_cmd_exports = EXPORTS $@
|
| 370 | cmd_exports = \
|
| 371 | $(NM) -p --defined-only $< \
|
| 372 | | awk '/ (T|R|D) / {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@
|
| 373 |
|
| 374 | $(obj)/exports_core_generated.h: $(obj)/core.o FORCE
|
| 375 | $(call if_changed,exports)
|
| 376 |
|
| 377 | $(obj)/exports_alloc_generated.h: $(obj)/alloc.o FORCE
|
| 378 | $(call if_changed,exports)
|
| 379 |
|
| 380 | $(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
|
| 381 | $(call if_changed,exports)
|
| 382 |
|
| 383 | $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
|
| 384 | $(call if_changed,exports)
|
| 385 |
|
| 386 | quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
|
| 387 | cmd_rustc_procmacro = \
|
| 388 | $(RUSTC_OR_CLIPPY) $(rust_common_flags) \
|
| 389 | -Clinker-flavor=gcc -Clinker=$(HOSTCC) \
|
| 390 | -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
|
| 391 | --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
|
| 392 | --crate-type proc-macro \
|
| 393 | --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 | $(obj)/libmacros.so: $(src)/macros/lib.rs $(obj)/core.o FORCE
|
| 399 | $(call if_changed_dep,rustc_procmacro)
|
| 400 |
|
| 401 | quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
|
| 402 | cmd_rustc_library = \
|
| 403 | OBJTREE=$(abspath $(objtree)) \
|
| 404 | $(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
|
| 405 | $(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
|
| 406 | --emit=dep-info=$(depfile) --emit=obj=$@ \
|
| 407 | --emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
|
| 408 | --crate-type rlib -L$(objtree)/$(obj) \
|
| 409 | --crate-name $(patsubst %.o,%,$(notdir $@)) $< \
|
| 410 | --sysroot=/dev/null \
|
| 411 | $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)
|
| 412 |
|
| 413 | rust-analyzer:
|
| 414 | $(Q)$(srctree)/scripts/generate_rust_analyzer.py \
|
| 415 | --cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \
|
| 416 | $(abs_srctree) $(abs_objtree) \
|
| 417 | $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \
|
| 418 | $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json
|
| 419 |
|
| 420 | redirect-intrinsics = \
|
| 421 | __addsf3 __eqsf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __unordsf2 \
|
| 422 | __adddf3 __ledf2 __ltdf2 __muldf3 __unorddf2 \
|
| 423 | __muloti4 __multi3 \
|
| 424 | __udivmodti4 __udivti3 __umodti3
|
| 425 |
|
| 426 | ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
|
| 427 |
|
| 428 | redirect-intrinsics += \
|
| 429 | __ashrti3 \
|
| 430 | __ashlti3 __lshrti3
|
| 431 | endif
|
| 432 |
|
| 433 | $(obj)/core.o: private skip_clippy = 1
|
| 434 | $(obj)/core.o: private skip_flags = -Dunreachable_pub
|
| 435 | $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
|
| 436 | $(obj)/core.o: private rustc_target_flags = $(core-cfgs)
|
| 437 | $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE
|
| 438 | $(call if_changed_dep,rustc_library)
|
| 439 |
|
| 440 | $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
|
| 441 | $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
|
| 442 | $(call if_changed_dep,rustc_library)
|
| 443 |
|
| 444 | $(obj)/alloc.o: private skip_clippy = 1
|
| 445 | $(obj)/alloc.o: private skip_flags = -Dunreachable_pub
|
| 446 | $(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
|
| 447 | $(obj)/alloc.o: $(src)/alloc/lib.rs $(obj)/compiler_builtins.o FORCE
|
| 448 | $(call if_changed_dep,rustc_library)
|
| 449 |
|
| 450 | $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
|
| 451 | $(call if_changed_dep,rustc_library)
|
| 452 |
|
| 453 | $(obj)/bindings.o: $(src)/bindings/lib.rs \
|
| 454 | $(obj)/compiler_builtins.o \
|
| 455 | $(obj)/bindings/bindings_generated.rs \
|
| 456 | $(obj)/bindings/bindings_helpers_generated.rs FORCE
|
| 457 | $(call if_changed_dep,rustc_library)
|
| 458 |
|
| 459 | $(obj)/uapi.o: $(src)/uapi/lib.rs \
|
| 460 | $(obj)/compiler_builtins.o \
|
| 461 | $(obj)/uapi/uapi_generated.rs FORCE
|
| 462 | $(call if_changed_dep,rustc_library)
|
| 463 |
|
| 464 | $(obj)/kernel.o: private rustc_target_flags = --extern alloc \
|
| 465 | --extern build_error --extern macros --extern bindings --extern uapi
|
| 466 | $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \
|
| 467 | $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE
|
| 468 | $(call if_changed_dep,rustc_library)
|
| 469 |
|
| 470 | endif
|