It seems a WORKSPACE snippet to set up gcc-toolchain is missing from the current documentation. It would be nice to include the WORKSPACE snippet in documentation or the release page so that users can start using gcc-toolchain without troubles by copying the WORKSPACE snippet into their WORKSPACE files.
Based on this repo's WORKSPACE, below is an example of the WORKSPACE snippet and .bazelrc to use gcc-toolchain v0.4.2 to build binaries for x86_64. It would be great to confirm that there is something wrong or redundant with the snippet. I mentioned this because unusual configs, --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 and --incompatible_enable_cc_toolchain_resolution were required to add to .bazelrc so that Bazel can use the C/C++ toolchain managed by gcc-toolchain. If these configs are required indeed, I think it worth noting it in the documentation because these configs not so obvious for non-Bazel experts.
WORKSPACE:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Skylib
# gcc-toolchain depends on bazel-skylib
http_archive(
name = "bazel_skylib",
sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
],
)
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
http_archive(
name = "aspect_gcc_toolchain",
sha256 = "3341394b1376fb96a87ac3ca01c582f7f18e7dc5e16e8cf40880a31dd7ac0e1e",
strip_prefix = "gcc-toolchain-0.4.2",
url = "https://github.com/aspect-build/gcc-toolchain/archive/refs/tags/0.4.2.tar.gz",
)
load("@aspect_gcc_toolchain//toolchain:defs.bzl", "ARCHS", "gcc_register_toolchain")
gcc_register_toolchain(
name = "gcc_toolchain_x86_64",
gcc_version = "10.3.0",
sysroot_variant = "x86_64",
target_arch = ARCHS.x86_64,
)
.bazelrc:
# Required to use the C/C++ toolchain managed by gcc-toolchain
build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build --incompatible_enable_cc_toolchain_resolution
# optional, but preferred for performance as per https://github.com/aspect-build/gcc-toolchain/issues/85
build --experimental_reuse_sandbox_directories
It seems a
WORKSPACEsnippet to set up gcc-toolchain is missing from the current documentation. It would be nice to include theWORKSPACEsnippet in documentation or the release page so that users can start using gcc-toolchain without troubles by copying theWORKSPACEsnippet into theirWORKSPACEfiles.Based on this repo's
WORKSPACE, below is an example of theWORKSPACEsnippet and.bazelrcto use gcc-toolchain v0.4.2 to build binaries for x86_64. It would be great to confirm that there is something wrong or redundant with the snippet. I mentioned this because unusual configs,--action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1and--incompatible_enable_cc_toolchain_resolutionwere required to add to.bazelrcso that Bazel can use the C/C++ toolchain managed by gcc-toolchain. If these configs are required indeed, I think it worth noting it in the documentation because these configs not so obvious for non-Bazel experts.WORKSPACE:.bazelrc: