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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arch/x86/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ config ARCH_DEFCONFIG
default "arch/x86/configs/i386_defconfig" if X86_32
default "arch/x86/configs/x86_64_defconfig" if X86_64

config ARCH_RUST_TARGET
string
default "x86_64-linux-kernel" if X86_64

config LOCKDEP_SUPPORT
def_bool y

Expand Down
26 changes: 26 additions & 0 deletions init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,32 @@ config PROFILING
config TRACEPOINTS
bool

config HAS_RUST
def_bool $(success,rustc --version)

config HAS_CARGO
def_bool $(success,cargo --version)

config MENU_RUST
bool "Enables building kernel modules written in Rust"
depends on HAS_RUST
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we only need to know if "cargo xbuild" works, and that sufficient for "HAS_RUST" in the sense that there's nothing we can do with only the existing HAS_RUST nor HAS_CARGO. Only HAS_CARGO_XBUILD is meaningful (it requires rustc and cargo), and the kernel needs full 'cargo xbuild' support.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo xbuild isn't even required anymore -- as of a week or two ago, everything we need is in upstream cargo!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we need to check for any of this. If Rust modules get into mainline, we will build them as any other, so we will assume we have rustc etc. available no matter what (and we will want to be able to change it like we do with CC). And if there are no modules, we don't care anyway.

depends on HAS_CARGO
help
Whether to support building modules written in Rust.

config RUST_DISABLE
bool
depends on RUST_MENU
help
This option disables the support for Rust, so that make
allyesconfig and make allmodconfig will not enable it. To
build modules written in Rust, leave this option set to 'n'.

config RUST
bool
default y
depends on RUST_MENU && !RUST_DISABLE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think any of this is needed -- just leave it "config RUST" with a depends on HAS_RUST that does the "cargo xbuild" test. An "allmodconfig" will not include things that require RUST if HAS_RUST isn't set, etc.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you saying the whole RUST_DISABLE should be removed entirely, or just that this particular line can be simplified?


endmenu # General setup

source "arch/Kconfig"
Expand Down
13 changes: 13 additions & 0 deletions scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ quiet_cmd_cc_lst_c = MKLST $@
$(obj)/%.lst: $(src)/%.c FORCE
$(call if_changed_dep,cc_lst_c)

# Compile Rust sources
# --------------------
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same length as the other sections for the --- line.


ifdef CONFIG_RUST
CARGO ?= cargo

# TODO: release/debug
$(obj)/%.rust.o: $(src)/Cargo.toml $(src)/Cargo.lock $(wildcard $(src)/src/*.rs) FORCE
cd $(src); env -u MAKE -u MAKEFLAGS KDIR="$(CURDIR)/$(srctree)" $(CARGO) build -Z build-std=core,alloc --target=$(CONFIG_ARCH_RUST_TARGET)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split long lines with backslashes.

$(LD) -r -o $@ --whole-archive $(src)/target/$(CONFIG_ARCH_RUST_TARGET)/debug/lib$(patsubst %.rust.o,%.a,$(@F))

endif

# header test (header-test-y, header-test-m target)
# ---------------------------------------------------------------------------

Expand Down