From c55b9cf6e5d6ff5022c82fc68330c359dbb98f16 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 13 Nov 2021 12:37:03 +0100 Subject: [PATCH] Consistent x86_64/armv7/aarch64 builds for synit-pid1 --- packaging/Dockerfile.rust | 18 +++++++++++ packaging/Makefile | 26 ++++++++++++---- packaging/packages/synit-pid1/.gitignore | 1 + packaging/packages/synit-pid1/APKBUILD | 30 +++++++++++++++++++ .../packages/synit-pid1/sync-binaries.sh | 14 +++++++++ synit-pid1/Makefile | 15 ++++++++-- 6 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 packaging/Dockerfile.rust create mode 100644 packaging/packages/synit-pid1/.gitignore create mode 100644 packaging/packages/synit-pid1/APKBUILD create mode 100755 packaging/packages/synit-pid1/sync-binaries.sh diff --git a/packaging/Dockerfile.rust b/packaging/Dockerfile.rust new file mode 100644 index 0000000..8a9fb3f --- /dev/null +++ b/packaging/Dockerfile.rust @@ -0,0 +1,18 @@ +ARG ALPINE_ARCH +ARG DOCKER_ARCH +FROM --platform=linux/${DOCKER_ARCH} synit-build:${ALPINE_ARCH} + +ARG http_proxy +# Running without proxy for now, to ensure reasonable freshness and consistency: +# RUN http_proxy=${http_proxy} https_proxy=${http_proxy} rustup-init -y --default-toolchain nightly +# +RUN rustup-init -y --default-toolchain nightly + +ARG BUILD_USER +ENV PATH=/home/${BUILD_USER}/.cargo/bin:$PATH + +# Prime the crates.io index +RUN cargo search --limit 0 + +# Hack to workaround https://github.com/rust-lang/rust/issues/89626 +ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Zgcc-ld=lld" diff --git a/packaging/Makefile b/packaging/Makefile index 85a3094..5d6f3a0 100644 --- a/packaging/Makefile +++ b/packaging/Makefile @@ -32,6 +32,15 @@ DOCKER_CMD=\ -v $(CURDIR)/distfiles:/var/cache/distfiles \ synit-build:$(ARCH) +DOCKER_BUILD_ARGS=\ + --build-arg http_proxy=$(HTTP_PROXY) \ + --build-arg http_proxy_hostname=$(DOCKER_SQUID_IP) \ + --build-arg ALPINE_ARCH=$(ARCH) \ + --build-arg DOCKER_ARCH=$(DOCKER_ARCH) \ + --build-arg KEYFILE=$(KEYFILE) \ + --build-arg UID=$(UID) \ + --build-arg BUILD_USER=$(BUILD_USER) + build: build-image $(DOCKER_CMD) make -f Makefile.internal $@ KEYFILE=$(KEYFILE) sign: build-image @@ -55,16 +64,21 @@ build-image: .build-image.$(ARCH) .build-image.$(ARCH): $(KEYFILE) docker buildx build \ --progress plain \ + $(DOCKER_BUILD_ARGS) \ --platform=linux/$(DOCKER_ARCH) \ - --build-arg http_proxy=$(HTTP_PROXY) \ - --build-arg http_proxy_hostname=$(DOCKER_SQUID_IP) \ - --build-arg DOCKER_ARCH=$(DOCKER_ARCH) \ - --build-arg KEYFILE=$(KEYFILE) \ - --build-arg UID=$(UID) \ - --build-arg BUILD_USER=$(BUILD_USER) \ -t synit-build:$(ARCH) . touch $@ +build-image.rust: .build-image.rust.$(ARCH) + +.build-image.rust.$(ARCH): .build-image.$(ARCH) + docker buildx build \ + --progress plain \ + $(DOCKER_BUILD_ARGS) \ + --platform=linux/$(DOCKER_ARCH) \ + -t synit-build-rust:$(ARCH) -f Dockerfile.rust . + touch $@ + keyfile: $(KEYFILE) $(KEYFILE): diff --git a/packaging/packages/synit-pid1/.gitignore b/packaging/packages/synit-pid1/.gitignore new file mode 100644 index 0000000..12fb65c --- /dev/null +++ b/packaging/packages/synit-pid1/.gitignore @@ -0,0 +1 @@ +buildlog.* diff --git a/packaging/packages/synit-pid1/APKBUILD b/packaging/packages/synit-pid1/APKBUILD new file mode 100644 index 0000000..226e2f7 --- /dev/null +++ b/packaging/packages/synit-pid1/APKBUILD @@ -0,0 +1,30 @@ +# Contributor: Tony Garnock-Jones +# Maintainer: Tony Garnock-Jones +pkgname=synit-pid1 +pkgver=0.0.1 +pkgrel=0 +pkgdesc="synit pid 1 program" +url="https://synit.org/" +arch="all" +license="GPLv3" +depends="" +makedepends="" +source="" +builddir="$srcdir/" +options="!check" + +# This allows us to stomple on /sbin/init, which is owned by the busybox package +replaces="busybox" + +build() { + pwd + ls -laR + false +} + +package() { + : +} + +sha512sums=" +" diff --git a/packaging/packages/synit-pid1/sync-binaries.sh b/packaging/packages/synit-pid1/sync-binaries.sh new file mode 100755 index 0000000..7b060cd --- /dev/null +++ b/packaging/packages/synit-pid1/sync-binaries.sh @@ -0,0 +1,14 @@ +#!/bin/sh +cd "$(dirname "$0")" + +set -e + +build() { + make -C ../../../synit-pid1 $1-binary-release 2>&1 | tee buildlog.$1 + cp -p ../../../synit-pid1/target/$1-*/release/synit-pid1 synit-pid1.$1 +} + +build x86_64 & +build armv7 & +build aarch64 & +wait diff --git a/synit-pid1/Makefile b/synit-pid1/Makefile index 9c11a8a..1e5fa33 100644 --- a/synit-pid1/Makefile +++ b/synit-pid1/Makefile @@ -1,9 +1,20 @@ all: cargo build --all-targets -arm-binary: arm-binary-release +x86_64-binary: x86_64-binary-release -arm-binary-release: +x86_64-binary-release: + $(MAKE) -C ../packaging build-image.rust ARCH=x86_64 + docker run -i --rm \ + -v $(HOME)/.cargo:/home/build/.cargo \ + -v `pwd`:/data \ + -e CARGO_TARGET_DIR=target/x86_64-unknown-linux-musl \ + synit-build-rust:x86_64 \ + cargo build --release --all-targets + +armv7-binary: armv7-binary-release + +armv7-binary-release: cross build --target=armv7-unknown-linux-musleabihf --release --all-targets # Hack to workaround https://github.com/rust-embedded/cross/issues/598