Add rolling release built with Zig's musl toolchain
Build a static Linux x86_64 binary with zig cc, linking OpenSSL in and serving it to moonbitlang/async through a dlopen shim. CI publishes it to the rolling release on every push to main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3ca9e8ed1d
commit
2d815bbb75
9 files changed
+368
No files matched your search
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#!/bin/sh
|
||||
# Build a fully static Orbit with Zig's musl toolchain:
|
||||
# dist/orbit-linux-x86_64 and dist/SHA256SUMS
|
||||
#
|
||||
# Needs moon, zig, perl, make, and curl. OpenSSL is built once, with zig, into
|
||||
# _build/musl-deps (set ORBIT_MUSL_DEPS to keep it elsewhere).
|
||||
set -eu
|
||||
|
||||
openssl_version=3.5.9
|
||||
openssl_sha256=603f5602e2eef00d77fbd429d34dcd5822bb301757a1bc9cdb24c670f1eb859a
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
root=$PWD
|
||||
|
||||
# Only x86_64: the libbacktrace.a that moon links is prebuilt for the host.
|
||||
if [ "$(uname -sm)" != "Linux x86_64" ]; then
|
||||
echo "build-musl.sh only supports Linux x86_64" >&2
|
||||
exit 1
|
||||
fi
|
||||
export ORBIT_MUSL_TARGET=x86_64-linux-musl
|
||||
|
||||
deps=${ORBIT_MUSL_DEPS:-$root/_build/musl-deps}
|
||||
prefix=$deps/openssl-$openssl_version-zig-$(zig version)
|
||||
|
||||
if [ ! -f "$prefix/lib/libssl.a" ]; then
|
||||
echo "Building OpenSSL $openssl_version with zig $(zig version)" >&2
|
||||
mkdir -p "$deps"
|
||||
work=$(mktemp -d "$deps/build.XXXXXX")
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
curl -fsSL --retry 5 -o "$work/openssl.tar.gz" \
|
||||
"https://github.com/openssl/openssl/releases/download/openssl-$openssl_version/openssl-$openssl_version.tar.gz"
|
||||
printf '%s %s\n' "$openssl_sha256" "$work/openssl.tar.gz" | sha256sum -c - >&2
|
||||
tar -xzf "$work/openssl.tar.gz" -C "$work"
|
||||
(
|
||||
cd "$work/openssl-$openssl_version"
|
||||
# no-autoload-config: the host's openssl.cnf may name modules we can't load.
|
||||
CC="$root/scripts/musl/cc" AR="$root/scripts/musl/ar" RANLIB="zig ranlib" \
|
||||
./Configure linux-x86_64 --prefix="$work/out" --libdir=lib --openssldir=/etc/ssl \
|
||||
no-shared no-module no-dso no-apps no-tests no-docs no-legacy no-autoload-config \
|
||||
no-ssl3 no-tls1 no-tls1_1 no-dtls no-comp no-afalgeng
|
||||
make -s -j"$(nproc)" build_libs
|
||||
make -s install_dev
|
||||
) > "$work/log" 2>&1 || { tail -n 60 "$work/log" >&2; exit 1; }
|
||||
rm -rf "$prefix"
|
||||
mv "$work/out" "$prefix"
|
||||
fi
|
||||
|
||||
if [ ! -d .mooncakes/moonbitlang/async ]; then moon install >&2; fi
|
||||
obj=$root/_build/musl-shim
|
||||
mkdir -p "$obj"
|
||||
sed -nE 's/^ *IMPORT_FUNC(_WITH_ALT_NAMES)?\([^,]+, *([A-Za-z0-9_]+) *,.*/ORBIT_SYMBOL(\2)/p' \
|
||||
.mooncakes/moonbitlang/async/src/tls/openssl.c > "$obj/openssl_symbols.h"
|
||||
if [ "$(wc -l < "$obj/openssl_symbols.h")" -lt 20 ]; then
|
||||
echo "Could not read the OpenSSL imports from moonbitlang/async" >&2
|
||||
exit 1
|
||||
fi
|
||||
scripts/musl/cc -c -O2 -I"$prefix/include" -I"$obj" \
|
||||
scripts/musl/openssl_static.c -o "$obj/openssl_static.o"
|
||||
|
||||
# A separate target directory keeps these objects apart from the usual glibc ones.
|
||||
# moon doesn't track ORBIT_MUSL_LINK, so relink every time.
|
||||
rm -f _build/musl/native/release/build/main/main.exe
|
||||
# async's dir.c uses NAME_MAX without limits.h, which only glibc's dirent.h pulls in.
|
||||
MOON_CC=$root/scripts/musl/cc MOON_AR=$root/scripts/musl/ar \
|
||||
ORBIT_MUSL_CFLAGS="-include limits.h" \
|
||||
ORBIT_MUSL_LINK="$obj/openssl_static.o $prefix/lib/libssl.a $prefix/lib/libcrypto.a" \
|
||||
moon build --target native --release --target-dir _build/musl >&2
|
||||
|
||||
mkdir -p dist
|
||||
install -m 755 _build/musl/native/release/build/main/main.exe dist/orbit-linux-x86_64
|
||||
if readelf -lW dist/orbit-linux-x86_64 | grep -q INTERP; then
|
||||
echo "dist/orbit-linux-x86_64 is not static" >&2
|
||||
exit 1
|
||||
fi
|
||||
(cd dist && sha256sum orbit-linux-x86_64 > SHA256SUMS)
|
||||
ls -l dist >&2
|
||||
Reference in new issue
Block a user