bazelbuild / bazelbuild/bazel-toolchains

Bazel_Toolchain issue while using for crosscompilation

Open
#1,004 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
202
Forks
100
PR merge metrics
No merged PRs in 30d

Description

**Description of the problem:**
I'm using bazel_toolchain to cross compile the c++ code. while i configure the bazel workspace with bazel_toolchain repo, it fails to download.
**Below is the Example:**
**Worspace file:**
load("@`bazel_tools//tools/build_defs/repo:git.bzl`", "git_repository")

git_repository(

name = "`bazel_toolchains`",

commit = "`6146252bda912a77a25c3b0ebe55ed0d00a1fa4d`",

remote = "`https://github.com/bazelbuild/bazel-toolchains.git`",

)

load("@`bazel_toolchains//:rbe_autoconfig.bzl`", "`rbe_autoconfig`")

load("@`bazel_toolchains//rules:envs.bzl`", "`bazel_toolchain`")

bazel_toolchain(
name = "x86_64-linux",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
toolchain = ":cc-compiler-x86_64-linux",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

bazel_toolchain(
name = "x86_64-windows",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
target_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
toolchain = ":cc-compiler-x86_64-windows",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

cc_toolchain_config(
name = "cc-compiler-x86_64-linux",
cpu = "k8",
compiler = "gcc",
host_system_name = "x86_64-unknown-linux-gnu",
target_system_name = "x86_64-unknown-linux-gnu",
target_libc = "glibc_2.24",
)

cc_toolchain_config(
name = "cc-compiler-x86_64-windows",
cpu= "k8",
compiler = "msvc-cl",
host_system_name = "x86_64-unknown-linux-gnu",
target_system_name = "x86_64-unknown-windows",
target_libc = "msvcrt",
)

**BUILD FILE:**
load("@bazel_toolchains//rules:environments.bzl", "clang_env")

clang_env(
name = "linux-x86_64",
base_cc_toolchain_config = ":cc-compiler-x86_64-linux",
extra_toolchains = ["@`bazel_toolchains//configs/ubuntu16_04_clang/x86_64_gcc:cc-toolchain-clang-x86_64-default`"],
visibility = ["//visibility:public"],
)

clang_env(
name = "windows-x86_64",
base_cc_toolchain_config = ":cc-compiler-x86_64-windows",
extra_toolchains = ["@`bazel_toolchains//configs/windows_clang:x86_64`"],
visibility = ["//visibility:public"],
)

cc_library(
name = "hello_greet",
srcs = ["hello_greet.cc"],
hdrs = ["hello_greet.h"],
copts = ["-D__STDC_FORMAT_MACROS"],
)

cc_shared_library(
name = "hello_greet_shared",
deps = [":hello_greet"],
copts = ["-D__STDC_FORMAT_MACROS"],
)

cc_binary(
name = "hello_world_linux",
srcs = ["hello_world.cc"],
deps = [":hello_greet"],
dynamic_deps = [":hello_greet_shared"],
copts = ["-D__STDC_FORMAT_MACROS"],
toolchain = ":linux-x86_64",
)

cc_binary(
name = "hello_world_windows",
srcs = ["hello_world.cc"],
deps = [":hello_greet"],
dynamic_deps = [":hello_greet_shared"],
copts = ["-D__STDC_FORMAT_MACROS"],
toolchain = ":windows-x86_64",
)

**bazel.rc file**
build:windows --copt=-DWIN32
build:windows --cxxopt=-std=c++14

build:linux --copt=-DLINUX
build:linux --cxxopt=-std=c++14

build:windows --cpu=x64_windows
build:linux --cpu=x64_linux

build:windows --compilation_mode=dbg
build:windows --compilation_mode=opt

build:linux --compilation_mode=dbg
build:linux --compilation_mode=opt

build:dbg --copt=-g
build:dbg -c dbg
build:opt --copt=-O3
build:opt --copt=-DNDEBUG
build:opt -c opt

**Translation units to Build:**

**hello_greet.h**
#ifndef LIB_HELLO_GREET_H_
#define LIB_HELLO_GREET_H_

#include

std::string get_greet(const std::string &thing);

#endif

**hello_greet.cc**
#include "hello_greet.h"
#include

std::string get_greet(const std::string& world) {
return "Hello " + world;
}

**hello_world.cc**

#include "hello_greet.h"
#include
#include

int main(int argc, char** argv) {
std::cout << get_greet("world") << std::endl;
return 0;
}

I configured the WORKSPACE file with "**bazel_toolchain**" this should fetch the code from git repo and the build file is configured for cross compiled translation units (Linux & Windows) by loading bazel_toochains and clangenv is used to set for cross compilation for windows and linux.
However, the following error throws when building:

`bazel build //main:hello_world_linux`

`ERROR: Error computing the main repository mapping: cannot load '@@bazel_toolchains//:rbe_autoconfig.bzl': no such file
`
The above error indicates that `reb_autoconfig.bzl `no such file exists since the git download didnt happen for the same though proper commit id is given.

Manually downloaded `bazel_Toolchain` but with this toolchain there is no `reb_autoconfig.bzl `is present and looks deprecated or removed.

**Bazel version used:** `bazel version 7.0.0`
**Debain version used:** `Debian GNU/Linux rodete`

Let me know if you need any more information

Contributor guide

Open the contributing guide

Research direction

Start with the WORKSPACE reference to rbe_autoconfig.bzl and the pinned bazel-toolchains commit, then reproduce the failure using Bazel 7.0.0 on Debian GNU/Linux. Check the manually downloaded repository contents and the referenced rules and configs. Done means establishing why the file is unavailable and documenting a confirmed resolution or current compatibility status.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.