Skip to content

Commit

Permalink
ci: custom cross compile
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarble committed May 1, 2024
1 parent 971f2ca commit 0a91e8b
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 39 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ jobs:
uses: arduino/setup-task@v2
- name: Install Go
uses: actions/setup-go@v4
- name: setup release environment
run: |-
echo 'GITHUB_TOKEN=${{secrets.GITHUB_TOKEN}}' > .release-env
- name: Create release
- name: Prepare assets
run: task cross
- name: Create release
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ coverage.txt
.task
/zmk-layout-viewer
/zmk-viewer
.release-env
/zmk-viewer-*
84 changes: 65 additions & 19 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,82 @@ before:
hooks:
- go mod tidy

builds:
- skip: true
goos:
- "linux"
- "windows"
- "darwin"

release:
github:
owner: mrmarble
name: zmk-viewer

builds:
- binary: zmk-viewer
env:
- CGO_ENABLED=1
goos:
- linux
- windows
- darwin
main: ./cmd/zmk-viewer
flags:
- -trimpath
mod_timestamp: '{{ .CommitTimestamp }}'
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.CommitDate}}

archives:
- format: tar.gz
id: darwin-amd64
meta: true
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}'
name_template: '{{ .ProjectName }}-{{ .Version }}-darwin-amd64'
files:
- LICENSE
- README.md

- '{{ .ProjectName }}-v{{ .Version }}-darwin-amd64'
- format: tar.gz
id: darwin-arm64
meta: true
wrap_in_directory: true
name_template: '{{ .ProjectName }}-{{ .Version }}-darwin-arm64'
files:
- LICENSE
- README.md
- '{{ .ProjectName }}-v{{ .Version }}-darwin-arm64'
- format: tar.gz
id: linux-386
meta: true
wrap_in_directory: true
name_template: '{{ .ProjectName }}-{{ .Version }}-linux-386'
files:
- LICENSE
- README.md
- '{{ .ProjectName }}-v{{ .Version }}-linux-386'
- format: tar.gz
id: linux-amd64
meta: true
wrap_in_directory: true
name_template: '{{ .ProjectName }}-{{ .Version }}-linux-amd64'
files:
- LICENSE
- README.md
- '{{ .ProjectName }}-v{{ .Version }}-linux-amd64'
- format: tar.gz
id: linux-arm64
meta: true
wrap_in_directory: true
name_template: '{{ .ProjectName }}-{{ .Version }}-linux-arm64'
files:
- LICENSE
- README.md
- '{{ .ProjectName }}-v{{ .Version }}-linux-arm64'
- format: zip
id: windows-386
meta: true
wrap_in_directory: true
name_template: '{{ .ProjectName }}-{{ .Version }}-windows-386'
files:
- LICENSE
- README.md
- '{{ .ProjectName }}-v{{ .Version }}-windows-386.exe'
- format: zip
id: windows-amd64
meta: true
wrap_in_directory: true
name_template: '{{ .ProjectName }}-{{ .Version }}-windows-amd64'
files:
- LICENSE
- README.md
- '{{ .ProjectName }}-v{{ .Version }}-windows-amd64.exe'
checksum:
name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt'

Expand Down
28 changes: 14 additions & 14 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
version: '3'

env:
GO111MODULE: on
GOPROXY: https://proxy.golang.org,direct
CGO_ENABLED: 1

Expand Down Expand Up @@ -95,16 +94,17 @@ tasks:

cross:
desc: Cross compile the binary
preconditions:
- test -e .release-env
cmd: |
docker run \
--rm \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/zmk-viewer \
-v `pwd`/sysroot:/sysroot \
-w /go/src/zmk-viewer \
ghcr.io/goreleaser/goreleaser-cross:v1.22 \
release --clean
vars:
VERSION:
sh: git describe --tags --always
COMMIT:
sh: git rev-parse --short HEAD
DATE:
sh: git log -1 --format=%cd --date=format:'%Y-%m-%d'
cmds:
- |
xgo -targets='darwin/amd64,darwin/arm64,linux/386,linux/amd64,linux/arm64,windows-6.0/*' \
-ldflags='-s -w -X main.version={{.VERSION}} -X main.commit={{.COMMIT}} -X main.date={{.DATE}}' \
-out zmk-viewer-{{.VERSION}} \
./cmd/zmk-viewer
- find . -maxdepth 1 -name 'zmk-viewer-*' -exec bash -c 'mv $0 ${0/-[0-9]*-/-}' {} \;
1 change: 0 additions & 1 deletion pkg/devicetree/binding.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package devicetree

// #cgo CFLAGS: -std=c11 -fPIC
// #cgo LDFLAGS: -Wl,--allow-multiple-definition
// #include "./tree-sitter-devicetree/src/parser.c"
import "C"

Expand Down

0 comments on commit 0a91e8b

Please sign in to comment.