aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-05-15 16:20:16 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-05-15 20:14:58 -0400
commit14cdb01f35b35972b06e95a3a438f9f7910b97f8 (patch)
tree652a48bb218b86c581ebe7c747167c47a0236541 /std
parent3aa43dc31c468b2f80bf065f850618a981c5fca2 (diff)
downloadzig-14cdb01f35b35972b06e95a3a438f9f7910b97f8.tar.gz
zig-14cdb01f35b35972b06e95a3a438f9f7910b97f8.zip
improvements to zig's implementation of libc and WebAssembly
* rename std/special/builtin.zig to std/special/c.zig not to be confused with @import("builtin") which is entirely different, this is zig's multi-target libc implementation. * WebAssembly: build-exe is for executables which have a main(). build-lib is for building libraries of functions to use from, for example, a web browser environment. - for now pass --export-all for libraries when there are any C objects because we have no way to detect the list of exports when compiling C code. - stop passing --no-entry for executables. if you want --no-entry then use build-lib. * make the "musl" ABI the default ABI for wasm32-freestanding. * zig provides libc for wasm32-freestanding-musl.
Diffstat (limited to 'std')
-rw-r--r--std/special/c.zig (renamed from std/special/builtin.zig)20
1 files changed, 18 insertions, 2 deletions
diff --git a/std/special/builtin.zig b/std/special/c.zig
index 3776cc22bf..d5de52a6a3 100644
--- a/std/special/builtin.zig
+++ b/std/special/c.zig
@@ -1,10 +1,26 @@
-// These functions are provided when not linking against libc because LLVM
-// sometimes generates code that calls them.
+// This is Zig's multi-target implementation of libc.
+// When builtin.link_libc is true, we need to export all the functions and
+// provide an entire C API.
+// Otherwise, only the functions which LLVM generates calls to need to be generated,
+// such as memcpy, memset, and some math functions.
const std = @import("std");
const builtin = @import("builtin");
const maxInt = std.math.maxInt;
+const is_wasm = switch (builtin.arch) { .wasm32, .wasm64 => true, else => false};
+const is_freestanding = switch (builtin.os) { .freestanding => true, else => false };
+comptime {
+ if (is_freestanding and is_wasm) {
+ @export("_start", wasm_start, .Strong);
+ }
+}
+
+extern fn main(argc: c_int, argv: [*][*]u8) c_int;
+extern fn wasm_start() c_int {
+ return main(0, undefined);
+}
+
// Avoid dragging in the runtime safety mechanisms into this .o file,
// unless we're trying to test this file.
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {