From 28f50a750f18035d0bae50f71dc54b0b463961c1 Mon Sep 17 00:00:00 2001 From: Laan Tungir Date: Mon, 4 May 2026 05:57:46 -0400 Subject: [PATCH] v0.0.10 - Fix ARM64 static release build via buildx/QEMU and arch-aware nostr_core linking --- Dockerfile.alpine-musl | 52 +++++++++++++++++++++++++----------------- build_static.sh | 19 ++++++++++++++- src/main.c | 4 ++-- 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/Dockerfile.alpine-musl b/Dockerfile.alpine-musl index c7f6935..07d7f5d 100644 --- a/Dockerfile.alpine-musl +++ b/Dockerfile.alpine-musl @@ -46,7 +46,10 @@ RUN cd /tmp && \ # Copy and build nostr_core_lib from project resources COPY resources/nostr_core_lib /build/nostr_core_lib/ -RUN cd /build/nostr_core_lib && \ +RUN if [ "$(uname -m)" = "aarch64" ] && ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then \ + ln -s "$(command -v gcc)" /usr/local/bin/aarch64-linux-gnu-gcc; \ + fi && \ + cd /build/nostr_core_lib && \ chmod +x ./build.sh && \ ./build.sh --nips=1,4,6,19,44 @@ -54,26 +57,33 @@ RUN cd /build/nostr_core_lib && \ COPY src/ /build/src/ # Build nsigner as a fully static binary -RUN gcc -static -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -s -Wall -Wextra -std=c99 \ - -I/build/nostr_core_lib \ - -I/build/nostr_core_lib/nostr_core \ - -I/build/nostr_core_lib/cjson \ - /build/src/main.c \ - /build/src/secure_mem.c \ - /build/src/mnemonic.c \ - /build/src/role_table.c \ - /build/src/selector.c \ - /build/src/enforcement.c \ - /build/src/dispatcher.c \ - /build/src/policy.c \ - /build/src/server.c \ - /build/src/transport_frame.c \ - /build/src/key_store.c \ - /build/src/socket_name.c \ - /build/nostr_core_lib/libnostr_core_x64.a \ - -o /build/nsigner_static \ - $(pkg-config --static --libs libcurl openssl) \ - -lsecp256k1 -lsqlite3 -lz -lpthread -lm +RUN ARCH="$(uname -m)"; \ + case "$ARCH" in \ + aarch64|arm64) NOSTR_LIB="/build/nostr_core_lib/libnostr_core_arm64.a" ;; \ + x86_64|amd64) NOSTR_LIB="/build/nostr_core_lib/libnostr_core_x64.a" ;; \ + *) echo "Unsupported build arch: $ARCH"; exit 1 ;; \ + esac; \ + [ -f "$NOSTR_LIB" ] || { echo "Missing nostr core lib: $NOSTR_LIB"; ls -la /build/nostr_core_lib; exit 1; }; \ + gcc -static -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -s -Wall -Wextra -std=c99 \ + -I/build/nostr_core_lib \ + -I/build/nostr_core_lib/nostr_core \ + -I/build/nostr_core_lib/cjson \ + /build/src/main.c \ + /build/src/secure_mem.c \ + /build/src/mnemonic.c \ + /build/src/role_table.c \ + /build/src/selector.c \ + /build/src/enforcement.c \ + /build/src/dispatcher.c \ + /build/src/policy.c \ + /build/src/server.c \ + /build/src/transport_frame.c \ + /build/src/key_store.c \ + /build/src/socket_name.c \ + "$NOSTR_LIB" \ + -o /build/nsigner_static \ + $(pkg-config --static --libs libcurl openssl) \ + -lsecp256k1 -lsqlite3 -lz -lpthread -lm RUN strip /build/nsigner_static || true RUN file /build/nsigner_static && \ diff --git a/build_static.sh b/build_static.sh index 4cc2b20..6e79405 100755 --- a/build_static.sh +++ b/build_static.sh @@ -105,12 +105,29 @@ echo "Platform: $PLATFORM" echo "Output: $BUILD_DIR/$OUTPUT_NAME" echo "" +if [ "$ARCH" != "$HOST_ARCH" ]; then + echo "[0/3] Preparing buildx + QEMU for cross-architecture build" + if ! docker buildx inspect >/dev/null 2>&1; then + echo "ERROR: docker buildx is not available" + exit 1 + fi + docker run --privileged --rm tonistiigi/binfmt --install all >/dev/null + + if ! docker buildx inspect nsigner-builder >/dev/null 2>&1; then + docker buildx create --name nsigner-builder --driver docker-container --use >/dev/null + else + docker buildx use nsigner-builder >/dev/null + fi + docker buildx inspect --bootstrap >/dev/null +fi + echo "[1/3] Building builder stage from project root context" -docker build \ +docker buildx build \ --platform "$PLATFORM" \ --target builder \ -f "$DOCKERFILE" \ -t "$IMAGE_TAG" \ + --load \ "$SCRIPT_DIR" echo "[2/3] Extracting static binary" diff --git a/src/main.c b/src/main.c index b44742e..7bd117d 100644 --- a/src/main.c +++ b/src/main.c @@ -451,8 +451,8 @@ int socket_name_random(char *out, size_t out_len); /* Version information (auto-updated by build/version tooling) */ #define NSIGNER_VERSION_MAJOR 0 #define NSIGNER_VERSION_MINOR 0 -#define NSIGNER_VERSION_PATCH 9 -#define NSIGNER_VERSION "v0.0.9" +#define NSIGNER_VERSION_PATCH 10 +#define NSIGNER_VERSION "v0.0.10" /* NSIGNER_HEADERLESS_DECLS_END */