Commit c6a18e9534

Alex Rønne Petersen <alex@alexrp.com>
2025-07-13 22:58:54
libcxx: fix building for wasm32-wasi by disabling exceptions
I accidentally regressed this in the LLVM 20 upgrade. Closes #24437.
1 parent 5696bbb
Changed files (1)
src
src/libs/libcxx.zig
@@ -211,6 +211,10 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
         try cflags.append("-DLIBCXX_BUILDING_LIBCXXABI");
         try cflags.append("-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER");
 
+        if (target.os.tag == .wasi) {
+            try cflags.append("-fno-exceptions");
+        }
+
         try cflags.append("-fvisibility=hidden");
         try cflags.append("-fvisibility-inlines-hidden");
 
@@ -388,6 +392,9 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
     for (libcxxabi_files) |cxxabi_src| {
         if (!comp.config.any_non_single_threaded and std.mem.startsWith(u8, cxxabi_src, "src/cxa_thread_atexit.cpp"))
             continue;
+        if (target.os.tag == .wasi and
+            (std.mem.eql(u8, cxxabi_src, "src/cxa_exception.cpp") or std.mem.eql(u8, cxxabi_src, "src/cxa_personality.cpp")))
+            continue;
 
         var cflags = std.ArrayList([]const u8).init(arena);
 
@@ -403,6 +410,10 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
                 try cflags.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL");
         }
 
+        if (target.os.tag == .wasi) {
+            try cflags.append("-fno-exceptions");
+        }
+
         try cflags.append("-fvisibility=hidden");
         try cflags.append("-fvisibility-inlines-hidden");