bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Cross-Compilation Documentation is Confusing

Open kwhitehouse opened this issue 1 year ago • 0 comments

Page link:

https://bazel.build/concepts/platforms, https://bazel.build/tutorials/ccp-toolchain-config

Problem description (include actual vs expected text, if applicable):

What I'm Trying to Do I'm trying to do something which sounds simple, at it's core. I'd like to use Bazel to build a command-line tool that's written primarily in C++ (one library dependency is written in Rust). I need the tool to be able to run on Mac and Windows machines, but I only want to build the tool on a single machine, likely a Linux machine. So I'm trying to configure Bazel to cross-compile when building the command-line tool.

What's Confusing

  • The documentation at https://bazel.build/concepts/platforms and https://bazel.build/extending/platforms is really challenging to digest. Are there platforms/toolchains that can be used 'off-the-shelf', or should I expect to need to define my own platform/toolchain? It sounds like there might be some off-the-shelf options in https://github.com/bazelbuild/platforms, but I struggled to find any.
  • I did find what I think are off-the-shelf toolchains mentioned in this documentation which appear to be provided by io_bazel_rules_go. The instructions there note that you can reference these toolchains via the --platforms flag, as can be seen below. Am I reading this correctly? Are these types of off-the-shelf toolchains available for other languages, like C++? (Per above, I'd like to use Bazel to build a C++ binary, so I'm interested in C++ toolchains.)
# Documentation in `bazelbuild/rules_go` uses this example.
$ bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //my/project

# What I'm hoping would exist for C++!
$ bazel build --platforms=@bazel_rules_cc//cc/toolchain:linux_amd64 //my/project
  • If there's no standardized toolchains that can be used off-the-shelf for my use-case, it'd be wonderful if this how-to guide https://bazel.build/tutorials/ccp-toolchain-config could be made simpler. For my use-case (cross-compiling a simple C++ binary), would all of these steps be required?

Full disclaimer: It's very possible that I'm underestimating the complexity of what I'm trying to do :) If so, and the documentation is as simple as it can be, then you can mark this issue as obsolete / working as intended.

Where do you see this issue? (include link to specific section of the page, if applicable)

  • https://bazel.build/concepts/platforms
  • https://bazel.build/tutorials/ccp-toolchain-config

Any other information you'd like to share?

No response

kwhitehouse avatar Aug 06 '24 07:08 kwhitehouse