| author | |
| committer | |
| log | 5d9a8cbe1a1e399284a78a2ac88bb5916f47e87a |
| tree | e616a53f075e225287bc880ca507d4cb4b8f2681 |
| parent | 8eae4a096752b7e477d16ee0c5fd40d8871e973a |
| parent | e08a4ea62d9814e6c0125ff467f67626f3a22e4f |
19 files changed, 173 insertions(+), 110 deletions(-)
CMakeLists.txt+12| ... | ... | @@ -570,6 +570,14 @@ set(ZIG_C_HEADER_FILES |
| 570 | 570 | "xtestintrin.h" |
| 571 | 571 | ) |
| 572 | 572 | |
| 573 | if(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() | |
| 579 | endif() | |
| 580 | ||
| 573 | 581 | set(ZIG_LIB_DIR "lib/zig") |
| 574 | 582 | set(C_HEADERS_DEST "${ZIG_LIB_DIR}/include") |
| 575 | 583 | set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std") |
| ... | ... | @@ -631,6 +639,10 @@ target_link_libraries(zig LINK_PUBLIC |
| 631 | 639 | ${LLVM_LIBRARIES} |
| 632 | 640 | ${CMAKE_THREAD_LIBS_INIT} |
| 633 | 641 | ) |
| 642 | if(ZIG_DIA_GUIDS_LIB) | |
| 643 | target_link_libraries(zig LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB}) | |
| 644 | endif() | |
| 645 | ||
| 634 | 646 | if(MSVC OR MINGW) |
| 635 | 647 | target_link_libraries(zig LINK_PUBLIC version) |
| 636 | 648 | endif() |
README.md+1-2| ... | ... | @@ -154,8 +154,7 @@ make install |
| 154 | 154 | `ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_STATIC_LIB_DIR` are unused. |
| 155 | 155 | |
| 156 | 156 | ``` |
| 157 | brew install cmake | |
| 158 | brew install llvm@6 | |
| 157 | brew install cmake llvm@6 | |
| 159 | 158 | brew outdated llvm@6 || brew upgrade llvm@6 |
| 160 | 159 | mkdir build |
| 161 | 160 | cd build |
build.zig+68-58| ... | ... | @@ -35,55 +35,67 @@ pub fn build(b: &Builder) { |
| 35 | 35 | |
| 36 | 36 | const test_step = b.step("test", "Run all the tests"); |
| 37 | 37 | |
| 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); | |
| 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); | |
| 66 | 69 | |
| 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); | |
| 71 | 74 | |
| 72 | exe.linkSystemLibrary("pthread"); | |
| 73 | } | |
| 75 | exe.linkSystemLibrary("pthread"); | |
| 76 | } else if (exe.target.isDarwin()) { | |
| 77 | exe.linkSystemLibrary("c++"); | |
| 78 | } | |
| 74 | 79 | |
| 75 | exe.linkSystemLibrary("c"); | |
| 80 | if (dia_guids_lib.len != 0) { | |
| 81 | exe.addObjectFile(dia_guids_lib); | |
| 82 | } | |
| 76 | 83 | |
| 77 | b.default_step.dependOn(&exe.step); | |
| 78 | b.default_step.dependOn(docs_step); | |
| 79 | test_step.dependOn(&exe.step); | |
| 84 | exe.linkSystemLibrary("c"); | |
| 80 | 85 | |
| 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); | |
| 84 | 88 | |
| 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); | |
| 86 | 95 | |
| 96 | b.installArtifact(exe); | |
| 97 | installStdLib(b, std_files); | |
| 98 | installCHeaders(b, c_header_files); | |
| 87 | 99 | |
| 88 | 100 | const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); |
| 89 | 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 | 154 | includes: ArrayList([]const u8), |
| 143 | 155 | }; |
| 144 | 156 | |
| 145 | fn 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 | }; | |
| 157 | fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep { | |
| 159 | 158 | const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"}); |
| 160 | 159 | const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"}); |
| 161 | 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 | 222 | |
| 224 | 223 | fn nextValue(index: &usize, build_info: []const u8) -> []const u8 { |
| 225 | 224 | 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 | } | |
| 230 | 240 | } |
ci/appveyor/appveyor.yml+1-1| ... | ... | @@ -6,4 +6,4 @@ build_script: |
| 6 | 6 | after_build: |
| 7 | 7 | - '%APPVEYOR_BUILD_FOLDER%\ci\appveyor\after_build.bat' |
| 8 | 8 | cache: |
| 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 | SET "MSYSTEM=MINGW64" |
| 8 | 8 | SET "APPVEYOR_CACHE_ENTRY_ZIP_ARGS=-m0=Copy" |
| 9 | 9 | |
| 10 | 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 | |
| 10 | 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 | |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | SET "PATH=%PREVPATH%" |
| ... | ... | @@ -15,12 +15,16 @@ SET "MSYSTEM=%PREVMSYSTEM%" |
| 15 | 15 | SET "ZIGBUILDDIR=%APPVEYOR_BUILD_FOLDER%\build-msvc-release" |
| 16 | 16 | SET "ZIGPREFIXPATH=%APPVEYOR_BUILD_FOLDER%\llvm+clang-6.0.0-win64-msvc-release" |
| 17 | 17 | |
| 18 | call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 | |
| 19 | call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64 | |
| 20 | >>>>>>> origin/master | |
| 21 | ||
| 18 | 22 | mkdir %ZIGBUILDDIR% |
| 19 | 23 | cd %ZIGBUILDDIR% |
| 20 | 24 | 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 |
| 21 | 25 | msbuild /p:Configuration=Release INSTALL.vcxproj || exit /b |
| 22 | 26 | |
| 23 | bin\zig.exe build --build-file ..\build.zig test || exit /b | |
| 27 | bin\zig.exe build --build-file ..\build.zig test -Dverbose-link || exit /b | |
| 24 | 28 | |
| 25 | 29 | @echo "MSVC build succeeded, proceeding with MinGW build" |
| 26 | 30 | cd %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 | 9 | make VERBOSE=1 |
| 10 | 10 | make install |
| 11 | 11 | |
| 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 @@ |
| 50 | 50 | </ul> |
| 51 | 51 | <h2 id="reading-material">Reading Material</h2> |
| 52 | 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 | 54 | <li>2017-10-17 - <a href="download/0.1.1/release-notes.html">Zig 0.1.1 Release Notes</a></li> |
| 54 | 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 | 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 | 3397 | <pre><code class="zig">fn doAThing(nullable_foo: ?&amp;Foo) { |
| 3398 | 3398 | // do some stuff |
| 3399 | 3399 | |
| 3400 | if (const foo ?= nullable_foo) { | |
| 3400 | if (nullable_foo) |foo| { | |
| 3401 | 3401 | doSomethingWithFoo(foo); |
| 3402 | 3402 | } |
| 3403 | 3403 |
src-self-hosted/module.zig+1-1| ... | ... | @@ -208,7 +208,7 @@ pub const Module = struct { |
| 208 | 208 | |
| 209 | 209 | const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path"); |
| 210 | 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 | 212 | return err; |
| 213 | 213 | }; |
| 214 | 214 | %defer self.allocator.free(root_src_real_path); |
src/config.h.in+2| ... | ... | @@ -29,7 +29,9 @@ |
| 29 | 29 | #define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@" |
| 30 | 30 | #define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@" |
| 31 | 31 | #define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@" |
| 32 | #define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@" | |
| 32 | 33 | #define ZIG_STD_FILES "@ZIG_STD_FILES@" |
| 33 | 34 | #define ZIG_C_HEADER_FILES "@ZIG_C_HEADER_FILES@" |
| 35 | #define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@" | |
| 34 | 36 | |
| 35 | 37 | #endif |
src/main.cpp+4-2| ... | ... | @@ -267,13 +267,15 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) { |
| 267 | 267 | |
| 268 | 268 | int main(int argc, char **argv) { |
| 269 | 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 | 271 | ZIG_CMAKE_BINARY_DIR, |
| 272 | 272 | ZIG_CXX_COMPILER, |
| 273 | ZIG_LLVM_CONFIG_EXE, | |
| 273 | 274 | ZIG_LLD_INCLUDE_PATH, |
| 274 | 275 | ZIG_LLD_LIBRARIES, |
| 275 | 276 | ZIG_STD_FILES, |
| 276 | ZIG_C_HEADER_FILES); | |
| 277 | ZIG_C_HEADER_FILES, | |
| 278 | ZIG_DIA_GUIDS_LIB); | |
| 277 | 279 | return 0; |
| 278 | 280 | } |
| 279 | 281 |
src/os.cpp+5| ... | ... | @@ -1055,6 +1055,11 @@ int os_find_windows_sdk(ZigWindowsSDK **out_sdk) { |
| 1055 | 1055 | if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 1056 | 1056 | int c0 = 0, c1 = 0, c2 = 0, c3 = 0; |
| 1057 | 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 | 1063 | if ((c0 > v0) || (c1 > v1) || (c2 > v2) || (c3 > v3)) { |
| 1059 | 1064 | v0 = c0, v1 = c1, v2 = c2, v3 = c3; |
| 1060 | 1065 | buf_init_from_str(&result_sdk->version10, ffd.cFileName); |
std/build.zig+6-9| ... | ... | @@ -842,10 +842,10 @@ pub const LibExeObjStep = struct { |
| 842 | 842 | lib_paths: ArrayList([]const u8), |
| 843 | 843 | disable_libc: bool, |
| 844 | 844 | frameworks: BufSet, |
| 845 | verbose_link: bool, | |
| 845 | 846 | |
| 846 | 847 | // zig only stuff |
| 847 | 848 | root_src: ?[]const u8, |
| 848 | verbose: bool, | |
| 849 | 849 | output_h_path: ?[]const u8, |
| 850 | 850 | out_h_filename: []const u8, |
| 851 | 851 | assembly_files: ArrayList([]const u8), |
| ... | ... | @@ -923,7 +923,7 @@ pub const LibExeObjStep = struct { |
| 923 | 923 | var self = LibExeObjStep { |
| 924 | 924 | .strip = false, |
| 925 | 925 | .builder = builder, |
| 926 | .verbose = false, | |
| 926 | .verbose_link = false, | |
| 927 | 927 | .build_mode = builtin.Mode.Debug, |
| 928 | 928 | .static = static, |
| 929 | 929 | .kind = kind, |
| ... | ... | @@ -988,7 +988,7 @@ pub const LibExeObjStep = struct { |
| 988 | 988 | .linker_script = null, |
| 989 | 989 | |
| 990 | 990 | .root_src = undefined, |
| 991 | .verbose = undefined, | |
| 991 | .verbose_link = false, | |
| 992 | 992 | .output_h_path = undefined, |
| 993 | 993 | .out_h_filename = undefined, |
| 994 | 994 | .assembly_files = undefined, |
| ... | ... | @@ -1087,8 +1087,8 @@ pub const LibExeObjStep = struct { |
| 1087 | 1087 | %%self.source_files.append(file); |
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 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; | |
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) { |
| ... | ... | @@ -1223,15 +1223,12 @@ pub const LibExeObjStep = struct { |
| 1223 | 1223 | %%zig_args.append(builder.pathFromRoot(asm_file)); |
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | if (self.verbose) { | |
| 1227 | %%zig_args.append("--verbose"); | |
| 1228 | } | |
| 1229 | 1226 | if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize"); |
| 1230 | 1227 | if (builder.verbose_ast) %%zig_args.append("--verbose-ast"); |
| 1231 | 1228 | if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport"); |
| 1232 | 1229 | if (builder.verbose_ir) %%zig_args.append("--verbose-ir"); |
| 1233 | 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"); | |
| 1235 | 1232 | |
| 1236 | 1233 | if (self.strip) { |
| 1237 | 1234 | %%zig_args.append("--strip"); |
std/c/darwin.zig+2| ... | ... | @@ -1,4 +1,6 @@ |
| 1 | 1 | extern "c" fn __error() -> &c_int; |
| 2 | pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) -> c_int; | |
| 3 | ||
| 2 | 4 | |
| 3 | 5 | pub use @import("../os/darwin_errno.zig"); |
| 4 | 6 |
std/io.zig+1-1| ... | ... | @@ -513,7 +513,7 @@ pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len |
| 513 | 513 | %defer allocator.free(buf); |
| 514 | 514 | |
| 515 | 515 | var adapter = FileInStream.init(&file); |
| 516 | %return adapter.stream.readNoEof(buf); | |
| 516 | %return adapter.stream.readNoEof(buf[0..size]); | |
| 517 | 517 | return buf; |
| 518 | 518 | } |
| 519 | 519 |
std/os/child_process.zig+2| ... | ... | @@ -15,6 +15,7 @@ const LinkedList = std.LinkedList; |
| 15 | 15 | |
| 16 | 16 | error PermissionDenied; |
| 17 | 17 | error ProcessNotFound; |
| 18 | error InvalidName; | |
| 18 | 19 | |
| 19 | 20 | var children_nodes = LinkedList(&ChildProcess).init(); |
| 20 | 21 | |
| ... | ... | @@ -643,6 +644,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ? |
| 643 | 644 | return switch (err) { |
| 644 | 645 | windows.ERROR.FILE_NOT_FOUND, windows.ERROR.PATH_NOT_FOUND => error.FileNotFound, |
| 645 | 646 | windows.ERROR.INVALID_PARAMETER => unreachable, |
| 647 | windows.ERROR.INVALID_NAME => error.InvalidName, | |
| 646 | 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 | 1516 | /// and you get an unexpected error. |
| 1517 | 1517 | pub fn unexpectedErrorPosix(errno: usize) -> error { |
| 1518 | 1518 | 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(); | |
| 1521 | 1521 | } |
| 1522 | 1522 | return error.Unexpected; |
| 1523 | 1523 | } |
| ... | ... | @@ -1526,8 +1526,8 @@ pub fn unexpectedErrorPosix(errno: usize) -> error { |
| 1526 | 1526 | /// and you get an unexpected error. |
| 1527 | 1527 | pub fn unexpectedErrorWindows(err: windows.DWORD) -> error { |
| 1528 | 1528 | 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(); | |
| 1531 | 1531 | } |
| 1532 | 1532 | return error.Unexpected; |
| 1533 | 1533 | } |
| ... | ... | @@ -1544,6 +1544,53 @@ pub fn openSelfExe() -> %io.File { |
| 1544 | 1544 | } |
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 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. | |
| 1553 | pub 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 | 1594 | /// Get the directory path that contains the current executable. |
| 1548 | 1595 | /// Caller owns returned memory. |
| 1549 | 1596 | pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 { |
| ... | ... | @@ -1558,20 +1605,11 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 { |
| 1558 | 1605 | const dir = path.dirname(full_exe_path); |
| 1559 | 1606 | return allocator.shrink(u8, full_exe_path, dir.len); |
| 1560 | 1607 | }, |
| 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); | |
| 1575 | 1613 | }, |
| 1576 | 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 | 48 | |
| 49 | 49 | pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL; |
| 50 | 50 | |
| 51 | pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) -> DWORD; | |
| 52 | ||
| 51 | 53 | pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD; |
| 52 | 54 | |
| 53 | 55 | pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE, |
std/special/build_runner.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ pub fn main() -> %void { |
| 14 | 14 | var arg_it = os.args(); |
| 15 | 15 | |
| 16 | 16 | // 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 | 18 | defer inc_allocator.deinit(); |
| 19 | 19 | |
| 20 | 20 | const allocator = &inc_allocator.allocator; |