Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile dependencies during the container build #326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions xc/raspberry-pi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
FROM debian:bullseye
FROM debian:bullseye AS base

RUN apt update && apt install --no-install-recommends -y libssl-dev pkg-config libasound2-dev gcc-aarch64-linux-gnu curl ca-certificates libc6-dev-arm64-cross

WORKDIR /workdir

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -t 'aarch64-unknown-linux-gnu'
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -t 'aarch64-unknown-linux-gnu' && \
. $HOME/.cargo/env && \
cargo install cargo-chef


FROM base AS planner
COPY . .
RUN . $HOME/.cargo/env && cargo chef prepare --recipe-path recipe.json


FROM base AS builder
COPY --from=planner /workdir/recipe.json recipe.json
RUN . $HOME/.cargo/env && cargo chef cook --release --recipe-path recipe.json --target aarch64-unknown-linux-gnu
10 changes: 9 additions & 1 deletion xc/raspberry-pi/build_container.sh
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
docker build -t "rpi-xc-bullseye-aarch64" .
#!/bin/bash

SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
REPO_DIR=$(cd "$SCRIPT_DIR/../.." && pwd)

(
cd "$REPO_DIR" && \
docker build -t "rpi-xc-bullseye-aarch64" -f "$SCRIPT_DIR/Dockerfile" "$REPO_DIR"
)
7 changes: 5 additions & 2 deletions xc/raspberry-pi/do_xc_build.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/bin/bash

set -x

TARGET_TRIPLE="aarch64-unknown-linux-gnu"
IMAGE_NAME="rpi-xc-bullseye-aarch64"

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CARGO_ARGS="build --bin refbox --bin overlay --target $TARGET_TRIPLE --release"
CONTAINER_WORKDIR="/workdir/uwh-refbox-rs"
CONTAINER_WORKDIR="/workdir"

CONTAINER_NAME="$(docker create -t -w "$CONTAINER_WORKDIR/" $IMAGE_NAME /root/.cargo/bin/cargo $CARGO_ARGS)"

BASE_DIR="$(dirname "$0")/../.."
BASE_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"

for file in $(ls "$BASE_DIR" | grep -v target | grep -v xc); do
docker cp "$BASE_DIR/$file" "$CONTAINER_NAME:$CONTAINER_WORKDIR/"
Expand Down
20 changes: 16 additions & 4 deletions xc/windows/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# We'll just use the official Rust image rather than build our own from scratch
FROM docker.io/library/rust:1.75.0-slim-bullseye
FROM lukemathwalker/cargo-chef:latest-rust-1.77.2-slim-bullseye AS builder

ENV KEYRINGS /usr/local/share/keyrings

Expand All @@ -22,9 +21,11 @@ RUN set -eux; \
llvm-13 \
lld-13 \
# get a recent wine so we can run tests
winehq-staging \
winehq-stable \
# Unpack xwin
tar; \
tar \
# Needed for wine to work
libfreetype6; \
# ensure that clang/clang++ are callable directly
ln -s clang-13 /usr/bin/clang && ln -s clang /usr/bin/clang++ && ln -s lld-13 /usr/bin/ld.lld; \
# We also need to setup symlinks ourselves for the MSVC shims because they aren't in the debian packages
Expand Down Expand Up @@ -83,3 +84,14 @@ ENV CFLAGS_x86_64_pc_windows_msvc="$CL_FLAGS" \
# Run wineboot just to setup the default WINEPREFIX so we don't do it every
# container run
RUN wine wineboot --init

FROM lukemathwalker/cargo-chef:latest-rust-1.77.2-slim-bullseye AS planner
WORKDIR /workdir
COPY . .
RUN find . -type d -name "target" -exec rm -rf {} +
RUN find . -type d -name "xc" -exec rm -rf {} +
RUN ls -la && cargo chef prepare --recipe-path recipe.json

FROM builder AS development
COPY --from=planner /workdir/recipe.json recipe.json
RUN cargo chef cook --recipe-path recipe.json --target x86_64-pc-windows-msvc --release
10 changes: 9 additions & 1 deletion xc/windows/build_container.sh
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
docker build -t windows-rust-1.75-xc .
#!/bin/bash

SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
REPO_DIR=$(cd "$SCRIPT_DIR/../.." && pwd)

(
cd "$REPO_DIR" && \
docker build -t windows-rust-1.77-xc -f "$SCRIPT_DIR/Dockerfile" "$REPO_DIR"
)
15 changes: 8 additions & 7 deletions xc/windows/do_xc_build.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
CONTAINER_CMD="cargo build --bin refbox --target x86_64-pc-windows-msvc --release"
CONTAINER_WORKDIR="/workdir/uwh-refbox-rs"
#!/bin/bash

CONTAINER_NAME="$(docker create -t -w "$CONTAINER_WORKDIR/" windows-rust-1.75-xc /bin/bash -c "$CONTAINER_CMD")"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONTAINER_CMD="cargo build --bin refbox --target x86_64-pc-windows-msvc --release"
CONTAINER_WORKDIR="/workdir"

BASE_DIR="$(dirname "$0")/../.."
CONTAINER_NAME="$(docker create -t -w "$CONTAINER_WORKDIR/" windows-rust-1.77-xc /bin/bash -c "$CONTAINER_CMD")"

for file in $(ls "$BASE_DIR" | grep -v target | grep -v xc); do
docker cp "$BASE_DIR/$file" "$CONTAINER_NAME:$CONTAINER_WORKDIR/"
for file in $(ls "$SCRIPT_DIR/../.." | grep -v target | grep -v xc); do
docker cp "$SCRIPT_DIR/../../$file" "$CONTAINER_NAME:$CONTAINER_WORKDIR/"
done

docker start -a "$CONTAINER_NAME"

docker cp "$CONTAINER_NAME:$CONTAINER_WORKDIR/target/x86_64-pc-windows-msvc/release/refbox.exe" "$(dirname "$0")/output/"
docker cp "$CONTAINER_NAME:$CONTAINER_WORKDIR/target/x86_64-pc-windows-msvc/release/refbox.exe" "$SCRIPT_DIR/output/"

docker rm "$CONTAINER_NAME"
Loading