| 1 |
|
| 2 |
|
| 3 | obj-$(CONFIG_RUST) += core.o compiler_builtins.o
|
| 4 | always-$(CONFIG_RUST) += exports_core_generated.h
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 | obj-$(CONFIG_RUST) += helpers.o
|
| 9 | CFLAGS_REMOVE_helpers.o = -Wmissing-prototypes -Wmissing-declarations
|
| 10 |
|
| 11 | always-$(CONFIG_RUST) += libmacros.so
|
| 12 | no-clean-files += libmacros.so
|
| 13 |
|
| 14 | always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs
|
| 15 | obj-$(CONFIG_RUST) += alloc.o bindings.o kernel.o
|
| 16 | always-$(CONFIG_RUST) += exports_alloc_generated.h exports_bindings_generated.h \
|
| 17 | exports_kernel_generated.h
|
| 18 |
|
| 19 | ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW
|
| 20 | obj-$(CONFIG_RUST) += build_error.o
|
| 21 | else
|
| 22 | always-$(CONFIG_RUST) += build_error.o
|
| 23 | endif
|
| 24 |
|
| 25 | obj-$(CONFIG_RUST) += exports.o
|
| 26 |
|
| 27 |
|
| 28 | ifdef CONFIG_RUST
|
| 29 |
|
| 30 |
|
| 31 | rustc_sysroot := $(shell $(RUSTC) $(rust_flags) --print sysroot)
|
| 32 | rustc_host_target := $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cut -d' ' -f2)
|
| 33 | RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/src/rust/library
|
| 34 |
|
| 35 | ifeq ($(quiet),silent_)
|
| 36 | cargo_quiet=-q
|
| 37 | rust_test_quiet=-q
|
| 38 | rustdoc_test_quiet=--test-args -q
|
| 39 | else ifeq ($(quiet),quiet_)
|
| 40 | rust_test_quiet=-q
|
| 41 | rustdoc_test_quiet=--test-args -q
|
| 42 | else
|
| 43 | cargo_quiet=--verbose
|
| 44 | endif
|
| 45 |
|
| 46 | core-cfgs = \
|
| 47 | --cfg no_fp_fmt_parse
|
| 48 |
|
| 49 | alloc-cfgs = \
|
| 50 | --cfg no_borrow \
|
| 51 | --cfg no_fmt \
|
| 52 | --cfg no_global_oom_handling \
|
| 53 | --cfg no_macros \
|
| 54 | --cfg no_rc \
|
| 55 | --cfg no_str \
|
| 56 | --cfg no_string \
|
| 57 | --cfg no_sync \
|
| 58 | --cfg no_thin
|
| 59 |
|
| 60 | quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
|
| 61 | cmd_rustdoc = \
|
| 62 | OBJTREE=$(abspath $(objtree)) \
|
| 63 | $(RUSTDOC) $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags)) \
|
| 64 | $(rustc_target_flags) -L$(objtree)/$(obj) \
|
| 65 | --output $(objtree)/$(obj)/doc \
|
| 66 | --crate-name $(subst rustdoc-,,$@) \
|
| 67 | @$(objtree)/include/generated/rustc_cfg $<
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 | rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
|
| 81 | rustdoc-alloc rustdoc-kernel
|
| 82 | $(Q)cp $(srctree)/Documentation/images/logo.svg $(objtree)/$(obj)/doc
|
| 83 | $(Q)cp $(srctree)/Documentation/images/COPYING-logo $(objtree)/$(obj)/doc
|
| 84 | $(Q)find $(objtree)/$(obj)/doc -name '*.html' -type f -print0 | xargs -0 sed -Ei \
|
| 85 | -e 's:rust-logo\.svg:logo.svg:g' \
|
| 86 | -e 's:rust-logo\.png:logo.svg:g' \
|
| 87 | -e 's:favicon\.svg:logo.svg:g' \
|
| 88 | -e 's:<link rel="alternate icon" type="image/png" href="[./]*favicon-(16x16|32x32)\.png">::g'
|
| 89 | $(Q)echo '.logo-container > img { object-fit: contain; }' \
|
| 90 | >> $(objtree)/$(obj)/doc/rustdoc.css
|
| 91 |
|
| 92 | rustdoc-macros: private rustdoc_host = yes
|
| 93 | rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
|
| 94 | --extern proc_macro
|
| 95 | rustdoc-macros: $(src)/macros/lib.rs FORCE
|
| 96 | $(call if_changed,rustdoc)
|
| 97 |
|
| 98 | rustdoc-core: private rustc_target_flags = $(core-cfgs)
|
| 99 | rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
|
| 100 | $(call if_changed,rustdoc)
|
| 101 |
|
| 102 | rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
|
| 103 | $(call if_changed,rustdoc)
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 | rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \
|
| 110 | -Arustdoc::broken_intra_doc_links
|
| 111 | rustdoc-alloc: $(src)/alloc/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE
|
| 112 | $(call if_changed,rustdoc)
|
| 113 |
|
| 114 | rustdoc-kernel: private rustc_target_flags = --extern alloc \
|
| 115 | --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
|
| 116 | --extern bindings
|
| 117 | rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \
|
| 118 | rustdoc-compiler_builtins rustdoc-alloc $(obj)/libmacros.so \
|
| 119 | $(obj)/bindings.o FORCE
|
| 120 | $(call if_changed,rustdoc)
|
| 121 |
|
| 122 | quiet_cmd_rustc_test_library = RUSTC TL $<
|
| 123 | cmd_rustc_test_library = \
|
| 124 | OBJTREE=$(abspath $(objtree)) \
|
| 125 | $(RUSTC) $(rust_common_flags) \
|
| 126 | @$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \
|
| 127 | --crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \
|
| 128 | --out-dir $(objtree)/$(obj)/test --cfg testlib \
|
| 129 | --sysroot $(objtree)/$(obj)/test/sysroot \
|
| 130 | -L$(objtree)/$(obj)/test \
|
| 131 | --crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $<
|
| 132 |
|
| 133 | rusttestlib-build_error: $(src)/build_error.rs rusttest-prepare FORCE
|
| 134 | $(call if_changed,rustc_test_library)
|
| 135 |
|
| 136 | rusttestlib-macros: private rustc_target_flags = --extern proc_macro
|
| 137 | rusttestlib-macros: private rustc_test_library_proc = yes
|
| 138 | rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
|
| 139 | $(call if_changed,rustc_test_library)
|
| 140 |
|
| 141 | rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE
|
| 142 | $(call if_changed,rustc_test_library)
|
| 143 |
|
| 144 | quiet_cmd_rustdoc_test = RUSTDOC T $<
|
| 145 | cmd_rustdoc_test = \
|
| 146 | OBJTREE=$(abspath $(objtree)) \
|
| 147 | $(RUSTDOC) --test $(rust_common_flags) \
|
| 148 | @$(objtree)/include/generated/rustc_cfg \
|
| 149 | $(rustc_target_flags) $(rustdoc_test_target_flags) \
|
| 150 | --sysroot $(objtree)/$(obj)/test/sysroot $(rustdoc_test_quiet) \
|
| 151 | -L$(objtree)/$(obj)/test --output $(objtree)/$(obj)/doc \
|
| 152 | --crate-name $(subst rusttest-,,$@) $<
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 | quiet_cmd_rustc_test = RUSTC T $<
|
| 157 | cmd_rustc_test = \
|
| 158 | OBJTREE=$(abspath $(objtree)) \
|
| 159 | $(RUSTC) --test $(rust_common_flags) \
|
| 160 | @$(objtree)/include/generated/rustc_cfg \
|
| 161 | $(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \
|
| 162 | --sysroot $(objtree)/$(obj)/test/sysroot \
|
| 163 | -L$(objtree)/$(obj)/test \
|
| 164 | --crate-name $(subst rusttest-,,$@) $<; \
|
| 165 | $(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \
|
| 166 | $(rustc_test_run_flags)
|
| 167 |
|
| 168 | rusttest: rusttest-macros rusttest-kernel
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 | quiet_cmd_rustsysroot = RUSTSYSROOT
|
| 198 | cmd_rustsysroot = \
|
| 199 | rm -rf $(objtree)/$(obj)/test; \
|
| 200 | mkdir -p $(objtree)/$(obj)/test; \
|
| 201 | cp -a $(rustc_sysroot) $(objtree)/$(obj)/test/sysroot; \
|
| 202 | cp -r $(srctree)/$(src)/alloc/* \
|
| 203 | $(objtree)/$(obj)/test/sysroot/lib/rustlib/src/rust/library/alloc/src; \
|
| 204 | echo '\#!/bin/sh' > $(objtree)/$(obj)/test/rustc_sysroot; \
|
| 205 | echo "$(RUSTC) --sysroot=$(abspath $(objtree)/$(obj)/test/sysroot) \"\$$@\"" \
|
| 206 | >> $(objtree)/$(obj)/test/rustc_sysroot; \
|
| 207 | chmod u+x $(objtree)/$(obj)/test/rustc_sysroot; \
|
| 208 | $(CARGO) -q new $(objtree)/$(obj)/test/dummy; \
|
| 209 | RUSTC=$(objtree)/$(obj)/test/rustc_sysroot $(CARGO) $(cargo_quiet) \
|
| 210 | test -Zbuild-std --target $(rustc_host_target) \
|
| 211 | --manifest-path $(objtree)/$(obj)/test/dummy/Cargo.toml; \
|
| 212 | rm $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib/*; \
|
| 213 | cp $(objtree)/$(obj)/test/dummy/target/$(rustc_host_target)/debug/deps/* \
|
| 214 | $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib
|
| 215 |
|
| 216 | rusttest-prepare: FORCE
|
| 217 | $(call if_changed,rustsysroot)
|
| 218 |
|
| 219 | rusttest-macros: private rustc_target_flags = --extern proc_macro
|
| 220 | rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
|
| 221 | rusttest-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
|
| 222 | $(call if_changed,rustc_test)
|
| 223 | $(call if_changed,rustdoc_test)
|
| 224 |
|
| 225 | rusttest-kernel: private rustc_target_flags = --extern alloc \
|
| 226 | --extern build_error --extern macros --extern bindings
|
| 227 | rusttest-kernel: $(src)/kernel/lib.rs rusttest-prepare \
|
| 228 | rusttestlib-build_error rusttestlib-macros rusttestlib-bindings FORCE
|
| 229 | $(call if_changed,rustc_test)
|
| 230 | $(call if_changed,rustc_test_library)
|
| 231 |
|
| 232 | ifdef CONFIG_CC_IS_CLANG
|
| 233 | bindgen_c_flags = $(c_flags)
|
| 234 | else
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 | bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
|
| 242 | -mskip-rax-setup -mgeneral-regs-only -msign-return-address=% \
|
| 243 | -mindirect-branch=thunk-extern -mindirect-branch-register \
|
| 244 | -mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \
|
| 245 | -mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \
|
| 246 | -mno-pointers-to-nested-functions -mno-string \
|
| 247 | -mno-strict-align -mstrict-align \
|
| 248 | -fconserve-stack -falign-jumps=% -falign-loops=% \
|
| 249 | -femit-struct-debug-baseonly -fno-ipa-cp-clone -fno-ipa-sra \
|
| 250 | -fno-partial-inlining -fplugin-arg-arm_ssp_per_task_plugin-% \
|
| 251 | -fno-reorder-blocks -fno-allow-store-data-races -fasan-shadow-offset=% \
|
| 252 | -fzero-call-used-regs=% -fno-stack-clash-protection \
|
| 253 | -fno-inline-functions-called-once \
|
| 254 | --param=% --param asan-%
|
| 255 |
|
| 256 |
|
| 257 | BINDGEN_TARGET_x86 := x86_64-linux-gnu
|
| 258 | BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 | bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET)
|
| 264 |
|
| 265 | bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
|
| 266 | $(bindgen_extra_c_flags)
|
| 267 | endif
|
| 268 |
|
| 269 | ifdef CONFIG_LTO
|
| 270 | bindgen_c_flags_lto = $(filter-out $(CC_FLAGS_LTO), $(bindgen_c_flags))
|
| 271 | else
|
| 272 | bindgen_c_flags_lto = $(bindgen_c_flags)
|
| 273 | endif
|
| 274 |
|
| 275 | bindgen_c_flags_final = $(bindgen_c_flags_lto) -D__BINDGEN__
|
| 276 |
|
| 277 | quiet_cmd_bindgen = BINDGEN $@
|
| 278 | cmd_bindgen = \
|
| 279 | $(BINDGEN) $< $(bindgen_target_flags) \
|
| 280 | --use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
|
| 281 | --no-debug '.*' \
|
| 282 | --size_t-is-usize -o $@ -- $(bindgen_c_flags_final) -DMODULE \
|
| 283 | $(bindgen_target_cflags) $(bindgen_target_extra)
|
| 284 |
|
| 285 | $(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
|
| 286 | $(shell grep -v '^\#\|^$$' $(srctree)/$(src)/bindgen_parameters)
|
| 287 | $(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
|
| 288 | $(src)/bindgen_parameters FORCE
|
| 289 | $(call if_changed_dep,bindgen)
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 | $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \
|
| 296 | --blacklist-type '.*' --whitelist-var '' \
|
| 297 | --whitelist-function 'rust_helper_.*'
|
| 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_]*)/
|
| 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 $< \
|
| 308 | | grep -E ' (T|R|D) ' | cut -d ' ' -f 3 \
|
| 309 | | xargs -Isymbol \
|
| 310 | echo 'EXPORT_SYMBOL_RUST_GPL(symbol);' > $@
|
| 311 |
|
| 312 | $(obj)/exports_core_generated.h: $(obj)/core.o FORCE
|
| 313 | $(call if_changed,exports)
|
| 314 |
|
| 315 | $(obj)/exports_alloc_generated.h: $(obj)/alloc.o FORCE
|
| 316 | $(call if_changed,exports)
|
| 317 |
|
| 318 | $(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
|
| 319 | $(call if_changed,exports)
|
| 320 |
|
| 321 | $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
|
| 322 | $(call if_changed,exports)
|
| 323 |
|
| 324 | quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
|
| 325 | cmd_rustc_procmacro = \
|
| 326 | $(RUSTC_OR_CLIPPY) $(rust_common_flags) \
|
| 327 | --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
|
| 328 | --crate-type proc-macro \
|
| 329 | --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 | $(obj)/libmacros.so: $(src)/macros/lib.rs $(obj)/core.o FORCE
|
| 335 | $(call if_changed_dep,rustc_procmacro)
|
| 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)) \
|
| 342 | --emit=dep-info=$(depfile) --emit=obj=$@ \
|
| 343 | --emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
|
| 344 | --crate-type rlib -L$(objtree)/$(obj) \
|
| 345 | --crate-name $(patsubst %.o,%,$(notdir $@)) $< \
|
| 346 | $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)
|
| 347 |
|
| 348 | rust-analyzer:
|
| 349 | $(Q)$(srctree)/scripts/generate_rust_analyzer.py $(srctree) $(objtree) \
|
| 350 | $(RUST_LIB_SRC) > $(objtree)/rust-project.json
|
| 351 |
|
| 352 | redirect-intrinsics = \
|
| 353 | __eqsf2 __gesf2 __lesf2 __nesf2 __unordsf2 \
|
| 354 | __unorddf2 \
|
| 355 | __muloti4 __multi3 \
|
| 356 | __udivmodti4 __udivti3 __umodti3
|
| 357 |
|
| 358 | ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
|
| 359 |
|
| 360 | redirect-intrinsics += \
|
| 361 | __ashrti3 \
|
| 362 | __ashlti3 __lshrti3
|
| 363 | endif
|
| 364 |
|
| 365 | $(obj)/core.o: private skip_clippy = 1
|
| 366 | $(obj)/core.o: private skip_flags = -Dunreachable_pub
|
| 367 | $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
|
| 368 | $(obj)/core.o: private rustc_target_flags = $(core-cfgs)
|
| 369 | $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE
|
| 370 | $(call if_changed_dep,rustc_library)
|
| 371 |
|
| 372 | $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
|
| 373 | $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
|
| 374 | $(call if_changed_dep,rustc_library)
|
| 375 |
|
| 376 | $(obj)/alloc.o: private skip_clippy = 1
|
| 377 | $(obj)/alloc.o: private skip_flags = -Dunreachable_pub
|
| 378 | $(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
|
| 379 | $(obj)/alloc.o: $(src)/alloc/lib.rs $(obj)/compiler_builtins.o FORCE
|
| 380 | $(call if_changed_dep,rustc_library)
|
| 381 |
|
| 382 | $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
|
| 383 | $(call if_changed_dep,rustc_library)
|
| 384 |
|
| 385 | $(obj)/bindings.o: $(src)/bindings/lib.rs \
|
| 386 | $(obj)/compiler_builtins.o \
|
| 387 | $(obj)/bindings/bindings_generated.rs \
|
| 388 | $(obj)/bindings/bindings_helpers_generated.rs FORCE
|
| 389 | $(call if_changed_dep,rustc_library)
|
| 390 |
|
| 391 | $(obj)/kernel.o: private rustc_target_flags = --extern alloc \
|
| 392 | --extern build_error --extern macros --extern bindings
|
| 393 | $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \
|
| 394 | $(obj)/libmacros.so $(obj)/bindings.o FORCE
|
| 395 | $(call if_changed_dep,rustc_library)
|
| 396 |
|
| 397 | endif
|