unify main entry point regardless of whether linking libc

closes #248
This commit is contained in:
Andrew Kelley
2017-03-22 11:26:30 -04:00
parent e1c47d6fe8
commit 87bc97daef
12 changed files with 86 additions and 57 deletions

View File

@@ -1,17 +1,16 @@
// This file is in a package which has the root source file exposed as "@root".
// It is included in the compilation unit when exporting an executable.
const root = @import("@root");
const std = @import("std");
const want_start_symbol = switch(@compileVar("os")) {
Os.linux => true,
else => false,
};
const want_main_symbol = !want_start_symbol;
const want_main_symbol = std.build.linkingLibrary("c");
const want_start_symbol = !want_main_symbol;
const exit = switch(@compileVar("os")) {
Os.linux => std.linux.exit,
Os.darwin => std.darwin.exit,
else => @compileError("Unsupported OS"),
};
var argc: usize = undefined;

13
std/build.zig Normal file
View File

@@ -0,0 +1,13 @@
const mem = @import("mem.zig");
pub fn linkingLibrary(lib_name: []const u8) -> bool {
// TODO shouldn't need this if
if (@compileVar("link_libs").len != 0) {
for (@compileVar("link_libs")) |link_lib| {
if (mem.eql(u8, link_lib, lib_name)) {
return true;
}
}
}
return false;
}

View File

@@ -1,3 +1,4 @@
pub const build = @import("build.zig");
pub const cstr = @import("cstr.zig");
pub const debug = @import("debug.zig");
pub const fmt = @import("fmt.zig");

View File

@@ -7,7 +7,7 @@ const TestFn = struct {
extern var zig_test_fn_list: []TestFn;
pub fn runTests() -> %void {
pub fn main(args: [][]u8) -> %void {
for (zig_test_fn_list) |testFn, i| {
%%io.stderr.printf("Test {}/{} {}...", i + 1, zig_test_fn_list.len, testFn.name);

View File

@@ -1,6 +0,0 @@
const test_runner = @import("test_runner.zig");
export fn main(argc: c_int, argv: &&u8) -> c_int {
test_runner.runTests() %% return -1;
return 0;
}

View File

@@ -1,5 +0,0 @@
const test_runner = @import("test_runner.zig");
pub fn main(args: [][]u8) -> %void {
return test_runner.runTests();
}