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 {...@@ -114,7 +114,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {
114 var cflags = std.ArrayList([]const u8).init(arena);114 var cflags = std.ArrayList([]const u8).init(arena);
115115
116 if (target.os.tag == .windows or target.os.tag == .wasi) {116 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.
118 if (std.mem.startsWith(u8, cxx_src, "src/filesystem/"))118 if (std.mem.startsWith(u8, cxx_src, "src/filesystem/"))
119 continue;119 continue;
120 }120 }
...@@ -131,12 +131,18 @@ pub fn buildLibCXX(comp: *Compilation) !void {...@@ -131,12 +131,18 @@ pub fn buildLibCXX(comp: *Compilation) !void {
131 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");131 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
132 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");132 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
133 try cflags.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");133 try cflags.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");
134 try cflags.append("-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS");
135 try cflags.append("-fvisibility=hidden");134 try cflags.append("-fvisibility=hidden");
136 try cflags.append("-fvisibility-inlines-hidden");135 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) {
139 try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");142 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");
140 }146 }
141147
142 try cflags.append("-I");148 try cflags.append("-I");
...@@ -240,14 +246,29 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -240,14 +246,29 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
240246
241 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });247 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
242 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });248 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;252 for (libcxxabi_files) |cxxabi_src| {
245 for (libcxxabi_files) |cxxabi_src, i| {
246 var cflags = std.ArrayList([]const u8).init(arena);253 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
249 try cflags.append("-D_LIBCPP_DISABLE_EXTERN_TEMPLATE");271 try cflags.append("-D_LIBCPP_DISABLE_EXTERN_TEMPLATE");
250 try cflags.append("-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS");
251 try cflags.append("-D_LIBCXXABI_BUILDING_LIBRARY");272 try cflags.append("-D_LIBCXXABI_BUILDING_LIBRARY");
252 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");273 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
253 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");274 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
...@@ -272,10 +293,10 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -272,10 +293,10 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
272 try cflags.append("-funwind-tables");293 try cflags.append("-funwind-tables");
273 try cflags.append("-std=c++11");294 try cflags.append("-std=c++11");
274295
275 c_source_files[i] = .{296 c_source_files.appendAssumeCapacity(.{
276 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", cxxabi_src }),297 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", cxxabi_src }),
277 .extra_flags = cflags.items,298 .extra_flags = cflags.items,
278 };299 });
279 }300 }
280301
281 const sub_compilation = try Compilation.create(comp.gpa, .{302 const sub_compilation = try Compilation.create(comp.gpa, .{
...@@ -305,7 +326,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -305,7 +326,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
305 .is_native_os = comp.bin_file.options.is_native_os,326 .is_native_os = comp.bin_file.options.is_native_os,
306 .is_native_abi = comp.bin_file.options.is_native_abi,327 .is_native_abi = comp.bin_file.options.is_native_abi,
307 .self_exe_path = comp.self_exe_path,328 .self_exe_path = comp.self_exe_path,
308 .c_source_files = &c_source_files,329 .c_source_files = c_source_files.items,
309 .verbose_cc = comp.verbose_cc,330 .verbose_cc = comp.verbose_cc,
310 .verbose_link = comp.bin_file.options.verbose_link,331 .verbose_link = comp.bin_file.options.verbose_link,
311 .verbose_air = comp.verbose_air,332 .verbose_air = comp.verbose_air,
src/link/Wasm.zig+1
...@@ -719,6 +719,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -719,6 +719,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
719719
720 if (self.base.options.link_libcpp) {720 if (self.base.options.link_libcpp) {
721 try argv.append(comp.libcxx_static_lib.?.full_object_path);721 try argv.append(comp.libcxx_static_lib.?.full_object_path);
722 try argv.append(comp.libcxxabi_static_lib.?.full_object_path);
722 }723 }
723 }724 }
724 }725 }