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: cmd/go: bundle GOROOT in cmd/go tool #36266

Closed
Merith-TK opened this issue Dec 24, 2019 · 11 comments
Closed

proposal: cmd/go: bundle GOROOT in cmd/go tool #36266

Merith-TK opened this issue Dec 24, 2019 · 11 comments
Labels
Projects
Milestone

Comments

@Merith-TK
Copy link

@Merith-TK Merith-TK commented Dec 24, 2019

So here is the idea/concept,
I was looking at the details that go build bundles the needed runtimes inside the compiled binary for the program to run (hence why a simple hello world is 2mb),

I was thinking if the base stuff could be bundled into the main binary? So that the need for a GOROOT would not exist?

This idea came to mind when I was trying to work off a flashdrive as it was one less factor I would have to worry about breaking when I updated some component of my USB.

Technically speaking, could this exist? If so, how practical would it be?
Sure the bundled Binary would be 300+mb in size, maybe less if done right (maybe removing unnecessary components? Like documentatiob for example if that's a thing.)

@agnivade

This comment has been minimized.

Copy link
Contributor

@agnivade agnivade commented Dec 24, 2019

You do not need GOROOT to run a binary. A binary contains everything to run itself. You just need libc (conditionally) to exist.

I am going to close this as this doesn't sounds like a bug. But please feel free to ask it in any of these forums below:

Thanks

@agnivade agnivade closed this Dec 24, 2019
@Merith-TK

This comment has been minimized.

Copy link
Author

@Merith-TK Merith-TK commented Dec 24, 2019

@randall77

This comment has been minimized.

Copy link
Contributor

@randall77 randall77 commented Dec 24, 2019

The system on which you run go build is not necessarily the system where you run the resulting binary.
The system where you run the binary might not have Go installed at all.
This happens especially in the case of cross-compilation.

@Merith-TK

This comment has been minimized.

Copy link
Author

@Merith-TK Merith-TK commented Dec 24, 2019

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Dec 26, 2019

I don't think we are likely to implement this, but I agree that it makes sense conceptually, so reopening.

@ianlancetaylor ianlancetaylor changed the title (concept, IDEA, free to close) Bundle GOROOT in binary? proposal: cmd/go: bundle GOROOT in cmd/go tool Dec 26, 2019
@gopherbot gopherbot added this to the Proposal milestone Dec 26, 2019
@gopherbot gopherbot added the Proposal label Dec 26, 2019
@Merith-TK

This comment has been minimized.

Copy link
Author

@Merith-TK Merith-TK commented Dec 26, 2019

@randall77

This comment has been minimized.

Copy link
Contributor

@randall77 randall77 commented Dec 27, 2019

I see, I misunderstood what you were suggesting.

This would be challenging. Currently the Go tools (compile, link, asm, etc.) are all separate binaries. If we just packed their data into the go binary as is, then to run them we'd need to copy them out to a temporary location, chmod+x them, and then run them. We could also make the go binary a swiss army knife that contains all the tools in a single binary, and it could re-exec itself to access the tools.

All those tools would then need to be able to access the stdlib, which we'd also have to unpack somewhere. Or have those tools be able to read files from a packed (.zip?) format in the binary itself?

The Go distribution directory also provides a place to cache build artifacts (the pkg directory). We'd need to figure out a new place for that (if we used a temp dir, then there'd be no build caching between invocations).

Finally, there'd be no place for a bunch of ancillary stuff, like the license, docs, tests.

@Merith-TK

This comment has been minimized.

Copy link
Author

@Merith-TK Merith-TK commented Dec 27, 2019

@rsc rsc added this to Incoming in Proposals Jan 8, 2020
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Jan 8, 2020

If you really want this, one approach would be to make a container and run it under podman.
Another approach would be to put the entire GOROOT file system onto the USB stick.

For all the reasons outlined in the discussion above, this seems like a likely decline.
It would be a lot of work to duplicate things that can already be done in other ways today.

Leaving open for a week for final comments.

@rsc rsc moved this from Incoming to Likely Decline in Proposals Jan 8, 2020
@Merith-TK

This comment has been minimized.

Copy link
Author

@Merith-TK Merith-TK commented Jan 8, 2020

@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Jan 15, 2020

No change in consensus, so declining.

@rsc rsc closed this Jan 15, 2020
@rsc rsc moved this from Likely Decline to Declined in Proposals Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Proposals
Declined
6 participants
You can’t perform that action at this time.