Skip to content

Commit 00b7dce

Browse files
committed
config: add rust build configurations
Starting with the upcoming v6.1, mainline Linux has merged the initial Rust infrastructure so this adds some configs for build testing it together with some sample modules. The kernel requires a specific version of rustc, so we add the rustc-1.62 build environment which derives from clang-15, since a C compiler is still required to build the kernel. Obviously GCC can be used as well but for now testing all the toolchain combinations does not add significant value. In the future more toolchain combinations can be used as needed. The official "rustup" toolchain installation method is used as documented in the upstream kernel and because some distros like Debian stable might not provide up to date toolchain and crates to keep up with the mainline kernel. Only the x86_64 architecture is supported by the kernel for now. We also add the Rust-for-Linux kernel maintainer trees which contain additional modules and bindings. Signed-off-by: Adrian Ratiu <[email protected]>
1 parent 61f7dc0 commit 00b7dce

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

config/core/build-configs.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ trees:
106106
rt-stable:
107107
url: "https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git"
108108

109+
rust-for-linux:
110+
url: "https://github.com/Rust-for-Linux/linux.git"
111+
109112
samsung:
110113
url: "https://git.kernel.org/pub/scm/linux/kernel/git/kgene/linux-samsung.git"
111114

@@ -225,6 +228,42 @@ fragments:
225228
- 'CONFIG_PREEMPT_RT=y'
226229
- 'CONFIG_PREEMPT_RT_FULL=y' # <= v4.19
227230

231+
rust:
232+
path: "kernel/configs/rust.config"
233+
configs:
234+
- 'CONFIG_RUST=y'
235+
236+
rust-samples:
237+
path: "kernel/configs/rust-samples.config"
238+
configs:
239+
- 'CONFIG_SAMPLES=y'
240+
- 'CONFIG_SAMPLES_RUST=y'
241+
- 'CONFIG_SAMPLE_RUST_HOSTPROGS=y'
242+
- 'CONFIG_SAMPLE_RUST_MINIMAL=m'
243+
244+
rust-for-linux-samples:
245+
path: "kernel/configs/rust-samples.config"
246+
configs:
247+
- 'CONFIG_SAMPLES=y'
248+
- 'CONFIG_SAMPLES_RUST=y'
249+
- 'CONFIG_SAMPLE_RUST_MINIMAL=m'
250+
- 'CONFIG_SAMPLE_RUST_HOSTPROGS=m'
251+
- 'CONFIG_SAMPLE_RUST_PRINT=m'
252+
- 'CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m'
253+
- 'CONFIG_SAMPLE_RUST_SYNC=m'
254+
- 'CONFIG_SAMPLE_RUST_CHRDEV=m'
255+
- 'CONFIG_SAMPLE_RUST_MISCDEV=m'
256+
- 'CONFIG_SAMPLE_RUST_STACK_PROBING=m'
257+
- 'CONFIG_SAMPLE_RUST_SEMAPHORE=m'
258+
- 'CONFIG_SAMPLE_RUST_SEMAPHORE_C=m'
259+
- 'CONFIG_SAMPLE_RUST_RANDOM=m'
260+
- 'CONFIG_SAMPLE_RUST_PLATFORM=m'
261+
- 'CONFIG_SAMPLE_RUST_FS=m'
262+
- 'CONFIG_SAMPLE_RUST_NETFILTER=m'
263+
- 'CONFIG_SAMPLE_RUST_ECHO_SERVER=m'
264+
- 'CONFIG_SAMPLE_RUST_HOSTPROGS=m'
265+
- 'CONFIG_SAMPLE_RUST_SELFTESTS=m'
266+
228267
tinyconfig:
229268
path: "kernel/configs/tiny.config"
230269
defconfig: 'tinyconfig'
@@ -384,6 +423,10 @@ build_environments:
384423
arch_params:
385424
<<: *clang_12_arch_params
386425

426+
rustc-1.62:
427+
cc: clang
428+
cc_version: 16
429+
387430
# Default config with full build coverage
388431
build_configs_defaults:
389432
variants:
@@ -939,6 +982,26 @@ build_configs:
939982
branch: 'v5.15-rt'
940983
variants: *preempt_rt_variants
941984

985+
rust:
986+
tree: mainline
987+
branch: 'master'
988+
variants:
989+
rustc-1.62:
990+
build_environment: rustc-1.62
991+
fragments: [rust, rust-samples]
992+
architectures:
993+
x86_64: *x86_64_arch
994+
995+
rust-for-linux:
996+
tree: rust-for-linux
997+
branch: 'rust'
998+
variants:
999+
rustc-1.62:
1000+
build_environment: rustc-1.62
1001+
fragments: [rust, rust-for-linux-samples]
1002+
architectures:
1003+
x86_64: *x86_64_arch
1004+
9421005
samsung:
9431006
tree: samsung
9441007
branch: 'for-next'

config/docker/rustc-1.62.jinja2

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{% extends 'clang-15.jinja2' %}
2+
3+
{% block packages %}
4+
{{ super() }}
5+
6+
ENV RUST_VER=1.62.0
7+
ENV BINDGEN_VER=0.56.0
8+
9+
ENV RUST_TRIPLE=rust-${RUST_VER}-x86_64-unknown-linux-gnu
10+
11+
ENV CARGO_HOME=/usr/$RUST_TRIPLE/cargo
12+
13+
ENV PATH=/usr/$RUST_TRIPLE/bin:${PATH}
14+
15+
# fetch, validate and import the rust team key
16+
RUN wget https://static.rust-lang.org/rust-key.gpg.ascii
17+
RUN gpg --import --import-options show-only rust-key.gpg.ascii | \
18+
grep -q 108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE
19+
RUN gpg --import rust-key.gpg.ascii
20+
21+
# fetch, verify the toolchain
22+
RUN wget https://static.rust-lang.org/dist/${RUST_TRIPLE}.tar.gz
23+
RUN wget https://static.rust-lang.org/dist/${RUST_TRIPLE}.tar.gz.asc
24+
RUN gpg --verify ${RUST_TRIPLE}.tar.gz.asc ${RUST_TRIPLE}.tar.gz
25+
26+
# install & cleanup tmp files
27+
RUN tar -xf ${RUST_TRIPLE}.tar.gz -C /tmp/
28+
RUN /tmp/${RUST_TRIPLE}/install.sh --prefix=/usr/${RUST_TRIPLE} \
29+
--components=rustc,cargo,rust-std-x86_64-unknown-linux-gnu
30+
RUN rm -rf /tmp/${RUST_TRIPLE}
31+
RUN rm /${RUST_TRIPLE}*
32+
33+
RUN mkdir $CARGO_HOME
34+
RUN printf '[build]\nrustflags = ["-C", "linker=clang"]' > $CARGO_HOME/config.toml
35+
36+
RUN git clone --recurse-submodules --branch $RUST_VER \
37+
https://github.com/rust-lang/rust \
38+
$(rustc --print sysroot)/lib/rustlib/src/rust
39+
40+
RUN cargo install --locked --version $BINDGEN_VER bindgen
41+
42+
{%- endblock %}

0 commit comments

Comments
 (0)