Compare commits
2 Commits
f5357cc6e0
...
7a96634b5a
Author | SHA1 | Date | |
---|---|---|---|
7a96634b5a | |||
f6fb48e08c |
25
Dockerfile-zig
Normal file
25
Dockerfile-zig
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
FROM docker.io/library/rust:${RUST_VERSION}-slim
|
||||||
|
LABEL maintainer 'Jacob Kiers <code@kie.rs>'
|
||||||
|
ENV ZIG_VERSION=${ZIG_VERSION}
|
||||||
|
|
||||||
|
# Install zig, binstall and zigbuild
|
||||||
|
COPY zig/install-dependencies.sh /tmp/install-dependencies.sh
|
||||||
|
RUN chmod +x /tmp/install-dependencies.sh && /tmp/install-dependencies.sh && rm /tmp/install-dependencies.sh
|
||||||
|
|
||||||
|
# Install macOS SDKs
|
||||||
|
RUN curl -L "https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX10.9.sdk.tar.xz" | tar -J -x -C /opt
|
||||||
|
RUN curl -L "https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz" | tar -J -x -C /opt
|
||||||
|
ENV SDKROOT=/opt/MacOSX11.3.sdk
|
||||||
|
|
||||||
|
# Install Rust targets
|
||||||
|
RUN rustup target add \
|
||||||
|
x86_64-unknown-linux-gnu \
|
||||||
|
x86_64-unknown-linux-musl \
|
||||||
|
aarch64-unknown-linux-gnu \
|
||||||
|
aarch64-unknown-linux-musl \
|
||||||
|
arm-unknown-linux-gnueabihf \
|
||||||
|
arm-unknown-linux-musleabihf \
|
||||||
|
x86_64-apple-darwin \
|
||||||
|
aarch64-apple-darwin \
|
||||||
|
x86_64-pc-windows-gnu
|
||||||
|
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) <year> <copyright holders>
|
Copyright (c) 2022-2024 Jacob Kiers
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
@ -9,14 +9,17 @@ By default, it uses the latest [Rust][2] and [`cross`][3] versions.
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
USAGE: ./build.sh <slim|full> [rust version] [cross version]
|
USAGE: ./build.sh <slim|full|zig> [rust version] [cross version] [zig version]
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
<slim|full> Slim build (without targets) or Full build (with targets)
|
<slim|full> Slim build (without targets) or Full build (with targets)
|
||||||
|
|
||||||
[rust version] Version of rust (https://github.com/rust-lang/rust)
|
[rust version] Version of rust (https://github.com/rust-lang/rust)
|
||||||
[cross version] Version of cross (https://github.com/cross-rs/cross)
|
[cross version] Version of cross (https://github.com/cross-rs/cross)
|
||||||
|
[zig version] Version of zig (https://ziglang.org/download)
|
||||||
|
Use 'master' for master version of zig
|
||||||
|
|
||||||
Both versions default to the latest version.
|
All versions default to the latest release.
|
||||||
```
|
```
|
||||||
|
|
||||||
[1]: https://code.kiers.eu/newsletter-to-web/newsletter-to-web
|
[1]: https://code.kiers.eu/newsletter-to-web/newsletter-to-web
|
||||||
|
48
build.sh
Executable file → Normal file
48
build.sh
Executable file → Normal file
@ -2,14 +2,17 @@
|
|||||||
|
|
||||||
print_usage()
|
print_usage()
|
||||||
{
|
{
|
||||||
echo "USAGE: $0 <slim|full> [rust version] [cross version]"
|
echo "USAGE: $0 <slim|full|zig> [rust version] [cross version] [zig version]"
|
||||||
echo
|
echo
|
||||||
echo "Arguments:"
|
echo "Arguments:"
|
||||||
echo -e "\t<slim|full>\tSlim build (without targets) or Full build (with targets)"
|
echo -e "\t<slim|full>\tSlim build (without targets) or Full build (with targets)"
|
||||||
|
echo
|
||||||
echo -e "\t[rust version]\tVersion of rust (https://github.com/rust-lang/rust)"
|
echo -e "\t[rust version]\tVersion of rust (https://github.com/rust-lang/rust)"
|
||||||
echo -e "\t[cross version]\tVersion of cross (https://github.com/cross-rs/cross)"
|
echo -e "\t[cross version]\tVersion of cross (https://github.com/cross-rs/cross)"
|
||||||
|
echo -e "\t[zig version]\tVersion of zig (https://ziglang.org/download)"
|
||||||
|
echo -e "\t\t\tUse 'master' for master version of zig"
|
||||||
echo
|
echo
|
||||||
echo "Both versions default to the latest version."
|
echo "All versions default to the latest release."
|
||||||
}
|
}
|
||||||
|
|
||||||
get_latest_release() {
|
get_latest_release() {
|
||||||
@ -18,6 +21,18 @@ get_latest_release() {
|
|||||||
sed -E 's/.*"v?([^"]+)".*/\1/' # Pluck JSON value
|
sed -E 's/.*"v?([^"]+)".*/\1/' # Pluck JSON value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_version() {
|
||||||
|
case $2 in
|
||||||
|
latest | "")
|
||||||
|
echo $(get_latest_release $1)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo $2
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if command -v podman &> /dev/null
|
if command -v podman &> /dev/null
|
||||||
then
|
then
|
||||||
@ -42,7 +57,7 @@ if [ $# -lt 1 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
case ${1} in
|
case ${1} in
|
||||||
full | slim)
|
full | slim | zig)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
@ -56,7 +71,7 @@ esac
|
|||||||
set -e -o pipefail
|
set -e -o pipefail
|
||||||
|
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
RUST_VERSION=$(get_latest_release 'rust-lang/rust')
|
RUST_VERSION=$(get_version 'rust-lang/rust' $2)
|
||||||
else
|
else
|
||||||
RUST_VERSION=$2
|
RUST_VERSION=$2
|
||||||
fi
|
fi
|
||||||
@ -67,12 +82,25 @@ else
|
|||||||
CROSS_VERSION=$3
|
CROSS_VERSION=$3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Creating a ${1} build with Rust ${RUST_VERSION} and cross ${CROSS_VERSION}"
|
ZIG_VERSION=$(get_latest_release 'ziglang/zig')
|
||||||
|
|
||||||
export RUST_VERSION
|
export RUST_VERSION
|
||||||
export CROSS_VERSION
|
export CROSS_VERSION
|
||||||
|
export ZIG_VERSION
|
||||||
|
|
||||||
IMAGE="img.kie.rs/jjkiers/rust-dind-cross:rust${RUST_VERSION}-cross${CROSS_VERSION}-${1}"
|
echo "Creating a ${1} build with the following versions:"
|
||||||
|
echo -e "\tRust:\t${RUST_VERSION}"
|
||||||
|
echo -e "\tcross:\t${CROSS_VERSION}"
|
||||||
|
echo -e "\tzig:\t${ZIG_VERSION}"
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
full | slim)
|
||||||
|
IMAGE="img.kie.rs/jjkiers/rust-crossbuild:rust${RUST_VERSION}-cross${CROSS_VERSION}-${1}"
|
||||||
|
;;
|
||||||
|
zig)
|
||||||
|
IMAGE="img.kie.rs/jjkiers/rust-crossbuild:rust${RUST_VERSION}-zig${ZIG_VERSION}-${1}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
envsubst < Dockerfile-${1} | ${BUILDER} build -f - \
|
envsubst < Dockerfile-${1} | ${BUILDER} build -f - \
|
||||||
-t ${IMAGE} \
|
-t ${IMAGE} \
|
||||||
@ -80,6 +108,12 @@ envsubst < Dockerfile-${1} | ${BUILDER} build -f - \
|
|||||||
|
|
||||||
echo "Built image ${IMAGE}"
|
echo "Built image ${IMAGE}"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
${BUILDER} push ${IMAGE}
|
${BUILDER} push ${IMAGE}
|
||||||
|
|
||||||
echo "Pushed image ${IMAGE}"
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Pushing failed: ${BUILDER} push ${IMAGE}"
|
||||||
|
else
|
||||||
|
echo "Pushed image ${IMAGE}"
|
||||||
|
fi
|
||||||
|
51
zig/install-dependencies.sh
Normal file
51
zig/install-dependencies.sh
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -xo pipefail
|
||||||
|
|
||||||
|
apt-get update && apt-get install -y jq curl xz-utils
|
||||||
|
|
||||||
|
TMP_DIR=$(mktemp -d)
|
||||||
|
|
||||||
|
pushd ${TMP_DIR}
|
||||||
|
|
||||||
|
# Install minisign
|
||||||
|
curl -Ls https://github.com/jedisct1/minisign/releases/download/0.11/minisign-0.11-linux.tar.gz -o - | tar --strip-components 2 -C /usr/local/bin/ -vxzf - minisign-linux/x86_64/minisign
|
||||||
|
|
||||||
|
# Installing zig, checking its validity
|
||||||
|
mkdir -p /usr/local/bin
|
||||||
|
curl -Ls https://ziglang.org/download/index.json -o zig-versions.json
|
||||||
|
|
||||||
|
ZIG_SHASUM=".\"${ZIG_VERSION}\".\"x86_64-linux\".shasum"
|
||||||
|
ZIG_TARBALL_URL=".\"${ZIG_VERSION}\".\"x86_64-linux\".tarball"
|
||||||
|
|
||||||
|
echo "$(jq -r ${ZIG_SHASUM} zig-versions.json) zig.tar.xz" > zig.tar.xz.shasum
|
||||||
|
curl -Ls "$(jq -r ${ZIG_TARBALL_URL} zig-versions.json)" -o zig.tar.xz
|
||||||
|
curl -Ls "$(jq -r ${ZIG_TARBALL_URL} zig-versions.json).minisig" -o zig.tar.xz.minisig
|
||||||
|
sha256sum -c zig.tar.xz.shasum
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error in SHA256 hash!"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "SHA256 hash OK"
|
||||||
|
fi
|
||||||
|
|
||||||
|
minisign -P 'RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U' -Vm zig.tar.xz
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error in signature!"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Signature OK"
|
||||||
|
fi
|
||||||
|
|
||||||
|
tar -C /usr/local/bin --strip-components 1 -xf zig.tar.xz
|
||||||
|
|
||||||
|
# Installing binstall and zigbuild
|
||||||
|
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
|
||||||
|
cargo binstall -y cargo-zigbuild
|
||||||
|
|
||||||
|
popd
|
||||||
|
rm -rf ${TMP_DIR}
|
||||||
|
|
||||||
|
apt-get clean
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
Loading…
Reference in New Issue
Block a user