From 2687b74d5869c52d5034e482d6bce96b411f8f03 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 17 Jul 2023 02:03:51 -0400 Subject: [PATCH] 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 --- Makefile | 29 ++++------------------------- scripts/Makefile.rust | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 scripts/Makefile.rust diff --git a/Makefile b/Makefile index 836643eaefee0e..0923b004746653 100644 --- a/Makefile +++ b/Makefile @@ -452,26 +452,12 @@ KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \ KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS) KBUILD_USERLDFLAGS := $(USERLDFLAGS) -# These flags apply to all Rust code in the tree, including the kernel and -# host programs. -export rust_common_flags := --edition=2021 \ - -Zbinary_dep_depinfo=y \ - -Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \ - -Dunreachable_pub -Dnon_ascii_idents \ - -Wmissing_docs \ - -Drustdoc::missing_crate_level_docs \ - -Dclippy::correctness -Dclippy::style \ - -Dclippy::suspicious -Dclippy::complexity \ - -Dclippy::perf \ - -Dclippy::let_unit_value -Dclippy::mut_mut \ - -Dclippy::needless_bitwise_bool \ - -Dclippy::needless_continue \ - -Wclippy::dbg_macro +# Include configuration for building with Rust +include $(srctree)/scripts/Makefile.rust KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS) KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) -KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \ - -Zallow-features= $(HOSTRUSTFLAGS) +KBUILD_HOSTRUSTFLAGS := $(rust_kbuild_host_flags) KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS) KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS) @@ -560,14 +546,7 @@ KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ -Werror=return-type -Wno-format-security -funsigned-char \ -std=gnu11 KBUILD_CPPFLAGS := -D__KERNEL__ -KBUILD_RUSTFLAGS := $(rust_common_flags) \ - --target=$(objtree)/scripts/target.json \ - -Cpanic=abort -Cembed-bitcode=n -Clto=n \ - -Cforce-unwind-tables=n -Ccodegen-units=1 \ - -Csymbol-mangling-version=v0 \ - -Crelocation-model=static \ - -Zfunction-sections=n \ - -Dclippy::float_arithmetic +KBUILD_RUSTFLAGS := $(rust_kbuild_flags) KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := diff --git a/scripts/Makefile.rust b/scripts/Makefile.rust new file mode 100644 index 00000000000000..5f7a73343daeea --- /dev/null +++ b/scripts/Makefile.rust @@ -0,0 +1,30 @@ +# Configuration of flags specific to Rust support + +# These flags apply to all Rust code in the tree, including the kernel and +# host programs. +export rust_common_flags := --edition=2021 \ + -Zbinary_dep_depinfo=y \ + -Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \ + -Dunreachable_pub -Dnon_ascii_idents \ + -Wmissing_docs \ + -Drustdoc::missing_crate_level_docs \ + -Dclippy::correctness -Dclippy::style \ + -Dclippy::suspicious -Dclippy::complexity \ + -Dclippy::perf \ + -Dclippy::let_unit_value -Dclippy::mut_mut \ + -Dclippy::needless_bitwise_bool \ + -Dclippy::needless_continue \ + -Wclippy::dbg_macro + +export rust_kbuild_host_flags := $(rust_common_flags) \ + -O -Cstrip=debuginfo \ + -Zallow-features= $(HOSTRUSTFLAGS) + +export rust_kbuild_flags := $(rust_common_flags) \ + --target=$(objtree)/scripts/target.json \ + -Cpanic=abort -Cembed-bitcode=n -Clto=n \ + -Cforce-unwind-tables=n -Ccodegen-units=1 \ + -Csymbol-mangling-version=v0 \ + -Crelocation-model=static \ + -Zfunction-sections=n \ + -Dclippy::float_arithmetic