Skip to content

Commit 414fb6f

Browse files
authored
0.9.2 --- a standard header compiles for every target, not only Linux (#17)
libc++'s musl locale support calls strtof_l, strtod_l, strtold_l and vasprintf, which musl declares only under _GNU_SOURCE. Clang predefines _GNU_SOURCE for C++ on Linux targets only, so any consumer translation unit that includes a standard header (every module wrapper of a header library does) failed for macOS and Windows. __config_site now states _GNU_SOURCE, and CI cross-builds examples/cxx, which includes <filesystem>, for both targets.
1 parent d4c88df commit 414fb6f

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,26 @@ jobs:
331331
file "$RUNNER_TEMP/cross/openkal-same-source.exe" | grep -q 'PE32+ executable'
332332
file "$RUNNER_TEMP/cross/openkal-same-source" | grep -q 'Mach-O 64-bit arm64'
333333
334+
# ⭐ AND A TRANSLATION UNIT THAT INCLUDES A STANDARD HEADER, FOR THE SAME TWO.
335+
#
336+
# `same-source` imports std, and the std module is compiled with this
337+
# package's own flags, so it cannot see what a consumer's translation unit
338+
# sees. `examples/cxx` includes <filesystem> the way every module wrapper
339+
# of a header library does, and that path reaches libc++'s musl locale
340+
# support, which calls strtof_l and vasprintf. musl declares those only
341+
# under _GNU_SOURCE, and Clang predefines _GNU_SOURCE for C++ on Linux
342+
# targets alone -- so this example ran on Linux and did not compile for
343+
# either of these targets until __config_site stated it.
344+
- name: A standard header, built here for Windows and for macOS
345+
if: matrix.toolchain == 'llvm@22.1.8'
346+
run: |
347+
set -euo pipefail
348+
cd examples/cxx
349+
for t in x86_64-windows-gnu aarch64-macos; do
350+
rm -rf target
351+
mcpp build --target "$t"
352+
done
353+
334354
- uses: actions/upload-artifact@v4
335355
if: matrix.toolchain == 'llvm@22.1.8'
336356
with:

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,18 @@ position in it is a **claim about the environment beneath**:
3939
#define _LIBCPP_HAS_RANDOM_DEVICE 1 /* openkal.random reaches a source */
4040
#define _LIBCPP_HAS_FILESYSTEM 1 /* openkal.fs, and its sources built */
4141
#define _LIBCPP_HAS_TERMINAL 1 /* isatty answers, rather than lying */
42+
#define _GNU_SOURCE 1 /* musl's GNU interfaces, on every target */
4243
```
4344
45+
The last line is not a libc++ switch, and it is here for the same reason as the
46+
others. This configuration's locale support calls `strtof_l`, `strtod_l`,
47+
`strtold_l` and `vasprintf`, which musl declares only under `_GNU_SOURCE`.
48+
Clang predefines `_GNU_SOURCE` for C++ on Linux targets and on no other, so a
49+
translation unit that includes a standard header — which is what every module
50+
wrapper of a header library does — built for Linux and failed for macOS and
51+
Windows with `no member named 'strtof_l' in the global namespace`. Stating it
52+
in the configuration gives every target what the Linux target already had.
53+
4454
The first was measured rather than assumed. With it at `0` — the value a
4555
toolchain configured for glibc ships — a translation unit that includes
4656
`<vector>` fails with twenty errors, of which the first names the cause:

llvm-generated/generic/__config_site

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
#ifndef _LIBCPP___CONFIG_SITE
1010
#define _LIBCPP___CONFIG_SITE
1111

12+
// openkal: the C library beneath is musl, and this configuration's locale
13+
// support (__locale_dir/support/linux.h) calls strtof_l, strtod_l, strtold_l and
14+
// vasprintf, which musl declares only under _GNU_SOURCE. Clang predefines
15+
// _GNU_SOURCE for C++ on Linux targets and on no other, so a translation unit
16+
// that includes a standard header -- as every module wrapper of a header
17+
// library does -- compiled for the Linux target and failed for the macOS and
18+
// Windows targets. Stating it here gives every target the environment the
19+
// Linux target already had; this header is included before any C header.
20+
#ifndef _GNU_SOURCE
21+
# define _GNU_SOURCE 1
22+
#endif
23+
1224
#define _LIBCPP_ABI_VERSION 1
1325
#define _LIBCPP_ABI_NAMESPACE __1
1426
#define _LIBCPP_ABI_FORCE_ITANIUM 0

mcpp.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
namespace = "mcpplibs"
33
name = "openkal-llvm-runtime"
4-
version = "0.9.1"
4+
version = "0.9.2"
55
description = "LLVM's C++ runtime libraries — libc++, libc++abi and libunwind — configured for openkal-musl rather than for a host C library."
66
license = "Apache-2.0"
77
authors = ["mcpplibs"]

0 commit comments

Comments
 (0)