Skip to content

Commit 9ab29bc

Browse files
committed
Dockerfile: Add Rust support
Updates the `build` container image to be able to build Rust code (including Rust UEFI code). The following additional applications are installed to assist with setting up Rust dependencies: `curl`, `jq`, and `unzip` The `CARGO_HOME` and `RUSTUP_HOME` environment variables are set in the image and the cargo directory is added to the system path. The version of Rust specified in `Version.njk` is installed alongside support for other tools used in Project Mu Rust builds such as `cargo-make` and `cargo-tarpaulin`. The latest release binaries are pulled directly from their GitHub releases to minimze container size impact. The resulting container images can be used for local development and within pipelines. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
1 parent 55cb1ca commit 9ab29bc

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

Containers/Ubuntu-22/Dockerfile

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ RUN apt-get update && \
3333
apt-get install --yes --no-install-recommends \
3434
bison \
3535
ca-certificates \
36+
curl \
3637
flex \
3738
git \
3839
lcov \
40+
jq \
3941
m4 \
4042
make \
4143
mono-complete \
@@ -88,6 +90,35 @@ RUN wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/pac
8890
dpkg -i packages-microsoft-prod.deb && rm packages-microsoft-prod.deb && \
8991
apt-get update && apt-get install -y powershell && apt-get clean
9092

93+
#
94+
# Rust support
95+
#
96+
97+
ENV CARGO_HOME="$HOME/.cargo"
98+
ENV RUSTUP_HOME="$HOME/.rustup"
99+
ENV PATH="$CARGO_HOME/bin:$PATH"
100+
101+
# Install Rust/Cargo and extras (rust-src, rust fmt, cargo-make, cargo-tarpaulin)
102+
RUN VERSION_URL="https://raw.githubusercontent.com/microsoft/mu_devops/main/.sync/Version.njk" && \
103+
RUST_VERSION=$(curl -s ${VERSION_URL} | grep -oP '(?<=rust_toolchain = ").*(?=")') && \
104+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${RUST_VERSION} --profile minimal && \
105+
rustup component add rustfmt rust-src --toolchain ${RUST_VERSION}-x86_64-unknown-linux-gnu
106+
107+
RUN mkdir cargo_downloads && \
108+
cd cargo_downloads && \
109+
TAG_NAME=$(curl -s https://api.github.com/repos/sagiegurari/cargo-make/releases/latest | jq -r '.tag_name') && \
110+
DOWNLOAD_URL="https://github.com/sagiegurari/cargo-make/releases/download/$TAG_NAME/cargo-make-v$TAG_NAME-x86_64-unknown-linux-gnu.zip" && \
111+
curl -L -o cargo-make.zip "$DOWNLOAD_URL" && \
112+
unzip cargo-make.zip && \
113+
mv cargo-make-v$TAG_NAME-x86_64-unknown-linux-gnu/cargo-make $CARGO_HOME/bin/ && \
114+
TAG_NAME=$(curl -s https://api.github.com/repos/xd009642/tarpaulin/releases/latest | jq -r '.tag_name') && \
115+
DOWNLOAD_URL="https://github.com/xd009642/tarpaulin/releases/download/$TAG_NAME/cargo-tarpaulin-x86_64-unknown-linux-gnu.tar.gz" && \
116+
curl -L -o cargo-tarpaulin.tar.gz "$DOWNLOAD_URL" && \
117+
tar -xzvf cargo-tarpaulin.tar.gz && \
118+
mv cargo-tarpaulin $CARGO_HOME/bin/ && \
119+
cd .. && \
120+
rm -r cargo_downloads
121+
91122
#
92123
# Alternatives
93124
#
@@ -145,7 +176,6 @@ RUN apt-get update && apt-get install --yes --no-install-recommends \
145176
autotools-dev \
146177
bc \
147178
build-essential \
148-
curl \
149179
dosfstools \
150180
gcc \
151181
libglib2.0-dev \

0 commit comments

Comments
 (0)