Skip to content

Commit cca8692

Browse files
committed
New build system based on sh file, also version is substituted via env var
1 parent 4a0d26e commit cca8692

File tree

4 files changed

+51
-31
lines changed

4 files changed

+51
-31
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ on:
66
- "v*"
77

88
env:
9-
GO_VERSION: "1.23.5"
9+
GO_VERSION: "1.24.2"
1010
REGISTRY_IMAGE: "ghcr.io/proofrock/ws4sql"
11+
VERSION: ${{ github.ref_name }}
1112

1213
jobs:
1314
test:
@@ -31,10 +32,6 @@ jobs:
3132
- name: Checkout
3233
uses: actions/checkout@v4
3334

34-
- name: Modify version number
35-
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
36-
working-directory: src/
37-
3835
- name: Build dir generation
3936
run: mkdir bin/
4037

@@ -45,7 +42,7 @@ jobs:
4542

4643
- name: Compile and Pack Artifact
4744
run: |
48-
apk add --no-cache musl-dev go g++ git make openssl openssl-dev openssl-libs-static zstd
45+
apk add --no-cache musl-dev go g++ git make openssl openssl-dev openssl-libs-static zstd bash
4946
make build-static-ci-linux-musl-amd64
5047
tar czf bin/ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz -C bin/ ws4sql
5148
shell: alpine.sh --root {0}
@@ -64,10 +61,6 @@ jobs:
6461
- name: Checkout
6562
uses: actions/checkout@v4
6663

67-
- name: Modify version number
68-
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
69-
working-directory: src/
70-
7164
- name: Build dir generation
7265
run: mkdir bin/
7366

@@ -79,7 +72,7 @@ jobs:
7972

8073
- name: Compile and Pack Artifact
8174
run: |
82-
apk add --no-cache musl-dev go g++ git make openssl openssl-dev openssl-libs-static zstd
75+
apk add --no-cache musl-dev go g++ git make openssl openssl-dev openssl-libs-static zstd bash
8376
make build-static-ci-linux-musl-arm64
8477
tar czf bin/ws4sql-${{ github.ref_name }}-linux-arm64.tar.gz -C bin/ ws4sql
8578
shell: alpine.sh --root {0}
@@ -102,10 +95,6 @@ jobs:
10295
with:
10396
go-version: ${{ env.GO_VERSION }}
10497

105-
- name: Modify version number
106-
run: sed -i.bkp 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
107-
working-directory: src/
108-
10998
- name: Build dir generation
11099
run: mkdir bin/
111100

@@ -133,10 +122,6 @@ jobs:
133122
with:
134123
go-version: ${{ env.GO_VERSION }}
135124

136-
- name: Modify version number
137-
run: sed -i.bkp 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
138-
working-directory: src/
139-
140125
- name: Build dir generation
141126
run: mkdir bin/
142127

@@ -164,10 +149,6 @@ jobs:
164149
with:
165150
go-version: ${{ env.GO_VERSION }}
166151

167-
- name: Modify version number
168-
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
169-
working-directory: src/
170-
171152
- name: Build dir generation
172153
run: mkdir bin/
173154

Makefile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,27 @@ build-nostatic:
2323

2424
build-static-linux:
2525
make build-prepare
26-
cd src; go build -trimpath -a -tags="netgo osusergo sqlite_omit_load_extension" -ldflags='-w -extldflags "-static"'
26+
cd src; VERSION="v0.0.999" bash build.sh LINUX
2727
mv src/ws4sql bin/
2828

2929
build-static-windows:
3030
make build-prepare
31-
cd src; go build -trimpath -a -tags="netgo osusergo sqlite_omit_load_extension" -ldflags='-w -extldflags "-static"'
31+
cd src; VERSION="v0.0.999" bash build.sh WIN
3232
mv src/ws4sql.exe bin/
3333

3434
build-static-macos:
3535
make build-prepare
36-
cd src; go build -trimpath -a -tags="netgo osusergo sqlite_omit_load_extension" -ldflags='-w'
36+
cd src; VERSION="v0.0.999" bash build.sh MAC
3737
mv src/ws4sql bin/
3838

3939
# The following three targets are used in Github Actions
4040
# Can be also run in an Alpine Linux context with the following packages
41-
# musl-dev go g++ make openssl openssl-dev openssl-libs-static zstd
41+
# musl-dev go g++ make openssl openssl-dev openssl-libs-static zstd bash
4242

4343
build-static-ci-common:
4444
make build-prepare
45-
cd src && zstd -d libduckdb_bundle.a.zst
46-
cd src && CGO_CFLAGS="-O2 -fPIC" CGO_CXXFLAGS="-O2 -fPIC" CGO_LDFLAGS="-lduckdb_bundle -lssl -lcrypto -L./" go build -buildvcs=false -trimpath -a -tags="netgo osusergo sqlite_omit_load_extension duckdb_use_static_lib" -ldflags='-w -extldflags "-static"'
45+
cd src && bash build.sh CI
4746
mv src/ws4sql bin/
48-
rm src/libduckdb_bundle.a
4947

5048
build-static-ci-linux-musl-amd64:
5149
cp precompiled/libduckdb_bundle/linux-musl-amd64/libduckdb_bundle.a.zst src/

src/build.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# This script is used to build a binary
4+
5+
# Copy inside the src/ dir
6+
# Env vars that must be already set: VERSION
7+
8+
case $1 in
9+
"MAC")
10+
go build -trimpath -a -o ws4sql \
11+
-tags="netgo osusergo sqlite_omit_load_extension" \
12+
-ldflags="-w -buildid=\"$VERSION\" -X \"main.version=$VERSION\""
13+
;;
14+
"LINUX")
15+
go build -trimpath -a -o ws4sql \
16+
-tags="netgo osusergo sqlite_omit_load_extension" \
17+
-ldflags="-w -buildid=\"$VERSION\" -X \"main.version=$VERSION\" -extldflags \"-static\""
18+
;;
19+
"WIN")
20+
go build -trimpath -a -o ws4sql.exe \
21+
-tags="netgo osusergo sqlite_omit_load_extension" \
22+
-ldflags="-w -buildid=\"$VERSION\" -X \"main.version=$VERSION\" -extldflags \"-static\""
23+
;;
24+
"CI" )
25+
zstd -dk libduckdb_bundle.a.zst
26+
# '-O3' gives a warning in sqlite
27+
# Maybe -ldflags="buildid=\"$VERSION\" ..."
28+
CGO_ENABLED=1 \
29+
CPPFLAGS="-DDUCKDB_STATIC_BUILD" \
30+
CGO_CFLAGS="-O2" CGO_CXXFLAGS="-O2" \
31+
CGO_LDFLAGS="-static -lduckdb_bundle -lssl -lcrypto -lstdc++ -L." \
32+
go build \
33+
-buildvcs=false \
34+
-trimpath \
35+
-tags="netgo osusergo sqlite_omit_load_extension duckdb_use_static_lib" \
36+
-ldflags="-X \"main.version=$VERSION\"" \
37+
-o ws4sql
38+
rm libduckdb_bundle.a
39+
rm libduckdb_bundle.a.zst
40+
esac
41+

src/ws4sql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
_ "github.com/mattn/go-sqlite3"
3939
)
4040

41-
const version = "v0.0.0"
41+
var version string // Set at build time, var VERSION
4242

4343
// Simply prints a header, parses the cli parameters and calls
4444
// launch(), that is the real entry point. It's separate from the

0 commit comments

Comments
 (0)