diff --git a/CMakeLists.txt b/CMakeLists.txt index 08c2cf4761..1c9f374d29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -570,6 +570,14 @@ set(ZIG_C_HEADER_FILES "xtestintrin.h" ) +if(MSVC) + set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK") + if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR}) + set(ZIG_DIA_GUIDS_LIB "${MSVC_DIA_SDK_DIR}/lib/amd64/diaguids.lib") + string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_DIA_GUIDS_LIB_ESCAPED "${ZIG_DIA_GUIDS_LIB}") + endif() +endif() + set(ZIG_LIB_DIR "lib/zig") set(C_HEADERS_DEST "${ZIG_LIB_DIR}/include") set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std") @@ -631,6 +639,10 @@ target_link_libraries(zig LINK_PUBLIC ${LLVM_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) +if(ZIG_DIA_GUIDS_LIB) + target_link_libraries(zig LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB}) +endif() + if(MSVC OR MINGW) target_link_libraries(zig LINK_PUBLIC version) endif() diff --git a/README.md b/README.md index afe680e5fe..87b737e580 100644 --- a/README.md +++ b/README.md @@ -154,8 +154,7 @@ make install `ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_STATIC_LIB_DIR` are unused. ``` -brew install cmake -brew install llvm@6 +brew install cmake llvm@6 brew outdated llvm@6 || brew upgrade llvm@6 mkdir build cd build diff --git a/build.zig b/build.zig index 679c88bb71..9f66cf8728 100644 --- a/build.zig +++ b/build.zig @@ -35,55 +35,67 @@ pub fn build(b: &Builder) { const test_step = b.step("test", "Run all the tests"); - if (findLLVM(b)) |llvm| { - // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library - const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"}); - var index: usize = 0; - const cmake_binary_dir = nextValue(&index, build_info); - const cxx_compiler = nextValue(&index, build_info); - const lld_include_dir = nextValue(&index, build_info); - const lld_libraries = nextValue(&index, build_info); - const std_files = nextValue(&index, build_info); - const c_header_files = nextValue(&index, build_info); + // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library + const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"}); + var index: usize = 0; + const cmake_binary_dir = nextValue(&index, build_info); + const cxx_compiler = nextValue(&index, build_info); + const llvm_config_exe = nextValue(&index, build_info); + const lld_include_dir = nextValue(&index, build_info); + const lld_libraries = nextValue(&index, build_info); + const std_files = nextValue(&index, build_info); + const c_header_files = nextValue(&index, build_info); + const dia_guids_lib = nextValue(&index, build_info); - var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); - exe.setBuildMode(mode); - exe.addIncludeDir("src"); - exe.addIncludeDir(cmake_binary_dir); - addCppLib(b, exe, cmake_binary_dir, "zig_cpp"); - if (lld_include_dir.len != 0) { - exe.addIncludeDir(lld_include_dir); - var it = mem.split(lld_libraries, ";"); - while (it.next()) |lib| { - exe.addObjectFile(lib); - } - } else { - addCppLib(b, exe, cmake_binary_dir, "embedded_lld_elf"); - addCppLib(b, exe, cmake_binary_dir, "embedded_lld_coff"); - addCppLib(b, exe, cmake_binary_dir, "embedded_lld_lib"); + const llvm = findLLVM(b, llvm_config_exe); + + var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); + exe.setBuildMode(mode); + exe.addIncludeDir("src"); + exe.addIncludeDir(cmake_binary_dir); + addCppLib(b, exe, cmake_binary_dir, "zig_cpp"); + if (lld_include_dir.len != 0) { + exe.addIncludeDir(lld_include_dir); + var it = mem.split(lld_libraries, ";"); + while (it.next()) |lib| { + exe.addObjectFile(lib); } - dependOnLib(exe, llvm); + } else { + addCppLib(b, exe, cmake_binary_dir, "embedded_lld_elf"); + addCppLib(b, exe, cmake_binary_dir, "embedded_lld_coff"); + addCppLib(b, exe, cmake_binary_dir, "embedded_lld_lib"); + } + dependOnLib(exe, llvm); - if (!exe.target.isWindows()) { - const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"}); - const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next(); - exe.addObjectFile(libstdcxx_path); - - exe.linkSystemLibrary("pthread"); - } - - exe.linkSystemLibrary("c"); - - b.default_step.dependOn(&exe.step); - b.default_step.dependOn(docs_step); - test_step.dependOn(&exe.step); - - b.installArtifact(exe); - installStdLib(b, std_files); - installCHeaders(b, c_header_files); + if (exe.target.getOs() == builtin.Os.linux) { + const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"}); + const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next(); + exe.addObjectFile(libstdcxx_path); + exe.linkSystemLibrary("pthread"); + } else if (exe.target.isDarwin()) { + exe.linkSystemLibrary("c++"); } + if (dia_guids_lib.len != 0) { + exe.addObjectFile(dia_guids_lib); + } + + exe.linkSystemLibrary("c"); + + b.default_step.dependOn(&exe.step); + b.default_step.dependOn(docs_step); + + const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") ?? false; + if (!skip_self_hosted) { + test_step.dependOn(&exe.step); + } + const verbose_link_exe = b.option(bool, "verbose-link", "Print link command for self hosted compiler") ?? false; + exe.setVerboseLink(verbose_link_exe); + + b.installArtifact(exe); + installStdLib(b, std_files); + installCHeaders(b, c_header_files); const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); 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 { includes: ArrayList([]const u8), }; -fn findLLVM(b: &Builder) -> ?LibraryDep { - const llvm_config_exe = b.findProgram( - [][]const u8{"llvm-config-5.0", "llvm-config"}, - [][]const u8{ - "C:/Libraries/llvm-5.0.0/bin", - "/c/msys64/mingw64/bin", - "c:/msys64/mingw64/bin", - "/usr/local/opt/llvm@5/bin", - "/mingw64/bin", - }) %% |err| - { - warn("unable to find llvm-config: {}\n", err); - return null; - }; +fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep { const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"}); const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"}); 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) { fn nextValue(index: &usize, build_info: []const u8) -> []const u8 { const start = *index; - while (build_info[*index] != '\n' and build_info[*index] != '\r') : (*index += 1) { } - const result = build_info[start..*index]; - *index += 1; - return result; + while (true) : (*index += 1) { + switch (build_info[*index]) { + '\n' => { + const result = build_info[start..*index]; + *index += 1; + return result; + }, + '\r' => { + const result = build_info[start..*index]; + *index += 2; + return result; + }, + else => continue, + } + } } diff --git a/ci/appveyor/appveyor.yml b/ci/appveyor/appveyor.yml index 2009f92e43..0cae78027b 100644 --- a/ci/appveyor/appveyor.yml +++ b/ci/appveyor/appveyor.yml @@ -6,4 +6,4 @@ build_script: after_build: - '%APPVEYOR_BUILD_FOLDER%\ci\appveyor\after_build.bat' cache: - - 'llvm+clang-5.0.0-win64-msvc-release.tar.xz' + - 'llvm+clang-5.0.1-win64-msvc-release.tar.xz' diff --git a/ci/appveyor/build_script.bat b/ci/appveyor/build_script.bat index 3fa82a9b54..235b0e515e 100644 --- a/ci/appveyor/build_script.bat +++ b/ci/appveyor/build_script.bat @@ -7,7 +7,7 @@ SET "PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%" SET "MSYSTEM=MINGW64" SET "APPVEYOR_CACHE_ENTRY_ZIP_ARGS=-m0=Copy" -bash -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 +bash -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 SET "PATH=%PREVPATH%" @@ -15,12 +15,16 @@ SET "MSYSTEM=%PREVMSYSTEM%" SET "ZIGBUILDDIR=%APPVEYOR_BUILD_FOLDER%\build-msvc-release" SET "ZIGPREFIXPATH=%APPVEYOR_BUILD_FOLDER%\llvm+clang-6.0.0-win64-msvc-release" +call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 +call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64 +>>>>>>> origin/master + mkdir %ZIGBUILDDIR% cd %ZIGBUILDDIR% cmake.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 msbuild /p:Configuration=Release INSTALL.vcxproj || exit /b -bin\zig.exe build --build-file ..\build.zig test || exit /b +bin\zig.exe build --build-file ..\build.zig test -Dverbose-link || exit /b @echo "MSVC build succeeded, proceeding with MinGW build" cd %APPVEYOR_BUILD_FOLDER% diff --git a/ci/travis_osx_script b/ci/travis_osx_script index a55132395b..db3992aa8e 100755 --- a/ci/travis_osx_script +++ b/ci/travis_osx_script @@ -9,17 +9,4 @@ cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@5/ -DCMAKE_INSTALL_PREFIX=$(pwd make VERBOSE=1 make install -# TODO: we run the tests separately because when run all together there is some -# mysterious issue where after N child process spawns it crashes. I've been -# unable to reproduce the issue on my macbook - it only happens on Travis. -# ./zig build --build-file ../build.zig test - -./zig build --build-file ../build.zig test-behavior --verbose -./zig build --build-file ../build.zig test-std --verbose -./zig build --build-file ../build.zig test-compiler-rt --verbose -./zig build --build-file ../build.zig test-compare-output --verbose -./zig build --build-file ../build.zig test-build-examples --verbose -./zig build --build-file ../build.zig test-compile-errors --verbose -./zig build --build-file ../build.zig test-asm-link --verbose -./zig build --build-file ../build.zig test-debug-safety --verbose -./zig build --build-file ../build.zig test-translate-c --verbose +./zig build --build-file ../build.zig test diff --git a/doc/home.html.in b/doc/home.html.in index 3b2ef3407b..dd98222aa2 100644 --- a/doc/home.html.in +++ b/doc/home.html.in @@ -50,6 +50,7 @@
fn doAThing(nullable_foo: ?&Foo) {
// do some stuff
- if (const foo ?= nullable_foo) {
+ if (nullable_foo) |foo| {
doSomethingWithFoo(foo);
}
diff --git a/src-self-hosted/module.zig b/src-self-hosted/module.zig
index a8098217ec..2e1ebf0e3a 100644
--- a/src-self-hosted/module.zig
+++ b/src-self-hosted/module.zig
@@ -208,7 +208,7 @@ pub const Module = struct {
const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path");
const root_src_real_path = os.path.real(self.allocator, root_src_path) %% |err| {
- %return printError("unable to open '{}': {}", root_src_path, err);
+ %return printError("unable to get real path '{}': {}", root_src_path, err);
return err;
};
%defer self.allocator.free(root_src_real_path);
diff --git a/src/config.h.in b/src/config.h.in
index 4202e670ff..1fcc3fe12c 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -29,7 +29,9 @@
#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"
+#define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@"
#define ZIG_STD_FILES "@ZIG_STD_FILES@"
#define ZIG_C_HEADER_FILES "@ZIG_C_HEADER_FILES@"
+#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
#endif
diff --git a/src/main.cpp b/src/main.cpp
index a3ca1bc164..4acf4014ba 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -267,13 +267,15 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
int main(int argc, char **argv) {
if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) {
- printf("%s\n%s\n%s\n%s\n%s\n%s\n",
+ printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
ZIG_CMAKE_BINARY_DIR,
ZIG_CXX_COMPILER,
+ ZIG_LLVM_CONFIG_EXE,
ZIG_LLD_INCLUDE_PATH,
ZIG_LLD_LIBRARIES,
ZIG_STD_FILES,
- ZIG_C_HEADER_FILES);
+ ZIG_C_HEADER_FILES,
+ ZIG_DIA_GUIDS_LIB);
return 0;
}
diff --git a/src/os.cpp b/src/os.cpp
index a59fa12657..ef12464c8c 100644
--- a/src/os.cpp
+++ b/src/os.cpp
@@ -1055,6 +1055,11 @@ int os_find_windows_sdk(ZigWindowsSDK **out_sdk) {
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
sscanf(ffd.cFileName, "%d.%d.%d.%d", &c0, &c1, &c2, &c3);
+ if (c0 == 10 && c1 == 0 && c2 == 10240 && c3 == 0) {
+ // Microsoft released 26624 as 10240 accidentally.
+ // https://developer.microsoft.com/en-us/windows/downloads/sdk-archive
+ c2 = 26624;
+ }
if ((c0 > v0) || (c1 > v1) || (c2 > v2) || (c3 > v3)) {
v0 = c0, v1 = c1, v2 = c2, v3 = c3;
buf_init_from_str(&result_sdk->version10, ffd.cFileName);
diff --git a/std/build.zig b/std/build.zig
index bb5280837f..71ce56def3 100644
--- a/std/build.zig
+++ b/std/build.zig
@@ -842,10 +842,10 @@ pub const LibExeObjStep = struct {
lib_paths: ArrayList([]const u8),
disable_libc: bool,
frameworks: BufSet,
+ verbose_link: bool,
// zig only stuff
root_src: ?[]const u8,
- verbose: bool,
output_h_path: ?[]const u8,
out_h_filename: []const u8,
assembly_files: ArrayList([]const u8),
@@ -923,7 +923,7 @@ pub const LibExeObjStep = struct {
var self = LibExeObjStep {
.strip = false,
.builder = builder,
- .verbose = false,
+ .verbose_link = false,
.build_mode = builtin.Mode.Debug,
.static = static,
.kind = kind,
@@ -988,7 +988,7 @@ pub const LibExeObjStep = struct {
.linker_script = null,
.root_src = undefined,
- .verbose = undefined,
+ .verbose_link = false,
.output_h_path = undefined,
.out_h_filename = undefined,
.assembly_files = undefined,
@@ -1087,8 +1087,8 @@ pub const LibExeObjStep = struct {
%%self.source_files.append(file);
}
- pub fn setVerbose(self: &LibExeObjStep, value: bool) {
- self.verbose = value;
+ pub fn setVerboseLink(self: &LibExeObjStep, value: bool) {
+ self.verbose_link = value;
}
pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) {
@@ -1223,15 +1223,12 @@ pub const LibExeObjStep = struct {
%%zig_args.append(builder.pathFromRoot(asm_file));
}
- if (self.verbose) {
- %%zig_args.append("--verbose");
- }
if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize");
if (builder.verbose_ast) %%zig_args.append("--verbose-ast");
if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport");
if (builder.verbose_ir) %%zig_args.append("--verbose-ir");
if (builder.verbose_llvm_ir) %%zig_args.append("--verbose-llvm-ir");
- if (builder.verbose_link) %%zig_args.append("--verbose-link");
+ if (builder.verbose_link or self.verbose_link) %%zig_args.append("--verbose-link");
if (self.strip) {
%%zig_args.append("--strip");
diff --git a/std/c/darwin.zig b/std/c/darwin.zig
index 433463fde9..006dcc066b 100644
--- a/std/c/darwin.zig
+++ b/std/c/darwin.zig
@@ -1,4 +1,6 @@
extern "c" fn __error() -> &c_int;
+pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) -> c_int;
+
pub use @import("../os/darwin_errno.zig");
diff --git a/std/io.zig b/std/io.zig
index 44e5634ae0..9c39a02a8c 100644
--- a/std/io.zig
+++ b/std/io.zig
@@ -513,7 +513,7 @@ pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len
%defer allocator.free(buf);
var adapter = FileInStream.init(&file);
- %return adapter.stream.readNoEof(buf);
+ %return adapter.stream.readNoEof(buf[0..size]);
return buf;
}
diff --git a/std/os/child_process.zig b/std/os/child_process.zig
index 6e86c99056..3a1cd02b56 100644
--- a/std/os/child_process.zig
+++ b/std/os/child_process.zig
@@ -15,6 +15,7 @@ const LinkedList = std.LinkedList;
error PermissionDenied;
error ProcessNotFound;
+error InvalidName;
var children_nodes = LinkedList(&ChildProcess).init();
@@ -643,6 +644,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?
return switch (err) {
windows.ERROR.FILE_NOT_FOUND, windows.ERROR.PATH_NOT_FOUND => error.FileNotFound,
windows.ERROR.INVALID_PARAMETER => unreachable,
+ windows.ERROR.INVALID_NAME => error.InvalidName,
else => os.unexpectedErrorWindows(err),
};
}
diff --git a/std/os/index.zig b/std/os/index.zig
index e1b6a9dcce..8ebd586475 100644
--- a/std/os/index.zig
+++ b/std/os/index.zig
@@ -1516,8 +1516,8 @@ const unexpected_error_tracing = false;
/// and you get an unexpected error.
pub fn unexpectedErrorPosix(errno: usize) -> error {
if (unexpected_error_tracing) {
- io.stderr.printf("unexpected errno: {}\n", errno) %% return error.Unexpected;
- debug.printStackTrace() %% return error.Unexpected;
+ debug.warn("unexpected errno: {}\n", errno);
+ debug.dumpStackTrace();
}
return error.Unexpected;
}
@@ -1526,8 +1526,8 @@ pub fn unexpectedErrorPosix(errno: usize) -> error {
/// and you get an unexpected error.
pub fn unexpectedErrorWindows(err: windows.DWORD) -> error {
if (unexpected_error_tracing) {
- io.stderr.printf("unexpected GetLastError(): {}\n", err) %% return error.Unexpected;
- debug.printStackTrace() %% return error.Unexpected;
+ debug.warn("unexpected GetLastError(): {}\n", err);
+ debug.dumpStackTrace();
}
return error.Unexpected;
}
@@ -1544,6 +1544,53 @@ pub fn openSelfExe() -> %io.File {
}
}
+/// Get the path to the current executable.
+/// If you only need the directory, use selfExeDirPath.
+/// If you only want an open file handle, use openSelfExe.
+/// This function may return an error if the current executable
+/// was deleted after spawning.
+/// Caller owns returned memory.
+pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {
+ switch (builtin.os) {
+ Os.linux => {
+ // If the currently executing binary has been deleted,
+ // the file path looks something like `/a/b/c/exe (deleted)`
+ return readLink(allocator, "/proc/self/exe");
+ },
+ Os.windows => {
+ var out_path = %return Buffer.initSize(allocator, 0xff);
+ %defer out_path.deinit();
+ while (true) {
+ const dword_len = %return math.cast(windows.DWORD, out_path.len());
+ const copied_amt = windows.GetModuleFileNameA(null, out_path.ptr(), dword_len);
+ if (copied_amt <= 0) {
+ const err = windows.GetLastError();
+ return switch (err) {
+ else => unexpectedErrorWindows(err),
+ };
+ }
+ if (copied_amt < out_path.len()) {
+ out_path.shrink(copied_amt);
+ return out_path.toOwnedSlice();
+ }
+ const new_len = (out_path.len() << 1) | 0b1;
+ %return out_path.resize(new_len);
+ }
+ },
+ Os.darwin, Os.macosx, Os.ios => {
+ var u32_len: u32 = 0;
+ const ret1 = c._NSGetExecutablePath(undefined, &u32_len);
+ assert(ret1 != 0);
+ const bytes = %return allocator.alloc(u8, u32_len);
+ %defer allocator.free(bytes);
+ const ret2 = c._NSGetExecutablePath(bytes.ptr, &u32_len);
+ assert(ret2 == 0);
+ return bytes;
+ },
+ else => @compileError("Unsupported OS"),
+ }
+}
+
/// Get the directory path that contains the current executable.
/// Caller owns returned memory.
pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
@@ -1558,20 +1605,11 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
const dir = path.dirname(full_exe_path);
return allocator.shrink(u8, full_exe_path, dir.len);
},
- Os.windows => {
- @panic("TODO windows std.os.selfExeDirPath");
- //buf_resize(out_path, 256);
- //for (;;) {
- // DWORD copied_amt = GetModuleFileName(nullptr, buf_ptr(out_path), buf_len(out_path));
- // if (copied_amt <= 0) {
- // return ErrorFileNotFound;
- // }
- // if (copied_amt < buf_len(out_path)) {
- // buf_resize(out_path, copied_amt);
- // return 0;
- // }
- // buf_resize(out_path, buf_len(out_path) * 2);
- //}
+ Os.windows, Os.darwin, Os.macosx, Os.ios => {
+ const self_exe_path = %return selfExePath(allocator);
+ %defer allocator.free(self_exe_path);
+ const dirname = os.path.dirname(self_exe_path);
+ return allocator.shrink(u8, self_exe_path, dirname.len);
},
else => @compileError("unimplemented: std.os.selfExeDirPath for " ++ @tagName(builtin.os)),
}
diff --git a/std/os/windows/index.zig b/std/os/windows/index.zig
index 0ce3794cdc..d460e94f64 100644
--- a/std/os/windows/index.zig
+++ b/std/os/windows/index.zig
@@ -48,6 +48,8 @@ pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCo
pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL;
+pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) -> DWORD;
+
pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;
pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,
diff --git a/std/special/build_runner.zig b/std/special/build_runner.zig
index 0ae76a560b..18007538ab 100644
--- a/std/special/build_runner.zig
+++ b/std/special/build_runner.zig
@@ -14,7 +14,7 @@ pub fn main() -> %void {
var arg_it = os.args();
// TODO use a more general purpose allocator here
- var inc_allocator = %%std.heap.IncrementingAllocator.init(30 * 1024 * 1024);
+ var inc_allocator = %%std.heap.IncrementingAllocator.init(40 * 1024 * 1024);
defer inc_allocator.deinit();
const allocator = &inc_allocator.allocator;