Skip to content

Commit bcb5e05

Browse files
committed
Kbuild: rust: remove rust_cross_flags
Export the `rust_common_flags` and use those for proc macros, instead of tweaking `rust_flags` and having a `rust_cross_flags`. This simplifies things a bit and avoids later having to tweak the flags further during the `target.json` cleanups. Since now we use "standard" flags (i.e. no `-Cpanic=abort` etc.) for compiling the proc macros, we do not need the comment on proc macros breaking under non-`panic=unwind` builds (we still track it in the GitHub list in any case). Signed-off-by: Miguel Ojeda <[email protected]>
1 parent d51ec04 commit bcb5e05

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

Makefile

+14-13
Original file line numberDiff line numberDiff line change
@@ -445,19 +445,19 @@ export KBUILD_USERLDFLAGS :=
445445

446446
# These flags apply to all Rust code in the tree, including the kernel and
447447
# host programs.
448-
rust_common_flags := --edition=2021 \
449-
-Zbinary_dep_depinfo=y \
450-
-Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \
451-
-Dunreachable_pub -Dnon_ascii_idents \
452-
-Wmissing_docs \
453-
-Drustdoc::missing_crate_level_docs \
454-
-Dclippy::correctness -Dclippy::style \
455-
-Dclippy::suspicious -Dclippy::complexity \
456-
-Dclippy::perf \
457-
-Dclippy::let_unit_value -Dclippy::mut_mut \
458-
-Dclippy::needless_bitwise_bool \
459-
-Dclippy::needless_continue \
460-
-Wclippy::dbg_macro
448+
export rust_common_flags := --edition=2021 \
449+
-Zbinary_dep_depinfo=y \
450+
-Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \
451+
-Dunreachable_pub -Dnon_ascii_idents \
452+
-Wmissing_docs \
453+
-Drustdoc::missing_crate_level_docs \
454+
-Dclippy::correctness -Dclippy::style \
455+
-Dclippy::suspicious -Dclippy::complexity \
456+
-Dclippy::perf \
457+
-Dclippy::let_unit_value -Dclippy::mut_mut \
458+
-Dclippy::needless_bitwise_bool \
459+
-Dclippy::needless_continue \
460+
-Wclippy::dbg_macro
461461

462462
KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
463463
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
@@ -552,6 +552,7 @@ KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
552552
-std=gnu89
553553
KBUILD_CPPFLAGS := -D__KERNEL__
554554
KBUILD_RUSTFLAGS := $(rust_common_flags) \
555+
--target=$(objtree)/rust/target.json \
555556
-Cpanic=abort -Cembed-bitcode=n -Clto=n -Crpath=n \
556557
-Cforce-unwind-tables=n -Ccodegen-units=1 \
557558
-Csymbol-mangling-version=v0 \

rust/Makefile

