authorgravatar for takeshi@tetrate.ioTakeshi Yoneda <takeshi@tetrate.io> 2021-06-15 01:03:25+09:00
committergravatar for takeshi@tetrate.ioTakeshi Yoneda <takeshi@tetrate.io> 2021-06-15 01:03:25+09:00
logbc64664a0cb3dab4374e1053fb765872765f848c
treeee24cae9c3de9c24ea0b1d6f12a7fdbaac02dda4
parentc708962386017da349736e25dc689c94b73df251

add various flags/options, and link libcxxabi.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>

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

src/libcxx.zig+31-10
......@@ -114,7 +114,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {
114114 var cflags = std.ArrayList([]const u8).init(arena);
115115
116116 if (target.os.tag == .windows or target.os.tag == .wasi) {
117 // Filesystem stuff isn't supported on Windows and WASI.
117 // Filesystem stuff isn't supported on WASI and Windows.
118118 if (std.mem.startsWith(u8, cxx_src, "src/filesystem/"))
119119 continue;
120120 }
......@@ -131,12 +131,18 @@ pub fn buildLibCXX(comp: *Compilation) !void {
131131 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
132132 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
133133 try cflags.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");
134 try cflags.append("-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS");
135134 try cflags.append("-fvisibility=hidden");
136135 try cflags.append("-fvisibility-inlines-hidden");
137136
138 if (target.abi.isMusl() or target.os.tag == .wasi) {
137 if (target.abi.isMusl()) {
138 try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
139 }
140
141 if (target.os.tag == .wasi) {
139142 try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
143 try cflags.append("-D_LIBCPP_HAS_NO_THREADS");
144 try cflags.append("-D_LIBCPP_ABI_VERSION=2");
145 try cflags.append("-fno-exceptions");
140146 }
141147
142148 try cflags.append("-I");
......@@ -240,14 +246,29 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
240246
241247 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
242248 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
249 var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
250 try c_source_files.ensureCapacity(libcxxabi_files.len);
243251
244 var c_source_files: [libcxxabi_files.len]Compilation.CSourceFile = undefined;
245 for (libcxxabi_files) |cxxabi_src, i| {
252 for (libcxxabi_files) |cxxabi_src| {
246253 var cflags = std.ArrayList([]const u8).init(arena);
247254
248 try cflags.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL");
255 if (target.os.tag == .wasi) {
256 if (std.mem.startsWith(u8, cxxabi_src, "src/cxa_thread_atexit.cpp"))
257 continue;
258
259 if (std.mem.startsWith(u8, cxxabi_src, "src/cxa_exception.cpp"))
260 continue;
261
262 if (std.mem.startsWith(u8, cxxabi_src, "src/cxa_personality.cpp"))
263 continue;
264
265 try cflags.append("-fno-exceptions");
266 } else {
267 try cflags.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL");
268 try cflags.append("-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS");
269 }
270
249271 try cflags.append("-D_LIBCPP_DISABLE_EXTERN_TEMPLATE");
250 try cflags.append("-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS");
251272 try cflags.append("-D_LIBCXXABI_BUILDING_LIBRARY");
252273 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
253274 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
......@@ -272,10 +293,10 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
272293 try cflags.append("-funwind-tables");
273294 try cflags.append("-std=c++11");
274295
275 c_source_files[i] = .{
296 c_source_files.appendAssumeCapacity(.{
276297 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", cxxabi_src }),
277298 .extra_flags = cflags.items,
278 };
299 });
279300 }
280301
281302 const sub_compilation = try Compilation.create(comp.gpa, .{
......@@ -305,7 +326,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
305326 .is_native_os = comp.bin_file.options.is_native_os,
306327 .is_native_abi = comp.bin_file.options.is_native_abi,
307328 .self_exe_path = comp.self_exe_path,
308 .c_source_files = &c_source_files,
329 .c_source_files = c_source_files.items,
309330 .verbose_cc = comp.verbose_cc,
310331 .verbose_link = comp.bin_file.options.verbose_link,
311332 .verbose_air = comp.verbose_air,
src/link/Wasm.zig+1
......@@ -719,6 +719,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
719719
720720 if (self.base.options.link_libcpp) {
721721 try argv.append(comp.libcxx_static_lib.?.full_object_path);
722 try argv.append(comp.libcxxabi_static_lib.?.full_object_path);
722723 }
723724 }
724725 }