diff options
| -rwxr-xr-x | ci/drone/linux_script | 15 | ||||
| -rw-r--r-- | cmake/Findclang.cmake | 2 | ||||
| -rw-r--r-- | cmake/Findlld.cmake | 2 | ||||
| -rw-r--r-- | cmake/Findllvm.cmake | 2 | ||||
| -rw-r--r-- | lib/std/fs.zig | 46 | ||||
| -rw-r--r-- | lib/std/special/compiler_rt/floatunditf.zig | 10 | ||||
| -rw-r--r-- | lib/std/special/compiler_rt/floatunditf_test.zig | 2 | ||||
| -rw-r--r-- | src-self-hosted/print_targets.zig | 2 |
8 files changed, 34 insertions, 47 deletions
diff --git a/ci/drone/linux_script b/ci/drone/linux_script index da20068480..ca587eed8f 100755 --- a/ci/drone/linux_script +++ b/ci/drone/linux_script @@ -15,21 +15,6 @@ pip3 install s3cmd # This will affect the cmake command below. git config core.abbrev 9 -# This patch is a workaround for -# https://github.com/ziglang/zig/issues/4822 -patch <<'END_PATCH' ---- CMakeLists.txt -+++ CMakeLists.txt -@@ -430,7 +430,6 @@ set(BUILD_LIBSTAGE2_ARGS "build-lib" - --cache on - --output-dir "${CMAKE_BINARY_DIR}" - ${LIBSTAGE2_RELEASE_ARG} -- --bundle-compiler-rt - -fPIC - -lc - ${LIBSTAGE2_WINDOWS_ARGS} -END_PATCH - mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=$DISTDIR" -DZIG_STATIC=ON -DCMAKE_PREFIX_PATH=/deps/local diff --git a/cmake/Findclang.cmake b/cmake/Findclang.cmake index f67504068b..751cc5c824 100644 --- a/cmake/Findclang.cmake +++ b/cmake/Findclang.cmake @@ -56,6 +56,6 @@ FIND_AND_ADD_CLANG_LIB(clangCrossTU) FIND_AND_ADD_CLANG_LIB(clangIndex) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(CLANG DEFAULT_MSG CLANG_LIBRARIES CLANG_INCLUDE_DIRS) +find_package_handle_standard_args(clang DEFAULT_MSG CLANG_LIBRARIES CLANG_INCLUDE_DIRS) mark_as_advanced(CLANG_INCLUDE_DIRS CLANG_LIBRARIES CLANG_LIBDIRS) diff --git a/cmake/Findlld.cmake b/cmake/Findlld.cmake index cab6f34b57..4c69d51b24 100644 --- a/cmake/Findlld.cmake +++ b/cmake/Findlld.cmake @@ -47,6 +47,6 @@ else() endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LLD DEFAULT_MSG LLD_LIBRARIES LLD_INCLUDE_DIRS) +find_package_handle_standard_args(lld DEFAULT_MSG LLD_LIBRARIES LLD_INCLUDE_DIRS) mark_as_advanced(LLD_INCLUDE_DIRS LLD_LIBRARIES) diff --git a/cmake/Findllvm.cmake b/cmake/Findllvm.cmake index de5de2d6d1..b3a2b14f3e 100644 --- a/cmake/Findllvm.cmake +++ b/cmake/Findllvm.cmake @@ -304,6 +304,6 @@ else() endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LLVM DEFAULT_MSG LLVM_LIBRARIES LLVM_INCLUDE_DIRS) +find_package_handle_standard_args(llvm DEFAULT_MSG LLVM_LIBRARIES LLVM_INCLUDE_DIRS) mark_as_advanced(LLVM_INCLUDE_DIRS LLVM_LIBRARIES LLVM_LIBDIRS) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index e705966c97..077e668188 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -63,7 +63,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: const dirname = path.dirname(new_path) orelse "."; - var rand_buf: [12]u8 = undefined; + var rand_buf: [AtomicFile.RANDOM_BYTES]u8 = undefined; const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64.Base64Encoder.calcSize(rand_buf.len)); defer allocator.free(tmp_path); mem.copy(u8, tmp_path[0..], dirname); @@ -118,38 +118,31 @@ pub fn copyFileAbsolute(source_path: []const u8, dest_path: []const u8, args: Co /// TODO update this API to avoid a getrandom syscall for every operation. pub const AtomicFile = struct { file: File, - tmp_path_buf: [MAX_PATH_BYTES - 1:0]u8, + // TODO either replace this with rand_buf or use []u16 on Windows + tmp_path_buf: [TMP_PATH_LEN:0]u8, dest_path: []const u8, file_open: bool, file_exists: bool, + close_dir_on_deinit: bool, dir: Dir, const InitError = File.OpenError; - /// TODO rename this. Callers should go through Dir API - pub fn init2(dest_path: []const u8, mode: File.Mode, dir: Dir) InitError!AtomicFile { - const dirname = path.dirname(dest_path); - var rand_buf: [12]u8 = undefined; - const dirname_component_len = if (dirname) |d| d.len + 1 else 0; - const encoded_rand_len = comptime base64.Base64Encoder.calcSize(rand_buf.len); - const tmp_path_len = dirname_component_len + encoded_rand_len; - var tmp_path_buf: [MAX_PATH_BYTES - 1:0]u8 = undefined; - if (tmp_path_len > tmp_path_buf.len) return error.NameTooLong; - - if (dirname) |dn| { - mem.copy(u8, tmp_path_buf[0..], dn); - tmp_path_buf[dn.len] = path.sep; - } + const RANDOM_BYTES = 12; + const TMP_PATH_LEN = base64.Base64Encoder.calcSize(RANDOM_BYTES); - tmp_path_buf[tmp_path_len] = 0; - const tmp_path_slice = tmp_path_buf[0..tmp_path_len :0]; + /// TODO rename this. Callers should go through Dir API + pub fn init2(dest_path: []const u8, mode: File.Mode, dir: Dir, close_dir_on_deinit: bool) InitError!AtomicFile { + var rand_buf: [RANDOM_BYTES]u8 = undefined; + var tmp_path_buf: [TMP_PATH_LEN:0]u8 = undefined; + tmp_path_buf[base64.Base64Encoder.calcSize(RANDOM_BYTES)] = 0; while (true) { try crypto.randomBytes(rand_buf[0..]); - base64_encoder.encode(tmp_path_slice[dirname_component_len..tmp_path_len], &rand_buf); + base64_encoder.encode(&tmp_path_buf, &rand_buf); const file = dir.createFileC( - tmp_path_slice, + &tmp_path_buf, .{ .mode = mode, .exclusive = true }, ) catch |err| switch (err) { error.PathAlreadyExists => continue, @@ -162,6 +155,7 @@ pub const AtomicFile = struct { .dest_path = dest_path, .file_open = true, .file_exists = true, + .close_dir_on_deinit = close_dir_on_deinit, .dir = dir, }; } @@ -169,7 +163,7 @@ pub const AtomicFile = struct { /// Deprecated. Use `Dir.atomicFile`. pub fn init(dest_path: []const u8, mode: File.Mode) InitError!AtomicFile { - return init2(dest_path, mode, cwd()); + return cwd().atomicFile(dest_path, .{ .mode = mode }); } /// always call deinit, even after successful finish() @@ -182,6 +176,9 @@ pub const AtomicFile = struct { self.dir.deleteFileC(&self.tmp_path_buf) catch {}; self.file_exists = false; } + if (self.close_dir_on_deinit) { + self.dir.close(); + } self.* = undefined; } @@ -1281,7 +1278,12 @@ pub const Dir = struct { /// `dest_path` must remain valid for the lifetime of `AtomicFile`. /// Call `AtomicFile.finish` to atomically replace `dest_path` with contents. pub fn atomicFile(self: Dir, dest_path: []const u8, options: AtomicFileOptions) !AtomicFile { - return AtomicFile.init2(dest_path, options.mode, self); + if (path.dirname(dest_path)) |dirname| { + const dir = try self.openDir(dirname, .{}); + return AtomicFile.init2(path.basename(dest_path), options.mode, dir, true); + } else { + return AtomicFile.init2(dest_path, options.mode, self, false); + } } }; diff --git a/lib/std/special/compiler_rt/floatunditf.zig b/lib/std/special/compiler_rt/floatunditf.zig index b574d21bd8..209f66fc2e 100644 --- a/lib/std/special/compiler_rt/floatunditf.zig +++ b/lib/std/special/compiler_rt/floatunditf.zig @@ -2,7 +2,7 @@ const builtin = @import("builtin"); const is_test = builtin.is_test; const std = @import("std"); -pub fn __floatunditf(a: u128) callconv(.C) f128 { +pub fn __floatunditf(a: u64) callconv(.C) f128 { @setRuntimeSafety(is_test); if (a == 0) { @@ -14,11 +14,11 @@ pub fn __floatunditf(a: u128) callconv(.C) f128 { const exponent_bias = (1 << (exponent_bits - 1)) - 1; const implicit_bit = 1 << mantissa_bits; - const exp = (u128.bit_count - 1) - @clz(u128, a); - const shift = mantissa_bits - @intCast(u7, exp); + const exp: u128 = (u64.bit_count - 1) - @clz(u64, a); + const shift: u7 = mantissa_bits - @intCast(u7, exp); - var result: u128 align(16) = (a << shift) ^ implicit_bit; - result += (@intCast(u128, exp) + exponent_bias) << mantissa_bits; + var result: u128 = (@intCast(u128, a) << shift) ^ implicit_bit; + result += (exp + exponent_bias) << mantissa_bits; return @bitCast(f128, result); } diff --git a/lib/std/special/compiler_rt/floatunditf_test.zig b/lib/std/special/compiler_rt/floatunditf_test.zig index 5b4e195870..7bb3333693 100644 --- a/lib/std/special/compiler_rt/floatunditf_test.zig +++ b/lib/std/special/compiler_rt/floatunditf_test.zig @@ -1,6 +1,6 @@ const __floatunditf = @import("floatunditf.zig").__floatunditf; -fn test__floatunditf(a: u128, expected_hi: u64, expected_lo: u64) void { +fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) void { const x = __floatunditf(a); const x_repr = @bitCast(u128, x); diff --git a/src-self-hosted/print_targets.zig b/src-self-hosted/print_targets.zig index 997cfcfddc..f84a4a2cbc 100644 --- a/src-self-hosted/print_targets.zig +++ b/src-self-hosted/print_targets.zig @@ -75,7 +75,7 @@ pub fn cmdTargets( var dir = try std.fs.cwd().openDir(zig_lib_dir, .{}); defer dir.close(); - const vers_txt = try dir.readFileAlloc(allocator, "libc/glibc/vers.txt", 10 * 1024); + const vers_txt = try dir.readFileAlloc(allocator, "libc" ++ std.fs.path.sep_str ++ "glibc" ++ std.fs.path.sep_str ++ "vers.txt", 10 * 1024); defer allocator.free(vers_txt); var list = std.ArrayList(std.builtin.Version).init(allocator); |
