C++ Logo


Advanced search

Re: Packaging: Where should "library interface object files" live?

From: Ben Boeckel <ben.boeckel_at_[hidden]>
Date: Sun, 25 Feb 2024 09:11:39 -0500
On Sun, Feb 18, 2024 at 10:32:22 +0800, Chuanqi Xu via SG15 wrote:
> The reason/history why the object file of `std.cppm` of libc++ is
> produced on the consumer's side is that: when we (clang/libc++ guys)
> don't have an idea how this should happen, Ben (cmake developer)
> pointed out this should be the job of the cmake (or build systems) and
> the standard library is able to distribute the source files only.
> So my understanding to the issue is: this is more specific to std
> modules instead of the general cases.

It is the job of the build system to compile the *BMI* for consumers.
The object should be provided by the provider of the module interface.
This avoids trying to figure out which version of the initializer should
be used.

Note that if there are different ABIs for different options, it can be
done doing something like (untested, but I don't see why this couldn't

add_library(libc++-modules-variantA OBJECT)
target_sources(libc++modules-variantA …)
target_compile_options(libc++modules-variantA PRIVATE …)

add_library(libc++-modules-variantB OBJECT)
target_sources(libc++modules-variantB …)
target_compile_options(libc++modules-variantB PRIVATE …)

target_link_libraries(libc++ PRIVATE # probably want `libc++experimental for now
  # The `PROJECT_LOCAL_INTERFACE` avoids the targets from showing up in
  # the exported bits of `libc++` itself.

Note that this does require the variant set to be relatively small
(which I don't see how it wouldn't be as the ABI mangling logic would be
similarly "small").

If *this* has problems with duplicate symbols, I don't see how consumers
are going to cope with it via consumer-side object generation.

Note that even when I end up supporting per-consumer-usage-hash BMIs in
CMake, I'm *still* only going to have a single object compilation to
rely upon without generating those `-variant*` targets like above…at
which point it's just easier for the compiler to provide it because it
knows the set of variants that are possible/supported. CMake providing
it means that new variants require a CMake update to use which


Received on 2024-02-25 14:11:41