Skip to content

Conversation

@chandlerc
Copy link
Contributor

@chandlerc chandlerc commented Nov 24, 2025

This builds on the previous work to flesh out more on-demand runtimes
building. It adds building of the libc++.a archive runtime.

A number of changes are required for this to work:

  • The runtimes build infrastructure needs to support building sources
    from multiple parts of LLVM rather than a single part. We do this by
    lifting the root of the runtimes source paths up a level to a common
    runtimes tree, and installing the runtimes sources below this
    directory.

  • Both libc++ and libc++abi runtimes sources need to be installed, and
    we even need to install some interesting parts of llvm-libc that are
    used in the build of libc++.

  • We need to generate the site configuration header file for libc++ from
    the CMake template. This includes both setting up a set of
    platform-independent defines and introducing some basic Bazel support
    for processing the CMake template itself.

Doing all of this also exposed some missing features and limitations of
the runtimes building infrastructure that are addressed here.

One note is that all of this just adds libc++ to the explicit
build-runtimes command for testing. It doesn't yet trigger
automatically building these prior to linking, or configuring any of the
other subcommands to automatically use these runtimes. All of that will
come in follow-up PRs.

Also, this makes the clang_runtimes_test ... very slow in our
default build configuration. Compiling libc++, even with many threads on
a large Linux server requires up to 50 seconds. I'm open to any
suggestions on how to handle this, including disabling the test in
non-optimized builds. I have some ideas to speed this up, but
fundamentally building libc++ is... not cheap.

I did look at some of the existing Bazel tools to process the CMake
template, but they all seemed significantly more complex than what we
need and didn't have broad adoption. Given that, it seemed slightly
better to just roll our own given the simple format.

Two of the new LLVM patch are currently under review upstream and so
hopefully temporary:

Comment on lines 176 to 185
# We can inject custom logic at the end of the site configuration with
# the ABI defines. This can custom set (or re-set) any of the relevant
# configuration defines. Note that while this is sorted here in the
# BUILD file, it is expanded at the _end_ of the configuration header
# and so overrides the other configuration settings.
"_LIBCPP_ABI_DEFINES": "\n".join([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a fairly large chunk of C++ code to be including in a build rule. Would it make sense to move the contents of _LIBCPP_ABI_DEFINES out into a separate header file and add a #include here instead?

(Admittedly that only helps a little, as the remaining cmake defines are equally large.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit torn about this...

On one hand, separating out seems much cleaner as the C++ code is no longer embedded in a BUILD file.

On the other hand, there are complex interactions between this C++ code and the defines here, and moving those further apart seems unfortunate.

But seems worth exploring in a follow-up. I've left a TODO to document that this should be revisited and I'll prep a PR we can look at concretely.

Copy link
Contributor Author

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review, merging!

Will send follow-ups to tidy up TODOs and the next steps.

Comment on lines 176 to 185
# We can inject custom logic at the end of the site configuration with
# the ABI defines. This can custom set (or re-set) any of the relevant
# configuration defines. Note that while this is sorted here in the
# BUILD file, it is expanded at the _end_ of the configuration header
# and so overrides the other configuration settings.
"_LIBCPP_ABI_DEFINES": "\n".join([
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit torn about this...

On one hand, separating out seems much cleaner as the C++ code is no longer embedded in a BUILD file.

On the other hand, there are complex interactions between this C++ code and the defines here, and moving those further apart seems unfortunate.

But seems worth exploring in a follow-up. I've left a TODO to document that this should be revisited and I'll prep a PR we can look at concretely.

@chandlerc chandlerc enabled auto-merge November 25, 2025 04:08
This builds on the previous work to flesh out more on-demand runtimes
building. It adds building of the `libc++.a` archive runtime.

A number of changes are required for this to work:

- The runtimes build infrastructure needs to support building sources
  from multiple parts of LLVM rather than a single part. We do this by
  lifting the root of the runtimes source paths up a level to a common
  runtimes tree, and installing the runtimes sources below this
  directory.

- Both libc++ and libc++abi runtimes sources need to be installed, and
  we even need to install some interesting parts of llvm-libc that are
  used in the build of libc++.

- We need to generate the site configuration header file for libc++ from
  the CMake template. This includes both setting up a set of
  platform-independent defines and introducing some basic Bazel support
  for processing the CMake template itself.

Doing all of this also exposed some missing features and limitations of
the runtimes building infrastructure that are addressed here.

One note is that all of this just adds libc++ to the explicit
`build-runtimes` command for testing. It doesn't yet trigger
automatically building these prior to linking, or configuring any of the
other subcommands to automatically use these runtimes. All of that will
come in follow-up PRs.

Also, this makes the `clang_runtimes_test` ... _very_ slow in our
default build configuration. Compiling libc++, even with many threads on
a large Linux server requires up to 50 seconds. I'm open to any
suggestions on how to handle this, including disabling the test in
non-optimized builds. I have some ideas to speed this up, but
fundamentally building libc++ is... not cheap.

I did look at some of the existing Bazel tools to process the CMake
template, but they all seemed significantly more complex than what we
need and didn't have broad adoption. Given that, it seemed slightly
better to just roll our own given the simple format.

The second new LLVM patch is currently under review upstream and so
hopefully temporary: llvm/llvm-project#169155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants