authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-04 15:30:22-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-04 15:30:22-05:00
logd008e209e7446311bda1b555284978dfabb91308
tree0e2fd31e36f0db7eaf431ca92bd621919b5a508c
parente1c03d9e8eb52b489d9b47bbe2f12cacac8a999f

self-hosted compiler works on macos


5 files changed, 24 insertions(+), 21 deletions(-)

README.md+1-2
......@@ -154,8 +154,7 @@ make install
154154`ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_STATIC_LIB_DIR` are unused.
155155
156156```
157brew install cmake
158brew install llvm@5
157brew install cmake llvm@5
159158brew outdated llvm@5 || brew upgrade llvm@5
160159mkdir build
161160cd build
build.zig+3-1
......@@ -66,12 +66,14 @@ pub fn build(b: &Builder) {
6666 }
6767 dependOnLib(exe, llvm);
6868
69 if (!exe.target.isWindows()) {
69 if (exe.target.getOs() == builtin.Os.linux) {
7070 const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"});
7171 const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next();
7272 exe.addObjectFile(libstdcxx_path);
7373
7474 exe.linkSystemLibrary("pthread");
75 } else if (exe.target.isDarwin()) {
76 exe.linkSystemLibrary("c++");
7577 }
7678
7779 exe.linkSystemLibrary("c");
ci/travis_osx_script+1-14
......@@ -9,17 +9,4 @@ cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@5/ -DCMAKE_INSTALL_PREFIX=$(pwd
99make VERBOSE=1
1010make install
1111
12# TODO: we run the tests separately because when run all together there is some
13# mysterious issue where after N child process spawns it crashes. I've been
14# unable to reproduce the issue on my macbook - it only happens on Travis.
15# ./zig build --build-file ../build.zig test
16
17./zig build --build-file ../build.zig test-behavior --verbose
18./zig build --build-file ../build.zig test-std --verbose
19./zig build --build-file ../build.zig test-compiler-rt --verbose
20./zig build --build-file ../build.zig test-compare-output --verbose
21./zig build --build-file ../build.zig test-build-examples --verbose
22./zig build --build-file ../build.zig test-compile-errors --verbose
23./zig build --build-file ../build.zig test-asm-link --verbose
24./zig build --build-file ../build.zig test-debug-safety --verbose
25./zig build --build-file ../build.zig test-translate-c --verbose
12./zig build --build-file ../build.zig test
std/c/darwin.zig+2
......@@ -1,4 +1,6 @@
11extern "c" fn __error() -> &c_int;
2pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) -> c_int;
3
24
35pub use @import("../os/darwin_errno.zig");
46
std/os/index.zig+17-4
......@@ -1553,10 +1553,12 @@ pub fn openSelfExe() -> %io.File {
15531553pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {
15541554 switch (builtin.os) {
15551555 Os.linux => {
1556 @compileError("TODO: selfExePath for linux");
1556 // If the currently executing binary has been deleted,
1557 // the file path looks something like `/a/b/c/exe (deleted)`
1558 return readLink(allocator, "/proc/self/exe");
15571559 },
15581560 Os.windows => {
1559 var out_path = %return Buffer.initSize(allocator, 256);
1561 var out_path = %return Buffer.initSize(allocator, 0xff);
15601562 %defer out_path.deinit();
15611563 while (true) {
15621564 const dword_len = %return math.cast(windows.DWORD, out_path.len());
......@@ -1571,9 +1573,20 @@ pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {
15711573 out_path.shrink(copied_amt);
15721574 return out_path.toOwnedSlice();
15731575 }
1574 %return out_path.resize(out_path.len() * 2);
1576 const new_len = (%return math.shlExact(out_path.len(), 1)) | 0b1;
1577 %return out_path.resize(new_len);
15751578 }
15761579 },
1580 Os.darwin, Os.macosx, Os.ios => {
1581 var u32_len: u32 = 0;
1582 const ret1 = c._NSGetExecutablePath(undefined, &u32_len);
1583 assert(ret1 != 0);
1584 const bytes = %return allocator.alloc(u8, u32_len);
1585 %defer allocator.free(bytes);
1586 const ret2 = c._NSGetExecutablePath(bytes.ptr, &u32_len);
1587 assert(ret2 == 0);
1588 return bytes;
1589 },
15771590 else => @compileError("Unsupported OS"),
15781591 }
15791592}
......@@ -1592,7 +1605,7 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
15921605 const dir = path.dirname(full_exe_path);
15931606 return allocator.shrink(u8, full_exe_path, dir.len);
15941607 },
1595 Os.windows => {
1608 Os.windows, Os.darwin, Os.macosx, Os.ios => {
15961609 const self_exe_path = %return selfExePath(allocator);
15971610 %defer allocator.free(self_exe_path);
15981611 const dirname = os.path.dirname(self_exe_path);