How to setup WORKSPACE/CROSSTOOL for linux & darwin toolchains
I'm trying to setup Bazel for cross-compiling with gcc-arm-none-eabi for developers using either Linux or Mac OS.
I followed the examples at https://github.com/bazelbuild/bazel/wiki/Building-with-a-custom-toolchain and setup a workspace that works with gcc-arm-none-eabi on Mac OS (https://github.com/jemdiggity/bazel_arm_none). I would like it to work on Linux as well.
The WORKSPACE has gcc-arm-none-eabi toolchain for Mac OS as a dependency so it's automatically fetched. If I add the toolchain for Linux as well, they will both be fetched even though the developer on the Linux host doesn't require the toolchain for Mac OS, and vice versa.
new_http_archive(
name = 'toolchain_gcc_arm_none_darwin',
build_file = 'compilers/gcc_arm_none.BUILD',
url = 'https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/gcc-arm-none-eabi-5_4-2016q3-20160926-mac.tar.bz2',
strip_prefix = 'gcc-arm-none-eabi-5_4-2016q3',
)
It doesn't seem to be possible to make the external dependencies in the WORKSPACE file dependent on the host OS.
I would like only the relevant toolchain to be fetched and to use the same wrapper scripts and CROSSTOOL file on either linux or mac os.
Do I need to write a custom repository rule? Similar to https://github.com/tensorflow/tensorflow/blob/master/third_party/gpus/cuda_configure.bzl.
Is there a simpler approach? Any guidance would be appreciated.
Thanks for your time.
Environment info
-
Operating System: macOS 10.12.3 (16D32)
-
Bazel version (output of
bazel info release): release 0.4.4-homebrew -
If
bazel info releasereturns "development version" or "(@non-git)", please tell us what source tree you compiled Bazel from; git commit hash is appreciated (git rev-parse HEAD):
I did it like this: https://github.com/pedrokiefer/rules_stm32/blob/master/stm32f4/rules.bzl#L101
I made a repository rule similar to http_archive but selects archive based on the OS. https://github.com/jemdiggity/rules_os_dependent_http_archive
os_dependent_http_archive(
name = "toolchain_gcc_arm_none",
build_file = "//:compilers/gcc_arm_none.BUILD",
strip_prefix = 'gcc-arm-none-eabi-5_4-2016q3',
urls = {
"linux" : ["https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2"],
"darwin" : ['https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/gcc-arm-none-eabi-5_4-2016q3-20160926-mac.tar.bz2'],
},
sha256 = {
"linux" : "a397c49bdd0cf17a38a494cb691baf68b8dcffa4d4c06561ef3d71b2ab4c92a1",
"darwin" : "5656cdec40f99d5c054a85bbc694276e1c4a1488cdacbbc448bc6acd3bbe070d",
},
)
I know this issue is closed, but for anyone trying to set up the arm-none-eabi-gcc toolchain with more recent versions of Bazel, I published a packaged version of the toolchain with --crosstool and --platforms support that could be useful as a starting point.