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

Unable to cross compile go for linux in Mac OS #1401

Closed
kramasamy opened this issue Mar 22, 2018 · 5 comments
Closed

Unable to cross compile go for linux in Mac OS #1401

kramasamy opened this issue Mar 22, 2018 · 5 comments
Labels

Comments

@kramasamy
Copy link

kramasamy commented Mar 22, 2018

Getting the following errors - any help is appreciated. I am using bazel 0.11.1 and go rules version 0.10.0

bazel build --cpu k8 build/packages/...
ERROR: No default_toolchain found for cpu 'k8'. Valid cpus are: [
  darwin,
  armeabi-v7a,
  x64_windows,
  x64_windows_msvc,
  x64_windows_msys,
  s390x,
  ios_x86_64,
]
INFO: Elapsed time: 0.154s
FAILED: Build did NOT complete successfully (0 packages loaded)
Karthikz-MacBook-Pro:streamlio karthikz$ bazel version
Build label: 0.11.1
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue May 14 18:46:16 +50148 (1520362464376)
Build timestamp: 1520362464376
Build timestamp as int: 1520362464376
@jayconrod
Copy link
Contributor

If you're building a pure Go project (no cgo, C/C++ dependencies, or external linking), you can cross-compile with --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64.

If part of your build requires a cross C/C++ compiler or linker, in addition to setting --platforms, you'll need to write a CROSSTOOL that describes your toolchain (unfortunately this is not an easy process), then set --cpu to the name of your toolchain.

@kramasamy
Copy link
Author

Thanks @jayconrod - that works. Wondering if this can be simplified so that it is easy to remember.

@jayconrod
Copy link
Contributor

@kramasamy We've been talking with the Bazel team about improvements to cross-compilation, mostly in the context of multi-configuration builds. I think we'll have more capabilities in the future, but I don't expect the command line interface to change too much.

For now, I added a FAQ so it's easier to find out how to do this.

@prestonvanloon
Copy link
Contributor

prestonvanloon commented Oct 2, 2018

Sorry to necro-post, is there any example of a CROSS tool from linux to compile to Mac with cgo deps?

#1020

@jayconrod
Copy link
Contributor

@prestonvanloon You might take a look at https://github.com/grailbio/bazel-toolchain. They have a full LLVM toolchain for several platforms. Not sure if it supports cross-compilation, but it might make a good template for CROSSTOOL authoring in any case.

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

No branches or pull requests

3 participants