lkml.org 
[lkml]   [2021]   [Dec]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 15/19] Kbuild: add Rust support
On Mon, Dec 6, 2021 at 11:06 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> Having all the new files in place, we now enable Rust support
> in the build system, including `Kconfig` entries related to Rust,
> the Rust configuration printer, the target definition files,
> the version detection script and a few other bits.
>
> In the future, we will likely want to generate the target files
> on the fly via a script.
>
> Co-developed-by: Alex Gaynor <alex.gaynor@gmail.com>
> Signed-off-by: Alex Gaynor <alex.gaynor@gmail.com>
> Co-developed-by: Finn Behrens <me@kloenk.de>
> Signed-off-by: Finn Behrens <me@kloenk.de>
> Co-developed-by: Adam Bratschi-Kaye <ark.email@gmail.com>
> Signed-off-by: Adam Bratschi-Kaye <ark.email@gmail.com>
> Co-developed-by: Wedson Almeida Filho <wedsonaf@google.com>
> Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
> Co-developed-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> Co-developed-by: Sven Van Asbroeck <thesven73@gmail.com>
> Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
> Co-developed-by: Gary Guo <gary@garyguo.net>
> Signed-off-by: Gary Guo <gary@garyguo.net>
> Co-developed-by: Boris-Chengbiao Zhou <bobo1239@web.de>
> Signed-off-by: Boris-Chengbiao Zhou <bobo1239@web.de>
> Co-developed-by: Boqun Feng <boqun.feng@gmail.com>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> Co-developed-by: Douglas Su <d0u9.su@outlook.com>
> Signed-off-by: Douglas Su <d0u9.su@outlook.com>
> Co-developed-by: Dariusz Sosnowski <dsosnowski@dsosnowski.pl>
> Signed-off-by: Dariusz Sosnowski <dsosnowski@dsosnowski.pl>
> Co-developed-by: Antonio Terceiro <antonio.terceiro@linaro.org>
> Signed-off-by: Antonio Terceiro <antonio.terceiro@linaro.org>
> Co-developed-by: Daniel Xu <dxu@dxuuu.xyz>
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> .gitignore | 5 +
> .rustfmt.toml | 12 ++
> Makefile | 146 +++++++++++++-
> arch/arm/rust/target.json | 27 +++
> arch/arm64/rust/target.json | 34 ++++
> arch/powerpc/rust/target.json | 29 +++
> arch/riscv/Makefile | 1 +
> arch/riscv/rust/rv32ima.json | 36 ++++
> arch/riscv/rust/rv32imac.json | 36 ++++
> arch/riscv/rust/rv64ima.json | 36 ++++
> arch/riscv/rust/rv64imac.json | 36 ++++
> arch/x86/rust/target.json | 36 ++++
> init/Kconfig | 31 ++-
> lib/Kconfig.debug | 144 ++++++++++++++
> rust/.gitignore | 7 +
> rust/Makefile | 353 ++++++++++++++++++++++++++++++++++
> rust/bindgen_parameters | 13 ++
> scripts/Makefile.build | 22 +++
> scripts/Makefile.debug | 10 +
> scripts/Makefile.lib | 12 ++
> scripts/Makefile.modfinal | 8 +-
> scripts/is_rust_module.sh | 19 ++
> scripts/kconfig/confdata.c | 75 ++++++++
> scripts/rust-version.sh | 31 +++
> 24 files changed, 1147 insertions(+), 12 deletions(-)
> create mode 100644 .rustfmt.toml
> create mode 100644 arch/arm/rust/target.json
> create mode 100644 arch/arm64/rust/target.json
> create mode 100644 arch/powerpc/rust/target.json
> create mode 100644 arch/riscv/rust/rv32ima.json
> create mode 100644 arch/riscv/rust/rv32imac.json
> create mode 100644 arch/riscv/rust/rv64ima.json
> create mode 100644 arch/riscv/rust/rv64imac.json
> create mode 100644 arch/x86/rust/target.json
> create mode 100644 rust/.gitignore
> create mode 100644 rust/Makefile
> create mode 100644 rust/bindgen_parameters
> create mode 100755 scripts/is_rust_module.sh
> create mode 100755 scripts/rust-version.sh
>
> diff --git a/.gitignore b/.gitignore
> index 7afd412dadd2..48c68948f476 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -37,6 +37,7 @@
> *.o
> *.o.*
> *.patch
> +*.rmeta
> *.s
> *.so
> *.so.dbg
> @@ -96,6 +97,7 @@ modules.order
> !.gitattributes
> !.gitignore
> !.mailmap
> +!.rustfmt.toml
>
> #
> # Generated include files
> @@ -161,3 +163,6 @@ x509.genkey
>
> # Documentation toolchain
> sphinx_*/
> +
> +# Rust analyzer configuration
> +/rust-project.json
> diff --git a/.rustfmt.toml b/.rustfmt.toml
> new file mode 100644
> index 000000000000..3de5cc497465
> --- /dev/null
> +++ b/.rustfmt.toml
> @@ -0,0 +1,12 @@
> +edition = "2021"
> +newline_style = "Unix"
> +
> +# Unstable options that help catching some mistakes in formatting and that we may want to enable
> +# when they become stable.
> +#
> +# They are kept here since they are useful to run from time to time.
> +#format_code_in_doc_comments = true
> +#reorder_impl_items = true
> +#comment_width = 100
> +#wrap_comments = true
> +#normalize_comments = true
> diff --git a/Makefile b/Makefile
> index 0a6ecc8bb2d2..0f20ca9bd723 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -120,6 +120,13 @@ endif
>
> export KBUILD_CHECKSRC
>
> +# Enable "clippy" (a linter) as part of the Rust compilation.
> +#
> +# Use 'make CLIPPY=1' to enable it.
> +ifeq ("$(origin CLIPPY)", "command line")
> + KBUILD_CLIPPY := $(CLIPPY)
> +endif

