Skip to content

Conversation

suzuki-shunsuke
Copy link

@suzuki-shunsuke suzuki-shunsuke commented Jun 10, 2025

To build restish, CGO is required.

@suzuki-shunsuke suzuki-shunsuke changed the title chore: enable CGO chore: Enable CGO Jun 10, 2025
@suzuki-shunsuke
Copy link
Author

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
    │ build failed: exit status 1: # runtime/cgo
    │ gcc_libinit_windows.c:12:10: fatal error: 'windows.h' file not found
    target=windows_386_sse2

@terev
Copy link
Contributor

terev commented Jun 11, 2025

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/ .

@suzuki-shunsuke
Copy link
Author

Oh, I didn't know https://github.com/goreleaser/goreleaser-cross . Thank you.
I tried it a bit, but the error occurred.

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

@suzuki-shunsuke
Copy link
Author

suzuki-shunsuke commented Jun 11, 2025

Oh, I fixed the go directive in go.mod, then the above error was solved.

https://stackoverflow.com/questions/78519711/toolchain-not-available-error-prevents-me-from-using-any-go-commands

go 1.24.4

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'

@terev
Copy link
Contributor

terev commented Jun 11, 2025

@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 v1.24.2, could potentially be worth a try. Though it is strange there's no associated release for this tag.

@suzuki-shunsuke
Copy link
Author

assuming your build log is from your mac

Yes. I built on macOS.
Maybe the build will succeed on GitHub Actions ubuntu-latest.
To test on Linux, I added the job.

  • 59dd1bc
  • test-release:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
    uses: actions/checkout@v4
    with:
    fetch-depth: 0
    - name: Set up Go
    uses: actions/setup-go@v5
    with:
    go-version: 1.24
    - name: Install GoReleaser
    uses: goreleaser/goreleaser-action@v6
    with:
    version: latest
    install-only: true
    - name: Run GoReleaser (Dry Run)
    run: make release-dry-run
    env:
    GITHUB_TOKEN: ${{ secrets.GH_PAT }}

Can you approve the workflow to test the build on CI?

image

If it's difficult, I'll test on my fork.

@terev
Copy link
Contributor

terev commented Jun 11, 2025

I'm unable to unfortunately. The quickest option may be to try on your fork, but @cfunkhouser what do you think?

@suzuki-shunsuke
Copy link
Author

suzuki-shunsuke commented Jun 11, 2025

Okay. Thank you. I'm trying on my fork.

Still failed.

  ⨯ release failed after 4m57s                       error=failed to build for linux_386: exit status 1: # runtime/cgo
In file included from _cgo_export.c:3:
/usr/include/stdlib.h:25:10: fatal error: bits/libc-header-start.h: No such file or directory
   25 | #include <bits/libc-header-start.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:20: release-dry-run] Error 1

https://stackoverflow.com/questions/54082459/fatal-error-bits-libc-header-start-h-no-such-file-or-directory-while-compili

I'm trying goreleaser-cross image v1.24.2. https://github.com/suzuki-shunsuke/restish/actions/runs/15577385246/job/43864805990?pr=1

