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

go/build: provide function to enumerate valid target combinations #47790

Open
mcandre opened this issue Aug 18, 2021 · 6 comments
Open

go/build: provide function to enumerate valid target combinations #47790

mcandre opened this issue Aug 18, 2021 · 6 comments
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mcandre
Copy link

mcandre commented Aug 18, 2021

Please provide a reliable function to dynamically query the list of valid (GOOS, GOARCH) combinations, so that application maintainers can plug directly into this system and build as many ports as possible.

Certain workarounds have limitations:

This could all be streamlined with a first party API. An array of combination strings would be nice. Or a hashmap of valid combination strings, which could serve for both enumeration and efficient validation, acting logically as a mathematical set for existence / non-existence checks.

@cespare
Copy link
Contributor

cespare commented Aug 18, 2021

Use go tool dist list or go tool dist list -json.

@cespare cespare closed this as completed Aug 18, 2021
@cespare
Copy link
Contributor

cespare commented Aug 18, 2021

(See context at #12270.)

Actually, I'll leave this open since you specifically asked for a Go API. But I think the answer will probably be to use go tool dist.

@cespare cespare reopened this Aug 18, 2021
@mknyszek mknyszek changed the title Provide std lib function to enumerate valid target combinations go/build: provide function to enumerate valid target combinations Aug 18, 2021
@mknyszek
Copy link
Contributor

I'm not even sure which package this would go in, but I took a guess. Feel free to update the title if you have a better idea.

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 18, 2021
@mknyszek mknyszek added this to the Backlog milestone Aug 18, 2021
@mknyszek
Copy link
Contributor

CC @rsc I guess?

@mcandre
Copy link
Author

mcandre commented Aug 18, 2021

@cespare Yes, an API would be more efficient than a shell command.

I do appreciate the tip. I can use go tool dist list meanwhile as a workaround for a leaner mechanism.

I am planning on wrapping go tool dist list into a reusable tool for building as many ports as possible.

https://github.com/mcandre/factorio

Works similar to the venerable gox utility, but with simpler options. Mostly pass-through.

Now that the platform metadata comes dynamically from the real go command line tool, hopefully the data doesn't have to be manually updated as often. The intention is for the same factorio code to work with future Go releases, as the language continues to add (unanticipated) targets.

@mvdan
Copy link
Member

mvdan commented Apr 9, 2023

I agree with @cespare that you want go tool dist list -json; I use it in my own "cross compile for release assets" script.

Getting the information from go tool dist feels right, because I'm going to call go build right after, so the list of targets is exactly right as it comes from the same source. If it came from go/build via a Go program, I would have to be very careful to use the same Go version in both:

  1. building the program which imports go/build
  2. running go build to use each target

Executing cmd/go does add a few milliseconds worth of overhead, but I'm not sure that that's more important than having to worry about the version skew - and offering the same information in two ways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants