authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-05 13:46:21-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-05 13:46:21-05:00
log5d9a8cbe1a1e399284a78a2ac88bb5916f47e87a
treee616a53f075e225287bc880ca507d4cb4b8f2681
parent8eae4a096752b7e477d16ee0c5fd40d8871e973a
parente08a4ea62d9814e6c0125ff467f67626f3a22e4f

Merge remote-tracking branch 'origin/master' into llvm6


19 files changed, 173 insertions(+), 110 deletions(-)

CMakeLists.txt+12
......@@ -570,6 +570,14 @@ set(ZIG_C_HEADER_FILES
570570 "xtestintrin.h"
571571)
572572
573if(MSVC)
574 set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
575 if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
576 set(ZIG_DIA_GUIDS_LIB "${MSVC_DIA_SDK_DIR}/lib/amd64/diaguids.lib")
577 string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_DIA_GUIDS_LIB_ESCAPED "${ZIG_DIA_GUIDS_LIB}")
578 endif()
579endif()
580
573581set(ZIG_LIB_DIR "lib/zig")
574582set(C_HEADERS_DEST "${ZIG_LIB_DIR}/include")
575583set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")
......@@ -631,6 +639,10 @@ target_link_libraries(zig LINK_PUBLIC
631639 ${LLVM_LIBRARIES}
632640 ${CMAKE_THREAD_LIBS_INIT}
633641)
642if(ZIG_DIA_GUIDS_LIB)
643 target_link_libraries(zig LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB})
644endif()
645
634646if(MSVC OR MINGW)
635647 target_link_libraries(zig LINK_PUBLIC version)
636648endif()
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@6
157brew install cmake llvm@6
159158brew outdated llvm@6 || brew upgrade llvm@6
160159mkdir build
161160cd build
build.zig+68-58
......@@ -35,55 +35,67 @@ pub fn build(b: &Builder) {
3535
3636 const test_step = b.step("test", "Run all the tests");
3737
38 if (findLLVM(b)) |llvm| {
39 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
40 const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"});
41 var index: usize = 0;
42 const cmake_binary_dir = nextValue(&index, build_info);
43 const cxx_compiler = nextValue(&index, build_info);
44 const lld_include_dir = nextValue(&index, build_info);
45 const lld_libraries = nextValue(&index, build_info);
46 const std_files = nextValue(&index, build_info);
47 const c_header_files = nextValue(&index, build_info);
48
49 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
50 exe.setBuildMode(mode);
51 exe.addIncludeDir("src");
52 exe.addIncludeDir(cmake_binary_dir);
53 addCppLib(b, exe, cmake_binary_dir, "zig_cpp");
54 if (lld_include_dir.len != 0) {
55 exe.addIncludeDir(lld_include_dir);
56 var it = mem.split(lld_libraries, ";");
57 while (it.next()) |lib| {
58 exe.addObjectFile(lib);
59 }
60 } else {
61 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_elf");
62 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_coff");
63 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_lib");
38 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
39 const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"});
40 var index: usize = 0;
41 const cmake_binary_dir = nextValue(&index, build_info);
42 const cxx_compiler = nextValue(&index, build_info);
43 const llvm_config_exe = nextValue(&index, build_info);
44 const lld_include_dir = nextValue(&index, build_info);
45 const lld_libraries = nextValue(&index, build_info);
46 const std_files = nextValue(&index, build_info);
47 const c_header_files = nextValue(&index, build_info);
48 const dia_guids_lib = nextValue(&index, build_info);
49
50 const llvm = findLLVM(b, llvm_config_exe);
51
52 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
53 exe.setBuildMode(mode);
54 exe.addIncludeDir("src");
55 exe.addIncludeDir(cmake_binary_dir);
56 addCppLib(b, exe, cmake_binary_dir, "zig_cpp");
57 if (lld_include_dir.len != 0) {
58 exe.addIncludeDir(lld_include_dir);
59 var it = mem.split(lld_libraries, ";");
60 while (it.next()) |lib| {
61 exe.addObjectFile(lib);
6462 }
65 dependOnLib(exe, llvm);
63 } else {
64 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_elf");
65 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_coff");
66 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_lib");
67 }
68 dependOnLib(exe, llvm);
6669
67 if (!exe.target.isWindows()) {
68 const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"});
69 const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next();
70 exe.addObjectFile(libstdcxx_path);
70 if (exe.target.getOs() == builtin.Os.linux) {
71 const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"});
72 const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next();
73 exe.addObjectFile(libstdcxx_path);
7174
72 exe.linkSystemLibrary("pthread");
73 }
75 exe.linkSystemLibrary("pthread");
76 } else if (exe.target.isDarwin()) {
77 exe.linkSystemLibrary("c++");
78 }
7479
75 exe.linkSystemLibrary("c");
80 if (dia_guids_lib.len != 0) {
81 exe.addObjectFile(dia_guids_lib);
82 }
7683
77 b.default_step.dependOn(&exe.step);
78 b.default_step.dependOn(docs_step);
79 test_step.dependOn(&exe.step);
84 exe.linkSystemLibrary("c");
8085
81 b.installArtifact(exe);
82 installStdLib(b, std_files);
83 installCHeaders(b, c_header_files);
86 b.default_step.dependOn(&exe.step);
87 b.default_step.dependOn(docs_step);
8488
89 const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") ?? false;
90 if (!skip_self_hosted) {
91 test_step.dependOn(&exe.step);
8592 }
93 const verbose_link_exe = b.option(bool, "verbose-link", "Print link command for self hosted compiler") ?? false;
94 exe.setVerboseLink(verbose_link_exe);
8695
96 b.installArtifact(exe);
97 installStdLib(b, std_files);
98 installCHeaders(b, c_header_files);
8799
88100 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
89101 const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") ?? false;
......@@ -142,20 +154,7 @@ const LibraryDep = struct {
142154 includes: ArrayList([]const u8),
143155};
144156
145fn findLLVM(b: &Builder) -> ?LibraryDep {
146 const llvm_config_exe = b.findProgram(
147 [][]const u8{"llvm-config-5.0", "llvm-config"},
148 [][]const u8{
149 "C:/Libraries/llvm-5.0.0/bin",
150 "/c/msys64/mingw64/bin",
151 "c:/msys64/mingw64/bin",
152 "/usr/local/opt/llvm@5/bin",
153 "/mingw64/bin",
154 }) %% |err|
155 {
156 warn("unable to find llvm-config: {}\n", err);
157 return null;
158 };
157fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
159158 const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});
160159 const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});
161160 const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"});
......@@ -223,8 +222,19 @@ pub fn installCHeaders(b: &Builder, c_header_files: []const u8) {
223222
224223fn nextValue(index: &usize, build_info: []const u8) -> []const u8 {
225224 const start = *index;
226 while (build_info[*index] != '\n' and build_info[*index] != '\r') : (*index += 1) { }
227 const result = build_info[start..*index];
228 *index += 1;
229 return result;
225 while (true) : (*index += 1) {
226 switch (build_info[*index]) {
227 '\n' => {
228 const result = build_info[start..*index];
229 *index += 1;
230 return result;
231 },
232 '\r' => {
233 const result = build_info[start..*index];
234 *index += 2;
235 return result;
236 },
237 else => continue,
238 }
239 }
230240}
ci/appveyor/appveyor.yml+1-1
......@@ -6,4 +6,4 @@ build_script:
66after_build:
77 - '%APPVEYOR_BUILD_FOLDER%\ci\appveyor\after_build.bat'
88cache:
9 - 'llvm+clang-5.0.0-win64-msvc-release.tar.xz'
9 - 'llvm+clang-5.0.1-win64-msvc-release.tar.xz'
ci/appveyor/build_script.bat+6-2
......@@ -7,7 +7,7 @@ SET "PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%"
77SET "MSYSTEM=MINGW64"
88SET "APPVEYOR_CACHE_ENTRY_ZIP_ARGS=-m0=Copy"
99
10bash -lc "cd ${APPVEYOR_BUILD_FOLDER} && if [ -s ""llvm+clang-6.0.0-win64-msvc-release.tar.xz"" ]; then echo 'skipping LLVM download'; else wget 'https://s3.amazonaws.com/superjoe/temp/llvm%%2bclang-6.0.0-win64-msvc-release.tar.xz'; fi && tar xf llvm+clang-6.0.0-win64-msvc-release.tar.xz" || exit /b
10bash -lc "cd ${APPVEYOR_BUILD_FOLDER} && if [ -s ""llvm+clang-6.0.0-win64-msvc-release.tar.xz"" ]; then echo 'skipping LLVM download'; else wget 'https://s3.amazonaws.com/ziglang.org/deps/llvm%%2bclang-6.0.0-win64-msvc-release.tar.xz'; fi && tar xf llvm+clang-6.0.0-win64-msvc-release.tar.xz" || exit /b
1111
1212
1313SET "PATH=%PREVPATH%"
......@@ -15,12 +15,16 @@ SET "MSYSTEM=%PREVMSYSTEM%"
1515SET "ZIGBUILDDIR=%APPVEYOR_BUILD_FOLDER%\build-msvc-release"
1616SET "ZIGPREFIXPATH=%APPVEYOR_BUILD_FOLDER%\llvm+clang-6.0.0-win64-msvc-release"
1717
18call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
19call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
20>>>>>>> origin/master
21
1822mkdir %ZIGBUILDDIR%
1923cd %ZIGBUILDDIR%
2024cmake.exe .. -Thost=x64 -G"Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=%ZIGBUILDDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release "-DZIG_LIBC_INCLUDE_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt" "-DZIG_LIBC_LIB_DIR=C:\Program Files (x86)\Windows Kits\10\bin\x64\ucrt" "-DZIG_LIBC_STATIC_LIB_DIR=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64" || exit /b
2125msbuild /p:Configuration=Release INSTALL.vcxproj || exit /b
2226
23bin\zig.exe build --build-file ..\build.zig test || exit /b
27bin\zig.exe build --build-file ..\build.zig test -Dverbose-link || exit /b
2428
2529@echo "MSVC build succeeded, proceeding with MinGW build"
2630cd %APPVEYOR_BUILD_FOLDER%
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
doc/home.html.in+1
......@@ -50,6 +50,7 @@
5050 </ul>
5151 <h2 id="reading-material">Reading Material</h2>
5252 <ul>
53 <li>2018-01-03 - <a href="http://andrewkelley.me/post/zig-december-2017-in-review.html">December 2017 in Review</a></li>
5354 <li>2017-10-17 - <a href="download/0.1.1/release-notes.html">Zig 0.1.1 Release Notes</a></li>
5455 <li>2017-07-19 - <a href="http://tiehuis.github.io/iterative-replacement-of-c-with-zig">Iterative Replacement of C with Zig</a></li>
5556 <li>2017-02-16 - <a href="http://andrewkelley.me/post/a-better-way-to-implement-bit-fields.html">A Better Way to Implement Bit-Fields</a></li>
doc/langref.html.in+1-1
......@@ -3397,7 +3397,7 @@ fn doAThing() -&gt; ?&amp;Foo {
33973397 <pre><code class="zig">fn doAThing(nullable_foo: ?&amp;Foo) {
33983398 // do some stuff
33993399
3400 if (const foo ?= nullable_foo) {
3400 if (nullable_foo) |foo| {
34013401 doSomethingWithFoo(foo);
34023402 }
34033403
src-self-hosted/module.zig+1-1
......@@ -208,7 +208,7 @@ pub const Module = struct {
208208
209209 const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path");
210210 const root_src_real_path = os.path.real(self.allocator, root_src_path) %% |err| {
211 %return printError("unable to open '{}': {}", root_src_path, err);
211 %return printError("unable to get real path '{}': {}", root_src_path, err);
212212 return err;
213213 };
214214 %defer self.allocator.free(root_src_real_path);
src/config.h.in+2
......@@ -29,7 +29,9 @@
2929#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
3030#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
3131#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"
32#define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@"
3233#define ZIG_STD_FILES "@ZIG_STD_FILES@"
3334#define ZIG_C_HEADER_FILES "@ZIG_C_HEADER_FILES@"
35#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
3436
3537#endif
src/main.cpp+4-2
......@@ -267,13 +267,15 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
267267
268268int main(int argc, char **argv) {
269269 if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) {
270 printf("%s\n%s\n%s\n%s\n%s\n%s\n",
270 printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
271271 ZIG_CMAKE_BINARY_DIR,
272272 ZIG_CXX_COMPILER,
273 ZIG_LLVM_CONFIG_EXE,
273274 ZIG_LLD_INCLUDE_PATH,
274275 ZIG_LLD_LIBRARIES,
275276 ZIG_STD_FILES,
276 ZIG_C_HEADER_FILES);
277 ZIG_C_HEADER_FILES,
278 ZIG_DIA_GUIDS_LIB);
277279 return 0;
278280 }
279281
src/os.cpp+5
......@@ -1055,6 +1055,11 @@ int os_find_windows_sdk(ZigWindowsSDK **out_sdk) {
10551055 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
10561056 int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
10571057 sscanf(ffd.cFileName, "%d.%d.%d.%d", &c0, &c1, &c2, &c3);
1058 if (c0 == 10 && c1 == 0 && c2 == 10240 && c3 == 0) {
1059 // Microsoft released 26624 as 10240 accidentally.
1060 // https://developer.microsoft.com/en-us/windows/downloads/sdk-archive
1061 c2 = 26624;
1062 }
10581063 if ((c0 > v0) || (c1 > v1) || (c2 > v2) || (c3 > v3)) {
10591064 v0 = c0, v1 = c1, v2 = c2, v3 = c3;
10601065 buf_init_from_str(&result_sdk->version10, ffd.cFileName);
std/build.zig+6-9
......@@ -842,10 +842,10 @@ pub const LibExeObjStep = struct {
842842 lib_paths: ArrayList([]const u8),
843843 disable_libc: bool,
844844 frameworks: BufSet,
845 verbose_link: bool,
845846
846847 // zig only stuff
847848 root_src: ?[]const u8,
848 verbose: bool,
849849 output_h_path: ?[]const u8,
850850 out_h_filename: []const u8,
851851 assembly_files: ArrayList([]const u8),
......@@ -923,7 +923,7 @@ pub const LibExeObjStep = struct {
923923 var self = LibExeObjStep {
924924 .strip = false,
925925 .builder = builder,
926 .verbose = false,
926 .verbose_link = false,
927927 .build_mode = builtin.Mode.Debug,
928928 .static = static,
929929 .kind = kind,
......@@ -988,7 +988,7 @@ pub const LibExeObjStep = struct {
988988 .linker_script = null,
989989
990990 .root_src = undefined,
991 .verbose = undefined,
991 .verbose_link = false,
992992 .output_h_path = undefined,
993993 .out_h_filename = undefined,
994994 .assembly_files = undefined,
......@@ -1087,8 +1087,8 @@ pub const LibExeObjStep = struct {
10871087 %%self.source_files.append(file);
10881088 }
10891089
1090 pub fn setVerbose(self: &LibExeObjStep, value: bool) {
1091 self.verbose = value;
1090 pub fn setVerboseLink(self: &LibExeObjStep, value: bool) {
1091 self.verbose_link = value;
10921092 }
10931093
10941094 pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) {
......@@ -1223,15 +1223,12 @@ pub const LibExeObjStep = struct {
12231223 %%zig_args.append(builder.pathFromRoot(asm_file));
12241224 }
12251225
1226 if (self.verbose) {
1227 %%zig_args.append("--verbose");
1228 }
12291226 if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize");
12301227 if (builder.verbose_ast) %%zig_args.append("--verbose-ast");
12311228 if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport");
12321229 if (builder.verbose_ir) %%zig_args.append("--verbose-ir");
12331230 if (builder.verbose_llvm_ir) %%zig_args.append("--verbose-llvm-ir");
1234 if (builder.verbose_link) %%zig_args.append("--verbose-link");
1231 if (builder.verbose_link or self.verbose_link) %%zig_args.append("--verbose-link");
12351232
12361233 if (self.strip) {
12371234 %%zig_args.append("--strip");
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/io.zig+1-1
......@@ -513,7 +513,7 @@ pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len
513513 %defer allocator.free(buf);
514514
515515 var adapter = FileInStream.init(&file);
516 %return adapter.stream.readNoEof(buf);
516 %return adapter.stream.readNoEof(buf[0..size]);
517517 return buf;
518518}
519519
std/os/child_process.zig+2
......@@ -15,6 +15,7 @@ const LinkedList = std.LinkedList;
1515
1616error PermissionDenied;
1717error ProcessNotFound;
18error InvalidName;
1819
1920var children_nodes = LinkedList(&ChildProcess).init();
2021
......@@ -643,6 +644,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?
643644 return switch (err) {
644645 windows.ERROR.FILE_NOT_FOUND, windows.ERROR.PATH_NOT_FOUND => error.FileNotFound,
645646 windows.ERROR.INVALID_PARAMETER => unreachable,
647 windows.ERROR.INVALID_NAME => error.InvalidName,
646648 else => os.unexpectedErrorWindows(err),
647649 };
648650 }
std/os/index.zig+56-18
......@@ -1516,8 +1516,8 @@ const unexpected_error_tracing = false;
15161516/// and you get an unexpected error.
15171517pub fn unexpectedErrorPosix(errno: usize) -> error {
15181518 if (unexpected_error_tracing) {
1519 io.stderr.printf("unexpected errno: {}\n", errno) %% return error.Unexpected;
1520 debug.printStackTrace() %% return error.Unexpected;
1519 debug.warn("unexpected errno: {}\n", errno);
1520 debug.dumpStackTrace();
15211521 }
15221522 return error.Unexpected;
15231523}
......@@ -1526,8 +1526,8 @@ pub fn unexpectedErrorPosix(errno: usize) -> error {
15261526/// and you get an unexpected error.
15271527pub fn unexpectedErrorWindows(err: windows.DWORD) -> error {
15281528 if (unexpected_error_tracing) {
1529 io.stderr.printf("unexpected GetLastError(): {}\n", err) %% return error.Unexpected;
1530 debug.printStackTrace() %% return error.Unexpected;
1529 debug.warn("unexpected GetLastError(): {}\n", err);
1530 debug.dumpStackTrace();
15311531 }
15321532 return error.Unexpected;
15331533}
......@@ -1544,6 +1544,53 @@ pub fn openSelfExe() -> %io.File {
15441544 }
15451545}
15461546
1547/// Get the path to the current executable.
1548/// If you only need the directory, use selfExeDirPath.
1549/// If you only want an open file handle, use openSelfExe.
1550/// This function may return an error if the current executable
1551/// was deleted after spawning.
1552/// Caller owns returned memory.
1553pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {
1554 switch (builtin.os) {
1555 Os.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");
1559 },
1560 Os.windows => {
1561 var out_path = %return Buffer.initSize(allocator, 0xff);
1562 %defer out_path.deinit();
1563 while (true) {
1564 const dword_len = %return math.cast(windows.DWORD, out_path.len());
1565 const copied_amt = windows.GetModuleFileNameA(null, out_path.ptr(), dword_len);
1566 if (copied_amt <= 0) {
1567 const err = windows.GetLastError();
1568 return switch (err) {
1569 else => unexpectedErrorWindows(err),
1570 };
1571 }
1572 if (copied_amt < out_path.len()) {
1573 out_path.shrink(copied_amt);
1574 return out_path.toOwnedSlice();
1575 }
1576 const new_len = (out_path.len() << 1) | 0b1;
1577 %return out_path.resize(new_len);
1578 }
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 },
1590 else => @compileError("Unsupported OS"),
1591 }
1592}
1593
15471594/// Get the directory path that contains the current executable.
15481595/// Caller owns returned memory.
15491596pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
......@@ -1558,20 +1605,11 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
15581605 const dir = path.dirname(full_exe_path);
15591606 return allocator.shrink(u8, full_exe_path, dir.len);
15601607 },
1561 Os.windows => {
1562 @panic("TODO windows std.os.selfExeDirPath");
1563 //buf_resize(out_path, 256);
1564 //for (;;) {
1565 // DWORD copied_amt = GetModuleFileName(nullptr, buf_ptr(out_path), buf_len(out_path));
1566 // if (copied_amt <= 0) {
1567 // return ErrorFileNotFound;
1568 // }
1569 // if (copied_amt < buf_len(out_path)) {
1570 // buf_resize(out_path, copied_amt);
1571 // return 0;
1572 // }
1573 // buf_resize(out_path, buf_len(out_path) * 2);
1574 //}
1608 Os.windows, Os.darwin, Os.macosx, Os.ios => {
1609 const self_exe_path = %return selfExePath(allocator);
1610 %defer allocator.free(self_exe_path);
1611 const dirname = os.path.dirname(self_exe_path);
1612 return allocator.shrink(u8, self_exe_path, dirname.len);
15751613 },
15761614 else => @compileError("unimplemented: std.os.selfExeDirPath for " ++ @tagName(builtin.os)),
15771615 }
std/os/windows/index.zig+2
......@@ -48,6 +48,8 @@ pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCo
4848
4949pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL;
5050
51pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) -> DWORD;
52
5153pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;
5254
5355pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,
std/special/build_runner.zig+1-1
......@@ -14,7 +14,7 @@ pub fn main() -> %void {
1414 var arg_it = os.args();
1515
1616 // TODO use a more general purpose allocator here
17 var inc_allocator = %%std.heap.IncrementingAllocator.init(30 * 1024 * 1024);
17 var inc_allocator = %%std.heap.IncrementingAllocator.init(40 * 1024 * 1024);
1818 defer inc_allocator.deinit();
1919
2020 const allocator = &inc_allocator.allocator;