Skip to content

Commit

Permalink
Add build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
csnewman committed Dec 9, 2024
1 parent 2ec0b38 commit d00b7b4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 10 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build

on:
push:
branches: [ master ]

permissions:
pull-requests: write
contents: write

jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'

- name: Set up Zig
uses: mlugg/setup-zig@v1
with:
version: master

- name: Install deps
run: sudo apt-get install -y mingw-w64 build-essential

- name: Build
run: make build-all

- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
title: "[CI] Rebuild native files"
body: Automated changes by CI pipeline.
commit-message: "[CI] Rebuild native files"
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
sign-commits: true
branch: ci/rebuild
add-paths: '*.syso'
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build-all:
cd runtime && make build-all
cd examples/add && make build-all
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o add_linux_arm64 ./examples/add
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o add_darwin_arm64 ./examples/add
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o add_windows_amd64.exe ./examples/add
36 changes: 26 additions & 10 deletions runtime/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
linux-arm64:
zig build-obj -O ReleaseFast -target aarch64-linux-gnu --library c -femit-bin=runtime_linux_arm64.syso \
gcc_libinit.c gcc_stack_unix.c gcc_linux_arm64.c gcc_arm64.S gcc_util.c gcc_setenv.c linux_syscall.c \
gcc_mmap.c gcc_sigaction.c

DARWIN_ARM64_FILES := gcc_libinit.c gcc_stack_darwin.c gcc_darwin_arm64.c gcc_arm64.S gcc_util.c gcc_setenv.c gcc_sigaction.c
LINUX_COMMON_FILES := gcc_libinit.c gcc_stack_unix.c gcc_util.c gcc_setenv.c linux_syscall.c gcc_mmap.c gcc_sigaction.c
LINUX_ARM64_FILES := $(LINUX_COMMON_FILES) gcc_linux_arm64.c gcc_arm64.S
WINDOWS_COMMON_FILES := gcc_libinit_windows.c gcc_util.c gcc_stack_windows.c gcc_windows_amd64.c
WINDOWS_AMD64_FILES := $(WINDOWS_COMMON_FILES) gcc_amd64.S gcc_windows_amd64.c

DARWIN_FILES := gcc_libinit.c gcc_stack_darwin.c gcc_darwin_arm64.c gcc_arm64.S gcc_util.c gcc_setenv.c gcc_sigaction.c
build-all: linux-arm64 windows-amd64 darwin-arm64

.PHONY: $(DARWIN_FILES)
linux-arm64:
zig build-obj -O ReleaseFast -target aarch64-linux-gnu --library c -femit-bin=runtime_linux_arm64.syso \
$(LINUX_ARM64_FILES)

$(DARWIN_FILES):
zig build-obj -O ReleaseFast -target aarch64-macos-none --library c -femit-bin=bin_${*}_darwin_arm64.syso ${@}
windows-amd64:
rm -rf ./btmp
mkdir btmp
zig build-lib -static -O ReleaseSmall -target x86_64-windows-gnu -fno-stack-protector -fno-stack-check \
-fno-sanitize-c --library c -femit-bin=btmp/lib.a $(WINDOWS_AMD64_FILES)
cd btmp && x86_64-w64-mingw32-ar x lib.a
cd btmp && x86_64-w64-mingw32-ld -o ../runtime_windows_amd64.syso -r *.obj
rm -rf ./btmp

darwin-arm64: $(DARWIN_FILES)
darwin-arm64:
rm -rf ./btmp
mkdir btmp
zig build-lib -static -O ReleaseSmall -target aarch64-macos-none -fno-stack-protector -fno-stack-check \
-fno-sanitize-c --library c -femit-bin=btmp/lib.a $(DARWIN_ARM64_FILES)
cd btmp && zig ar x -U lib.a
cd btmp && chmod +rw *.o
cd btmp && find . -name '*.o' -exec sh -c 'cp "$$0" "../runtime_$$(basename $${0%.o})_darwin_arm64.syso"' {} \;
rm -rf ./btmp

0 comments on commit d00b7b4

Please sign in to comment.