-
Notifications
You must be signed in to change notification settings - Fork 5
185 lines (165 loc) · 6.24 KB
/
cross_compile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: Cross Compile Go Project
on:
pull_request:
types: [opened, synchronize]
push:
tags:
- '*'
jobs:
build-ubuntu:
name: Build on ${{ matrix.os }} for ${{ matrix.goarch }}
runs-on: ubuntu-latest #here
strategy:
matrix:
include:
- os: linux
goarch: amd64
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21.1' # Set to specific Go version.
- name: Install build dependencies (Ubuntu)
if: matrix.os == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential libc6-dev libsqlite3-dev
- name: Create output directory
run: mkdir -p output
- name: Compile Go for target
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 1
run: |
if [ "$GOOS" = "windows" ]; then
go build -ldflags="-s -w" -o output/gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}.exe
else
go build -ldflags="-s -w" -o output/gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}
fi
shell: bash
- name: Compress executable files with UPX (except for gensokyo-android-arm64)
run: |
sudo apt-get update
sudo apt-get install -y upx
if [[ "${{ matrix.os }}" == *"windows"* ]]; then
FILENAME="output/gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}.exe"
else
FILENAME="output/gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}"
fi
if [[ "${{ matrix.os }}" == "android" && "${{ matrix.goarch }}" == "arm64" ]]; then
echo "Skipping UPX compression for $FILENAME"
else
upx --best --lzma "$FILENAME"
fi
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}
path: output/gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}${{ endsWith(matrix.os, 'windows') && '.exe' || '' }}
build-win:
name: Build on ${{ matrix.os }} for ${{ matrix.goarch }}
runs-on: windows-latest
strategy:
matrix:
include:
- os: windows
goarch: amd64
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21.1' # Set to specific Go version.
- name: Install build dependencies (Windows)
if: matrix.os == 'windows'
run: |
choco install msys2 --params "/NoUpdate /InstallDir:C:\msys64" --no-progress -y
C:\msys64\usr\bin\bash -lc "pacman -Syu --noconfirm"
C:\msys64\usr\bin\bash -lc "pacman -S --noconfirm mingw-w64-x86_64-gcc mingw64/mingw-w64-x86_64-pkg-config mingw-w64-x86_64-cmake mingw-w64-x86_64-extra-cmake-modules mingw-w64-x86_64-toolchain"
echo "CGO_ENABLED=1" >> $GITHUB_ENV
echo "CC=x86_64-w64-mingw32-gcc" >> $GITHUB_ENV
echo "CXX=x86_64-w64-mingw32-g++" >> $GITHUB_ENV
- name: Create output directory
run: mkdir -p output
- name: Compile Go for target
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 1
run: |
if [ "$GOOS" = "windows" ]; then
go build -ldflags="-s -w" -o output/gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}.exe
else
go build -ldflags="-s -w" -o output/gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}
fi
shell: bash
- name: Setup UPX on Windows
run: |
Invoke-WebRequest -Uri "https://github.com/upx/upx/releases/download/v3.96/upx-3.96-win64.zip" -OutFile "upx.zip"
Expand-Archive -Path "upx.zip" -DestinationPath "${{ github.workspace }}"
echo "${{ github.workspace }}/upx-3.96-win64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
shell: powershell
- name: Compress executable files with UPX (except for gensokyo-android-arm64)
run: |
if [[ "${{ matrix.os }}" == *"windows"* ]]; then
FILENAME="output/gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}.exe"
else
FILENAME="output/gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}"
fi
if [[ "${{ matrix.os }}" == "android" && "${{ matrix.goarch }}" == "arm64" ]]; then
echo "Skipping UPX compression for $FILENAME"
else
upx --best --lzma "$FILENAME"
fi
shell: bash
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}
path: output/gensokyo-llm-${{ matrix.os }}-${{ matrix.goarch }}${{ endsWith(matrix.os, 'windows') && '.exe' || '' }}
prepare_release:
needs: [build-ubuntu, build-win]
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v2
with:
path: output
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
draft: false
- name: Upload Release Assets
run: |
for dir in output/*; do
if [ -d "$dir" ]; then
for file in "$dir"/*; do
if [ -f "$file" ]; then
asset_name=$(basename "$file")
echo "Uploading ${asset_name}"
GITHUB_UPLOAD_URL=${{ steps.create_release.outputs.upload_url }}
GITHUB_UPLOAD_URL="${GITHUB_UPLOAD_URL%\{*}"
GITHUB_UPLOAD_URL="${GITHUB_UPLOAD_URL%\?*}"
curl \
-X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"${file}" \
"${GITHUB_UPLOAD_URL}?name=${asset_name}&label=${asset_name}"
else
echo "Expected a file in ${dir}, but found something else."
fi
done
else
echo "Expected ${dir} to be a directory."
fi
done