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...@@ -570,6 +570,14 @@ set(ZIG_C_HEADER_FILES
570 "xtestintrin.h"570 "xtestintrin.h"
571)571)
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
573set(ZIG_LIB_DIR "lib/zig")581set(ZIG_LIB_DIR "lib/zig")
574set(C_HEADERS_DEST "${ZIG_LIB_DIR}/include")582set(C_HEADERS_DEST "${ZIG_LIB_DIR}/include")
575set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")583set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")
...@@ -631,6 +639,10 @@ target_link_libraries(zig LINK_PUBLIC...@@ -631,6 +639,10 @@ target_link_libraries(zig LINK_PUBLIC
631 ${LLVM_LIBRARIES}639 ${LLVM_LIBRARIES}
632 ${CMAKE_THREAD_LIBS_INIT}640 ${CMAKE_THREAD_LIBS_INIT}
633)641)
642if(ZIG_DIA_GUIDS_LIB)
643 target_link_libraries(zig LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB})
644endif()
645
634if(MSVC OR MINGW)646if(MSVC OR MINGW)
635 target_link_libraries(zig LINK_PUBLIC version)647 target_link_libraries(zig LINK_PUBLIC version)
636endif()648endif()
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@6
158brew install llvm@6
159brew outdated llvm@6 || brew upgrade llvm@6158brew outdated llvm@6 || brew upgrade llvm@6
160mkdir build159mkdir build
161cd build160cd build
build.zig+68-58
...@@ -35,55 +35,67 @@ pub fn build(b: &Builder) {...@@ -35,55 +35,67 @@ pub fn build(b: &Builder) {
3535
36 const test_step = b.step("test", "Run all the tests");36 const test_step = b.step("test", "Run all the tests");
3737
38 if (findLLVM(b)) |llvm| {38 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
39 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library39 const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"});
40 const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"});40 var index: usize = 0;
41 var index: usize = 0;41 const cmake_binary_dir = nextValue(&index, build_info);
42 const cmake_binary_dir = nextValue(&index, build_info);42 const cxx_compiler = nextValue(&index, build_info);
43 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);44 const lld_include_dir = nextValue(&index, build_info);
45 const lld_libraries = nextValue(&index, build_info);45 const lld_libraries = nextValue(&index, build_info);
46 const std_files = nextValue(&index, build_info);46 const std_files = nextValue(&index, build_info);
47 const c_header_files = nextValue(&index, build_info);47 const c_header_files = nextValue(&index, build_info);
4848 const dia_guids_lib = nextValue(&index, build_info);
49 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");49
50 exe.setBuildMode(mode);50 const llvm = findLLVM(b, llvm_config_exe);
51 exe.addIncludeDir("src");51
52 exe.addIncludeDir(cmake_binary_dir);52 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
53 addCppLib(b, exe, cmake_binary_dir, "zig_cpp");53 exe.setBuildMode(mode);
54 if (lld_include_dir.len != 0) {54 exe.addIncludeDir("src");
55 exe.addIncludeDir(lld_include_dir);55 exe.addIncludeDir(cmake_binary_dir);
56 var it = mem.split(lld_libraries, ";");56 addCppLib(b, exe, cmake_binary_dir, "zig_cpp");
57 while (it.next()) |lib| {57 if (lld_include_dir.len != 0) {
58 exe.addObjectFile(lib);58 exe.addIncludeDir(lld_include_dir);
59 }59 var it = mem.split(lld_libraries, ";");
60 } else {60 while (it.next()) |lib| {
61 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_elf");61 exe.addObjectFile(lib);
62 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_coff");
63 addCppLib(b, exe, cmake_binary_dir, "embedded_lld_lib");
64 }62 }
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()) {70 if (exe.target.getOs() == builtin.Os.linux) {
68 const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"});71 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();72 const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next();
70 exe.addObjectFile(libstdcxx_path);73 exe.addObjectFile(libstdcxx_path);
7174
72 exe.linkSystemLibrary("pthread");75 exe.linkSystemLibrary("pthread");
73 }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);84 exe.linkSystemLibrary("c");
78 b.default_step.dependOn(docs_step);
79 test_step.dependOn(&exe.step);
8085
81 b.installArtifact(exe);86 b.default_step.dependOn(&exe.step);
82 installStdLib(b, std_files);87 b.default_step.dependOn(docs_step);
83 installCHeaders(b, c_header_files);
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);
85 }92 }
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
88 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");100 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
89 const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") ?? false;101 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 {...@@ -142,20 +154,7 @@ const LibraryDep = struct {
142 includes: ArrayList([]const u8),154 includes: ArrayList([]const u8),
143};155};
144156
145fn findLLVM(b: &Builder) -> ?LibraryDep {157fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> 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 };
159 const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});158 const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});
160 const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});159 const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});
161 const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"});160 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) {...@@ -223,8 +222,19 @@ pub fn installCHeaders(b: &Builder, c_header_files: []const u8) {
223222
224fn nextValue(index: &usize, build_info: []const u8) -> []const u8 {223fn nextValue(index: &usize, build_info: []const u8) -> []const u8 {
225 const start = *index;224 const start = *index;
226 while (build_info[*index] != '\n' and build_info[*index] != '\r') : (*index += 1) { }225 while (true) : (*index += 1) {
227 const result = build_info[start..*index];226 switch (build_info[*index]) {
228 *index += 1;227 '\n' => {
229 return result;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 }
230}240}
ci/appveyor/appveyor.yml+1-1
...@@ -6,4 +6,4 @@ build_script:...@@ -6,4 +6,4 @@ build_script:
6after_build:6after_build:
7 - '%APPVEYOR_BUILD_FOLDER%\ci\appveyor\after_build.bat'7 - '%APPVEYOR_BUILD_FOLDER%\ci\appveyor\after_build.bat'
8cache:8cache:
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%"...@@ -7,7 +7,7 @@ SET "PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%"
7SET "MSYSTEM=MINGW64"7SET "MSYSTEM=MINGW64"
8SET "APPVEYOR_CACHE_ENTRY_ZIP_ARGS=-m0=Copy"8SET "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 /b10bash -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
13SET "PATH=%PREVPATH%"13SET "PATH=%PREVPATH%"
...@@ -15,12 +15,16 @@ SET "MSYSTEM=%PREVMSYSTEM%"...@@ -15,12 +15,16 @@ SET "MSYSTEM=%PREVMSYSTEM%"
15SET "ZIGBUILDDIR=%APPVEYOR_BUILD_FOLDER%\build-msvc-release"15SET "ZIGBUILDDIR=%APPVEYOR_BUILD_FOLDER%\build-msvc-release"
16SET "ZIGPREFIXPATH=%APPVEYOR_BUILD_FOLDER%\llvm+clang-6.0.0-win64-msvc-release"16SET "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
18mkdir %ZIGBUILDDIR%22mkdir %ZIGBUILDDIR%
19cd %ZIGBUILDDIR%23cd %ZIGBUILDDIR%
20cmake.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 /b24cmake.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
21msbuild /p:Configuration=Release INSTALL.vcxproj || exit /b25msbuild /p:Configuration=Release INSTALL.vcxproj || exit /b
2226
23bin\zig.exe build --build-file ..\build.zig test || exit /b27bin\zig.exe build --build-file ..\build.zig test -Dverbose-link || exit /b
2428
25@echo "MSVC build succeeded, proceeding with MinGW build"29@echo "MSVC build succeeded, proceeding with MinGW build"
26cd %APPVEYOR_BUILD_FOLDER%30cd %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...@@ -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
doc/home.html.in+1
...@@ -50,6 +50,7 @@...@@ -50,6 +50,7 @@
50 </ul>50 </ul>
51 <h2 id="reading-material">Reading Material</h2>51 <h2 id="reading-material">Reading Material</h2>
52 <ul>52 <ul>
53 <li>2018-01-03 - <a href="http://andrewkelley.me/post/zig-december-2017-in-review.html">December 2017 in Review</a></li>
53 <li>2017-10-17 - <a href="download/0.1.1/release-notes.html">Zig 0.1.1 Release Notes</a></li>54 <li>2017-10-17 - <a href="download/0.1.1/release-notes.html">Zig 0.1.1 Release Notes</a></li>
54 <li>2017-07-19 - <a href="http://tiehuis.github.io/iterative-replacement-of-c-with-zig">Iterative Replacement of C with Zig</a></li>55 <li>2017-07-19 - <a href="http://tiehuis.github.io/iterative-replacement-of-c-with-zig">Iterative Replacement of C with Zig</a></li>
55 <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>56 <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 {...@@ -3397,7 +3397,7 @@ fn doAThing() -&gt; ?&amp;Foo {
3397 <pre><code class="zig">fn doAThing(nullable_foo: ?&amp;Foo) {3397 <pre><code class="zig">fn doAThing(nullable_foo: ?&amp;Foo) {
3398 // do some stuff3398 // do some stuff
33993399
3400 if (const foo ?= nullable_foo) {3400 if (nullable_foo) |foo| {
3401 doSomethingWithFoo(foo);3401 doSomethingWithFoo(foo);
3402 }3402 }
34033403
src-self-hosted/module.zig+1-1
...@@ -208,7 +208,7 @@ pub const Module = struct {...@@ -208,7 +208,7 @@ pub const Module = struct {
208208
209 const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path");209 const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path");
210 const root_src_real_path = os.path.real(self.allocator, root_src_path) %% |err| {210 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);
212 return err;212 return err;
213 };213 };
214 %defer self.allocator.free(root_src_real_path);214 %defer self.allocator.free(root_src_real_path);
src/config.h.in+2
...@@ -29,7 +29,9 @@...@@ -29,7 +29,9 @@
29#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"29#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
30#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"30#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
31#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"31#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"
32#define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@"
32#define ZIG_STD_FILES "@ZIG_STD_FILES@"33#define ZIG_STD_FILES "@ZIG_STD_FILES@"
33#define ZIG_C_HEADER_FILES "@ZIG_C_HEADER_FILES@"34#define ZIG_C_HEADER_FILES "@ZIG_C_HEADER_FILES@"
35#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
3436
35#endif37#endif
src/main.cpp+4-2
...@@ -267,13 +267,15 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {...@@ -267,13 +267,15 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
267267
268int main(int argc, char **argv) {268int main(int argc, char **argv) {
269 if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) {269 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",
271 ZIG_CMAKE_BINARY_DIR,271 ZIG_CMAKE_BINARY_DIR,
272 ZIG_CXX_COMPILER,272 ZIG_CXX_COMPILER,
273 ZIG_LLVM_CONFIG_EXE,
273 ZIG_LLD_INCLUDE_PATH,274 ZIG_LLD_INCLUDE_PATH,
274 ZIG_LLD_LIBRARIES,275 ZIG_LLD_LIBRARIES,
275 ZIG_STD_FILES,276 ZIG_STD_FILES,
276 ZIG_C_HEADER_FILES);277 ZIG_C_HEADER_FILES,
278 ZIG_DIA_GUIDS_LIB);
277 return 0;279 return 0;
278 }280 }
279281
src/os.cpp+5
...@@ -1055,6 +1055,11 @@ int os_find_windows_sdk(ZigWindowsSDK **out_sdk) {...@@ -1055,6 +1055,11 @@ int os_find_windows_sdk(ZigWindowsSDK **out_sdk) {
1055 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {1055 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1056 int c0 = 0, c1 = 0, c2 = 0, c3 = 0;1056 int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
1057 sscanf(ffd.cFileName, "%d.%d.%d.%d", &c0, &c1, &c2, &c3);1057 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 }
1058 if ((c0 > v0) || (c1 > v1) || (c2 > v2) || (c3 > v3)) {1063 if ((c0 > v0) || (c1 > v1) || (c2 > v2) || (c3 > v3)) {
1059 v0 = c0, v1 = c1, v2 = c2, v3 = c3;1064 v0 = c0, v1 = c1, v2 = c2, v3 = c3;
1060 buf_init_from_str(&result_sdk->version10, ffd.cFileName);1065 buf_init_from_str(&result_sdk->version10, ffd.cFileName);
std/build.zig+6-9
...@@ -842,10 +842,10 @@ pub const LibExeObjStep = struct {...@@ -842,10 +842,10 @@ pub const LibExeObjStep = struct {
842 lib_paths: ArrayList([]const u8),842 lib_paths: ArrayList([]const u8),
843 disable_libc: bool,843 disable_libc: bool,
844 frameworks: BufSet,844 frameworks: BufSet,
845 verbose_link: bool,
845846
846 // zig only stuff847 // zig only stuff
847 root_src: ?[]const u8,848 root_src: ?[]const u8,
848 verbose: bool,
849 output_h_path: ?[]const u8,849 output_h_path: ?[]const u8,
850 out_h_filename: []const u8,850 out_h_filename: []const u8,
851 assembly_files: ArrayList([]const u8),851 assembly_files: ArrayList([]const u8),
...@@ -923,7 +923,7 @@ pub const LibExeObjStep = struct {...@@ -923,7 +923,7 @@ pub const LibExeObjStep = struct {
923 var self = LibExeObjStep {923 var self = LibExeObjStep {
924 .strip = false,924 .strip = false,
925 .builder = builder,925 .builder = builder,
926 .verbose = false,926 .verbose_link = false,
927 .build_mode = builtin.Mode.Debug,927 .build_mode = builtin.Mode.Debug,
928 .static = static,928 .static = static,
929 .kind = kind,929 .kind = kind,
...@@ -988,7 +988,7 @@ pub const LibExeObjStep = struct {...@@ -988,7 +988,7 @@ pub const LibExeObjStep = struct {
988 .linker_script = null,988 .linker_script = null,
989989
990 .root_src = undefined,990 .root_src = undefined,
991 .verbose = undefined,991 .verbose_link = false,
992 .output_h_path = undefined,992 .output_h_path = undefined,
993 .out_h_filename = undefined,993 .out_h_filename = undefined,
994 .assembly_files = undefined,994 .assembly_files = undefined,
...@@ -1087,8 +1087,8 @@ pub const LibExeObjStep = struct {...@@ -1087,8 +1087,8 @@ pub const LibExeObjStep = struct {
1087 %%self.source_files.append(file);1087 %%self.source_files.append(file);
1088 }1088 }
10891089
1090 pub fn setVerbose(self: &LibExeObjStep, value: bool) {1090 pub fn setVerboseLink(self: &LibExeObjStep, value: bool) {
1091 self.verbose = value;1091 self.verbose_link = value;
1092 }1092 }
10931093
1094 pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) {1094 pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) {
...@@ -1223,15 +1223,12 @@ pub const LibExeObjStep = struct {...@@ -1223,15 +1223,12 @@ pub const LibExeObjStep = struct {
1223 %%zig_args.append(builder.pathFromRoot(asm_file));1223 %%zig_args.append(builder.pathFromRoot(asm_file));
1224 }1224 }
12251225
1226 if (self.verbose) {
1227 %%zig_args.append("--verbose");
1228 }
1229 if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize");1226 if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize");
1230 if (builder.verbose_ast) %%zig_args.append("--verbose-ast");1227 if (builder.verbose_ast) %%zig_args.append("--verbose-ast");
1231 if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport");1228 if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport");
1232 if (builder.verbose_ir) %%zig_args.append("--verbose-ir");1229 if (builder.verbose_ir) %%zig_args.append("--verbose-ir");
1233 if (builder.verbose_llvm_ir) %%zig_args.append("--verbose-llvm-ir");1230 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
1236 if (self.strip) {1233 if (self.strip) {
1237 %%zig_args.append("--strip");1234 %%zig_args.append("--strip");
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/io.zig+1-1
...@@ -513,7 +513,7 @@ pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len...@@ -513,7 +513,7 @@ pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len
513 %defer allocator.free(buf);513 %defer allocator.free(buf);
514514
515 var adapter = FileInStream.init(&file);515 var adapter = FileInStream.init(&file);
516 %return adapter.stream.readNoEof(buf);516 %return adapter.stream.readNoEof(buf[0..size]);
517 return buf;517 return buf;
518}518}
519519
std/os/child_process.zig+2
...@@ -15,6 +15,7 @@ const LinkedList = std.LinkedList;...@@ -15,6 +15,7 @@ const LinkedList = std.LinkedList;
1515
16error PermissionDenied;16error PermissionDenied;
17error ProcessNotFound;17error ProcessNotFound;
18error InvalidName;
1819
19var children_nodes = LinkedList(&ChildProcess).init();20var children_nodes = LinkedList(&ChildProcess).init();
2021
...@@ -643,6 +644,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?...@@ -643,6 +644,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?
643 return switch (err) {644 return switch (err) {
644 windows.ERROR.FILE_NOT_FOUND, windows.ERROR.PATH_NOT_FOUND => error.FileNotFound,645 windows.ERROR.FILE_NOT_FOUND, windows.ERROR.PATH_NOT_FOUND => error.FileNotFound,
645 windows.ERROR.INVALID_PARAMETER => unreachable,646 windows.ERROR.INVALID_PARAMETER => unreachable,
647 windows.ERROR.INVALID_NAME => error.InvalidName,
646 else => os.unexpectedErrorWindows(err),648 else => os.unexpectedErrorWindows(err),
647 };649 };
648 }650 }
std/os/index.zig+56-18
...@@ -1516,8 +1516,8 @@ const unexpected_error_tracing = false;...@@ -1516,8 +1516,8 @@ const unexpected_error_tracing = false;
1516/// and you get an unexpected error.1516/// and you get an unexpected error.
1517pub fn unexpectedErrorPosix(errno: usize) -> error {1517pub fn unexpectedErrorPosix(errno: usize) -> error {
1518 if (unexpected_error_tracing) {1518 if (unexpected_error_tracing) {
1519 io.stderr.printf("unexpected errno: {}\n", errno) %% return error.Unexpected;1519 debug.warn("unexpected errno: {}\n", errno);
1520 debug.printStackTrace() %% return error.Unexpected;1520 debug.dumpStackTrace();
1521 }1521 }
1522 return error.Unexpected;1522 return error.Unexpected;
1523}1523}
...@@ -1526,8 +1526,8 @@ pub fn unexpectedErrorPosix(errno: usize) -> error {...@@ -1526,8 +1526,8 @@ pub fn unexpectedErrorPosix(errno: usize) -> error {
1526/// and you get an unexpected error.1526/// and you get an unexpected error.
1527pub fn unexpectedErrorWindows(err: windows.DWORD) -> error {1527pub fn unexpectedErrorWindows(err: windows.DWORD) -> error {
1528 if (unexpected_error_tracing) {1528 if (unexpected_error_tracing) {
1529 io.stderr.printf("unexpected GetLastError(): {}\n", err) %% return error.Unexpected;1529 debug.warn("unexpected GetLastError(): {}\n", err);
1530 debug.printStackTrace() %% return error.Unexpected;1530 debug.dumpStackTrace();
1531 }1531 }
1532 return error.Unexpected;1532 return error.Unexpected;
1533}1533}
...@@ -1544,6 +1544,53 @@ pub fn openSelfExe() -> %io.File {...@@ -1544,6 +1544,53 @@ pub fn openSelfExe() -> %io.File {
1544 }1544 }
1545}1545}
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
1547/// Get the directory path that contains the current executable.1594/// Get the directory path that contains the current executable.
1548/// Caller owns returned memory.1595/// Caller owns returned memory.
1549pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {1596pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
...@@ -1558,20 +1605,11 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {...@@ -1558,20 +1605,11 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
1558 const dir = path.dirname(full_exe_path);1605 const dir = path.dirname(full_exe_path);
1559 return allocator.shrink(u8, full_exe_path, dir.len);1606 return allocator.shrink(u8, full_exe_path, dir.len);
1560 },1607 },
1561 Os.windows => {1608 Os.windows, Os.darwin, Os.macosx, Os.ios => {
1562 @panic("TODO windows std.os.selfExeDirPath");1609 const self_exe_path = %return selfExePath(allocator);
1563 //buf_resize(out_path, 256);1610 %defer allocator.free(self_exe_path);
1564 //for (;;) {1611 const dirname = os.path.dirname(self_exe_path);
1565 // DWORD copied_amt = GetModuleFileName(nullptr, buf_ptr(out_path), buf_len(out_path));1612 return allocator.shrink(u8, self_exe_path, dirname.len);
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 //}
1575 },1613 },
1576 else => @compileError("unimplemented: std.os.selfExeDirPath for " ++ @tagName(builtin.os)),1614 else => @compileError("unimplemented: std.os.selfExeDirPath for " ++ @tagName(builtin.os)),
1577 }1615 }
std/os/windows/index.zig+2
...@@ -48,6 +48,8 @@ pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCo...@@ -48,6 +48,8 @@ pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCo
4848
49pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL;49pub 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
51pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;53pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;
5254
53pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,55pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,
std/special/build_runner.zig+1-1
...@@ -14,7 +14,7 @@ pub fn main() -> %void {...@@ -14,7 +14,7 @@ pub fn main() -> %void {
14 var arg_it = os.args();14 var arg_it = os.args();
1515
16 // TODO use a more general purpose allocator here16 // 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);
18 defer inc_allocator.deinit();18 defer inc_allocator.deinit();
1919
20 const allocator = &inc_allocator.allocator;20 const allocator = &inc_allocator.allocator;