authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-15 12:20:44+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-15 12:20:44+02:00
log7f9076c77124d9fdc10863e96f17b4ad36626ddb
treea2dc611423aa94f323799164d8cd9a69153fd3af
parentdb08d4c3d63cfee9da0e4c6825c906d4083e8303
parentfb0ecdbe1accdb8521fa3539101941a880216292

Merge branch 'mathetake-cpp-wasi'


2 files changed, 34 insertions(+), 10 deletions(-)

src/libcxx.zig+29-10
......@@ -113,11 +113,13 @@ pub fn buildLibCXX(comp: *Compilation) !void {
113113 for (libcxx_files) |cxx_src| {
114114 var cflags = std.ArrayList([]const u8).init(arena);
115115
116 if (target.os.tag == .windows) {
117 // Filesystem stuff isn't supported on Windows.
116 if (target.os.tag == .windows or target.os.tag == .wasi) {
117 // Filesystem stuff isn't supported on WASI and Windows.
118118 if (std.mem.startsWith(u8, cxx_src, "src/filesystem/"))
119119 continue;
120 } else {
120 }
121
122 if (target.os.tag != .windows) {
121123 if (std.mem.startsWith(u8, cxx_src, "src/support/win32/"))
122124 continue;
123125 }
......@@ -129,7 +131,6 @@ pub fn buildLibCXX(comp: *Compilation) !void {
129131 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
130132 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
131133 try cflags.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");
132 try cflags.append("-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS");
133134 try cflags.append("-fvisibility=hidden");
134135 try cflags.append("-fvisibility-inlines-hidden");
135136
......@@ -137,6 +138,12 @@ pub fn buildLibCXX(comp: *Compilation) !void {
137138 try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
138139 }
139140
141 if (target.os.tag == .wasi) {
142 // WASI doesn't support thread and exception yet.
143 try cflags.append("-D_LIBCPP_HAS_NO_THREADS");
144 try cflags.append("-fno-exceptions");
145 }
146
140147 try cflags.append("-I");
141148 try cflags.append(cxx_include_path);
142149
......@@ -238,12 +245,24 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
238245
239246 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
240247 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
248 var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
249 try c_source_files.ensureCapacity(libcxxabi_files.len);
241250
242 var c_source_files: [libcxxabi_files.len]Compilation.CSourceFile = undefined;
243 for (libcxxabi_files) |cxxabi_src, i| {
251 for (libcxxabi_files) |cxxabi_src| {
244252 var cflags = std.ArrayList([]const u8).init(arena);
245253
246 try cflags.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL");
254 if (target.os.tag == .wasi) {
255 // WASI doesn't support thread and exception yet.
256 if (std.mem.startsWith(u8, cxxabi_src, "src/cxa_thread_atexit.cpp") or
257 std.mem.startsWith(u8, cxxabi_src, "src/cxa_exception.cpp") or
258 std.mem.startsWith(u8, cxxabi_src, "src/cxa_personality.cpp"))
259 continue;
260 try cflags.append("-D_LIBCXXABI_HAS_NO_THREADS");
261 try cflags.append("-fno-exceptions");
262 } else {
263 try cflags.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL");
264 }
265
247266 try cflags.append("-D_LIBCPP_DISABLE_EXTERN_TEMPLATE");
248267 try cflags.append("-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS");
249268 try cflags.append("-D_LIBCXXABI_BUILDING_LIBRARY");
......@@ -270,10 +289,10 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
270289 try cflags.append("-funwind-tables");
271290 try cflags.append("-std=c++11");
272291
273 c_source_files[i] = .{
292 c_source_files.appendAssumeCapacity(.{
274293 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", cxxabi_src }),
275294 .extra_flags = cflags.items,
276 };
295 });
277296 }
278297
279298 const sub_compilation = try Compilation.create(comp.gpa, .{
......@@ -303,7 +322,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
303322 .is_native_os = comp.bin_file.options.is_native_os,
304323 .is_native_abi = comp.bin_file.options.is_native_abi,
305324 .self_exe_path = comp.self_exe_path,
306 .c_source_files = &c_source_files,
325 .c_source_files = c_source_files.items,
307326 .verbose_cc = comp.verbose_cc,
308327 .verbose_link = comp.bin_file.options.verbose_link,
309328 .verbose_air = comp.verbose_air,
src/link/Wasm.zig+5
......@@ -716,6 +716,11 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
716716 ));
717717 try argv.append(try comp.get_libc_crt_file(arena, "libc.a"));
718718 }
719
720 if (self.base.options.link_libcpp) {
721 try argv.append(comp.libcxx_static_lib.?.full_object_path);
722 try argv.append(comp.libcxxabi_static_lib.?.full_object_path);
723 }
719724 }
720725 }
721726