Add rolling release built with Zig's musl toolchain
Rolling Release / build (push) Successful in 1m40s
Rolling Release / publish (push) Successful in 8s

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:
nandiandClaude Opus 5.5 committed 2026-11-30 16:50:10 -08:00
1 parent 3ca9e8ed1d
commit 2d815bbb75
9 files changed
+368

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
#!/bin/sh
exec zig ar "$@"
+11
View File
@@ -0,0 +1,11 @@
#!/bin/sh
# MOON_CC for static musl builds: `zig cc`, plus the static OpenSSL objects when linking.
set -eu
# shellcheck disable=SC2086 # ORBIT_MUSL_* are space-separated lists
for arg in "$@"; do
case $arg in
-c) exec zig cc -target "$ORBIT_MUSL_TARGET" -ffunction-sections -fdata-sections ${ORBIT_MUSL_CFLAGS-} "$@" ;;
esac
done
exec zig cc -target "$ORBIT_MUSL_TARGET" -static -s -Wl,--gc-sections "$@" ${ORBIT_MUSL_LINK-}
+66
View File
@@ -0,0 +1,66 @@
// moonbitlang/async loads OpenSSL with dlopen/dlsym, which a static musl binary
// can't do. These definitions replace musl's stubs (nothing else in Orbit uses
// them) and hand out the statically linked OpenSSL functions instead.
//
// openssl_symbols.h is generated by scripts/build-musl.sh from async's own
// import list, so a function OpenSSL lacks fails the link, not the first request.
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
// SSL_CTX_set_default_verify_paths only checks the OPENSSLDIR chosen at build
// time (/etc/ssl). Also load the CA bundle from where other distros keep it,
// unless the user picked their own with SSL_CERT_FILE or SSL_CERT_DIR.
static int set_default_verify_paths(SSL_CTX *ctx) {
static const char *const bundles[] = {
"/etc/ssl/certs/ca-certificates.crt", // Debian, Arch, Alpine, Nix
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", // Fedora, RHEL
"/etc/pki/tls/certs/ca-bundle.crt", // older Fedora, RHEL
"/etc/ssl/ca-bundle.pem", // openSUSE
"/etc/ssl/cert.pem", // Alpine, Void
};
if (!SSL_CTX_set_default_verify_paths(ctx)) return 0;
if (getenv("SSL_CERT_FILE") || getenv("SSL_CERT_DIR")) return 1;
for (size_t i = 0; i < sizeof(bundles) / sizeof(bundles[0]); ++i) {
if (access(bundles[i], R_OK) == 0 &&
SSL_CTX_load_verify_file(ctx, bundles[i])) {
break;
}
}
return 1;
}
static const struct {
const char *name;
void *address;
} symbols[] = {
{ "OpenSSL_version_num", (void *)OpenSSL_version_num },
#define ORBIT_SYMBOL(name) { #name, (void *)name },
#include "openssl_symbols.h"
#undef ORBIT_SYMBOL
};
void *dlopen(const char *file, int mode) {
(void)mode;
return file && strncmp(file, "libssl.so", 9) == 0 ? (void *)symbols : NULL;
}
void *dlsym(void *handle, const char *name) {
if (handle != (void *)symbols) return NULL;
if (strcmp(name, "SSL_CTX_set_default_verify_paths") == 0) {
return (void *)set_default_verify_paths;
}
for (size_t i = 0; i < sizeof(symbols) / sizeof(symbols[0]); ++i) {
if (strcmp(name, symbols[i].name) == 0) return symbols[i].address;
}
return NULL;
}