| author | |
| committer | |
| log | 8a344fab3908e1b793fe8f9590696142aee2a1be |
| tree | 4c16400718fb200acd2e7766454520dfa90f6772 |
| parent | 7d6596e979df799782b77ce3fed722b792509388 |
| parent | cb635e084b0c36e3c7a6bf63f49f7e7e9918532d |
| signature |
8 files changed, 77 insertions(+), 34 deletions(-)
CMakeLists.txt+10-11| ... | ... | @@ -1017,9 +1017,9 @@ if("${ZIG_EXECUTABLE}" STREQUAL "") |
| 1017 | 1017 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 1018 | 1018 | ) |
| 1019 | 1019 | if (WIN32) |
| 1020 | set(ZIG_EXECUTABLE "${zig2_BINARY_DIR}/zig2.exe") | |
| 1020 | set(ZIG_EXECUTABLE "${CMAKE_BINARY_DIR}/zig2.exe") | |
| 1021 | 1021 | else() |
| 1022 | set(ZIG_EXECUTABLE "${zig2_BINARY_DIR}/zig2") | |
| 1022 | set(ZIG_EXECUTABLE "${CMAKE_BINARY_DIR}/zig2") | |
| 1023 | 1023 | endif() |
| 1024 | 1024 | else() |
| 1025 | 1025 | add_custom_command( |
| ... | ... | @@ -1045,15 +1045,8 @@ elseif(MINGW) |
| 1045 | 1045 | target_link_libraries(zig2 ntdll) |
| 1046 | 1046 | endif() |
| 1047 | 1047 | |
| 1048 | # Dummy install command so that the "install" target is not missing. | |
| 1049 | # This is redundant from the "stage3" custom target below. | |
| 1050 | if(NOT ZIG_SKIP_INSTALL_LIB_FILES) | |
| 1051 | install(FILES "lib/compiler_rt.zig" DESTINATION "lib/zig") | |
| 1052 | endif() | |
| 1053 | ||
| 1054 | set(ZIG_INSTALL_ARGS "build" | |
| 1048 | set(ZIG_BUILD_ARGS | |
| 1055 | 1049 | --zig-lib-dir "${CMAKE_SOURCE_DIR}/lib" |
| 1056 | --prefix "${CMAKE_INSTALL_PREFIX}" | |
| 1057 | 1050 | "-Dconfig_h=${ZIG_CONFIG_H_OUT}" |
| 1058 | 1051 | "-Denable-llvm" |
| 1059 | 1052 | "-Denable-stage1" |
| ... | ... | @@ -1067,8 +1060,14 @@ set(ZIG_INSTALL_ARGS "build" |
| 1067 | 1060 | ) |
| 1068 | 1061 | |
| 1069 | 1062 | add_custom_target(stage3 ALL |
| 1070 | COMMAND zig2 ${ZIG_INSTALL_ARGS} | |
| 1063 | COMMAND zig2 build compile ${ZIG_BUILD_ARGS} | |
| 1071 | 1064 | DEPENDS zig2 |
| 1072 | 1065 | COMMENT STATUS "Building stage3" |
| 1073 | 1066 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 1074 | 1067 | ) |
| 1068 | ||
| 1069 | install(CODE "set(ZIG_EXECUTABLE \"${ZIG_EXECUTABLE}\")") | |
| 1070 | install(CODE "set(ZIG_BUILD_ARGS \"${ZIG_BUILD_ARGS}\")") | |
| 1071 | install(CODE "set(CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\")") | |
| 1072 | install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")") | |
| 1073 | install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/install.cmake") |
build.zig+4| ... | ... | @@ -142,6 +142,10 @@ pub fn build(b: *Builder) !void { |
| 142 | 142 | }; |
| 143 | 143 | |
| 144 | 144 | const exe = b.addExecutable("zig", main_file); |
| 145 | ||
| 146 | const compile_step = b.step("compile", "Build the self-hosted compiler"); | |
| 147 | compile_step.dependOn(&exe.step); | |
| 148 | ||
| 145 | 149 | exe.stack_size = stack_size; |
| 146 | 150 | exe.strip = strip; |
| 147 | 151 | exe.sanitize_thread = sanitize_thread; |
cmake/install.cmake created+27| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | set(ZIG_INSTALL_ARGS build ${ZIG_BUILD_ARGS} --prefix "${CMAKE_INSTALL_PREFIX}") | |
| 2 | execute_process( | |
| 3 | COMMAND "${ZIG_EXECUTABLE}" ${ZIG_INSTALL_ARGS} | |
| 4 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" | |
| 5 | RESULT_VARIABLE _result) | |
| 6 | ||
| 7 | if(_result) | |
| 8 | message("::") | |
| 9 | message(":: ERROR: ${_result}") | |
| 10 | message(":: (execute_process)") | |
| 11 | ||
| 12 | list(JOIN ZIG_INSTALL_ARGS " " s_INSTALL_LIBSTAGE2_ARGS) | |
| 13 | message("::") | |
| 14 | message(":: argv: ${ZIG_EXECUTABLE} ${s_INSTALL_LIBSTAGE2_ARGS}") | |
| 15 | ||
| 16 | set(_args ${ZIG_EXECUTABLE} ${ZIG_INSTALL_ARGS}) | |
| 17 | list(LENGTH _args _len) | |
| 18 | math(EXPR _len "${_len} - 1") | |
| 19 | message("::") | |
| 20 | foreach(_i RANGE 0 ${_len}) | |
| 21 | list(GET _args ${_i} _arg) | |
| 22 | message(":: argv[${_i}]: ${_arg}") | |
| 23 | endforeach() | |
| 24 | ||
| 25 | message("::") | |
| 26 | message(FATAL_ERROR) | |
| 27 | endif() |
lib/std/os/windows.zig+1| ... | ... | @@ -134,6 +134,7 @@ pub fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!HAN |
| 134 | 134 | .OBJECT_NAME_COLLISION => return error.PathAlreadyExists, |
| 135 | 135 | .FILE_IS_A_DIRECTORY => return error.IsDir, |
| 136 | 136 | .NOT_A_DIRECTORY => return error.NotDir, |
| 137 | .INVALID_HANDLE => unreachable, | |
| 137 | 138 | else => return unexpectedStatus(rc), |
| 138 | 139 | } |
| 139 | 140 | } |
lib/std/zig/system/NativePaths.zig+6-7| ... | ... | @@ -96,7 +96,7 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths |
| 96 | 96 | return self; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | if (comptime native_target.os.tag == .solaris) { | |
| 99 | if (builtin.os.tag == .solaris) { | |
| 100 | 100 | try self.addLibDir("/usr/lib/64"); |
| 101 | 101 | try self.addLibDir("/usr/local/lib/64"); |
| 102 | 102 | try self.addLibDir("/lib/64"); |
| ... | ... | @@ -107,7 +107,7 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths |
| 107 | 107 | return self; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | if (native_target.os.tag != .windows) { | |
| 110 | if (builtin.os.tag != .windows) { | |
| 111 | 111 | const triple = try native_target.linuxTriple(allocator); |
| 112 | 112 | defer allocator.free(triple); |
| 113 | 113 | |
| ... | ... | @@ -136,11 +136,10 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths |
| 136 | 136 | // libz.so.1 is in /lib/x86_64-linux-gnu (added here) |
| 137 | 137 | try self.addLibDirFmt("/lib/{s}", .{triple}); |
| 138 | 138 | |
| 139 | // NOTE: distro like guix doesn't use FHS, so it relies on envorinment | |
| 140 | // variables (C_INCLUDE_PATH, CPLUS_INCLUDE_PATH and LIBRARY_PATH) to | |
| 141 | // search for headers and libraries | |
| 142 | // NOTE: we use os.getenv here since this part won't be executed on | |
| 143 | // windows, to get rid of unnecessary error handling | |
| 139 | // Distros like guix don't use FHS, so they rely on environment | |
| 140 | // variables to search for headers and libraries. | |
| 141 | // We use os.getenv here since this part won't be executed on | |
| 142 | // windows, to get rid of unnecessary error handling. | |
| 144 | 143 | if (std.os.getenv("C_INCLUDE_PATH")) |c_include_path| { |
| 145 | 144 | var it = mem.tokenize(u8, c_include_path, ":"); |
| 146 | 145 | while (it.next()) |dir| { |
src/Compilation.zig+22-7| ... | ... | @@ -1109,11 +1109,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1109 | 1109 | |
| 1110 | 1110 | const use_stage1 = options.use_stage1 orelse false; |
| 1111 | 1111 | |
| 1112 | const cache_mode = if (use_stage1 and !options.disable_lld_caching) | |
| 1113 | CacheMode.whole | |
| 1114 | else | |
| 1115 | options.cache_mode; | |
| 1116 | ||
| 1117 | 1112 | // Make a decision on whether to use LLVM or our own backend. |
| 1118 | 1113 | const use_llvm = build_options.have_llvm and blk: { |
| 1119 | 1114 | if (options.use_llvm) |explicit| |
| ... | ... | @@ -1154,6 +1149,14 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1154 | 1149 | } |
| 1155 | 1150 | } |
| 1156 | 1151 | |
| 1152 | // TODO: once we support incremental compilation for the LLVM backend via | |
| 1153 | // saving the LLVM module into a bitcode file and restoring it, along with | |
| 1154 | // compiler state, the second clause here can be removed so that incremental | |
| 1155 | // cache mode is used for LLVM backend too. We need some fuzz testing before | |
| 1156 | // that can be enabled. | |
| 1157 | const cache_mode = if ((use_stage1 and !options.disable_lld_caching) or | |
| 1158 | (use_llvm and !options.disable_lld_caching)) CacheMode.whole else options.cache_mode; | |
| 1159 | ||
| 1157 | 1160 | const tsan = options.want_tsan orelse false; |
| 1158 | 1161 | // TSAN is implemented in C++ so it requires linking libc++. |
| 1159 | 1162 | const link_libcpp = options.link_libcpp or tsan; |
| ... | ... | @@ -2387,9 +2390,21 @@ pub fn update(comp: *Compilation) !void { |
| 2387 | 2390 | const o_sub_path = try std.fs.path.join(comp.gpa, &[_][]const u8{ "o", &digest }); |
| 2388 | 2391 | defer comp.gpa.free(o_sub_path); |
| 2389 | 2392 | |
| 2393 | // Work around windows `AccessDenied` if any files within this directory are open | |
| 2394 | // by doing the makeExecutable/makeWritable dance. | |
| 2395 | const need_writable_dance = builtin.os.tag == .windows and comp.bin_file.file != null; | |
| 2396 | if (need_writable_dance) { | |
| 2397 | try comp.bin_file.makeExecutable(); | |
| 2398 | } | |
| 2399 | ||
| 2390 | 2400 | try comp.bin_file.renameTmpIntoCache(comp.local_cache_directory, tmp_dir_sub_path, o_sub_path); |
| 2391 | 2401 | comp.wholeCacheModeSetBinFilePath(&digest); |
| 2392 | 2402 | |
| 2403 | // Has to be after the `wholeCacheModeSetBinFilePath` above. | |
| 2404 | if (need_writable_dance) { | |
| 2405 | try comp.bin_file.makeWritable(); | |
| 2406 | } | |
| 2407 | ||
| 2393 | 2408 | // This is intentionally sandwiched between renameTmpIntoCache() and writeManifest(). |
| 2394 | 2409 | if (comp.bin_file.options.module) |module| { |
| 2395 | 2410 | // We need to set the zig_cache_artifact_directory for -femit-asm, -femit-llvm-ir, |
| ... | ... | @@ -3204,8 +3219,8 @@ fn processOneJob(comp: *Compilation, job: Job) !void { |
| 3204 | 3219 | // TODO Surface more error details. |
| 3205 | 3220 | comp.lockAndSetMiscFailure( |
| 3206 | 3221 | .mingw_crt_file, |
| 3207 | "unable to build mingw-w64 CRT file: {s}", | |
| 3208 | .{@errorName(err)}, | |
| 3222 | "unable to build mingw-w64 CRT file {s}: {s}", | |
| 3223 | .{ @tagName(crt_file), @errorName(err) }, | |
| 3209 | 3224 | ); |
| 3210 | 3225 | }; |
| 3211 | 3226 | }, |
src/link.zig+6-8| ... | ... | @@ -403,10 +403,8 @@ pub const File = struct { |
| 403 | 403 | try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, emit.sub_path, .{}); |
| 404 | 404 | } |
| 405 | 405 | } |
| 406 | if (base.intermediary_basename == null) { | |
| 407 | f.close(); | |
| 408 | base.file = null; | |
| 409 | } | |
| 406 | f.close(); | |
| 407 | base.file = null; | |
| 410 | 408 | }, |
| 411 | 409 | .coff, .elf, .plan9, .wasm => if (base.file) |f| { |
| 412 | 410 | if (base.intermediary_basename != null) { |
| ... | ... | @@ -777,7 +775,7 @@ pub const File = struct { |
| 777 | 775 | _ = base; |
| 778 | 776 | while (true) { |
| 779 | 777 | if (builtin.os.tag == .windows) { |
| 780 | // workaround windows `renameW` can't fail with `PathAlreadyExists` | |
| 778 | // Work around windows `renameW` can't fail with `PathAlreadyExists` | |
| 781 | 779 | // See https://github.com/ziglang/zig/issues/8362 |
| 782 | 780 | if (cache_directory.handle.access(o_sub_path, .{})) |_| { |
| 783 | 781 | try cache_directory.handle.deleteTree(o_sub_path); |
| ... | ... | @@ -791,9 +789,9 @@ pub const File = struct { |
| 791 | 789 | tmp_dir_sub_path, |
| 792 | 790 | cache_directory.handle, |
| 793 | 791 | o_sub_path, |
| 794 | ) catch |err| switch (err) { | |
| 795 | error.AccessDenied => unreachable, // We are most likely trying to move a dir with open handles to its resources | |
| 796 | else => |e| return e, | |
| 792 | ) catch |err| { | |
| 793 | log.err("unable to rename cache dir {s} to {s}: {s}", .{ tmp_dir_sub_path, o_sub_path, @errorName(err) }); | |
| 794 | return err; | |
| 797 | 795 | }; |
| 798 | 796 | break; |
| 799 | 797 | } else { |
src/link/Elf.zig+1-1| ... | ... | @@ -1282,7 +1282,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v |
| 1282 | 1282 | // linked are in the hash that namespaces the directory we are outputting to. Therefore, |
| 1283 | 1283 | // we must hash those now, and the resulting digest will form the "id" of the linking |
| 1284 | 1284 | // job we are about to perform. |
| 1285 | // After a successful link, we store the id in the metadata of a symlink named "id.txt" in | |
| 1285 | // After a successful link, we store the id in the metadata of a symlink named "lld.id" in | |
| 1286 | 1286 | // the artifact directory. So, now, we check if this symlink exists, and if it matches |
| 1287 | 1287 | // our digest. If so, we can skip linking. Otherwise, we proceed with invoking LLD. |
| 1288 | 1288 | const id_symlink_basename = "lld.id"; |