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...@@ -154,8 +154,7 @@ make install
154`ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_STATIC_LIB_DIR` are unused.154`ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_STATIC_LIB_DIR` are unused.
155155
156```156```
157brew install cmake157brew install cmake llvm@5
158brew install llvm@5
159brew outdated llvm@5 || brew upgrade llvm@5158brew outdated llvm@5 || brew upgrade llvm@5
160mkdir build159mkdir build
161cd build160cd build
build.zig+3-1
...@@ -66,12 +66,14 @@ pub fn build(b: &Builder) {...@@ -66,12 +66,14 @@ pub fn build(b: &Builder) {
66 }66 }
67 dependOnLib(exe, llvm);67 dependOnLib(exe, llvm);
6868
69 if (!exe.target.isWindows()) {69 if (exe.target.getOs() == builtin.Os.linux) {
70 const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"});70 const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"});
71 const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next();71 const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next();
72 exe.addObjectFile(libstdcxx_path);72 exe.addObjectFile(libstdcxx_path);
7373
74 exe.linkSystemLibrary("pthread");74 exe.linkSystemLibrary("pthread");
75 } else if (exe.target.isDarwin()) {
76 exe.linkSystemLibrary("c++");
75 }77 }
7678
77 exe.linkSystemLibrary("c");79 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...@@ -9,17 +9,4 @@ cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@5/ -DCMAKE_INSTALL_PREFIX=$(pwd
9make VERBOSE=19make VERBOSE=1
10make install10make install
1111
12# TODO: we run the tests separately because when run all together there is some12./zig build --build-file ../build.zig test
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
std/c/darwin.zig+2
...@@ -1,4 +1,6 @@...@@ -1,4 +1,6 @@
1extern "c" fn __error() -> &c_int;1extern "c" fn __error() -> &c_int;
2pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) -> c_int;
3
24
3pub use @import("../os/darwin_errno.zig");5pub use @import("../os/darwin_errno.zig");
46
std/os/index.zig+17-4
...@@ -1553,10 +1553,12 @@ pub fn openSelfExe() -> %io.File {...@@ -1553,10 +1553,12 @@ pub fn openSelfExe() -> %io.File {
1553pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {1553pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {
1554 switch (builtin.os) {1554 switch (builtin.os) {
1555 Os.linux => {1555 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");
1557 },1559 },
1558 Os.windows => {1560 Os.windows => {
1559 var out_path = %return Buffer.initSize(allocator, 256);1561 var out_path = %return Buffer.initSize(allocator, 0xff);
1560 %defer out_path.deinit();1562 %defer out_path.deinit();
1561 while (true) {1563 while (true) {
1562 const dword_len = %return math.cast(windows.DWORD, out_path.len());1564 const dword_len = %return math.cast(windows.DWORD, out_path.len());
...@@ -1571,9 +1573,20 @@ pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {...@@ -1571,9 +1573,20 @@ pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {
1571 out_path.shrink(copied_amt);1573 out_path.shrink(copied_amt);
1572 return out_path.toOwnedSlice();1574 return out_path.toOwnedSlice();
1573 }1575 }
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);
1575 }1578 }
1576 },1579 },
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 },
1577 else => @compileError("Unsupported OS"),1590 else => @compileError("Unsupported OS"),
1578 }1591 }
1579}1592}
...@@ -1592,7 +1605,7 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {...@@ -1592,7 +1605,7 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
1592 const dir = path.dirname(full_exe_path);1605 const dir = path.dirname(full_exe_path);
1593 return allocator.shrink(u8, full_exe_path, dir.len);1606 return allocator.shrink(u8, full_exe_path, dir.len);
1594 },1607 },
1595 Os.windows => {1608 Os.windows, Os.darwin, Os.macosx, Os.ios => {
1596 const self_exe_path = %return selfExePath(allocator);1609 const self_exe_path = %return selfExePath(allocator);
1597 %defer allocator.free(self_exe_path);1610 %defer allocator.free(self_exe_path);
1598 const dirname = os.path.dirname(self_exe_path);1611 const dirname = os.path.dirname(self_exe_path);