<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63888>63888</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            LIBCXX_ENABLE_STATIC_ABI_LIBRARY almost not working
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          haruomaki
      </td>
    </tr>
</table>

<pre>
    # Summary

The build option `LIBCXX_ENABLE_STATIC_ABI_LIBRARY` is actually almost out of order. It is observed in the two cases.
 
1. When building libc++ directly, `LIBCXX_ENABLE_STATIC_ABI_LIBRARY` works properly **only at first-time configuration**.
2. When doing the bootstrapping build (with `LLVM_ENABLE_RUNTIMES`), **the option doesn't have any effect**.

# Detail
I tested what is going on in `libcxx/CMakeLists.txt` dumping `LIBCXX_ENABLE_STATIC_ABI_LIBRARY`, `LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY`, and `LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY`.

https://github.com/haruomaki/llvm-project/blob/c49a926cbebce480dc880cb762a26b1c998c9bca/libcxx/CMakeLists.txt#L230

The output format is `BOOL BOOL BOOL`. If `LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY` (displayed second) is `ON`, libc++abi is going to be linked to libc++.a statically. `LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY` (displayed third) asserted means that libc++abi will be linked to libc++.so statically.

## 1. Direct build

For the first time, run `cmake -G Ninja -S runtimes -B build-libcxx -DCMAKE_BUILD_TYPE='RelWithDebInfo' -DCMAKE_C_COMPILER='/usr/bin/clang' -DCMAKE_CXX_COMPILER='/usr/bin/clang++
' -DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi;libunwind' -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON && cmake --build build-libcxx`, and

```
🥺🥺🥺🥺🥺 ON ON ON
```

will be shown. It's fine.

Then, run `cmake -S runtimes -B build-libcxx -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=OFF && cmake --build build-libcxx`. The result is

```
🥺🥺🥺🥺🥺 OFF ON ON
```

. This is not desirable. It should have been `OFF OFF OFF`.

## 2. Bootstrapping build

Run the below build command. (Sorry for being very long. Make sure it contains `-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON`.)

```bash
cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE='RelWithDebInfo' -DCMAKE_C_COMPILER='/usr/bin/clang' -DCMAKE_CXX_COMPILER='/usr/bin/clang++' -DLLVM_DEFAULT_TARGET_TRIPLE='x86_64-pc-linux-gnu' -DCMAKE_INSTALL_PREFIX='/opt/clang17' -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra' -DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind' -DLLVM_CCACHE_BUILD=ON -DLLVM_USE_SPLIT_DWARF=ON -DLLVM_OPTIMIZED_TABLEGEN=ON -DBUILD_SHARED_LIBS=ON -DLLVM_TARGETS_TO_BUILD='X86' -DLLVM_ENABLE_LLD=ON -DCLANG_DEFAULT_LINKER='lld' -DCLANG_DEFAULT_CXX_STDLIB='libc++' -DCLANG_DEFAULT_RTLIB='compiler-rt' -DCLANG_DEFAULT_UNWINDLIB='libunwind' -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON -DLIBCXX_USE_COMPILER_RT=ON -DLIBCXXABI_USE_COMPILER_RT=ON -DLIBCXXABI_USE_LLVM_UNWINDER=ON -DLIBUNWIND_USE_COMPILER_RT=ON && cmake --build build
```

The dumping output is 

```
🥺🥺🥺🥺🥺 ON OFF OFF
```

even though `-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON` is in. It should have been `ON ON ON`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV1tvozwT_jXOjRVETErCRS7IgS7f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