Do you really want to support CLIPPY=1
in addition to KBUILD_CLIPPY=1 ?

(Refer to C= V= M= O=, which checks $(origin ) )



>
> KBUILD_LDFLAGS_MODULE += --build-id=sha1
> LDFLAGS_vmlinux += --build-id=sha1
> @@ -1095,6 +1163,11 @@ ifeq ($(KBUILD_EXTMOD),)
> core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/
> core-$(CONFIG_BLOCK) += block/
>
> +# Keep this one as an `ifdef` block since its `Makefile` runs `rustc`.
> +ifdef CONFIG_RUST
> +core-y += rust/
> +endif



Is there any reason why
you did not write like

core-$(CONFIG_RUST) += rust/

?








> diff --git a/rust/.gitignore b/rust/.gitignore
> new file mode 100644
> index 000000000000..168cb26a31b9
> --- /dev/null
> +++ b/rust/.gitignore
> @@ -0,0 +1,7 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +bindings_generated.rs
> +bindings_helpers_generated.rs
> +exports_*_generated.h
> +doc/
> +test/
> diff --git a/rust/Makefile b/rust/Makefile
> new file mode 100644
> index 000000000000..2d08314e7031
> --- /dev/null
> +++ b/rust/Makefile
> @@ -0,0 +1,353 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +obj-$(CONFIG_RUST) += core.o compiler_builtins.o helpers.o
> +extra-$(CONFIG_RUST) += exports_core_generated.h
> +
> +extra-$(CONFIG_RUST) += libmacros.so
> +
> +extra-$(CONFIG_RUST) += bindings_generated.rs bindings_helpers_generated.rs
> +obj-$(CONFIG_RUST) += alloc.o kernel.o
> +extra-$(CONFIG_RUST) += exports_alloc_generated.h exports_kernel_generated.h
> +
> +ifdef CONFIG_RUST_BUILD_ASSERT_DENY
> +extra-$(CONFIG_RUST) += build_error.o
> +else
> +obj-$(CONFIG_RUST) += build_error.o
> +endif


extra-y does nothing for 'make modules'.
Is this your expected behavior?

(commit d0e628cd817f3)





> +$(objtree)/rust/build_error.o: $(srctree)/rust/build_error.rs \
> + $(objtree)/rust/compiler_builtins.o FORCE
> + $(call if_changed_dep,rustc_library)
> +
> +# ICE on `--extern macros`: https://github.com/rust-lang/rust/issues/56935
> +$(objtree)/rust/kernel.o: private rustc_target_flags = --extern alloc \
> + --extern build_error \
> + --extern macros=$(objtree)/rust/libmacros.so
> +$(objtree)/rust/kernel.o: $(srctree)/rust/kernel/lib.rs $(objtree)/rust/alloc.o \
> + $(objtree)/rust/build_error.o \
> + $(objtree)/rust/libmacros.so $(objtree)/rust/bindings_generated.rs \
> + $(objtree)/rust/bindings_helpers_generated.rs FORCE
> + $(call if_changed_dep,rustc_library)
> +
> +# Targets that need to expand twice
> +.SECONDEXPANSION:

Why is .SECONDEXPANSION: needed ?





--
Best Regards
Masahiro Yamada

\
 
 \ /
  Last update: 2021-12-11 16:55    [W:0.428 / U:0.232 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site