Skip to content

Commit cbee227

Browse files
committed
rust: Define probing macros for rustc
Creates flag probe macro variants for `rustc`. These are helpful because: 1. `rustc` support will soon be a minimum rather than a pinned version. 2. We already support multiple LLVMs linked into `rustc`, and these are needed to probe what LLVM parameters `rustc` will accept. Signed-off-by: Matthew Maurer <[email protected]>
1 parent 1613e60 commit cbee227

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

scripts/Kconfig.include

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ ld-version := $(shell,set -- $(ld-info) && echo $2)
6363
cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
6464
m32-flag := $(cc-option-bit,-m32)
6565
m64-flag := $(cc-option-bit,-m64)
66+
67+
# $(rustc-option,<flag>)
68+
# Return y if the Rust compiler supports <flag>, n otherwise
69+
# Calls to this should be guarded so that they are not evaluated if CONFIG_HAVE_RUST is not set.
70+
rustc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(RUSTC) $(1) --crate-type=rlib /dev/null -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 -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 -o "$$TMP",y,n)

0 commit comments

Comments
 (0)