Skip to content

Commit

Permalink
libcxx: fix C++ builds with glibc <2.16 without aligned_alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Tywoniak authored and andrewrk committed Jan 19, 2024
1 parent 9b714e0 commit b80cad2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/libcxx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
}

if (target.isGnuLibC()) {
// glibc 2.16 introduced aligned_alloc
if (target.os.version_range.linux.glibc.order(.{ .major = 2, .minor = 16, .patch = 0 }) == .lt) {
try cflags.append("-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION");
}
}

if (target.os.tag == .wasi) {
// WASI doesn't support exceptions yet.
try cflags.append("-fno-exceptions");
Expand Down Expand Up @@ -433,6 +440,13 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
}

if (target.isGnuLibC()) {
// glibc 2.16 introduced aligned_alloc
if (target.os.version_range.linux.glibc.order(.{ .major = 2, .minor = 16, .patch = 0 }) == .lt) {
try cflags.append("-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION");
}
}

if (target_util.supports_fpic(target)) {
try cflags.append("-fPIC");
}
Expand Down

0 comments on commit b80cad2

Please sign in to comment.