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

Cross compiling filegroups #1104

Closed
achew22 opened this issue Dec 5, 2017 · 3 comments
Closed

Cross compiling filegroups #1104

achew22 opened this issue Dec 5, 2017 · 3 comments

Comments

@achew22
Copy link
Member

achew22 commented Dec 5, 2017

Is it possible to use filegroups output_group attribute to get a cross-compiled binary now that the preferred way of cross-compiling is not done through output groups?

@ianthehat
Copy link
Contributor

cross compiling was never done through output groups, only race/pure was done that way.
At the moment cross compiling can only be triggered by changing the toolchain, which means either using ---experimental_platforms or --cpu on the command line, and only one can be built at a time.
What changed is that the files generated will not overwrite each other, so it's build cache friendly, and also you can build a couple of platforms in sequence and then collect all the results when you are done if you like.
The changes to propagate the target goos and goarch through the mode in theory mean we could now build multiple pure go target architectures in a single bazel invocation, but cgo will not be possible until dynamic platform transitions arrives (no idea when the Bazel team will have time for that, but it's definitely planned)

@achew22
Copy link
Member Author

achew22 commented Dec 5, 2017

The specific case I'm trying to deal with is trying to package up a project that has binary is compile for multiple operating system to distribute on NPM. Right now I have a shell script that does a bunch of gross stuff compiling it twice and making temp directories. I would like to move it over to bring all in build files. Do you have any theories on how I could do that?

@ianthehat
Copy link
Contributor

Persuade the Bazel team to implement toolchain transitions so we can have rules that state what toolchain they compile with....
Seriously, right now running bazel twice with the two toolchains is the best you are going to manage.
We could try adding goos and goarch controls to go_binary, it's probably not that hard, then you could declare separate go_binary rules for each target architecture, and collect up the results of all those rules, but it will break if you have any cgo anywhere in the system.

ianthehat added a commit to ianthehat/rules_go that referenced this issue Dec 7, 2017
This adds goos and goarch attributes to a go_binary
If specified they force the binary to cross compile to the specified
architecture.
It also adds a test that uses this to cross compile and verify the binary was
correctly cross compiled.
This also required multiple rules for the same binary in different modes, which
meant we needed control over the binary file name (so not using the rule name)

Fixes bazel-contrib#1104
Fixes bazel-contrib#1030
ianthehat added a commit to ianthehat/rules_go that referenced this issue Dec 7, 2017
This adds goos and goarch attributes to a go_binary
If specified they force the binary to cross compile to the specified
architecture.
It also adds a test that uses this to cross compile and verify the binary was
correctly cross compiled.
This also required multiple rules for the same binary in different modes, which
meant we needed control over the binary file name (so not using the rule name)

Fixes bazel-contrib#1104
Fixes bazel-contrib#1030
ianthehat added a commit that referenced this issue Dec 7, 2017
This adds goos and goarch attributes to a go_binary
If specified they force the binary to cross compile to the specified
architecture.
It also adds a test that uses this to cross compile and verify the binary was
correctly cross compiled.
This also required multiple rules for the same binary in different modes, which
meant we needed control over the binary file name (so not using the rule name)

Fixes #1104
Fixes #1030
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants