This guide explains how to use the GCC C++ Toolchain provided in S-CORE GCC Toolchain repository. The toolchain supports Linux-based GCC cross-compilation and is designed to integrate easily into Bazel-based C++ projects.
NOTE: The support for WORKSPACE file servers only as backup for projects/modules that are currently migrating to bzlmod and such should not be used in newly established projects.
To include the toolchain in any project (module), a project needs to declare dependency to the toolchain. This is done by updating projects MODULE.bazel file:
# MODULE.bazel
bazel_dep(name = "score_toolchains_gcc", version = "X.Y") # where the X and Y are version numbers.
To include the toolchain in any project, a project WORKSPACE file needs to collect all dependency which toolchain has:
# WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(name = "score_toolchains_gcc", . . .)
load("@score_toolchains_gcc//:deps.bzl", "toolchain_gcc_dependencies")
toolchain_gcc_dependencies()
The score_toolchains_gcc
module currently supports only GNU GCC version 12.2.0. Support for multiple GCC versions is planned, with future versions expected to be selectable via an extended toolchain interface. As of now, version 12.2.0 is the sole supported target.
The module exposes an API that allows consumers to enable or disable specific toolchain behaviors related to compilation diagnostics. The following features can be individually configured:
- Minimal warning flags — enables a basic set of compiler warnings
- Strict warning flags — enables a more aggressive set of warnings (e.g.,
-Wall, -Wextra
) - A
treat warnings as errors
flags — promotes all warnings to errors (e.g.,-Werror
)
These features provide fine-grained control over the compiler's warning policy. If no features are explicitly selected, the toolchain will apply no additional warning-related flags by default.
To set wanted flags, the following API needs to be used:
gcc = use_extension("@score_toolchains_gcc//extentions:gcc.bzl", "gcc")
gcc.extra_features(
features = [
"minimal_warnings",
"treat_warnings_as_errors",
],
)
gcc.warning_flags(
minimal_warnings = ["-Wall", "-Wno-error=deprecated-declarations"],
strict_warnings = ["-Wextra", "-Wpedantic"],
treat_warnings_as_errors = ["-Werror"],
)
use_repo(gcc, "gcc_toolchain", "gcc_toolchain_gcc")
extra_features
- This will enable all features which are set in the list.warning_flags
- This will set flags for selected features.
The same approuch needs to be done when configuring toolchain over WORKSPACE file:
load("@score_toolchains_gcc//rules:gcc.bzl", "gcc_toolchain")
gcc_toolchain(
name = "gcc_toolchain",
gcc_repo = "gcc_toolchain_gcc",
extra_features = [
"minimal_warnings",
"treat_warnings_as_errors",
],
warning_flags = {
"minimal_warnings": ["-Wall", "-Wno-error=deprecated-declarations"],
"strict_warnings": ["-Wextra", "-Wpedantic"],
"treat_warnings_as_errors": ["-Werror"],
},
)
Toolchain registration can be performed either directly in a MODULE.bazel file or globally through .bazelrc. When registering in MODULE.bazel:
register_toolchains("@gcc_toolchain//:host_gcc_12")
Or when registering globally:
build --extra_toolchains=@gcc_toolchain//:host_gcc_12
A minimal Bazel project demonstrating use of the toolchain can be found in the test/ directory of this module.
✅ Bazel version 6.x or newer (with Bzlmod enabled)
✅ Linux hosts