Skip to content

Toolchain customization#3

Open
oliverlee wants to merge 1 commit intoagoessling:masterfrom
oliverlee:toolchain-customization
Open

Toolchain customization#3
oliverlee wants to merge 1 commit intoagoessling:masterfrom
oliverlee:toolchain-customization

Conversation

@oliverlee
Copy link
Copy Markdown
Contributor

No description provided.

@oliverlee oliverlee force-pushed the toolchain-customization branch from 14d2e8c to 3647c6f Compare January 12, 2023 02:51
@oliverlee
Copy link
Copy Markdown
Contributor Author

I had to make some changes to the link line in order for any of my tests to run. I added directories based on the libraries I use but perhaps I'm missing some (or there is a better approach).

@oliverlee oliverlee force-pushed the toolchain-customization branch 3 times, most recently from 29975c2 to 423763d Compare January 12, 2023 19:30
@oliverlee oliverlee force-pushed the toolchain-customization branch from 423763d to 0644fa2 Compare January 12, 2023 20:22
@agoessling
Copy link
Copy Markdown
Owner

@oliverlee thanks for this contribution! Could you provide some context on the motivation for this addition (intended use case) as well as some context around the implementation? I've been away from this repo for a while (although depending on it daily) and it would help me review it effectively.

@oliverlee
Copy link
Copy Markdown
Contributor Author

I'm currently working with a number of repositories that all share a common tooling dependency that defines and registers toolchains. Some of the changes are motivated by wanting to reduce the amount of boilerplate that needs to be written and updated for downstream repositories.

I'd like to set up multiple hermetic toolchains for a project (e.g. both GCC and Clang compilers) without needing to set copts for cc targets and without needing to define a number of configurations in a .bazelrc that define cxxopts.

While a lot of compiler options work for both GCC and Clang, there are some that are GCC or Clang specific so I'd like to avoid needing to use select with copts.

I'd also like registration of the bootlin toolchain to allow use without needing to manually specify a platform (e.g. I'm using a linux machine in CI that doesn't have C++ toolchains installed and toolchain registration picks up the bootlin toolchain as it is the only one satisfying host/target exec constraints).

Currently I have something that looks like:

# @tooling//:defs.bzl

def register_toolchains(...):
    register_bootlin_toolchain(...) # e.g. gcc 11, linux, x86-64
    register_bootlin_toolchain(...) # e.g. gcc 10, linux, x86-64
    ...
    register_llvm_toolchain(...)
    register_llvm_toolchain(...)
    ...
    # other toolchains

where gcc11 toolchains are configured to use options that aren't available in older GCC versions or that aren't available with Clang (e.g. -Wctad-maybe-unsupported or -Wuseless-cast).

This is used in the WORKSPACE.bazel of a downstream project. With some aliases, the compiler version can be explicitly selected at the command line with

bazel build //... --extra_toolchains=@tooling//:llvm
bazel build //... --extra_toolchains=@tooling//:gcc
bazel build //... --extra_toolchains=@tooling//:gcc11
bazel build //... --extra_toolchains=@tooling//:gcc9

Also this PR is a work in progress as there are some issues with the current commit (eager fetching, wrong host cpu).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants