Skip to content
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

proposal: go build: natively support fat-binaries #53281

Closed
skyzyx opened this issue Jun 7, 2022 · 2 comments
Closed

proposal: go build: natively support fat-binaries #53281

skyzyx opened this issue Jun 7, 2022 · 2 comments

Comments

@skyzyx
Copy link

skyzyx commented Jun 7, 2022

The core of this proposal is to bring support for fat-binaries to go build.

  • Apple has done this during every CPU architecture transition they've made (like the one we're currently in), so there is certainly precedent in terms of use-case. Docker has also added support for multi-arch images, which work conceptually-similarly (multiple CPU builds with a single entrypoint).

  • GoReleaser has added support for macOS Universal Binaries. While this is a handy shortcut for macOS users, I know that teams have dabbled with it in Linux as well. With C it was "too hard", but with Go (and I'm avoiding talking about CGO), perhaps it could be easier?

  • GoReleaser’s implementation results in essentially a double-sized binary. If this is the best job that can be done, then so be it (this is outside the realm of my personal expertise). But it seems like there may be an opportunity to optimize the CPU-specific bits for each architecture from the CPU-agnostic bits (which, again, this is outside the realm of my personal expertise) which could result in a less-than-double-sized binary.

  • Proposed end-user syntax could be something like:

    GOOS=darwin GOARCH=amd64,arm64 go build ...
@skyzyx skyzyx added the Proposal label Jun 7, 2022
@gopherbot gopherbot added this to the Proposal milestone Jun 7, 2022
@randall77
Copy link
Contributor

There's no easy way to avoid the 2x blowup. The internal format of a fat binary is literally two independent binaries glued together. There is no provision for shared pieces.

You can use lipo or a simple tool I wrote to make them yourself.

It's not clear to me that we want to go down this route. There are lots of os/arch-specific things the go tool could do for you besides fattening, like signing, merging into a docker file, etc. We have to draw the line somewhere. I'm happy to leave a thing-that-is-only-needed-for-a-few-years-for-transition on the other side of the line.

@skyzyx
Copy link
Author

skyzyx commented Jun 7, 2022

Sure. Well I thought it was worth asking.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants