Skip to content

Commit 6ab7bf7

Browse files
authored
Fix CGO builds (#32)
* Optimize build process for CGO_ENABLED targets * Remove snapshot from build process * Add merge logic to Makefile, update gitignore and README * Bump version to v0.10.2
1 parent 384b4ea commit 6ab7bf7

7 files changed

Lines changed: 91 additions & 25 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ go.work
2222

2323
# Goreleaser
2424
dist/
25+
dist-linux-win/
26+
dist-macos/
2527

2628
# Nix build output
2729
result

.goreleaser.yaml

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,63 @@
1-
# This is an example .goreleaser.yml file with some sensible defaults.
2-
# Make sure to check the documentation at https://goreleaser.com
1+
version: 2
2+
33
before:
44
hooks:
5-
# You may remove this if you don't use go modules.
65
- go mod tidy
6+
77
builds:
8-
- env:
9-
- >-
10-
{{- if or (eq .Os "darwin") (eq .Os "linux") }}
11-
CGO_ENABLED=1
12-
{{- else }}
13-
CGO_ENABLED=0
14-
{{- end }}
8+
- id: macos
9+
goos:
10+
- darwin
11+
goarch:
12+
- amd64
13+
- arm64
14+
env:
15+
- CGO_ENABLED=1
16+
# Cross compile settings are disabled as MacOS builds can currently only
17+
# be built natively
18+
# - >-
19+
# {{- if eq .Arch "amd64" }}CC=o64-clang
20+
# {{- else }}CC=oa64-clang
21+
# {{ end }}
22+
# - >-
23+
# {{- if eq .Arch "amd64" }}CCX=o64-clang++
24+
# {{- else }}CCX=oa64-clang++
25+
# {{ end }}
26+
flags:
27+
- -trimpath
28+
29+
- id: linux
1530
goos:
1631
- linux
32+
goarch:
33+
- amd64
34+
- arm64
35+
env:
36+
- CGO_ENABLED=1
37+
- >-
38+
{{- if eq .Arch "amd64" }}CC=x86_64-linux-gnu-gcc
39+
{{- else }}CC=aarch64-linux-gnu-gcc
40+
{{ end }}
41+
- >-
42+
{{- if eq .Arch "amd64" }}CCX=x86_64-linux-gnu-g++
43+
{{- else }}CCX=aarch64-linux-gnu-g++
44+
{{ end }}
45+
flags:
46+
- -trimpath
47+
48+
- id: windows
49+
goos:
1750
- windows
18-
- darwin
51+
goarch:
52+
- amd64
53+
- 386
54+
env:
55+
- CGO_ENABLED=0
1956
flags:
2057
- -trimpath
2158

2259
archives:
2360
- format: tar.gz
24-
# this name template makes the OS and Arch compatible with the results of uname.
2561
name_template: >-
2662
{{ .ProjectName }}_
2763
{{- .Version }}_
@@ -30,22 +66,19 @@ archives:
3066
{{- else if eq .Arch "386" }}i386
3167
{{- else }}{{ .Arch }}{{ end }}
3268
{{- if .Arm }}v{{ .Arm }}{{ end }}
33-
# use zip for windows archives
3469
format_overrides:
3570
- goos: windows
3671
format: zip
72+
3773
checksum:
3874
name_template: 'checksums.txt'
75+
3976
snapshot:
4077
name_template: "{{ incpatch .Version }}-next"
78+
4179
changelog:
4280
sort: asc
4381
filters:
4482
exclude:
4583
- '^docs:'
4684
- '^test:'
47-
48-
# The lines beneath this are called `modelines`. See `:help modeline`
49-
# Feel free to remove those if you don't want/use them.
50-
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
51-
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

Dockerfile.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM ghcr.io/goreleaser/goreleaser-cross:v1.24.2
2+
3+
USER root
4+
5+
RUN apt-get update && apt-get install -y libx11-dev && rm -rf /var/lib/apt/lists/*

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.PHONY: clean build-linux-windows build-macos release
2+
3+
clean:
4+
rm -rf dist/ dist-linux-win/ dist-macos/
5+
6+
# Build Linux & Windows versions in Docker
7+
build-linux-windows:
8+
docker build -f Dockerfile.build -t goreleaser-cross-x11 .
9+
docker run --rm \
10+
-v "$$PWD:/app" -w /app goreleaser-cross-x11 \
11+
build --config .goreleaser.yaml --id linux --id windows --snapshot
12+
mv dist/ dist-linux-win/
13+
14+
# Build Mac versions natively (must be ran on MacOS)
15+
build-macos:
16+
goreleaser build --config .goreleaser.yaml --id macos --snapshot
17+
mv dist/ dist-macos/
18+
19+
# Merge dist folders into one
20+
merge:
21+
mkdir -p dist/
22+
rsync -a --exclude=artifacts.json --exclude=config.yaml dist-linux-win/ dist/
23+
rsync -a --exclude=artifacts.json --exclude=config.yaml dist-macos/ dist/
24+
jq -s 'add | unique_by(.name, .path)' \
25+
dist-linux-win/artifacts.json dist-macos/artifacts.json > dist/artifacts.json
26+
yq eval ' .builds as $$b1 | (load("dist-macos/config.yaml") | .builds) as $$b2 | .builds = ($$b1 + $$b2)' dist-linux-win/config.yaml > dist/config.yaml
27+
28+
# Release the built artifacts
29+
release: clean build-linux build-native
30+
goreleaser release --config .goreleaser.yaml --skip=build

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ docker pull ghcr.io/marevers/pleasant-cli:<version>
205205

206206
### Go
207207

208-
To build with Go, you must have Go installed (version 1.23).
208+
To build with Go, you must have Go installed (version 1.24).
209209

210210
```bash
211211
go build
@@ -217,7 +217,7 @@ It is also possible to run certain commands directly without first building. For
217217

218218
```bash
219219
go run . get entry --id <id>
220-
```
220+
```
221221

222222
### Nix
223223

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var cfgFile string
1313
var tokenFile string
1414

1515
// Pleasant-CLI version
16-
var version = "v0.10.1"
16+
var version = "v0.10.2"
1717

1818
// rootCmd represents the base command when called without any subcommands
1919
var rootCmd = &cobra.Command{

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9yS
2828
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
2929
github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA=
3030
github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo=
31-
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
32-
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
3331
github.com/spf13/cast v1.9.2 h1:SsGfm7M8QOFtEzumm7UZrZdLLquNdzFYfIbEXntcFbE=
3432
github.com/spf13/cast v1.9.2/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
3533
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
@@ -46,8 +44,6 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
4644
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
4745
golang.design/x/clipboard v0.7.1 h1:OEG3CmcYRBNnRwpDp7+uWLiZi3hrMRJpE9JkkkYtz2c=
4846
golang.design/x/clipboard v0.7.1/go.mod h1:i5SiIqj0wLFw9P/1D7vfILFK0KHMk7ydE72HRrUIgkg=
49-
golang.org/x/exp/shiny v0.0.0-20250606033433-dcc06ee1d476 h1:Wdx0vgH5Wgsw+lF//LJKmWOJBLWX6nprsMqnf99rYDE=
50-
golang.org/x/exp/shiny v0.0.0-20250606033433-dcc06ee1d476/go.mod h1:ygj7T6vSGhhm/9yTpOQQNvuAUFziTH7RUiH74EoE2C8=
5147
golang.org/x/exp/shiny v0.0.0-20250620022241-b7579e27df2b h1:zELBzk+7ERc6m8BxhzU2VYjp03wlEvi+cIgYQR5H3CI=
5248
golang.org/x/exp/shiny v0.0.0-20250620022241-b7579e27df2b/go.mod h1:ygj7T6vSGhhm/9yTpOQQNvuAUFziTH7RUiH74EoE2C8=
5349
golang.org/x/image v0.28.0 h1:gdem5JW1OLS4FbkWgLO+7ZeFzYtL3xClb97GaUzYMFE=

0 commit comments

Comments
 (0)