-
Couldn't load subscription status.
- Fork 0
Initial hack at kernel build system support for Rust #3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| 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 | ||
|
||
|
|
||
| endmenu # General setup | ||
|
|
||
| source "arch/Kconfig" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| # -------------------- | ||
|
||
|
|
||
| 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) | ||
|
||
| $(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) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cargo xbuildisn't even required anymore -- as of a week or two ago, everything we need is in upstream cargo!There was a problem hiding this comment.
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
rustcetc. available no matter what (and we will want to be able to change it like we do withCC). And if there are no modules, we don't care anyway.