Skip to content

Commit f5351d6

Browse files
mkchaurasmpe
authored andcommitted
rust: Fix image build error for ubuntu 24.04 or lower
ubuntu 16.06 doesn't ships with rust toolchain. Hence the build for the image was failing. Make sure that the rust toolchain is available only for ubuntu 24.04 or later. For now rust is using nightly toolchain as some required feature for rust-for-linux on ppc64le are not in stable yet. We will switch to stable once it's available. Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
1 parent 59ebcc3 commit f5351d6

3 files changed

Lines changed: 54 additions & 14 deletions

File tree

build/ubuntu/Dockerfile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ RUN apt-get -q -y update && \
1515
DEBIAN_FRONTEND=noninteractive \
1616
apt-get -q -y install --no-install-recommends \
1717
bc \
18-
bindgen \
1918
bison \
2019
bsdmainutils \
2120
bzip2 \
@@ -39,8 +38,6 @@ RUN apt-get -q -y update && \
3938
libfuse-dev \
4039
liblz4-tool \
4140
libssl-dev \
42-
lld \
43-
llvm \
4441
lzop \
4542
make \
4643
openssl \
@@ -49,23 +46,16 @@ RUN apt-get -q -y update && \
4946
u-boot-tools \
5047
rename \
5148
rsync \
52-
rustc \
53-
rustfmt \
54-
rust-clippy \
55-
rust-src \
5649
sparse \
5750
xz-utils \
5851
$(/tmp/packages.sh) && \
5952
rm -rf /var/lib/apt/lists/* /tmp/packages.sh /var/cache/* /var/log/dpkg.log
53+
6054
ENV RUSTUP_HOME=/opt/rustup
6155
ENV CARGO_HOME=/opt/cargo
6256
ENV PATH="/opt/cargo/bin:${PATH}"
63-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
64-
sh -s -- -y --no-modify-path
65-
RUN rustup toolchain install nightly-2026-01-28 \
66-
&& rustup default nightly-2026-01-28 \
67-
&& rustup component add rust-src --toolchain nightly-2026-01-28 \
68-
&& cargo install --locked bindgen-cli
57+
COPY ubuntu/rust-install.sh /tmp/rust-install.sh
58+
RUN /tmp/rust-install.sh && rm /tmp/rust-install.sh
6959
COPY ubuntu/make-links.sh /tmp/make-links.sh
7060
RUN /tmp/make-links.sh ${compiler_version} && rm /tmp/make-links.sh
7161

build/ubuntu/packages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ machine=$(uname -m)
99
major="${VERSION_ID%%.*}"
1010

1111
if [[ "$major" -ge 21 ]]; then
12-
PACKAGES+=" clang llvm"
12+
PACKAGES+=" clang llvm lld"
1313
fi
1414

1515
if [[ "$machine" == "ppc64le" ]]; then

build/ubuntu/rust-install.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Source OS release information
6+
. /etc/os-release
7+
8+
# Extract major version
9+
major="${VERSION_ID%%.*}"
10+
11+
# Only install Rust for Ubuntu 24.04 and later
12+
if [[ "$major" -ge 24 ]]; then
13+
echo "Installing Rust toolchain for Ubuntu $VERSION_ID..."
14+
15+
# Set up Rust environment variables
16+
export RUSTUP_HOME=/opt/rustup
17+
export CARGO_HOME=/opt/cargo
18+
export PATH="/opt/cargo/bin:${PATH}"
19+
20+
# Install rustup
21+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
22+
sh -s -- -y --no-modify-path
23+
24+
# Source cargo environment
25+
. "$CARGO_HOME/env"
26+
27+
# Install nightly toolchain with rust-src component
28+
rustup toolchain install nightly \
29+
&& rustup default nightly \
30+
&& rustup component add rust-src --toolchain nightly \
31+
&& cargo install --locked bindgen-cli
32+
33+
# Verify installation
34+
echo "Rust toolchain installed successfully:"
35+
rustc --version
36+
cargo --version
37+
bindgen --version
38+
39+
# Verify rust-src is available
40+
if [ -f "$(rustc --print sysroot)/lib/rustlib/src/rust/library/core/src/lib.rs" ]; then
41+
echo "rust-src component verified successfully"
42+
else
43+
echo "WARNING: rust-src component not found at expected location"
44+
exit 1
45+
fi
46+
else
47+
echo "Skipping Rust installation for Ubuntu $VERSION_ID (requires 24.04 or later)"
48+
fi
49+
50+
# Made with Bob

0 commit comments

Comments
 (0)