+9-10
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ alloc-cfgs = \
5151
quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
5252
cmd_rustdoc = \
5353
OBJTREE=$(abspath $(objtree)) \
54-
$(RUSTDOC) $(if $(rustdoc_host),,$(rust_cross_flags)) \
55-
$(filter-out -Cpanic=abort, $(rust_flags)) \
54+
$(RUSTDOC) $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags)) \
5655
$(rustc_target_flags) -L $(objtree)/rust \
5756
--output $(objtree)/rust/doc --crate-name $(subst rustdoc-,,$@) \
5857
@$(objtree)/include/generated/rustc_cfg $<
@@ -106,7 +105,8 @@ rustdoc-kernel: $(srctree)/rust/kernel/lib.rs rustdoc-core \
106105
quiet_cmd_rustc_test_library = RUSTC TL $<
107106
cmd_rustc_test_library = \
108107
OBJTREE=$(abspath $(objtree)) \
109-
$(RUSTC) $(filter-out --sysroot=%, $(filter-out -Cpanic=abort, $(rust_flags))) \
108+
$(RUSTC) $(rust_common_flags) \
109+
@$(objtree)/include/generated/rustc_cfg \
110110
$(rustc_target_flags) --crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \
111111
--out-dir $(objtree)/rust/test/ --cfg testlib \
112112
--sysroot $(objtree)/rust/test/sysroot \
@@ -123,7 +123,8 @@ rusttestlib-macros: $(srctree)/rust/macros/lib.rs rusttest-prepare FORCE
123123
quiet_cmd_rustdoc_test = RUSTDOC T $<
124124
cmd_rustdoc_test = \
125125
OBJTREE=$(abspath $(objtree)) \
126-
$(RUSTDOC) --test $(filter-out --sysroot=%, $(filter-out -Cpanic=abort, $(rust_flags))) \
126+
$(RUSTDOC) --test $(rust_common_flags) \
127+
@$(objtree)/include/generated/rustc_cfg \
127128
$(rustc_target_flags) $(rustdoc_test_target_flags) \
128129
--sysroot $(objtree)/rust/test/sysroot $(rustdoc_test_quiet) \
129130
-L $(objtree)/rust/test \
@@ -135,7 +136,8 @@ quiet_cmd_rustdoc_test = RUSTDOC T $<
135136
quiet_cmd_rustc_test = RUSTC T $<
136137
cmd_rustc_test = \
137138
OBJTREE=$(abspath $(objtree)) \
138-
$(RUSTC) --test $(filter-out --sysroot=%, $(filter-out -Cpanic=abort, $(rust_flags))) \
139+
$(RUSTC) --test $(rust_common_flags) \
140+
@$(objtree)/include/generated/rustc_cfg \
139141
$(rustc_target_flags) --out-dir $(objtree)/rust/test \
140142
--sysroot $(objtree)/rust/test/sysroot \
141143
-L $(objtree)/rust/test/ --crate-name $(subst rusttest-,,$@) $<; \
@@ -305,13 +307,10 @@ $(objtree)/rust/exports_alloc_generated.h: $(objtree)/rust/alloc.o FORCE
305307
$(objtree)/rust/exports_kernel_generated.h: $(objtree)/rust/kernel.o FORCE
306308
$(call if_changed,exports)
307309

308-
# `-Cpanic=unwind -Cforce-unwind-tables=y` overrides `rust_flags` in order to
309-
# avoid the https://github.com/rust-lang/rust/issues/82320 rustc crash.
310310
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
311311
cmd_rustc_procmacro = \
312-
$(RUSTC_OR_CLIPPY) $(rust_flags) \
312+
$(RUSTC_OR_CLIPPY) $(rust_common_flags) \
313313
--emit=dep-info,link --extern proc_macro \
314-
-Cpanic=unwind -Cforce-unwind-tables=y \
315314
--crate-type proc-macro --out-dir $(objtree)/rust/ \
316315
--crate-name $(patsubst lib%.so,%,$(notdir $@)) $<; \
317316
mv $(objtree)/rust/$(patsubst lib%.so,%,$(notdir $@)).d $(depfile); \
@@ -328,7 +327,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
328327
cmd_rustc_library = \
329328
OBJTREE=$(abspath $(objtree)) \
330329
$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
331-
$(filter-out $(skip_flags),$(rust_flags) $(rust_cross_flags) $(rustc_target_flags)) \
330+
$(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
332331
--emit=dep-info,obj,metadata \
333332
--crate-type rlib --out-dir $(objtree)/rust/ -L $(objtree)/rust/ \
334333
--crate-name $(patsubst %.o,%,$(notdir $@)) $<; \

scripts/Makefile.build

+1-3
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,10 @@ $(obj)/%.lst: $(src)/%.c FORCE
328328
# Compile Rust sources (.rs)
329329
# ---------------------------------------------------------------------------
330330

331-
rust_cross_flags := --target=$(objtree)/rust/target.json
332331
rust_allowed_features := allocator_api,bench_black_box,concat_idents,generic_associated_types
333332

334333
rust_common_cmd = \
335-
RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) \
336-
$(rust_flags) $(rust_cross_flags) \
334+
RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) $(rust_flags) \
337335
-Zallow-features=$(rust_allowed_features) \
338336
-Zcrate-attr=no_std \
339337
-Zcrate-attr='feature($(rust_allowed_features))' \

0 commit comments

Comments
 (0)