-
Notifications
You must be signed in to change notification settings - Fork 1
144 lines (132 loc) · 4.35 KB
/
_build-library.yml
File metadata and controls
144 lines (132 loc) · 4.35 KB
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
name: Reusable Library Build
on:
workflow_call:
inputs:
goos:
required: true
type: string
description: "Target OS"
goarch:
required: true
type: string
description: "Target architecture"
goarm:
required: false
type: string
default: ""
library_type:
required: true
type: string
description: "Library type: static, shared, or both"
build_tags:
required: false
type: string
default: ""
version:
required: true
type: string
artifact_name:
required: true
type: string
runner:
required: false
type: string
default: "ubuntu-latest"
outputs:
static_lib_path:
description: "Path to static library (.a)"
value: ${{ jobs.build.outputs.static_lib_path }}
shared_lib_path:
description: "Path to shared library (.so/.dll/.dylib)"
value: ${{ jobs.build.outputs.shared_lib_path }}
jobs:
build:
runs-on: ${{ inputs.runner }}
outputs:
static_lib_path: ${{ steps.build.outputs.static_lib_path }}
shared_lib_path: ${{ steps.build.outputs.shared_lib_path }}
env:
GOOS: ${{ inputs.goos }}
GOARCH: ${{ inputs.goarch }}
GOARM: ${{ inputs.goarm }}
CGO_ENABLED: "1"
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- name: Install cross-compilation tools
if: inputs.goos == 'linux' && inputs.goarch != 'amd64'
run: |
sudo apt-get update
case "${{ inputs.goarch }}" in
arm64)
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
;;
arm)
sudo apt-get install -y gcc-arm-linux-gnueabihf
echo "CC=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV
;;
esac
- name: Get project dependencies
run: go mod download
- name: Determine library extensions
id: ext
run: |
case "${{ inputs.goos }}" in
windows)
echo "shared_ext=dll" >> $GITHUB_OUTPUT
echo "static_ext=lib" >> $GITHUB_OUTPUT
;;
darwin)
echo "shared_ext=dylib" >> $GITHUB_OUTPUT
echo "static_ext=a" >> $GITHUB_OUTPUT
;;
*)
echo "shared_ext=so" >> $GITHUB_OUTPUT
echo "static_ext=a" >> $GITHUB_OUTPUT
;;
esac
- name: Build libraries
id: build
run: |
mkdir -p build_assets
BUILD_TAGS=""
if [[ -n "${{ inputs.build_tags }}" ]]; then
BUILD_TAGS="-tags ${{ inputs.build_tags }}"
fi
LIB_NAME="libhttps-vpn"
# Build shared library
if [[ "${{ inputs.library_type }}" == "shared" || "${{ inputs.library_type }}" == "both" ]]; then
echo "Building shared library..."
go build -o "build_assets/${LIB_NAME}.${{ steps.ext.outputs.shared_ext }}" \
-buildmode=c-shared \
-trimpath \
-buildvcs=false \
-ldflags="-X main.Version=${{ inputs.version }} -s -w" \
${BUILD_TAGS} \
./core
echo "shared_lib_path=build_assets/${LIB_NAME}.${{ steps.ext.outputs.shared_ext }}" >> $GITHUB_OUTPUT
fi
# Build static library
if [[ "${{ inputs.library_type }}" == "static" || "${{ inputs.library_type }}" == "both" ]]; then
echo "Building static library..."
go build -o "build_assets/${LIB_NAME}.${{ steps.ext.outputs.static_ext }}" \
-buildmode=c-archive \
-trimpath \
-buildvcs=false \
-ldflags="-X main.Version=${{ inputs.version }} -s -w" \
${BUILD_TAGS} \
./core
echo "static_lib_path=build_assets/${LIB_NAME}.${{ steps.ext.outputs.static_ext }}" >> $GITHUB_OUTPUT
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact_name }}
path: build_assets/
if-no-files-found: error