Skip to content

Commit f4f2c20

Browse files
10ne1mgalka
andcommitted
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 and the supported kernel version is 15 (we might bump this later). 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 "offline" toolchain installation method is used as documented at [1] with sha256sum 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. [1] https://forge.rust-lang.org/infra/other-installation-methods.html Co-authored-by: Michał Gałka <[email protected]> Signed-off-by: Adrian Ratiu <[email protected]>
1 parent 61f7dc0 commit f4f2c20

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

config/core/build-configs.yaml

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

426+
rustc-1.62:
427+
cc: clang
428+
cc_version: 15
429+
arch_params:
430+
x86_64:
431+
<<: *x86_64_params
432+
name:
433+
387434
# Default config with full build coverage
388435
build_configs_defaults:
389436
variants:
@@ -939,6 +986,26 @@ build_configs:
939986
branch: 'v5.15-rt'
940987
variants: *preempt_rt_variants
941988

989+
rust:
990+
tree: mainline
991+
branch: 'master'
992+
variants:
993+
rustc-1.62:
994+
build_environment: rustc-1.62
995+
fragments: [rust, rust-samples]
996+
architectures:
997+
x86_64: *x86_64_arch
998+
999+
rust-for-linux:
1000+
tree: rust-for-linux
1001+
branch: 'rust'
1002+
variants:
1003+
rustc-1.62:
1004+
build_environment: rustc-1.62
1005+
fragments: [rust, rust-for-linux-samples]
1006+
architectures:
1007+
x86_64: *x86_64_arch
1008+
9421009
samsung:
9431010
tree: samsung
9441011
branch: 'for-next'

config/docker/rustc-1.62.jinja2

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{% extends 'clang-15.jinja2' %}
2+
3+
{% block packages %}
4+
{{ super() }}
5+
6+
ARG RUST_VER=1.62.0
7+
ARG BINDGEN_VER=0.56.0
8+
9+
ARG RUST_TRIPLE=rust-${RUST_VER}-x86_64-unknown-linux-gnu
10+
11+
ENV CARGO_HOME=/usr/$RUST_TRIPLE/cargo
12+
ENV PATH=/usr/$RUST_TRIPLE/bin:${PATH}
13+
14+
ARG SHA256SUM=4172d3cb316498025410bdf33a4d0f756f5e77fbaee1fb042ccdef78239be1db
15+
16+
# fetch, verify the toolchain
17+
RUN wget https://static.rust-lang.org/dist/${RUST_TRIPLE}.tar.gz
18+
RUN echo "${SHA256SUM} ${RUST_TRIPLE}.tar.gz" | sha256sum --check --quiet
19+
20+
# install & cleanup tmp files
21+
RUN tar -xf ${RUST_TRIPLE}.tar.gz -C /tmp/
22+
RUN /tmp/${RUST_TRIPLE}/install.sh --prefix=/usr/${RUST_TRIPLE} \
23+
--components=rustc,cargo,rust-std-x86_64-unknown-linux-gnu
24+
RUN rm -rf /tmp/${RUST_TRIPLE}
25+
RUN rm /${RUST_TRIPLE}*
26+
27+
# This image is based on clang-*jinja2 which only has clang installed but rustc
28+
# defaults to linker "cc" which calls the non-existing GNU stack (gcc, libgcc, ld).
29+
# So we point cargo/rustc to use the LLVM stack via the clang linker entrypoint.
30+
RUN mkdir $CARGO_HOME
31+
RUN printf '[build]\nrustflags = ["-C", "linker=clang"]' > $CARGO_HOME/config.toml
32+
33+
RUN git clone --recurse-submodules --branch $RUST_VER \
34+
https://github.com/rust-lang/rust \
35+
$(rustc --print sysroot)/lib/rustlib/src/rust
36+
37+
RUN cargo install --locked --version ${BINDGEN_VER} bindgen
38+
39+
{%- endblock %}

0 commit comments

Comments
 (0)