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

Comments

@Merith-TK
Copy link

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
Copy link
Contributor

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

@Merith-TK
Copy link
Author

Merith-TK commented Dec 24, 2019 via email

@randall77
Copy link
Contributor

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
Copy link
Author

Merith-TK commented Dec 24, 2019 via email

@ianlancetaylor
Copy link
Contributor

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
@Merith-TK
Copy link
Author

Merith-TK commented Dec 26, 2019 via email

@randall77
Copy link
Contributor

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
Copy link
Author

Merith-TK commented Dec 27, 2019 via email

@rsc rsc added this to Incoming in Proposals (old) Jan 8, 2020
@rsc
Copy link
Contributor

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 (old) Jan 8, 2020
@Merith-TK
Copy link
Author

Merith-TK commented Jan 8, 2020 via email

@rsc
Copy link
Contributor

rsc commented Jan 15, 2020

No change in consensus, so declining.

@rsc rsc closed this as completed Jan 15, 2020
@rsc rsc moved this from Likely Decline to Declined in Proposals (old) Jan 15, 2020
@golang golang locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

6 participants