-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89bf3f4
commit 1439989
Showing
5 changed files
with
137 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,54 +9,22 @@ defaults: | |
|
||
jobs: | ||
build: | ||
name: "Build with Zig ${{ matrix.zig_version }}" | ||
name: "Build with Zig" | ||
runs-on: macos-11 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- zig_version: 0.9.0 | ||
- zig_version: 0.10.0-dev.183+5c228765f | ||
steps: | ||
- name: Check out code | ||
uses: actions/[email protected] | ||
- name: Set up Zig | ||
uses: goto-bus-stop/[email protected] | ||
with: | ||
version: ${{ matrix.zig_version }} | ||
version: 0.9.9 | ||
- name: Set up Golang | ||
uses: actions/[email protected] | ||
with: | ||
go-version: 1.17.5 | ||
- name: System information | ||
run: xcrun --show-sdk-path | ||
- name: "Build: shared darwin amd64" | ||
if: ${{ always() }} | ||
run: ./build.sh shared darwin amd64 | ||
- name: "Build: archive darwin amd64" | ||
if: ${{ always() }} | ||
run: ./build.sh archive darwin amd64 | ||
- name: "Build: shared darwin arm64" | ||
if: ${{ always() }} | ||
run: ./build.sh shared darwin arm64 | ||
- name: "Build: archive darwin arm64" | ||
if: ${{ always() }} | ||
run: ./build.sh archive darwin arm64 | ||
- name: "Build: shared linux amd64" | ||
if: ${{ always() }} | ||
run: ./build.sh shared linux amd64 | ||
- name: "Build: archive linux amd64" | ||
if: ${{ always() }} | ||
run: ./build.sh archive linux amd64 | ||
- name: "Build: shared linux arm64" | ||
if: ${{ always() }} | ||
run: ./build.sh shared linux arm64 | ||
- name: "Build: archive linux arm64" | ||
if: ${{ always() }} | ||
run: ./build.sh archive linux arm64 | ||
- name: "Build: shared windows amd64" | ||
if: ${{ always() }} | ||
run: ./build.sh shared windows amd64 | ||
- name: "Build: archive windows amd64" | ||
if: ${{ always() }} | ||
run: ./build.sh archive windows amd64 | ||
- name: Run local build | ||
run: ./build-native.sh shared | ||
- name: Run cross-compilation build | ||
run: ./build-cross.sh shared $(uname | tr '[:upper:]' '[:lower:]') $(uname -m) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#! /usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
BUILD_DIR="$PROJECT_ROOT/build" | ||
|
||
function main() { | ||
if [[ $# -ne 1 ]]; then | ||
echoRed "Must provide exactly one argument." | ||
exit 1 | ||
fi | ||
|
||
echoBlue "Preparing..." | ||
rm -rf "$BUILD_DIR" | ||
mkdir -p "$BUILD_DIR" | ||
|
||
clearGoBuildCache | ||
build "$1" | ||
} | ||
|
||
function clearGoBuildCache() { | ||
go clean -cache | ||
} | ||
|
||
function build() { | ||
local binaryType=$1 | ||
local os=$(uname | tr '[:upper:]' '[:lower:]') | ||
local arch=$(uname -m) | ||
|
||
echo | ||
echoBlue "Building $binaryType library for local environment ($os $arch)..." | ||
|
||
local outputDir="$BUILD_DIR/$os/$arch/$binaryType" | ||
mkdir -p "$outputDir" | ||
|
||
local outputFile | ||
|
||
case $binaryType in | ||
shared) | ||
case $os in | ||
linux) | ||
outputFile="libmain.so" | ||
;; | ||
darwin) | ||
outputFile="libmain.dylib" | ||
;; | ||
windows) | ||
outputFile="main.dll" | ||
;; | ||
*) | ||
echo "Unknown OS $os" >/dev/stderr | ||
;; | ||
esac | ||
;; | ||
archive) | ||
case $os in | ||
windows) | ||
outputFile="main.lib" | ||
;; | ||
*) | ||
outputFile="libmain.a" | ||
;; | ||
esac | ||
;; | ||
*) | ||
echo "Unknown binary type $binaryType" >/dev/stderr | ||
exit 1 | ||
;; | ||
esac | ||
|
||
{ | ||
cd "$PROJECT_ROOT/src" | ||
|
||
# -ldflags "-s" below is inspired by https://github.com/ziglang/zig/issues/9050#issuecomment-859939664 | ||
# and fixes errors like the following when building the shared library for darwin/amd64: | ||
# /opt/homebrew/Cellar/go/1.17.5/libexec/pkg/tool/darwin_arm64/link: /opt/homebrew/Cellar/go/1.17.5/libexec/pkg/tool/darwin_arm64/link: running strip failed: exit status 1 | ||
# /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip: error: bad n_sect for symbol table entry 556 in: /private/var/folders/7t/_rsz39554vvgvq2t6b4ztktc0000gn/T/go-build3526877506/b001/exe/libmain.dylib | ||
|
||
{ | ||
CGO_ENABLED=1 \ | ||
GOOS=$os \ | ||
GOARCH=$arch \ | ||
CC="$PROJECT_ROOT/helpers/cc.sh" \ | ||
CXX="$PROJECT_ROOT/helpers/cxx.sh" \ | ||
go build -buildmode="c-$binaryType" -o="$outputDir/$outputFile" -ldflags "-s" . 2>&1 && | ||
echoGreen "Succeeded."; | ||
} || { | ||
echoRed "Failed!"; | ||
} | ||
} | ||
} | ||
|
||
function echoRed() { | ||
local text=$1 | ||
|
||
echo "$(tput setaf 1)$text$(tput sgr0)" | ||
} | ||
|
||
function echoBlue() { | ||
local text=$1 | ||
|
||
echo "$(tput setaf 4)$text$(tput sgr0)" | ||
} | ||
|
||
function echoGreen() { | ||
local text=$1 | ||
|
||
echo "$(tput setaf 2)$text$(tput sgr0)" | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters