Skip to content

Split Rust arguments into a new scripts/Makefile.rust #1026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <tmgross@umich.edu>
  • Loading branch information
tgross35 committed Jul 17, 2023
commit 2687b74d5869c52d5034e482d6bce96b411f8f03
29 changes: 4 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 :=
Expand Down
30 changes: 30 additions & 0 deletions scripts/Makefile.rust
Original file line number Diff line number Diff line change
@@ -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