Skip to content

Commit c422974

Browse files
maurerojeda
authored andcommitted
kbuild: rust: Define probing macros for rustc
Creates flag probe macro variants for `rustc`. These are helpful because: 1. The kernel now supports a minimum `rustc` version rather than a single version. 2. `rustc` links against a range of LLVM revisions, occasionally even ones without an official release number. Since the availability of some Rust flags depends on which LLVM it has been linked against, probing is necessary. Signed-off-by: Matthew Maurer <[email protected]> Link: Rust-for-Linux#1087 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent cc1d98f commit c422974

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

scripts/Kconfig.include

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,11 @@ ld-version := $(shell,set -- $(ld-info) && echo $2)
6464
cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
6565
m32-flag := $(cc-option-bit,-m32)
6666
m64-flag := $(cc-option-bit,-m64)
67+
68+
# $(rustc-option,<flag>)
69+
# Return y if the Rust compiler supports <flag>, n otherwise
70+
# Calls to this should be guarded so that they are not evaluated if
71+
# CONFIG_RUST_IS_AVAILABLE is not set.
72+
# If you are testing for unstable features, consider testing RUSTC_VERSION
73+
# instead, as features may have different completeness while available.
74+
rustc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(RUSTC) $(1) --crate-type=rlib /dev/null --out-dir=.tmp_$$ -o .tmp_$$/tmp.rlib)

scripts/Makefile.compiler

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,18 @@ clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1)
7272
# ld-option
7373
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
7474
ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
75+
76+
# __rustc-option
77+
# Usage: MY_RUSTFLAGS += $(call __rustc-option,$(RUSTC),$(MY_RUSTFLAGS),-Cinstrument-coverage,-Zinstrument-coverage)
78+
__rustc-option = $(call try-run,\
79+
$(1) $(2) $(3) --crate-type=rlib /dev/null --out-dir=$$TMPOUT -o "$$TMP",$(3),$(4))
80+
81+
# rustc-option
82+
# Usage: rustflags-y += $(call rustc-option,-Cinstrument-coverage,-Zinstrument-coverage)
83+
rustc-option = $(call __rustc-option, $(RUSTC),\
84+
$(KBUILD_RUSTFLAGS),$(1),$(2))
85+
86+
# rustc-option-yn
87+
# Usage: flag := $(call rustc-option-yn,-Cinstrument-coverage)
88+
rustc-option-yn = $(call try-run,\
89+
$(RUSTC) $(KBUILD_RUSTFLAGS) $(1) --crate-type=rlib /dev/null --out-dir=$$TMPOUT -o "$$TMP",y,n)

0 commit comments

Comments
 (0)