rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: Miguel Ojeda <ojeda@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	rust-for-linux@vger.kernel.org,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Alex Gaynor <alex.gaynor@gmail.com>, Finn Behrens <me@kloenk.de>,
	Adam Bratschi-Kaye <ark.email@gmail.com>,
	Wedson Almeida Filho <wedsonaf@google.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Sven Van Asbroeck <thesven73@gmail.com>,
	Gary Guo <gary@garyguo.net>,
	Boris-Chengbiao Zhou <bobo1239@web.de>,
	Boqun Feng <boqun.feng@gmail.com>,
	Douglas Su <d0u9.su@outlook.com>,
	Dariusz Sosnowski <dsosnowski@dsosnowski.pl>,
	Antonio Terceiro <antonio.terceiro@linaro.org>,
	Daniel Xu <dxu@dxuuu.xyz>
Subject: Re: [PATCH 15/19] Kbuild: add Rust support
Date: Sun, 12 Dec 2021 00:53:15 +0900	[thread overview]
Message-ID: <CAK7LNAS+eiL-kcdnNyyCUNWjV5qGxrw4PM-oJFfw=o1fbhc2qw@mail.gmail.com> (raw)
In-Reply-To: <20211206140313.5653-16-ojeda@kernel.org>

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

  parent reply	other threads:[~2021-12-11 16:03 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 14:02 [PATCH 00/19] " Miguel Ojeda
2021-12-06 14:02 ` [PATCH 01/19] kallsyms: support "big" kernel symbols Miguel Ojeda
2021-12-06 14:18   ` Matthew Wilcox
2021-12-06 17:00     ` Miguel Ojeda
2021-12-06 14:02 ` [PATCH 02/19] kallsyms: increase maximum kernel symbol length to 512 Miguel Ojeda
2021-12-06 14:02 ` [PATCH 03/19] kallsyms: use the correct buffer size for symbols Miguel Ojeda
2021-12-06 14:02 ` [PATCH 04/19] rust: add C helpers Miguel Ojeda
2021-12-06 14:02 ` [PATCH 05/19] rust: add `compiler_builtins` crate Miguel Ojeda
2021-12-07 23:01   ` Nick Desaulniers
2021-12-09 19:34     ` Miguel Ojeda
2021-12-06 14:03 ` [PATCH 07/19] rust: add `build_error` crate Miguel Ojeda
2021-12-06 14:03 ` [PATCH 08/19] rust: add `macros` crate Miguel Ojeda
2021-12-06 14:03 ` [PATCH 10/19] rust: export generated symbols Miguel Ojeda
2021-12-06 14:03 ` [PATCH 11/19] vsprintf: add new `%pA` format specifier Miguel Ojeda
2021-12-06 15:02   ` Greg Kroah-Hartman
2021-12-06 15:56     ` Miguel Ojeda
2021-12-06 16:02       ` Greg Kroah-Hartman
2021-12-06 19:52         ` Nick Desaulniers
2021-12-06 19:55           ` Matthew Wilcox
2021-12-06 20:02             ` Nick Desaulniers
2021-12-06 14:03 ` [PATCH 12/19] scripts: add `generate_rust_analyzer.py` Miguel Ojeda
2021-12-06 14:03 ` [PATCH 13/19] scripts: decode_stacktrace: demangle Rust symbols Miguel Ojeda
2021-12-06 14:03 ` [PATCH 14/19] docs: add Rust documentation Miguel Ojeda
2021-12-08  1:29   ` Nick Desaulniers
2021-12-08 23:07     ` Miguel Ojeda
2021-12-06 14:03 ` [PATCH 15/19] Kbuild: add Rust support Miguel Ojeda
2021-12-07 22:45   ` Nick Desaulniers
2021-12-07 23:21     ` Nick Desaulniers
2021-12-07 23:25       ` Wedson Almeida Filho
2021-12-08  0:05         ` Nick Desaulniers
2021-12-08 22:52     ` Miguel Ojeda
2021-12-11 15:53   ` Masahiro Yamada [this message]
2022-01-17  4:45     ` Miguel Ojeda
2021-12-06 14:03 ` [PATCH 16/19] samples: add Rust examples Miguel Ojeda
2021-12-06 14:03 ` [PATCH 17/19] MAINTAINERS: Rust Miguel Ojeda
2021-12-06 14:03 ` [RFC PATCH 18/19] drivers: gpio: PrimeCell PL061 in Rust Miguel Ojeda
     [not found] ` <20211206140313.5653-20-ojeda@kernel.org>
2021-12-06 15:01   ` [RFC PATCH 19/19] drivers: android: Binder IPC " Greg Kroah-Hartman
2021-12-06 15:59     ` Wedson Almeida Filho
2021-12-06 16:02       ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAK7LNAS+eiL-kcdnNyyCUNWjV5qGxrw4PM-oJFfw=o1fbhc2qw@mail.gmail.com' \
    --to=masahiroy@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=antonio.terceiro@linaro.org \
    --cc=ark.email@gmail.com \
    --cc=bobo1239@web.de \
    --cc=boqun.feng@gmail.com \
    --cc=d0u9.su@outlook.com \
    --cc=dsosnowski@dsosnowski.pl \
    --cc=dxu@dxuuu.xyz \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@kloenk.de \
    --cc=mpe@ellerman.id.au \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=thesven73@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --cc=wedsonaf@google.com \
    --subject='Re: [PATCH 15/19] Kbuild: add Rust support' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).