cross compilation error when import both c toolchain and rules_go
See original GitHub issueDescription of the problem / feature request:
I wirte a test case for cross compile C file for ARM64 on x86_64 and it works well. However After I put rules go in WORKSPACE, and build the C file again. It shows
# bazel build --config aarch64 //example:hello
INFO: SHA256 (https://golang.org/dl/?mode=json&include=all) = c90367386219502d1d2f3c7fa5825884166e6fc2b260f95d3bb85c557aeaf10e
ERROR: While resolving toolchains for target //example:hello: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
ERROR: Analysis of target '//example:hello' failed; build aborted: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
INFO: Elapsed time: 4.022s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (13 packages loaded, 99 targets configured)
Following is my WORKSPACE and .bazelrc WORKSPACE
workspace(name = "bazel_cc_toolchains")
load(
"@bazel_tools//tools/build_defs/repo:http.bzl",
"http_archive",
)
http_archive(
name = "coral_crosstool",
sha256 = "088ef98b19a45d7224be13636487e3af57b1564880b67df7be8b3b7eee4a1bfc",
strip_prefix = "crosstool-142e930ac6bf1295ff3ba7ba2b5b6324dfb42839",
urls = [
"https://github.com/google-coral/crosstool/archive/142e930ac6bf1295ff3ba7ba2b5b6324dfb42839.tar.gz",
],
)
load("@coral_crosstool//:configure.bzl", "cc_crosstool")
cc_crosstool(name = "crosstool")
http_archive(
name = "io_bazel_rules_go",
sha256 = "7904dbecbaffd068651916dce77ff3437679f9d20e1a7956bff43826e7645fcc",
urls = [
"https://github.com/bazelbuild/rules_go/releases/download/v0.25.1/rules_go-v0.25.1.tar.gz",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
go_register_toolchains(version = "1.15.6")
.bazelrc
build:aarch64 --host_crosstool_top=@crosstool//:toolchains --crosstool_top=@crosstool//:toolchains
build:aarch64 --compiler=gcc --cpu=aarch64
build:aarch64 --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64
Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Following https://github.com/google-coral/crosstool to apply cross compile toolchain for C/C++ on x86 Following https://github.com/bazelbuild/rules_go to add rule_go into WORKSPACE Use bazel to build a c file.
What operating system are you running Bazel on?
Ubuntu Linux ubuntu 5.9.0+ #5 SMP Thu Nov 12 07:40:27 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
What’s the output of bazel info release
?
release 3.7.2
Have you found anything relevant by searching the web?
There are some discuss for same issue in following link, but no answer in it. https://github.com/bazelbuild/rules_go/issues/2089
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Issue with cross compilation - Stack Overflow
I would like to compile a simple test program in c with an ARM toolchain. My Makefile is as follows: CC=/project_path/arm-linux-uclibcgnueabi/ ...
Read more >Using Zig As Cross Platform C Toolchain - Ruoyu Sun
Currently, I do not use a cross-platform compilation toolchain ... There are two main approaches to import C code: @cImport and zig ...
Read more >Cross-compilation in Rust - Sylvain Kerkour
To increase the number of potential targets, we are going to use cross-compilation: we will compile a program from a Host Operating System ......
Read more >Tag Archives: cross compilation - Dave Cheney
It is currently not possible to produce a cgo enabled binary when cross compiling from one operating system to another. This is because...
Read more >C / C++ IDE (CDT) » Adding new "toolchain" to Eclipse.
works to compile C or C++ code on my Pi Zero with Raspian Jessie. ... I Eclipse terminology - I have can choose...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is an interaction between
rules_go
, which uses toolchain resolution, andrules_cc
, which currently does not. For Bazel, the cc toolchains that are autogenerated bytools/cpp/cc_configure.bzl
are only for the host platform. I haven’t looked into the coral-crosstool you are using, but I suspect that this is creating the legacycc_toolchain_suite
target, but isn’t actually creatingtoolchain
entries and usingregister_toolchains
to make Bazel aware of them.So, to fix your issue, you need to do the following:
toolchain
targets and callregister_toolchains
in theircc_crosstool
macro.--incompatible_enable_cc_toolchain_resolution
, so that the toolchain entries are used. You can add this to a bazelrc to make it simpler.--crosstool_top
,--host_crosstool_top
, and--cpu
, always use--platforms
to specify your target platform. a. You may want to write a customplatform
target in your project, instead of relying on the one fromio_bazel_rules_go
, just to ensure you have control over what your target platfom is.I don’t know who is behind coral-crosstool, but the work they need to do isn’t difficult, and is very similar to the current
toolchain
targets generated by Bazel intools/cpp/BUILD.toolchains.tpl
(although the specific target constraints will change based on the compiler, obviously). The registration for Bazel’s cc toolchains is intools/cpp/cc_configure.bzl:186
.This is not a Bazel failure, per se.
@katre - at a super-quick glance, does this look like the actual toolchain is missing? Which group seems best to route this to?