Skip to content

Commit 5539004

Browse files
committed
Initial hack at kernel build system support for Rust
1 parent 15d90b2 commit 5539004

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

arch/x86/x86_64-kernel-target.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"arch": "x86_64",
3+
"cpu": "x86-64",
4+
"code-model": "kernel",
5+
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
6+
"disable-redzone": true,
7+
"eliminate-frame-pointer": false,
8+
"env": "gnu",
9+
"features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float",
10+
"linker-flavor": "gcc",
11+
"linker-is-gnu": true,
12+
"llvm-target": "x86_64-elf",
13+
"max-atomic-width": 64,
14+
"no-compiler-rt": true,
15+
"os": "none",
16+
"panic-strategy": "abort",
17+
"position-independent-executables": true,
18+
"pre-link-args": {
19+
"gcc": [
20+
"-Wl,--as-needed",
21+
"-Wl,-z,noexecstack",
22+
"-m64"
23+
]
24+
},
25+
"relocation-model": "static",
26+
"relro-level": "full",
27+
"needs-plt": true,
28+
"target-c-int-width": "32",
29+
"target-endian": "little",
30+
"target-family": "unix",
31+
"target-pointer-width": "64",
32+
"vendor": "unknown"
33+
}

init/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,3 +2181,20 @@ config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
21812181
# <asm/syscall_wrapper.h>.
21822182
config ARCH_HAS_SYSCALL_WRAPPER
21832183
def_bool n
2184+
2185+
config HAS_RUST
2186+
def_bool $(success,rustc --version)
2187+
2188+
config HAS_CARGO
2189+
def_bool $(success,cargo --version)
2190+
2191+
config HAS_CARGO_XBUILD
2192+
def_bool $(success,cargo xbuild --version)
2193+
2194+
config RUST
2195+
bool
2196+
depends on HAS_RUST
2197+
depends on HAS_CARGO
2198+
depends on HAS_CARGO_XBUILD
2199+
help
2200+
Whether to support building modules written in Rust.

scripts/Makefile.build

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ quiet_cmd_cc_lst_c = MKLST $@
298298
$(obj)/%.lst: $(src)/%.c FORCE
299299
$(call if_changed_dep,cc_lst_c)
300300

301+
# Compile Rust sources
302+
# --------------------
303+
304+
ifdef CONFIG_RUST
305+
# TODO: release/debug
306+
$(obj)/%.rust.a: $(src)/Cargo.toml $(wildcard $(src)/src/*.rs) =$(srctree)/arc/$(SRCARCH)/$(ARCH)-kernel-target.json
307+
cd $(src); env -u MAKE -u MAKEFLAGS cargo xbuild --target=$(srctree)/arc/$(SRCARCH)/$(ARCH)-kernel-target.json
308+
cp $(src)/target/x86_64-linux-kernel-module/debug/lib%.a $(obj)/%.rust.a
309+
endif
310+
301311
# header test (header-test-y, header-test-m target)
302312
# ---------------------------------------------------------------------------
303313

0 commit comments

Comments
 (0)