Installed gcc-multilib, but CI still failed. CGO is difficult...
https://github.com/suzuki-shunsuke/restish/actions/runs/15577967587/job/43866474080?pr=1

  ⨯ release failed after 5m19s                      
    error=
    │ build failed: exit status 1: # runtime/cgo
    │ gcc_arm64.S: Assembler messages:
    │ gcc_arm64.S:30: Error: no such instruction: `stp x29,x30,[sp,'
    │ gcc_arm64.S:34: Error: too many memory references for `mov'
    │ gcc_arm64.S:36: Error: no such instruction: `stp x19,x20,[sp,'
    │ gcc_arm64.S:39: Error: no such instruction: `stp x21,x22,[sp,'
    │ gcc_arm64.S:42: Error: no such instruction: `stp x23,x24,[sp,'
    │ gcc_arm64.S:45: Error: no such instruction: `stp x25,x26,[sp,'
    │ gcc_arm64.S:48: Error: no such instruction: `stp x27,x28,[sp,'
    │ gcc_arm64.S:52: Error: too many memory references for `mov'
    │ gcc_arm64.S:53: Error: too many memory references for `mov'
    │ gcc_arm64.S:54: Error: too many memory references for `mov'
    │ gcc_arm64.S:56: Error: no such instruction: `blr x20'
    │ gcc_arm64.S:57: Error: no such instruction: `blr x19'
    │ gcc_arm64.S:59: Error: no such instruction: `ldp x27,x28,[sp,'
    │ gcc_arm64.S:62: Error: no such instruction: `ldp x25,x26,[sp,'
    │ gcc_arm64.S:65: Error: no such instruction: `ldp x23,x24,[sp,'
    │ gcc_arm64.S:68: Error: no such instruction: `ldp x21,x22,[sp,'
    │ gcc_arm64.S:71: Error: no such instruction: `ldp x19,x20,[sp,'
    │ gcc_arm64.S:74: Error: no such instruction: `ldp x29,x30,[sp],'
    target=linux_arm64_v8.0
make: *** [Makefile:21: release-dry-run] Error 1

Installed gcc-arm-linux-gnueabihf, but still failed.

https://github.com/suzuki-shunsuke/restish/actions/runs/15584250016/job/43886463582?pr=1

  ⨯ release failed after 5m2s                       
    error=
    │ build failed: exit status 1: # runtime/cgo
    │ In file included from /usr/include/bits/errno.h:26,
    │                  from /usr/include/errno.h:28,
    │                  from cgo-gcc-prolog:32:
    │ /usr/include/linux/errno.h:1:10: fatal error: asm/errno.h: No such file or directory
    │     1 | #include <asm/errno.h>
    │       |          ^~~~~~~~~~~~~
    │ compilation terminated.
    target=linux_386_sse2
make: *** [Makefile:21: release-dry-run] Error 1

@suzuki-shunsuke
Copy link
Author

Do we really need to build restish for 32 bit architecture?
If we can drop it, the build becomes fast and we can avoid the build error regarding 32 bit architecture like this.

@terev
Copy link
Contributor

terev commented Jun 11, 2025

Oh good point. I'd honestly be surprised if that is important to have.

@suzuki-shunsuke
Copy link
Author

I dropped 32-bit and tried to build, the build still failed.

  ⨯ release failed after 4m3s                       
    error=
    │ build failed: exit status 1: # runtime/cgo
    │ gcc_arm64.S: Assembler messages:
    │ gcc_arm64.S:30: Error: no such instruction: `stp x29,x30,[sp,'
    │ gcc_arm64.S:34: Error: too many memory references for `mov'
    │ gcc_arm64.S:36: Error: no such instruction: `stp x19,x20,[sp,'
    │ gcc_arm64.S:39: Error: no such instruction: `stp x21,x22,[sp,'
    │ gcc_arm64.S:42: Error: no such instruction: `stp x23,x24,[sp,'
    │ gcc_arm64.S:45: Error: no such instruction: `stp x25,x26,[sp,'
    │ gcc_arm64.S:48: Error: no such instruction: `stp x27,x28,[sp,'
    │ gcc_arm64.S:52: Error: too many memory references for `mov'
    │ gcc_arm64.S:53: Error: too many memory references for `mov'
    │ gcc_arm64.S:54: Error: too many memory references for `mov'
    │ gcc_arm64.S:56: Error: no such instruction: `blr x20'
    │ gcc_arm64.S:57: Error: no such instruction: `blr x19'
    │ gcc_arm64.S:59: Error: no such instruction: `ldp x27,x28,[sp,'
    │ gcc_arm64.S:62: Error: no such instruction: `ldp x25,x26,[sp,'
    │ gcc_arm64.S:65: Error: no such instruction: `ldp x23,x24,[sp,'
    │ gcc_arm64.S:68: Error: no such instruction: `ldp x21,x22,[sp,'
    │ gcc_arm64.S:71: Error: no such instruction: `ldp x19,x20,[sp,'
    │ gcc_arm64.S:74: Error: no such instruction: `ldp x29,x30,[sp],'
    target=linux_arm64_v8.0
make: *** [Makefile:21: release-dry-run] Error 1

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
https://github.com/goreleaser/example-cross/blob/c45dc32486e1532f330702104e2fd527891b44b9/.gitmodules

But this wasn't maintained and archived.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants