Skip to content

Commit 15572e9

Browse files
committed
rust: build: move Rust configuration to 'scripts/Makefile.rust'
Currently, all Rust flags live in the top level 'Makefile'. This patch moves these flags to a new file at 'scripts/Makefile.rust' so that wanted adjustments to Rust's CLI configuration can be applied without touching the root 'Makefile'. This change is intended to reduce noise and the potential for merge conflicts. Making this change will simplify the goals of (1) adding additional lints over time, and (2) changing from specifying lint groups (e.g. 'correctness', 'perf') to naming individual lints for better version compatibility. These changes are space consuming (>100 lines) and may have a few adjustments per cycle, so extracting these arguments out of the shared 'Makefile' should be much less noisy for everyone. Signed-off-by: Trevor Gross <[email protected]>
1 parent d2e3115 commit 15572e9

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

Makefile

+4-25
Original file line numberDiff line numberDiff line change
@@ -452,26 +452,12 @@ KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
452452
KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
453453
KBUILD_USERLDFLAGS := $(USERLDFLAGS)
454454

455-
# These flags apply to all Rust code in the tree, including the kernel and
456-
# host programs.
457-
export rust_common_flags := --edition=2021 \
458-
-Zbinary_dep_depinfo=y \
459-
-Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \
460-
-Dunreachable_pub -Dnon_ascii_idents \
461-
-Wmissing_docs \
462-
-Drustdoc::missing_crate_level_docs \
463-
-Dclippy::correctness -Dclippy::style \
464-
-Dclippy::suspicious -Dclippy::complexity \
465-
-Dclippy::perf \
466-
-Dclippy::let_unit_value -Dclippy::mut_mut \
467-
-Dclippy::needless_bitwise_bool \
468-
-Dclippy::needless_continue \
469-
-Wclippy::dbg_macro
455+
# Include configuration for building with Rust
456+
include $(srctree)/scripts/Makefile.rust
470457

471458
KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
472459
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
473-
KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
474-
-Zallow-features= $(HOSTRUSTFLAGS)
460+
KBUILD_HOSTRUSTFLAGS := $(rust_kbuild_host_flags)
475461
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
476462
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
477463

@@ -560,14 +546,7 @@ KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
560546
-Werror=return-type -Wno-format-security -funsigned-char \
561547
-std=gnu11
562548
KBUILD_CPPFLAGS := -D__KERNEL__
563-
KBUILD_RUSTFLAGS := $(rust_common_flags) \
564-
--target=$(objtree)/scripts/target.json \
565-
-Cpanic=abort -Cembed-bitcode=n -Clto=n \
566-
-Cforce-unwind-tables=n -Ccodegen-units=1 \
567-
-Csymbol-mangling-version=v0 \
568-
-Crelocation-model=static \
569-
-Zfunction-sections=n \
570-
-Dclippy::float_arithmetic
549+
KBUILD_RUSTFLAGS := $(rust_kbuild_flags)
571550

572551
KBUILD_AFLAGS_KERNEL :=
573552
KBUILD_CFLAGS_KERNEL :=

scripts/Makefile.rust

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Configuration of flags specific to Rust support
2+
3+
# These flags apply to all Rust code in the tree, including the kernel and
4+
# host programs.
5+
export rust_common_flags := --edition=2021 \
6+
-Zbinary_dep_depinfo=y \
7+
-Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \
8+
-Dunreachable_pub -Dnon_ascii_idents \
9+
-Wmissing_docs \
10+
-Drustdoc::missing_crate_level_docs \
11+
-Dclippy::correctness -Dclippy::style \
12+
-Dclippy::suspicious -Dclippy::complexity \
13+
-Dclippy::perf \
14+
-Dclippy::let_unit_value -Dclippy::mut_mut \
15+
-Dclippy::needless_bitwise_bool \
16+
-Dclippy::needless_continue \
17+
-Wclippy::dbg_macro
18+
19+
export rust_kbuild_host_flags := $(rust_common_flags) -O -Cstrip=debuginfo \
20+
-Zallow-features= $(HOSTRUSTFLAGS)
21+
22+
export rust_kbuild_flags := $(rust_common_flags) \
23+
--target=$(objtree)/scripts/target.json \
24+
-Cpanic=abort -Cembed-bitcode=n -Clto=n \
25+
-Cforce-unwind-tables=n -Ccodegen-units=1 \
26+
-Csymbol-mangling-version=v0 \
27+
-Crelocation-model=static \
28+
-Zfunction-sections=n \
29+
-Dclippy::float_arithmetic

0 commit comments

Comments
 (0)