Skip to content

Commit 43875d0

Browse files
10ne1mgalka
authored 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 Reviewed-by: Miguel Ojeda <ojeda@kernel.org> Co-authored-by: Michał Gałka <galka.michal@gmail.com> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
1 parent dec9436 commit 43875d0

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
@@ -109,6 +109,9 @@ trees:
109109
rt-stable:
110110
url: "https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git"
111111

112+
rust-for-linux:
113+
url: "https://github.com/Rust-for-Linux/linux.git"
114+
112115
samsung:
113116
url: "https://git.kernel.org/pub/scm/linux/kernel/git/kgene/linux-samsung.git"
114117

@@ -228,6 +231,42 @@ fragments:
228231
- 'CONFIG_PREEMPT_RT=y'
229232
- 'CONFIG_PREEMPT_RT_FULL=y' # <= v4.19
230233

234+
rust:
235+
path: "kernel/configs/rust.config"
236+
configs:
237+
- 'CONFIG_RUST=y'
238+
239+
rust-for-linux-samples:
240+
path: "kernel/configs/rust-for-linux-samples.config"
241+
configs:
242+
- 'CONFIG_SAMPLES=y'
243+
- 'CONFIG_SAMPLES_RUST=y'
244+
- 'CONFIG_SAMPLE_RUST_MINIMAL=m'
245+
- 'CONFIG_SAMPLE_RUST_HOSTPROGS=m'
246+
- 'CONFIG_SAMPLE_RUST_PRINT=m'
247+
- 'CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m'
248+
- 'CONFIG_SAMPLE_RUST_SYNC=m'
249+
- 'CONFIG_SAMPLE_RUST_CHRDEV=m'
250+
- 'CONFIG_SAMPLE_RUST_MISCDEV=m'
251+
- 'CONFIG_SAMPLE_RUST_STACK_PROBING=m'
252+
- 'CONFIG_SAMPLE_RUST_SEMAPHORE=m'
253+
- 'CONFIG_SAMPLE_RUST_SEMAPHORE_C=m'
254+
- 'CONFIG_SAMPLE_RUST_RANDOM=m'
255+
- 'CONFIG_SAMPLE_RUST_PLATFORM=m'
256+
- 'CONFIG_SAMPLE_RUST_FS=m'
257+
- 'CONFIG_SAMPLE_RUST_NETFILTER=m'
258+
- 'CONFIG_SAMPLE_RUST_ECHO_SERVER=m'
259+
- 'CONFIG_SAMPLE_RUST_HOSTPROGS=m'
260+
- 'CONFIG_SAMPLE_RUST_SELFTESTS=m'
261+
262+
rust-samples:
263+
path: "kernel/configs/rust-samples.config"
264+
configs:
265+
- 'CONFIG_SAMPLES=y'
266+
- 'CONFIG_SAMPLES_RUST=y'
267+
- 'CONFIG_SAMPLE_RUST_HOSTPROGS=y'
268+
- 'CONFIG_SAMPLE_RUST_MINIMAL=m'
269+
231270
tinyconfig:
232271
path: "kernel/configs/tiny.config"
233272
defconfig: 'tinyconfig'
@@ -396,6 +435,14 @@ build_environments:
396435
arch_params:
397436
<<: *clang_15_arch_params
398437

438+
rustc-1.62:
439+
cc: clang
440+
cc_version: 15
441+
arch_params:
442+
x86_64:
443+
<<: *x86_64_params
444+
name:
445+
399446
# Default config with full build coverage
400447
build_configs_defaults:
401448
variants:
@@ -960,6 +1007,26 @@ build_configs:
9601007
branch: 'v5.15-rt'
9611008
variants: *preempt_rt_variants
9621009

1010+
rust:
1011+
tree: mainline
1012+
branch: 'master'
1013+
variants:
1014+
rustc-1.62:
1015+
build_environment: rustc-1.62
1016+
fragments: [rust, rust-samples, kselftest]
1017+
architectures:
1018+
x86_64: *x86_64_arch
1019+
1020+
rust-for-linux:
1021+
tree: rust-for-linux
1022+
branch: 'rust'
1023+
variants:
1024+
rustc-1.62:
1025+
build_environment: rustc-1.62
1026+
fragments: [rust, rust-for-linux-samples, kselftest]
1027+
architectures:
1028+
x86_64: *x86_64_arch
1029+
9631030
samsung:
9641031
tree: samsung
9651032
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=/home/kernelci/.cargo
12+
ENV PATH=/usr/${RUST_TRIPLE}/bin:${CARGO_HOME}/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+
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+
/tmp/${RUST_TRIPLE}/install.sh --prefix=/usr/${RUST_TRIPLE} \
23+
--components=rustc,cargo,rust-std-x86_64-unknown-linux-gnu && \
24+
rm -rf /tmp/${RUST_TRIPLE} && \
25+
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).
29+
# So we point cargo/rustc to use the LLVM stack via the clang linker entrypoint.
30+
RUN mkdir -p ${CARGO_HOME} && \
31+
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)