A Bazel C++ toolchain for building shared libraries and dependent binaries which conform to typical Linux linking practices.
Repo adambreland/cpp-simple_bazel_cpp_toolchain, read from GitHub 2 h ago. adambreland has not joined Take My Repo.
adambreland/cpp-simple_bazel_cpp_toolchain is a public repo on GitHub by adambreland. A Bazel C++ toolchain for building shared libraries and dependent binaries which conform to typical Linux linking practices. It declares the MIT license on GitHub. It is written mainly in Starlark, has 4 stars and last changed on 2021-04-20. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-22.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
This Bazel workspace defines //:simple_x86_64_linux_toolchain. This
toolchain can be used with the standard C++ rules. As the default C++ toolchain
produces libraries and executables which do not conform to typical linking
practices (see, for example, this issue),
//:simple_x86_64_linux_toolchain was developed to have the
following features:
DT_NEEDED fields of these outputs hold shared library Bazel target
names by default. These names are not mangled in some fashion.-Wl,-soname=<library soname>.DT_RUNPATH are not used in executables and
shared libraries by default.g++.g++ version 9. They can be found
in //:toolchain_definition.bzl in list gcc_system_include_directories.This toolchain is intended to be a starting point in the definition of C++ toolchains which conform to typical Linux linking practices. It is not intended to be a drop-in replacement for the default C++ toolchain. As it is, it does not support all C++ rule attribute semantics. The toolchain is currently used by as_components for relatively simple build actions.
The -s flag for bazel build can be used to print build command lines. These
can then be inspected to ensure that a particular target is built correctly by
the toolchain.
dbg, fastbuild, and opt. If such behavior is
desired, it can be implemented without modifying the toolchain by specifying
the desired compilation mode and using instances of the --copt and
--linkopt command line build options.The toolchain is configured to be used with platforms.
Toolchain resolution which uses platforms only occurs for C++ rules when the
following build flag is enabled:
--incompatible_enable_cc_toolchain_resolution
When platforms are used, the definition of a cc_toolchain_suite target is not
necessary.
Using the toolchain without modification requires a few steps:
local_repository may be used if this repository
was cloned locally.WORKSPACE file as follows (assuming that the external repository is
accessed with @simple_bazel_cpp_toolchain):
register_execution_platforms(
"@local_config_platform//:host",
"@simple_bazel_cpp_toolchain//:simple_cpp_x86_64_linux_platform"
)
register_toolchains(
"@simple_bazel_cpp_toolchain//:simple_x86_64_linux_toolchain"
)
@local_config_platform//:host assumes that remote execution is
not performed and that the host is an x86-64 Linux system. Also, as
described above, use of the toolchain requires g++ and the presence of
the assumed system include directories.--incompatible_enable_cc_toolchain_resolution is used. For
example, a .bazelrc file may be used to provide this flag.The toolchain allows the definition of five kinds of conceptual targets.
Explanations of the target structure, Bazel attribute values, and features which are necessary to define targets of these types follow. Also given are explanations of:
cc_test targets//nonstandard_toolchain:simple_cpp_toolchain in its exec_compatible_with
attribute argument list.A shared library target is meant to represent a shared library which is linked to its direct dependencies and which relies on the proper installation of these dependencies.
Configuration:
cc_library target is defined for the shared library header.cc_binary target is defined for the shared library.foo:
cc_library): A conventional pattern such as foo_header is
suggested.cc_binary): libfoo.so or a versioned variant such as
libfoo.so.1.0.0deps): The cc_library header target.-Wl,-soname=libfoo.so.1 may be included in the linkopts attribute of the
cc_binary target."interpret_as_shared_library" (for the cc_binary target)Example:
cc_library(
name = "foo_header",
deps = [],
srcs = [],
hdrs = ["foo.h"]
)
cc_binary(
name = "libfoo.so.1.0.0",
deps = [":foo_header"],
srcs = ["foo.cc"],
linkopts = ["-Wl,-soname=libfoo.so.1"],
features = ["interpret_as_shared_library"],
exec_compatible_with = ["//nonstandard_toolchain:simple_cpp_toolchain"]
)
Any target which depends on a shared library which was defined in the way
described above must include the shared library header target in deps and the
shared library binary target in srcs.
Tests which depend on a versioned shared library which uses a major version
soname must have a target which defines a major version symbolic link to the
shared library in their data attribute.
Examples:
cc_binary(
name = "bar_on_foo",
deps = [":foo_header"],
srcs = [
"bar.cc",
":libfoo.so.1.0.0"
],
features = ["interpret_as_executable"],
exec_compatible_with = ["//nonstandard_toolchain:simple_cpp_toolchain"]
)
genrule(
name = "libfoo.so.1.0.0_soname_symlink",
srcs = [":libfoo.so.1.0.0"],
outs = ["libfoo.so.1"],
# Make variable substitution is used to access the output path.
cmd_bash = "ln -s libfoo.so.1.0.0 $@"
)
cc_test(
name = "test_on_foo",
deps = [":foo_header"],
srcs = [
"test_on_foo.cc",
":libfoo.so.1.0.0"
],
data = [":libfoo.so.1.0.0_soname_symlink"],
features = ["interpret_as_test_executable"],
exec_compatible_with = ["//nonstandard_toolchain:simple_cpp_toolchain"]
)
An executable target is meant to represent an executable program that can be executed independently of a Bazel installation provided that its shared library dependencies are properly installed.
Configuration:
cc_binary"interpret_as_executable"Example:
cc_binary(
name = "executable_target",
deps = [],
srcs = ["executable_target.cc"],
features = ["interpret_as_executable"],
exec_compatible_with = ["//nonstandard_toolchain:simple_cpp_toolchain"]
)
A test executable target is meant to represent a test which is executed by Bazel. It is assumed that the test must be able to execute when its shared library dependencies have not been installed.
Configuration:
cc_testLD_LIBRARY_PATH as explained below."interpret_as_test_executable"Example without indirect shared library dependencies:
cc_test(
name = "test_on_so",
deps = [":so_header"],
srcs = [
"test_on_so.cc",
":libso.so"
],
features = ["interpret_as_test_executable"],
exec_compatible_with = ["//nonstandard_toolchain:simple_cpp_toolchain"]
)
Tests can access their direct shared library dependencies without additional
configuration. Indirect shared library dependencies must be exposed using
the LD_LIBRARY_PATH environment variable of the Linux dynamic linker. The
ORIGIN token is expanded in the value of LD_LIBRARY_PATH to the directory
which contains the test executable. This can be used to describe the
directories which contain the indirect shared library dependencies of the test.
Notes on using ORIGIN for this purpose:
...external which is
located at the workspace root. The repository name as defined by
local_repository is used as the root of the repository under external.
The directory structure within a repository directory is the same as the
structure of the external repository.LD_LIBRARY_PATH.Example with indirect shared library dependencies:
libspam.so is located at the workspace root.libcram.so is located at the workspace root and is a dependency of
libspam.so.libham.so is located in package package1 under the workspace root and is
a dependency of libspam.so.libeggs.so is located in the external repository external_eggs at its
workspace root. It is a dependency of libspam.so.cc_library(
name = "spam_header",
deps = [],
srcs = [],
hdrs = ["spam.h"]
)
cc_binary(
name = "libspam.so",
deps = [
":spam_header",
":cram_header",
"//package1:ham_header",
"@external_eggs//:eggs_header"
],
srcs = [
"spam.cc",
":libcram.so",
"//package1:libham.so",
"@external_eggs//:libeggs.so"
],
features = ["interpret_as_shared_library"],
exec_compatible_with = ["//nonstandard_toolchain:simple_cpp_toolchain"]
)
cc_test(
name = "test_with_indirect_so_deps",
deps = [":spam_header"],
srcs = [
"test_with_indirect_so_deps.cc",
":libspam.so"
],
# Use $$ to escape $ and prevent Make variable substitution.
env = {
"LD_LIBRARY_PATH":
"$${ORIGIN}:$${ORIGIN}/package1:$${ORIGIN}/external/external_eggs"
},
features = ["interpret_as_test_executable"],
exec_compatible_with = ["//nonstandard_toolchain:simple_cpp_toolchain"]
)
Archive targets are intended to represent archives whose sources are not also directly compiled to shared object files or executables. This assumption separates library targets into two classes: those which define shared libraries and those which define static libraries.
PIC archives and archives are defined in the usual way with two additions:
linkstatic attribute is set to True to ensure that a shared library
is not generated."interpret_as_pic_archive" or
"interpret_as_archive", is used.Examples:
cc_library(
name = "pic_archive",
deps = [],
srcs = ["pic_archive.cc"],
hdrs = ["pic_archive.h"],
linkstatic = True,
features = ["interpret_as_pic_archive"],
exec_compatible_with = ["//nonstandard_toolchain:simple_cpp_toolchain"]
)
cc_library(
name = "archive",
deps = [],
srcs = ["archive.cc"],
hdrs = ["archive.h"],
linkstatic = True,
features = ["interpret_as_archive"],
exec_compatible_with = ["//nonstandard_toolchain:simple_cpp_toolchain"]
)
Trial targets are defined which possess various dependency relationships on the three kinds of targets which can be depended upon (shared library, PIC archive, and archive). For example, in addition to an executable which depends on a shared library and a test which depends on a shared library, a test which depends on a shared library which depends on a shared library is defined.
The command lines which are generated by the toolchain for these targets can
be inspected by using the -s flag when executing bazel build or
bazel test. For example, bazel build -s ... should succeed and print the
command lines which were used for each trial target.
Several test executables are defined to allow validation of shared library
loading. An execution of bazel test ... should pass.
This section provides a brief explanation of how to define a
C++ toolchain which uses platforms. The main goal of this process is
instantiating a toolchain target and registering it in the workspace. This
section may be useful if modifications to this toolchain are desired.
Instantiating toolchain for C++ toolchains requires several steps.
A rule must be defined which provides a CcToolchainConfigInfo provider
instance. This is done by having the implementation function of the rule return
the result of invoking cc_common.create_cc_toolchain_config_info with
object arguments with provide the logic of the toolchain. Defining these
objects is the major activity of defining a toolchain. For example, compilation
and linking command lines are generated by Bazel with the information provided
to create_cc_toolchain_config_info in these objects. This toolchain
definition uses action_config instead of tool_path as tool_path is
deprecated.
The rule is then instantiated in a BUILD file. The target created by
instantiating the rule is used in the instantiation of a cc_toolchain target.
Finally, the cc_toolchain target is used in the instantiation of a
toolchain target. To use this non-standard toolchain, the toolchain target
must include //nonstandard_toolchain:simple_cpp_toolchain in the list
argument of its exec_compatible_with attribute.
The following list gives a step-by-step summary of this process for this toolchain after the custom rule definition step.
Steps:
In a BUILD file, the rule cc_toolchain_config_info_generator is loaded
from //:toolchain_definition.bzl. This rule provides an appropriate
provider instance for the toolchain_config attribute of cc_toolchain.
The rule is instantiated to define a toolchain configuration target. The
name of this target conventionally ends with _config.
A cc_toolchain target is instantiated with the appropriate attribute
values. The value of the toolchain_config attribute is set to the
config target which was instantiated in the previous step.
A toolchain target is instantiated with:
exec_compatible_with and target_compatible_with
constraint values.
exec_compatible_with must include
//nonstandard_toolchain:simple_cpp_toolchain.toolchain attribute, the cc_toolchain target which
was instantiated in the previous step.toolchain_type attribute value @rules_cc//cc:toolchain_type.The name of the toolchain target conventionally end with _toolchain.
This target provides the information which is needed by the general
toolchain mechanism of Bazel to perform platform-based toolchain resolution
on this toolchain.
The execution platforms are registered as described above in "Simple description of use".
The toolchain target is registered in the WORKSPACE file with
register_toolchains.
Build and test actions use the
--incompatible_enable_cc_toolchain_resolution flag. This flag can be
provided on the command line or through the use of a .bazelrc file.
The BUILD and WORKSPACE files of this repository serve as examples for this
process.
adambreland/cpp-simple_bazel_cpp_toolchain is a public repo on GitHub by adambreland. A Bazel C++ toolchain for building shared libraries and dependent binaries which conform to typical Linux linking practices.
It declares the MIT license on GitHub.
Its maker tagged it for Linux. That is declared by the maker; Take My Repo has not tested it.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2021-04-20. GitHub counts 0 open issues and pull requests. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Reverse engineer anything with agents, from app behavior down to native binaries.
🥑 Language focused docker images, minus the operating system.

A collection of inspiring lists, manuals, cheatsheets, blogs, hacks, one-liners, cli/web tools and more.

Tuist builds infrastructure for faster, more reliable build and test workflows across developers, CI, and coding agents. Shared cache, tests, and insights that sit alongside your existing CI.
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/adambreland/cpp-simple_bazel_cpp_toolchainTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.