Coder Social home page Coder Social logo

Comments (8)

gowridurgad avatar gowridurgad commented on June 25, 2024 1

Hi @timandy, Starting from Go version 1.20, the dependency on cgo for the race detector has been removed on macOS. This allows for the building and running of programs with the race detector enabled without the requirement of Xcode. So From Go version 1.20 onwards, the race test can be executed successfully, regardless of whether CGO_ENABLED is set to '0' or '1'.. It's important to note that for Linux, other Unix systems, and Windows, a host C toolchain remains necessary to use the race
detector. This information is documented in the official Go release notes.

The build failure, even with CGO enabled (CGO_ENABLED=1), is due to a mismatch between the build and target architectures. In this case, the build architecture is ARM64, while the target architecture is AMD64. However, by disabling the race detector, the workflow runs successfully. Her's the screenshots for your reference.
Please feel to reach out us in case of any concerns. Thank you once again.
Screenshot 2024-06-12 at 5 47 15 PM
Screenshot 2024-06-12 at 5 12 41 PM

from setup-go.

aparnajyothi-y avatar aparnajyothi-y commented on June 25, 2024

Hello @timandy, zthank you for creating this issue and we will look into it :)

from setup-go.

matthewhughes934 avatar matthewhughes934 commented on June 25, 2024

I suspect this might be something to do with those versions of Go being built differently/in such a way that they don't support cross compilation. Possibly related to #181

EDIT: digging a bit more I see

$ tar -tzf go-1.20.14-darwin-arm64.tar.gz | grep 'src/runtime/.*syso'
./src/runtime/race/internal/amd64v1/race_windows.syso
./src/runtime/race/internal/amd64v1/race_darwin.syso
./src/runtime/race/internal/amd64v1/race_linux.syso
./src/runtime/race/internal/amd64v1/race_freebsd.syso
./src/runtime/race/internal/amd64v1/race_netbsd.syso
./src/runtime/race/internal/amd64v1/race_openbsd.syso
./src/runtime/race/internal/amd64v3/race_linux.syso
./src/runtime/race/race_darwin_arm64.syso
./src/runtime/race/syso_test.go
$ tar -tzf go1.18.10.darwin-arm64.tar.gz | grep 'src/runtime/.*syso'
go/src/runtime/race/race_darwin_arm64.syso
go/src/runtime/race/syso_test.go

files take from:

Indeed I see the same output in the upstream download from https://go.dev/dl/#go1.20.14 🤔 I wonder if those are meant to be there (via tar -tzf go1.20.14.darwin-arm64.tar.gz | grep 'src/runtime/.*syso') ... indeed it looks like the build process has involved quite a bit over time and I guess those are expected now

from setup-go.

gowridurgad avatar gowridurgad commented on June 25, 2024

Hi @timandy, When GOOS and GOARCH are manually specified, the Go compiler typically enters cross-compilation mode and defaults CGO_ENABLED to '0', effectively disabling cgo.

Exceptions exist for certain platforms, notably Linux and Windows. Even with GOOS and GOARCH manually set, CGO_ENABLED remains '1', leaving cgo enabled. This is attributed to Go's reliable support for these platforms.
In the case of macOS, despite the build system matching the target system, Go maintains its general rule for cross-compilation, setting CGO_ENABLED to '0'.

These are default behaviors and can be overridden if necessary. For example, if macOS builds necessitate cgo, CGO_ENABLED can be manually set to '1'. However, the build environment must be capable of cross-compiling C code for macOS.

env:
  CGO_ENABLED: 1

from setup-go.

timandy avatar timandy commented on June 25, 2024

@gowridurgad Thanks for your detailed answer, I will close this issue now.

from setup-go.

timandy avatar timandy commented on June 25, 2024

@gowridurgad Sorry for reopen this issue.
I want to known why go1.18 and go1.19 on mac can't run race test, But go1.20+ can, Is this situation normal?

https://github.com/timandy/routine/actions/runs/9475193593/job/26106126731

      # darwin
      - name: 'Test on [darwin] arch [amd64]'
        if: ${{ matrix.os == 'darwin' && contains(fromJson('["amd64"]'), matrix.arch) }}
        env:
          GOOS: ${{ matrix.os }}
          GOARCH: ${{ matrix.arch }}
          CGO_ENABLED: 1
        run: |
          echo ${CGO_ENABLED}
          go env CGO_ENABLED
          go test -v -race -coverprofile="coverage.txt" -covermode=atomic ./...

image

from setup-go.

matthewhughes934 avatar matthewhughes934 commented on June 25, 2024

@gowridurgad Sorry for reopen this issue. I want to known why go1.18 and go1.19 on mac can't run race test, But go1.20+ can, Is this situation normal?

Following from what I found above, I believe this is due to a change in how Go is built upstream, given the errors you see look to be similar to those in golang/go#42382 (i.e. missing runtime/race/*.syso files)

  • With golang/build@bbe91e8 Go builds no longer included those *.syso files
  • Go 1.18, 1.19 were built with that system and are hence don't include those files
  • Sometime after, they moved to a new build system which I believe doesn't strip these (I can't find evidence that it does...), the old build system was removed with golang/build@97ad0ce. Note the date is just after the release of Go 1.20, so I suspect that was built with the new system (including the files, hence race tests working)

based on the above, I suspect that if you also tried to build on Go 1.17 (or older) you'd see the issue there too

from setup-go.

timandy avatar timandy commented on June 25, 2024

@matthewhughes934 Thanks a lot. I found that github has upgrade macos-lastest to M1 CPU. That cause my amd64 race test work flow runs on arm64.

from setup-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.