From bebbfe419846944852c4d40b669109a76f1b23aa Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Thu, 22 Dec 2022 14:30:26 -0500 Subject: [PATCH] Add build.earth --- .cargo/config | 27 +++++++++++++++++++ .earthignore | 1 + build.earth | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 .cargo/config create mode 100644 .earthignore create mode 100644 build.earth diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..6dbd830 --- /dev/null +++ b/.cargo/config @@ -0,0 +1,27 @@ +# ARMv6 +[target.arm-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" + +[target.arm-unknown-linux-musleabi] +linker = "arm-linux-gnueabi-gcc" + +[target.arm-unknown-linux-musleabihf] +linker = "arm-linux-gnueabi-gcc" + +# ARMv7 +[target.armv7-unknown-linux-musleabi] +linker = "arm-linux-gnueabi-gcc" + +[target.armv7-unknown-linux-musleabihf] +linker = "arm-linux-gnueabi-gcc" + +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" + +# AARCH64 + +[target.aarch64-unknown-linux-musl] +linker = "aarch64-linux-gnu-gcc" + +[target.aarch64-unknown-linux-muslhf] +linker = "aarch64-linux-gnu-gcc" diff --git a/.earthignore b/.earthignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.earthignore @@ -0,0 +1 @@ +/target diff --git a/build.earth b/build.earth new file mode 100644 index 0000000..44cd88f --- /dev/null +++ b/build.earth @@ -0,0 +1,75 @@ +FROM rust:latest +ENV CARGO_HOME=/deps +ARG APP_NAME=live-cli +WORKDIR /work + +deps: + COPY ./Cargo.toml ./Cargo.lock . + # This is a binary program, expose a main.rs file + RUN mkdir src && touch src/main.rs + RUN cargo fetch + SAVE ARTIFACT /deps + +rust-builder: + # Linux + RUN rustup target add x86_64-unknown-linux-musl + RUN rustup target add i686-unknown-linux-musl + RUN rustup target add i686-unknown-linux-musl + RUN rustup target add aarch64-unknown-linux-musl + RUN rustup target add arm-unknown-linux-musleabi + RUN rustup target add armv7-unknown-linux-musleabi + # Windows + RUN rustup target add x86_64-pc-windows-gnu + RUN rustup target add i686-pc-windows-gnu + + RUN apt-get update + RUN DEBIAN_FRONTEND=noninteractive apt-get install -y gcc-arm-linux-gnueabi gcc-aarch64-linux-gnu gdb-mingw-w64 gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 + + RUN cargo install cargo-deb + + SAVE IMAGE docker-wg:5000/rust-builder + +build: + FROM +rust-builder + + COPY +deps/deps /deps + + ARG TOOLCHAIN + + # Cache whatever dependency builds you can + COPY ./Cargo.toml ./Cargo.lock . + RUN \ + mkdir src && touch src/lib.rs && \ + cargo build --offline --release --target "$TOOLCHAIN" --jobs 1 && \ + rm src/lib.rs && rmdir src && \ + : + + # Actually build the program + COPY . . + RUN cargo build --offline --release --target "$TOOLCHAIN" --jobs 1 + + ARG EXT + ARG STRIP_CMD + RUN if [ "$STRIP_CMD" ]; then "$STRIP_CMD" "target/$TOOLCHAIN/release/$APP_NAME$EXT"; fi + # --force for windows since multiple hardlinks + RUN xz --force --keep "target/$TOOLCHAIN/release/$APP_NAME$EXT" + + # Also build a deb file + IF [ -z "${TOOLCHAIN##*-linux-*}" ] + RUN echo "Building deb for ${TOOLCHAIN}" + RUN cargo deb --target "${TOOLCHAIN}" + + SAVE ARTIFACT target/$TOOLCHAIN/debian/$APP_NAME_*.deb AS LOCAL dist/ + END + + # SAVE ARTIFACT target/$TOOLCHAIN/release/$APP_NAME$EXT AS LOCAL dist/ + SAVE ARTIFACT target/$TOOLCHAIN/release/$APP_NAME$EXT.xz AS LOCAL dist/$APP_NAME$EXT.xt + +all: + BUILD --build-arg TOOLCHAIN=x86_64-unknown-linux-musl --build-arg STRIP_CMD=x86_64-linux-gnu-strip +build + BUILD --build-arg TOOLCHAIN=i686-unknown-linux-musl --build-arg STRIP_CMD=x86_64-linux-gnu-strip +build + BUILD --build-arg TOOLCHAIN=aarch64-unknown-linux-musl --build-arg STRIP_CMD=aarch64-linux-gnu-strip +build + BUILD --build-arg TOOLCHAIN=arm-unknown-linux-musleabi --build-arg STRIP_CMD=arm-linux-gnueabi-strip +build + BUILD --build-arg TOOLCHAIN=armv7-unknown-linux-musleabi --build-arg STRIP_CMD=arm-linux-gnueabi-strip +build + BUILD --build-arg TOOLCHAIN=x86_64-pc-windows-gnu --build-arg STRIP_CMD= --build-arg EXT=.exe +build + BUILD --build-arg TOOLCHAIN=i686-pc-windows-gnu --build-arg STRIP_CMD= --build-arg EXT=.exe +build