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
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user