Standardize release workflow
This commit is contained in:
parent
8a68a2c2ca
commit
0589f19985
6 changed files with 174 additions and 23 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#!/bin/sh
|
||||
# Build hate-no-d inside a FreeBSD VM and copy the binary back.
|
||||
# Build hate-no-d inside a FreeBSD VM and copy the binary and the static
|
||||
# library back.
|
||||
#
|
||||
# freebsd-build.sh <output-file> [source-dir]
|
||||
#
|
||||
|
|
|
|||
66
.forgejo/scripts/make-archive.sh
Executable file
66
.forgejo/scripts/make-archive.sh
Executable file
|
|
@ -0,0 +1,66 @@
|
|||
#!/bin/sh
|
||||
# Stage one release asset into a directory and pack it, so every download is a
|
||||
# self-contained "folder" instead of a bare binary.
|
||||
#
|
||||
# make-archive.sh <asset-name> <tar.gz|zip> <payload>...
|
||||
#
|
||||
# asset-name e.g. hate-no-d-linux-x86_64; also the directory inside the
|
||||
# archive, so unpacking never scatters files
|
||||
# format tar.gz for Unix payloads (keeps the executable bit), zip for
|
||||
# Windows ones
|
||||
# payload files to pack, each keeping its basename
|
||||
#
|
||||
# LICENSE and README.md are added from the working directory when present.
|
||||
# Writes ./<asset-name>.<format> and leaves the staging directory behind.
|
||||
set -eu
|
||||
|
||||
if [ $# -lt 3 ]; then
|
||||
echo "usage: $0 <asset-name> <tar.gz|zip> <payload>..." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
name=$1
|
||||
format=$2
|
||||
shift 2
|
||||
|
||||
# Guard the rm -rf below.
|
||||
case "$name" in
|
||||
'' | */*) echo "make-archive: bad asset name: '$name'" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
case "$format" in
|
||||
tar.gz | zip) ;;
|
||||
*) echo "make-archive: unknown format: '$format'" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
for f in "$@"; do
|
||||
[ -f "$f" ] || { echo "make-archive: no such file: $f" >&2; exit 1; }
|
||||
done
|
||||
|
||||
rm -rf "$name"
|
||||
mkdir -p "$name"
|
||||
|
||||
# The first payload is the binary: make its mode deterministic instead of
|
||||
# trusting whatever the build/copy path produced.
|
||||
first=1
|
||||
for f in "$@"; do
|
||||
cp "$f" "$name/$(basename "$f")"
|
||||
if [ "$first" = 1 ]; then
|
||||
chmod 755 "$name/$(basename "$f")"
|
||||
first=0
|
||||
fi
|
||||
done
|
||||
|
||||
for f in LICENSE README.md; do
|
||||
if [ -f "$f" ]; then
|
||||
cp "$f" "$name/"
|
||||
fi
|
||||
done
|
||||
|
||||
case "$format" in
|
||||
tar.gz) tar -czf "$name.tar.gz" "$name" ;;
|
||||
zip) zip -qr -X "$name.zip" "$name" >/dev/null ;;
|
||||
esac
|
||||
|
||||
echo "make-archive: wrote $name.$format"
|
||||
ls -l "$name" | sed 's/^/make-archive: /'
|
||||
|
|
@ -45,7 +45,7 @@ jobs:
|
|||
make \
|
||||
CFLAGS="-O2 -Wall -arch ${{ matrix.arch }}" \
|
||||
LUAJIT_EXTRA="TARGET_FLAGS=-arch ${{ matrix.arch }}" \
|
||||
all
|
||||
all lib
|
||||
|
||||
- name: Verify architecture
|
||||
run: |
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@
|
|||
# push / pull_request -> build only
|
||||
# tag 'v*' -> build + release assets
|
||||
#
|
||||
# Assets: hate-no-d-linux-*, -android-*, -windows_mingw_w64-*.exe, -freebsd-x86_64.
|
||||
# Assets: one archive per target, named hate-no-d-<os>-<arch>.tar.gz (zip on
|
||||
# Windows), each unpacking to a directory of the same name holding the binary
|
||||
# plus LICENSE and README.md. Release attachments are a flat list with no
|
||||
# folders, so the archive is what groups a target's files together.
|
||||
# macOS/iOS live in apple.yml; everything here builds on the Linux runner.
|
||||
name: release
|
||||
|
||||
|
|
@ -87,7 +90,7 @@ jobs:
|
|||
make gcc libc6-dev binutils jq curl ca-certificates ${{ matrix.packages }}
|
||||
|
||||
- name: Build
|
||||
run: make ${{ matrix.make_args }} all
|
||||
run: make ${{ matrix.make_args }} all lib
|
||||
|
||||
# A mis-set CC silently yields a host binary, so check the ELF machine.
|
||||
- name: Verify architecture
|
||||
|
|
@ -96,9 +99,12 @@ jobs:
|
|||
readelf -h ./hate-no-d | grep -F 'Machine:' | grep -F '${{ matrix.machine }}'
|
||||
echo "architecture ok: ${{ matrix.machine }}"
|
||||
|
||||
- name: Package
|
||||
run: sh .forgejo/scripts/make-archive.sh "hate-no-d-linux-${{ matrix.arch }}" tar.gz ./hate-no-d ./libhate-no-d.a
|
||||
|
||||
- name: Attach to release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: sh .forgejo/scripts/release-asset.sh ./hate-no-d "hate-no-d-linux-${{ matrix.arch }}"
|
||||
run: sh .forgejo/scripts/release-asset.sh "./hate-no-d-linux-${{ matrix.arch }}.tar.gz"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Android. One job for all ABIs so the ~630 MB NDK is downloaded once. The
|
||||
|
|
@ -149,13 +155,23 @@ jobs:
|
|||
make clean >/dev/null 2>&1 || true
|
||||
if [ "$abi" = armeabi-v7a ]; then
|
||||
make PLATFORM=Android ANDROID_NDK="$ANDROID_NDK" ANDROID_API="$ANDROID_API" \
|
||||
ANDROID_ABI="$abi" HOST_CC="gcc -m32" all
|
||||
ANDROID_ABI="$abi" HOST_CC="gcc -m32" all lib
|
||||
else
|
||||
make PLATFORM=Android ANDROID_NDK="$ANDROID_NDK" ANDROID_API="$ANDROID_API" \
|
||||
ANDROID_ABI="$abi" HOST_CC=gcc all
|
||||
ANDROID_ABI="$abi" HOST_CC=gcc all lib
|
||||
fi
|
||||
readelf -h ./hate-no-d | grep -F 'Machine:' | grep -E 'AArch64|ARM|X86-64'
|
||||
cp ./hate-no-d "dist/hate-no-d-android-$abi"
|
||||
mkdir -p "dist/$abi"
|
||||
cp ./hate-no-d "dist/$abi/hate-no-d"
|
||||
cp ./libhate-no-d.a "dist/$abi/libhate-no-d.a"
|
||||
done
|
||||
|
||||
- name: Package
|
||||
run: |
|
||||
set -eu
|
||||
for abi in arm64-v8a armeabi-v7a x86_64; do
|
||||
sh .forgejo/scripts/make-archive.sh "hate-no-d-android-$abi" tar.gz \
|
||||
"dist/$abi/hate-no-d" "dist/$abi/libhate-no-d.a"
|
||||
done
|
||||
|
||||
- name: Attach to release
|
||||
|
|
@ -163,7 +179,7 @@ jobs:
|
|||
run: |
|
||||
set -eu
|
||||
for abi in arm64-v8a armeabi-v7a x86_64; do
|
||||
sh .forgejo/scripts/release-asset.sh "dist/hate-no-d-android-$abi" "hate-no-d-android-$abi"
|
||||
sh .forgejo/scripts/release-asset.sh "hate-no-d-android-$abi.tar.gz"
|
||||
done
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
@ -197,16 +213,21 @@ jobs:
|
|||
run: |
|
||||
set -eu
|
||||
mkdir -p dist
|
||||
sh .forgejo/scripts/freebsd-build.sh dist/hate-no-d-freebsd-x86_64 .
|
||||
sh .forgejo/scripts/freebsd-build.sh dist/hate-no-d .
|
||||
|
||||
- name: Package
|
||||
run: sh .forgejo/scripts/make-archive.sh hate-no-d-freebsd-x86_64 tar.gz \
|
||||
dist/hate-no-d dist/libhate-no-d.a
|
||||
|
||||
- name: Attach to release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: sh .forgejo/scripts/release-asset.sh dist/hate-no-d-freebsd-x86_64 hate-no-d-freebsd-x86_64
|
||||
run: sh .forgejo/scripts/release-asset.sh ./hate-no-d-freebsd-x86_64.tar.gz
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Windows. Cross-compiled with mingw-w64; no Windows machine or MSVC involved.
|
||||
# i686 needs a 32-bit host compiler for the native buildvm. The build stays
|
||||
# hate-no-d.exe -- only the release asset name carries the toolchain.
|
||||
# i686 needs a 32-bit host compiler for the native buildvm. The asset is a zip
|
||||
# (Windows convention) holding hate-no-d.exe; the toolchain is not part of the
|
||||
# name because it is not a compatibility axis for anyone downloading it.
|
||||
# ---------------------------------------------------------------------------
|
||||
windows:
|
||||
name: windows/${{ matrix.arch }}
|
||||
|
|
@ -218,10 +239,8 @@ jobs:
|
|||
matrix:
|
||||
include:
|
||||
- arch: x86_64
|
||||
tag: windows_mingw_w64-x64
|
||||
host_cc: gcc
|
||||
- arch: i686
|
||||
tag: windows_mingw_w64-x86
|
||||
host_cc: gcc -m32
|
||||
steps:
|
||||
- name: Checkout
|
||||
|
|
@ -233,15 +252,16 @@ jobs:
|
|||
run: git submodule update --init --recursive
|
||||
|
||||
# --no-install-recommends omits libc6-dev, and minilua needs limits.h.
|
||||
# zip: the release asset is a .zip, matching the Windows convention.
|
||||
- name: Install toolchain
|
||||
run: |
|
||||
set -eu
|
||||
apt-get update -qq
|
||||
apt-get install -y --no-install-recommends \
|
||||
make gcc libc6-dev gcc-multilib mingw-w64 jq
|
||||
make gcc libc6-dev gcc-multilib mingw-w64 jq zip
|
||||
|
||||
- name: Build
|
||||
run: make PLATFORM=Windows WIN_ARCH=${{ matrix.arch }} HOST_CC="${{ matrix.host_cc }}" all
|
||||
run: make PLATFORM=Windows WIN_ARCH=${{ matrix.arch }} HOST_CC="${{ matrix.host_cc }}" all lib
|
||||
|
||||
- name: Verify executable
|
||||
run: |
|
||||
|
|
@ -253,6 +273,10 @@ jobs:
|
|||
bad=$(printf '%s\n' "$deps" | grep -v -E '^(KERNEL32|msvcrt)\.dll$' || true)
|
||||
[ -z "$bad" ] || { echo "unexpected runtime DLL dependency: $bad" >&2; exit 1; }
|
||||
|
||||
- name: Package
|
||||
run: sh .forgejo/scripts/make-archive.sh "hate-no-d-windows-${{ matrix.arch }}" zip \
|
||||
./hate-no-d.exe ./libhate-no-d.a
|
||||
|
||||
- name: Attach to release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: sh .forgejo/scripts/release-asset.sh ./hate-no-d.exe hate-no-d-${{ matrix.tag }}.exe
|
||||
run: sh .forgejo/scripts/release-asset.sh "./hate-no-d-windows-${{ matrix.arch }}.zip"
|
||||
|
|
|
|||
10
.gitignore
vendored
10
.gitignore
vendored
|
|
@ -1,3 +1,13 @@
|
|||
hate-no-d
|
||||
hate-no-d.exe
|
||||
quick-start.lua
|
||||
|
||||
# Release staging dirs and archives (.forgejo/scripts/make-archive.sh).
|
||||
hate-no-d-*/
|
||||
hate-no-d-*.tar.gz
|
||||
hate-no-d-*.zip
|
||||
|
||||
# Build artifacts (make lib).
|
||||
*.o
|
||||
*.mri
|
||||
libhate-no-d.a
|
||||
|
|
|
|||
60
Makefile
60
Makefile
|
|
@ -6,6 +6,10 @@
|
|||
# make PLATFORM=Android ANDROID_NDK=... ANDROID_ABI=armeabi-v7a ANDROID_API=21
|
||||
# make PLATFORM=iOS IOS_ARCH=arm64 IOS_MIN=12.0
|
||||
# make PLATFORM=Windows WIN_ARCH=x86_64 (cross build with mingw-w64)
|
||||
#
|
||||
# Targets:
|
||||
# make the CLI (hate-no-d, or hate-no-d.exe / libluajit.a on iOS)
|
||||
# make lib libhate-no-d.a, for embedding into another program
|
||||
|
||||
# luajit requires GNU Make (use `gmake` on FreeBSD/OpenBSD/NetBSD).
|
||||
ifndef .FEATURES
|
||||
|
|
@ -17,7 +21,22 @@ endif
|
|||
LUAJIT_DIR := submodules/luajit
|
||||
LUAJIT_SRC := $(LUAJIT_DIR)/src
|
||||
LUAJIT_AR := $(LUAJIT_SRC)/libluajit.a
|
||||
OBJ := hate-no-d.o
|
||||
BIN := hate-no-d
|
||||
LIB := libhate-no-d.a
|
||||
|
||||
# Everything that goes into $(LIB) besides LuaJIT itself. Empty today: the only
|
||||
# C in the tree is the CLI driver, and its main() belongs to the executable an
|
||||
# embedder already has, not to a library (a -all_load/--whole-archive link would
|
||||
# collide). Runtime modules added later get listed here, e.g.
|
||||
# LIB_OBJS += hnod.o
|
||||
# and are merged into the archive automatically -- that is why the archive has
|
||||
# a name of its own instead of just being LuaJIT's.
|
||||
LIB_OBJS :=
|
||||
|
||||
# Archiver used to merge $(LIB). Cross toolchains ship their own; Apple has no
|
||||
# `ar -M`, so those targets use libtool instead (see the $(LIB) rule).
|
||||
AR ?= ar
|
||||
|
||||
LUAJIT_XCFLAGS := -DLUAJIT_ENABLE_LUA52COMPAT
|
||||
LUAJIT_EXTRA :=
|
||||
|
|
@ -82,6 +101,7 @@ ifeq ($(OS_KIND),windows)
|
|||
endif
|
||||
|
||||
CC := $(WIN_ARCH)-w64-mingw32-gcc
|
||||
AR := $(WIN_ARCH)-w64-mingw32-ar
|
||||
HOST_CC ?= gcc
|
||||
PLAT_LIBS := -lm
|
||||
BIN := $(BIN).exe
|
||||
|
|
@ -152,6 +172,7 @@ ifeq ($(OS_KIND),android)
|
|||
ANDROID_CC := $(ANDROID_BIN)/$(ANDROID_TRIPLET)$(ANDROID_API)-clang
|
||||
|
||||
CC := $(ANDROID_CC)
|
||||
AR := $(ANDROID_BIN)/llvm-ar
|
||||
EXPORT_LDFLAGS := -Wl,-E
|
||||
PLAT_LIBS := -lm
|
||||
LINK_TARGET := $(BIN)
|
||||
|
|
@ -203,23 +224,52 @@ $(LUAJIT_AR):
|
|||
# Targets
|
||||
all: $(LINK_TARGET)
|
||||
|
||||
$(BIN): hate-no-d.c $(LUAJIT_AR)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ hate-no-d.c \
|
||||
$(OBJ): hate-no-d.c
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ hate-no-d.c
|
||||
|
||||
$(BIN): $(OBJ) $(LUAJIT_AR)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(OBJ) \
|
||||
$(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
|
||||
|
||||
luajit: $(LUAJIT_AR)
|
||||
|
||||
# Static library for embedding: $(LIB_OBJS) plus LuaJIT, merged into one archive
|
||||
# so a host program links a single file, and modules added to $(LIB_OBJS) later
|
||||
# join it without the host's link line changing.
|
||||
lib: $(LIB)
|
||||
|
||||
# Apple's ar (cctools) has no MRI script mode, so archives are merged with
|
||||
# libtool there. Everywhere else GNU ar, binutils ar and llvm-ar all parse MRI
|
||||
# scripts (ADDMOD for objects, ADDLIB for another archive).
|
||||
APPLE := $(filter macos ios,$(OS_KIND))
|
||||
|
||||
$(LIB): $(LIB_OBJS) $(LUAJIT_AR)
|
||||
ifeq ($(APPLE),)
|
||||
@rm -f $@ $@.mri
|
||||
@{ echo "CREATE $@"; \
|
||||
for o in $(LIB_OBJS); do echo "ADDMOD $$o"; done; \
|
||||
echo "ADDLIB $(LUAJIT_AR)"; \
|
||||
echo "SAVE"; echo "END"; } > $@.mri
|
||||
$(AR) -M < $@.mri
|
||||
@rm -f $@.mri
|
||||
else
|
||||
@rm -f $@
|
||||
libtool -static -o $@ $(LIB_OBJS) $(LUAJIT_AR)
|
||||
endif
|
||||
@echo "lib: built $@ ($$($(AR) t $@ | wc -l | tr -d ' ') members)"
|
||||
|
||||
# Show the resolved configuration for the current (or selected) platform.
|
||||
# Useful for checking a cross build before committing to it.
|
||||
print-config:
|
||||
@echo "PLATFORM = $(PLATFORM)"
|
||||
@echo "OS_KIND = $(OS_KIND)"
|
||||
@echo "CC = $(CC)"
|
||||
@echo "CC / AR = $(CC) / $(AR)"
|
||||
@echo "CFLAGS = $(CFLAGS)"
|
||||
@echo "CPPFLAGS = $(CPPFLAGS)"
|
||||
@echo "EXPORT_LDFLAGS = $(EXPORT_LDFLAGS)"
|
||||
@echo "PLAT_LIBS = $(PLAT_LIBS)"
|
||||
@echo "LINK_TARGET = $(LINK_TARGET)"
|
||||
@echo "OBJ / LIB = $(OBJ) / $(LIB) [$(LIB_OBJS)]"
|
||||
@echo "LUAJIT_MAKE_ARGS = $(LUAJIT_MAKE_ARGS)"
|
||||
@echo "MACOSX_DEPLOYMENT_TARGET = $(MACOSX_DEPLOYMENT_TARGET) (HRT=$(MACOSX_HRT))"
|
||||
@echo "ANDROID_ABI / API = $(ANDROID_ABI) / $(ANDROID_API)"
|
||||
|
|
@ -228,6 +278,6 @@ print-config:
|
|||
|
||||
clean:
|
||||
$(MAKE) -C $(LUAJIT_DIR) clean
|
||||
rm -f $(BIN)
|
||||
rm -f $(BIN) $(OBJ) $(LIB) $(LIB).mri
|
||||
|
||||
.PHONY: all clean luajit print-config
|
||||
.PHONY: all clean luajit print-config lib
|
||||
|
|
|
|||
Loading…
Reference in a new issue