-
Notifications
You must be signed in to change notification settings - Fork 87
chore: Enable CGO #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
chore: Enable CGO #291
Conversation
Hmm. I tried to build on macOS, but it failed. $ goreleaser build --snapshot --clean
• only version: 2 configuration files are supported, yours is version: 0 , please update your configuration
• skipping validate...
• cleaning distribution directory
• loading environment variables
• getting and validating git state
• git state commit=0dcd68bf1ff401595c21624bcee2d5708e40bc0e branch=enable-cgo current_tag=v0.21.0 previous_tag=v0.20.0 dirty=false
• pipe skipped or partially skipped reason=disabled during snapshot mode
• parsing tag
• setting defaults
• DEPRECATED: snapshot.name_template should not be used anymore, check https://goreleaser.com/deprecations#snapshotname_template for more info
• DEPRECATED: archives.format_overrides.format should not be used anymore, check https://goreleaser.com/deprecations#archivesformat_overridesformat for more info
• DEPRECATED: brews should not be used anymore, check https://goreleaser.com/deprecations#brews for more info
• snapshotting
• building snapshot... version=v0.21.0-next
• running before hooks
• running hook=go mod download
• ensuring distribution directory
• setting up metadata
• writing release metadata
• loading go mod information
• build prerequisites
• building binaries
• building binary=dist/restish_windows_386_sse2/restish.exe
• building binary=dist/restish_windows_arm64_v8.0/restish.exe
• building binary=dist/restish_linux_arm64_v8.0/restish
• building binary=dist/restish_windows_amd64_v1/restish.exe
• building binary=dist/restish_darwin_amd64_v1/restish
• building binary=dist/restish_darwin_arm64_v8.0/restish
• building binary=dist/restish_linux_386_sse2/restish
• building binary=dist/restish_linux_amd64_v1/restish
⨯ build failed after 7s
error=
│ build failed: exit status 1: # runtime/cgo
│ gcc_libinit_windows.c:12:10: fatal error: 'windows.h' file not found
target=windows_386_sse2
|
If it truly requires CGO and all of the targeted platforms, the easiest option may be to adapt the CI to this example https://github.com/goreleaser/example-cross/ . |
Oh, I didn't know https://github.com/goreleaser/goreleaser-cross . Thank you. Makefile: Based on https://github.com/goreleaser/example-cross/blob/c45dc32486e1532f330702104e2fd527891b44b9/Makefile PACKAGE_NAME := github.com/rest-sh/restish
GOLANG_CROSS_VERSION ?= v1.21.5
SYSROOT_DIR ?= sysroots
SYSROOT_ARCHIVE ?= sysroots.tar.bz2
.PHONY: sysroot-pack
sysroot-pack:
@tar cf - $(SYSROOT_DIR) -P | pv -s $[$(du -sk $(SYSROOT_DIR) | awk '{print $1}') * 1024] | pbzip2 > $(SYSROOT_ARCHIVE)
.PHONY: sysroot-unpack
sysroot-unpack:
@pv $(SYSROOT_ARCHIVE) | pbzip2 -cd | tar -xf -
.PHONY: release-dry-run
release-dry-run:
@docker run \
--rm \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--clean --skip=validate --skip=publish
.PHONY: release
release:
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
docker run \
--rm \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean $ make release-dry-run
• starting release...
• loading path=.goreleaser.yml
• skipping announce, publish and validate...
• loading environment variables
• getting and validating git state
• git state commit=0dcd68bf1ff401595c21624bcee2d5708e40bc0e branch=enable-cgo current_tag=v0.21.0 previous_tag=v0.20.0 dirty=true
• pipe skipped reason=validation is disabled
• parsing tag
• setting defaults
• took: 1s
• running before hooks
• running hook=go mod download
• took: 1s
⨯ release failed after 2s error=hook failed: go mod download: exit status 1; output: go: downloading go1.24 (linux/arm64)
go: download go1.24 for linux/arm64: toolchain not available
make: *** [release-dry-run] Error 1 |
Oh, I fixed the go directive in go.mod, then the above error was solved.
But the build still failed. $ make release-dry-run
• starting release...
• loading path=.goreleaser.yml
• skipping announce, publish and validate...
• loading environment variables
• getting and validating git state
• git state commit=0dcd68bf1ff401595c21624bcee2d5708e40bc0e branch=enable-cgo current_tag=v0.21.0 previous_tag=v0.20.0 dirty=true
• pipe skipped reason=validation is disabled
• parsing tag
• setting defaults
• took: 6s
• running before hooks
• running hook=go mod download
• took: 9s
• checking distribution directory
• cleaning dist
• loading go mod information
• build prerequisites
• writing effective config file
• writing config=dist/config.yaml
• building binaries
• building binary=dist/restish_linux_arm64/restish
• building binary=dist/restish_linux_amd64_v1/restish
• building binary=dist/restish_linux_386/restish
• building binary=dist/restish_darwin_amd64_v1/restish
• building binary=dist/restish_darwin_arm64/restish
• building binary=dist/restish_windows_amd64_v1/restish.exe
• building binary=dist/restish_windows_arm64/restish.exe
• building binary=dist/restish_windows_386/restish.exe
• took: 3m7s
⨯ release failed after 3m22s error=failed to build for linux_amd64_v1: exit status 1: # runtime/cgo
aarch64-linux-gnu-gcc: error: unrecognized command-line option '-m64' |
@suzuki-shunsuke Oh nice! Now that you've made that change it seems possible the build could succeed in CI on the linux like hosts (assuming your build log is from your mac). I did notice that there's a newer tag of the goreleaser-cross image |
Yes. I built on macOS.
Can you approve the workflow to test the build on CI? ![]() If it's difficult, I'll test on my fork. |
I'm unable to unfortunately. The quickest option may be to try on your fork, but @cfunkhouser what do you think? |
Okay. Thank you. I'm trying on my fork.
I'm trying goreleaser-cross image v1.24.2. https://github.com/suzuki-shunsuke/restish/actions/runs/15577385246/job/43864805990?pr=1 Installed
Installed https://github.com/suzuki-shunsuke/restish/actions/runs/15584250016/job/43886463582?pr=1
|
Do we really need to build restish for 32 bit architecture? |
Oh good point. I'd honestly be surprised if that is important to have. |
I dropped 32-bit and tried to build, the build still failed.
About goreleaser-cross, https://github.com/goreleaser/goreleaser-cross-example-sysroot is used as sysroot. https://github.com/goreleaser/example-cross/blob/c45dc32486e1532f330702104e2fd527891b44b9/Makefile#L22 But this wasn't maintained and archived. |
To build restish, CGO is required.