| author | |
| committer | |
| log | 902df103c6151c257c90de9ba5f29f7f4b9dbea2 |
| tree | 16a522f3c8bbe34b56038d4810bf2487e32e2d85 |
| parent | 173d56213b60fc570b6ba3922ee1d40bbf0d0e36 |
See #3811101 files changed, 1225 insertions(+), 1561 deletions(-)
CMakeLists.txt+1-1| ... | ... | @@ -534,7 +534,7 @@ set(ZIG_STAGE2_SOURCES |
| 534 | 534 | "${CMAKE_SOURCE_DIR}/lib/std/unicode.zig" |
| 535 | 535 | "${CMAKE_SOURCE_DIR}/lib/std/zig.zig" |
| 536 | 536 | "${CMAKE_SOURCE_DIR}/lib/std/zig/Ast.zig" |
| 537 | "${CMAKE_SOURCE_DIR}/lib/std/zig/cross_target.zig" | |
| 537 | "${CMAKE_SOURCE_DIR}/lib/std/zig/CrossTarget.zig" | |
| 538 | 538 | "${CMAKE_SOURCE_DIR}/lib/std/zig/parse.zig" |
| 539 | 539 | "${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig" |
| 540 | 540 | "${CMAKE_SOURCE_DIR}/lib/std/zig/string_literal.zig" |
build.zig+3-4| ... | ... | @@ -3,7 +3,6 @@ const builtin = std.builtin; |
| 3 | 3 | const Builder = std.build.Builder; |
| 4 | 4 | const tests = @import("test/tests.zig"); |
| 5 | 5 | const BufMap = std.BufMap; |
| 6 | const warn = std.debug.warn; | |
| 7 | 6 | const mem = std.mem; |
| 8 | 7 | const ArrayList = std.ArrayList; |
| 9 | 8 | const io = std.io; |
| ... | ... | @@ -558,9 +557,9 @@ fn addCxxKnownPath( |
| 558 | 557 | const path_unpadded = mem.tokenize(u8, path_padded, "\r\n").next().?; |
| 559 | 558 | if (mem.eql(u8, path_unpadded, objname)) { |
| 560 | 559 | if (errtxt) |msg| { |
| 561 | warn("{s}", .{msg}); | |
| 560 | std.debug.print("{s}", .{msg}); | |
| 562 | 561 | } else { |
| 563 | warn("Unable to determine path to {s}\n", .{objname}); | |
| 562 | std.debug.print("Unable to determine path to {s}\n", .{objname}); | |
| 564 | 563 | } |
| 565 | 564 | return error.RequiredLibraryNotFound; |
| 566 | 565 | } |
| ... | ... | @@ -687,7 +686,7 @@ fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeCon |
| 687 | 686 | } |
| 688 | 687 | |
| 689 | 688 | fn toNativePathSep(b: *Builder, s: []const u8) []u8 { |
| 690 | const duplicated = mem.dupe(b.allocator, u8, s) catch unreachable; | |
| 689 | const duplicated = b.allocator.dupe(u8, s) catch unreachable; | |
| 691 | 690 | for (duplicated) |*byte| switch (byte.*) { |
| 692 | 691 | '/' => byte.* = fs.path.sep, |
| 693 | 692 | else => {}, |
doc/langref.html.in+5-5| ... | ... | @@ -5708,7 +5708,7 @@ const mem = std.mem; |
| 5708 | 5708 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 5709 | 5709 | const window_name = [1][*]const u8{"window name"}; |
| 5710 | 5710 | const x: [*]const ?[*]const u8 = &window_name; |
| 5711 | try expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name")); | |
| 5711 | try expect(mem.eql(u8, std.mem.sliceTo(@ptrCast([*:0]const u8, x[0].?), 0), "window name")); | |
| 5712 | 5712 | } |
| 5713 | 5713 | {#code_end#} |
| 5714 | 5714 | {#header_close#} |
| ... | ... | @@ -7364,7 +7364,7 @@ fn amain() !void { |
| 7364 | 7364 | var global_download_frame: anyframe = undefined; |
| 7365 | 7365 | fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 7366 | 7366 | _ = url; // this is just an example, we don't actually do it! |
| 7367 | const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents"); | |
| 7367 | const result = try allocator.dupe(u8, "this is the downloaded url contents"); | |
| 7368 | 7368 | errdefer allocator.free(result); |
| 7369 | 7369 | suspend { |
| 7370 | 7370 | global_download_frame = @frame(); |
| ... | ... | @@ -7376,7 +7376,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 7376 | 7376 | var global_file_frame: anyframe = undefined; |
| 7377 | 7377 | fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { |
| 7378 | 7378 | _ = filename; // this is just an example, we don't actually do it! |
| 7379 | const result = try std.mem.dupe(allocator, u8, "this is the file contents"); | |
| 7379 | const result = try allocator.dupe(u8, "this is the file contents"); | |
| 7380 | 7380 | errdefer allocator.free(result); |
| 7381 | 7381 | suspend { |
| 7382 | 7382 | global_file_frame = @frame(); |
| ... | ... | @@ -7435,7 +7435,7 @@ fn amain() !void { |
| 7435 | 7435 | |
| 7436 | 7436 | fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 7437 | 7437 | _ = url; // this is just an example, we don't actually do it! |
| 7438 | const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents"); | |
| 7438 | const result = try allocator.dupe(u8, "this is the downloaded url contents"); | |
| 7439 | 7439 | errdefer allocator.free(result); |
| 7440 | 7440 | std.debug.print("fetchUrl returning\n", .{}); |
| 7441 | 7441 | return result; |
| ... | ... | @@ -7443,7 +7443,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 7443 | 7443 | |
| 7444 | 7444 | fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { |
| 7445 | 7445 | _ = filename; // this is just an example, we don't actually do it! |
| 7446 | const result = try std.mem.dupe(allocator, u8, "this is the file contents"); | |
| 7446 | const result = try allocator.dupe(u8, "this is the file contents"); | |
| 7447 | 7447 | errdefer allocator.free(result); |
| 7448 | 7448 | std.debug.print("readFile returning\n", .{}); |
| 7449 | 7449 | return result; |
lib/std/Thread.zig+1-3| ... | ... | @@ -17,8 +17,6 @@ pub const Mutex = @import("Thread/Mutex.zig"); |
| 17 | 17 | pub const Semaphore = @import("Thread/Semaphore.zig"); |
| 18 | 18 | pub const Condition = @import("Thread/Condition.zig"); |
| 19 | 19 | |
| 20 | pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint"); | |
| 21 | ||
| 22 | 20 | pub const use_pthreads = target.os.tag != .windows and target.os.tag != .wasi and builtin.link_libc; |
| 23 | 21 | const is_gnu = target.abi.isGnu(); |
| 24 | 22 | |
| ... | ... | @@ -361,7 +359,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) { |
| 361 | 359 | } |
| 362 | 360 | |
| 363 | 361 | @call(.{}, f, args) catch |err| { |
| 364 | std.debug.warn("error: {s}\n", .{@errorName(err)}); | |
| 362 | std.debug.print("error: {s}\n", .{@errorName(err)}); | |
| 365 | 363 | if (@errorReturnTrace()) |trace| { |
| 366 | 364 | std.debug.dumpStackTrace(trace.*); |
| 367 | 365 | } |
lib/std/array_hash_map.zig+2-15| ... | ... | @@ -201,8 +201,7 @@ pub fn ArrayHashMap( |
| 201 | 201 | return self.unmanaged.getOrPutValueContext(self.allocator, key, value, self.ctx); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. | |
| 205 | pub const ensureCapacity = ensureTotalCapacity; | |
| 204 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); | |
| 206 | 205 | |
| 207 | 206 | /// Increases capacity, guaranteeing that insertions up until the |
| 208 | 207 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| ... | ... | @@ -746,8 +745,7 @@ pub fn ArrayHashMapUnmanaged( |
| 746 | 745 | return res; |
| 747 | 746 | } |
| 748 | 747 | |
| 749 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. | |
| 750 | pub const ensureCapacity = ensureTotalCapacity; | |
| 748 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); | |
| 751 | 749 | |
| 752 | 750 | /// Increases capacity, guaranteeing that insertions up until the |
| 753 | 751 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| ... | ... | @@ -2217,17 +2215,6 @@ test "auto store_hash" { |
| 2217 | 2215 | try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Data, .hash).field_type != void); |
| 2218 | 2216 | } |
| 2219 | 2217 | |
| 2220 | test "compile everything" { | |
| 2221 | std.testing.refAllDecls(AutoArrayHashMap(i32, i32)); | |
| 2222 | std.testing.refAllDecls(StringArrayHashMap([]const u8)); | |
| 2223 | std.testing.refAllDecls(AutoArrayHashMap(i32, void)); | |
| 2224 | std.testing.refAllDecls(StringArrayHashMap(u0)); | |
| 2225 | std.testing.refAllDecls(AutoArrayHashMapUnmanaged(i32, i32)); | |
| 2226 | std.testing.refAllDecls(StringArrayHashMapUnmanaged([]const u8)); | |
| 2227 | std.testing.refAllDecls(AutoArrayHashMapUnmanaged(i32, void)); | |
| 2228 | std.testing.refAllDecls(StringArrayHashMapUnmanaged(u0)); | |
| 2229 | } | |
| 2230 | ||
| 2231 | 2218 | pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) { |
| 2232 | 2219 | return struct { |
| 2233 | 2220 | fn hash(ctx: Context, key: K) u32 { |
lib/std/array_list.zig+6-22| ... | ... | @@ -71,15 +71,6 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | pub const span = @compileError("deprecated: use `items` field directly"); | |
| 75 | pub const toSlice = @compileError("deprecated: use `items` field directly"); | |
| 76 | pub const toSliceConst = @compileError("deprecated: use `items` field directly"); | |
| 77 | pub const at = @compileError("deprecated: use `list.items[i]`"); | |
| 78 | pub const ptrAt = @compileError("deprecated: use `&list.items[i]`"); | |
| 79 | pub const setOrError = @compileError("deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.items[i] = item`"); | |
| 80 | pub const set = @compileError("deprecated: use `list.items[i] = item`"); | |
| 81 | pub const swapRemoveOrError = @compileError("deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.swapRemove(i)`"); | |
| 82 | ||
| 83 | 74 | /// ArrayList takes ownership of the passed in slice. The slice must have been |
| 84 | 75 | /// allocated with `allocator`. |
| 85 | 76 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| ... | ... | @@ -91,12 +82,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 91 | 82 | }; |
| 92 | 83 | } |
| 93 | 84 | |
| 94 | /// Initializes an ArrayListUnmanaged with the `items` and `capacity` fields | |
| 95 | /// of this ArrayList. This ArrayList retains ownership of underlying memory. | |
| 96 | /// Deprecated: use `moveToUnmanaged` which has different semantics. | |
| 97 | pub fn toUnmanaged(self: Self) ArrayListAlignedUnmanaged(T, alignment) { | |
| 98 | return .{ .items = self.items, .capacity = self.capacity }; | |
| 99 | } | |
| 85 | pub const toUnmanaged = @compileError("deprecated; use `moveToUnmanaged` which has different semantics."); | |
| 100 | 86 | |
| 101 | 87 | /// Initializes an ArrayListUnmanaged with the `items` and `capacity` fields |
| 102 | 88 | /// of this ArrayList. Empties this ArrayList. |
| ... | ... | @@ -307,8 +293,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 307 | 293 | self.capacity = 0; |
| 308 | 294 | } |
| 309 | 295 | |
| 310 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. | |
| 311 | pub const ensureCapacity = ensureTotalCapacity; | |
| 296 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); | |
| 312 | 297 | |
| 313 | 298 | /// Modify the array so that it can hold at least `new_capacity` items. |
| 314 | 299 | /// Invalidates pointers if additional memory is needed. |
| ... | ... | @@ -533,7 +518,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 533 | 518 | pub fn replaceRange(self: *Self, allocator: *Allocator, start: usize, len: usize, new_items: []const T) !void { |
| 534 | 519 | var managed = self.toManaged(allocator); |
| 535 | 520 | try managed.replaceRange(start, len, new_items); |
| 536 | self.* = managed.toUnmanaged(); | |
| 521 | self.* = managed.moveToUnmanaged(); | |
| 537 | 522 | } |
| 538 | 523 | |
| 539 | 524 | /// Extend the list by 1 element. Allocates more memory as necessary. |
| ... | ... | @@ -674,8 +659,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 674 | 659 | self.capacity = 0; |
| 675 | 660 | } |
| 676 | 661 | |
| 677 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. | |
| 678 | pub const ensureCapacity = ensureTotalCapacity; | |
| 662 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); | |
| 679 | 663 | |
| 680 | 664 | /// Modify the array so that it can hold at least `new_capacity` items. |
| 681 | 665 | /// Invalidates pointers if additional memory is needed. |
| ... | ... | @@ -1337,7 +1321,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" { |
| 1337 | 1321 | |
| 1338 | 1322 | const result = try list.toOwnedSliceSentinel(0); |
| 1339 | 1323 | defer a.free(result); |
| 1340 | try testing.expectEqualStrings(result, mem.spanZ(result.ptr)); | |
| 1324 | try testing.expectEqualStrings(result, mem.sliceTo(result.ptr, 0)); | |
| 1341 | 1325 | } |
| 1342 | 1326 | { |
| 1343 | 1327 | var list = ArrayListUnmanaged(u8){}; |
| ... | ... | @@ -1347,7 +1331,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" { |
| 1347 | 1331 | |
| 1348 | 1332 | const result = try list.toOwnedSliceSentinel(a, 0); |
| 1349 | 1333 | defer a.free(result); |
| 1350 | try testing.expectEqualStrings(result, mem.spanZ(result.ptr)); | |
| 1334 | try testing.expectEqualStrings(result, mem.sliceTo(result.ptr, 0)); | |
| 1351 | 1335 | } |
| 1352 | 1336 | } |
| 1353 | 1337 |
lib/std/base64.zig+3-8| ... | ... | @@ -64,14 +64,9 @@ pub const url_safe_no_pad = Codecs{ |
| 64 | 64 | .Decoder = Base64Decoder.init(url_safe_alphabet_chars, null), |
| 65 | 65 | }; |
| 66 | 66 | |
| 67 | // Backwards compatibility | |
| 68 | ||
| 69 | /// Deprecated - Use `standard.pad_char` | |
| 70 | pub const standard_pad_char = standard.pad_char; | |
| 71 | /// Deprecated - Use `standard.Encoder` | |
| 72 | pub const standard_encoder = standard.Encoder; | |
| 73 | /// Deprecated - Use `standard.Decoder` | |
| 74 | pub const standard_decoder = standard.Decoder; | |
| 67 | pub const standard_pad_char = @compileError("deprecated; use standard.pad_char"); | |
| 68 | pub const standard_encoder = @compileError("deprecated; use standard.Encoder"); | |
| 69 | pub const standard_decoder = @compileError("deprecated; use standard.Decoder"); | |
| 75 | 70 | |
| 76 | 71 | pub const Base64Encoder = struct { |
| 77 | 72 | alphabet_chars: [64]u8, |
lib/std/build.zig+7-19| ... | ... | @@ -6,7 +6,7 @@ const mem = std.mem; |
| 6 | 6 | const debug = std.debug; |
| 7 | 7 | const panic = std.debug.panic; |
| 8 | 8 | const assert = debug.assert; |
| 9 | const warn = std.debug.warn; | |
| 9 | const warn = std.debug.print; // TODO use the log system instead of this | |
| 10 | 10 | const ArrayList = std.ArrayList; |
| 11 | 11 | const StringHashMap = std.StringHashMap; |
| 12 | 12 | const Allocator = mem.Allocator; |
| ... | ... | @@ -1295,11 +1295,12 @@ test "builder.findProgram compiles" { |
| 1295 | 1295 | _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null; |
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | /// Deprecated. Use `std.builtin.Version`. | |
| 1299 | pub const Version = std.builtin.Version; | |
| 1300 | ||
| 1301 | /// Deprecated. Use `std.zig.CrossTarget`. | |
| 1302 | pub const Target = std.zig.CrossTarget; | |
| 1298 | /// TODO: propose some kind of `@deprecate` builtin so that we can deprecate | |
| 1299 | /// this while still having somewhat non-lazy decls. In this file we wanted to do | |
| 1300 | /// refAllDecls for example which makes it trigger `@compileError` if you try | |
| 1301 | /// to use that strategy. | |
| 1302 | pub const Version = @compileError("deprecated; Use `std.builtin.Version`"); | |
| 1303 | pub const Target = @compileError("deprecated; Use `std.zig.CrossTarget`"); | |
| 1303 | 1304 | |
| 1304 | 1305 | pub const Pkg = struct { |
| 1305 | 1306 | name: []const u8, |
| ... | ... | @@ -3277,16 +3278,3 @@ test "LibExeObjStep.addPackage" { |
| 3277 | 3278 | const dupe = exe.packages.items[0]; |
| 3278 | 3279 | try std.testing.expectEqualStrings(pkg_top.name, dupe.name); |
| 3279 | 3280 | } |
| 3280 | ||
| 3281 | test { | |
| 3282 | // The only purpose of this test is to get all these untested functions | |
| 3283 | // to be referenced to avoid regression so it is okay to skip some targets. | |
| 3284 | if (comptime builtin.cpu.arch.ptrBitWidth() == 64) { | |
| 3285 | std.testing.refAllDecls(@This()); | |
| 3286 | std.testing.refAllDecls(Builder); | |
| 3287 | ||
| 3288 | inline for (std.meta.declarations(@This())) |decl| | |
| 3289 | if (comptime mem.endsWith(u8, decl.name, "Step")) | |
| 3290 | std.testing.refAllDecls(decl.data.Type); | |
| 3291 | } | |
| 3292 | } |
lib/std/build/CheckFileStep.zig+1-2| ... | ... | @@ -4,7 +4,6 @@ const Step = build.Step; |
| 4 | 4 | const Builder = build.Builder; |
| 5 | 5 | const fs = std.fs; |
| 6 | 6 | const mem = std.mem; |
| 7 | const warn = std.debug.warn; | |
| 8 | 7 | |
| 9 | 8 | const CheckFileStep = @This(); |
| 10 | 9 | |
| ... | ... | @@ -40,7 +39,7 @@ fn make(step: *Step) !void { |
| 40 | 39 | |
| 41 | 40 | for (self.expected_matches) |expected_match| { |
| 42 | 41 | if (mem.indexOf(u8, contents, expected_match) == null) { |
| 43 | warn( | |
| 42 | std.debug.print( | |
| 44 | 43 | \\ |
| 45 | 44 | \\========= Expected to find: =================== |
| 46 | 45 | \\{s} |
lib/std/build/InstallRawStep.zig+1-2| ... | ... | @@ -12,7 +12,6 @@ const elf = std.elf; |
| 12 | 12 | const fs = std.fs; |
| 13 | 13 | const io = std.io; |
| 14 | 14 | const sort = std.sort; |
| 15 | const warn = std.debug.warn; | |
| 16 | 15 | |
| 17 | 16 | const BinaryElfSection = struct { |
| 18 | 17 | elfOffset: u64, |
| ... | ... | @@ -387,7 +386,7 @@ fn make(step: *Step) !void { |
| 387 | 386 | const builder = self.builder; |
| 388 | 387 | |
| 389 | 388 | if (self.artifact.target.getObjectFormat() != .elf) { |
| 390 | warn("InstallRawStep only works with ELF format.\n", .{}); | |
| 389 | std.debug.print("InstallRawStep only works with ELF format.\n", .{}); | |
| 391 | 390 | return error.InvalidObjectFormat; |
| 392 | 391 | } |
| 393 | 392 |
lib/std/build/RunStep.zig+12-13| ... | ... | @@ -10,7 +10,6 @@ const mem = std.mem; |
| 10 | 10 | const process = std.process; |
| 11 | 11 | const ArrayList = std.ArrayList; |
| 12 | 12 | const BufMap = std.BufMap; |
| 13 | const warn = std.debug.warn; | |
| 14 | 13 | |
| 15 | 14 | const max_stdout_size = 1 * 1024 * 1024; // 1 MiB |
| 16 | 15 | |
| ... | ... | @@ -189,7 +188,7 @@ fn make(step: *Step) !void { |
| 189 | 188 | printCmd(cwd, argv); |
| 190 | 189 | |
| 191 | 190 | child.spawn() catch |err| { |
| 192 | warn("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) }); | |
| 191 | std.debug.print("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) }); | |
| 193 | 192 | return err; |
| 194 | 193 | }; |
| 195 | 194 | |
| ... | ... | @@ -216,7 +215,7 @@ fn make(step: *Step) !void { |
| 216 | 215 | } |
| 217 | 216 | |
| 218 | 217 | const term = child.wait() catch |err| { |
| 219 | warn("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) }); | |
| 218 | std.debug.print("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) }); | |
| 220 | 219 | return err; |
| 221 | 220 | }; |
| 222 | 221 | |
| ... | ... | @@ -224,12 +223,12 @@ fn make(step: *Step) !void { |
| 224 | 223 | .Exited => |code| { |
| 225 | 224 | if (code != self.expected_exit_code) { |
| 226 | 225 | if (self.builder.prominent_compile_errors) { |
| 227 | warn("Run step exited with error code {} (expected {})\n", .{ | |
| 226 | std.debug.print("Run step exited with error code {} (expected {})\n", .{ | |
| 228 | 227 | code, |
| 229 | 228 | self.expected_exit_code, |
| 230 | 229 | }); |
| 231 | 230 | } else { |
| 232 | warn("The following command exited with error code {} (expected {}):\n", .{ | |
| 231 | std.debug.print("The following command exited with error code {} (expected {}):\n", .{ | |
| 233 | 232 | code, |
| 234 | 233 | self.expected_exit_code, |
| 235 | 234 | }); |
| ... | ... | @@ -240,7 +239,7 @@ fn make(step: *Step) !void { |
| 240 | 239 | } |
| 241 | 240 | }, |
| 242 | 241 | else => { |
| 243 | warn("The following command terminated unexpectedly:\n", .{}); | |
| 242 | std.debug.print("The following command terminated unexpectedly:\n", .{}); | |
| 244 | 243 | printCmd(cwd, argv); |
| 245 | 244 | return error.UncleanExit; |
| 246 | 245 | }, |
| ... | ... | @@ -250,7 +249,7 @@ fn make(step: *Step) !void { |
| 250 | 249 | .inherit, .ignore => {}, |
| 251 | 250 | .expect_exact => |expected_bytes| { |
| 252 | 251 | if (!mem.eql(u8, expected_bytes, stderr.?)) { |
| 253 | warn( | |
| 252 | std.debug.print( | |
| 254 | 253 | \\ |
| 255 | 254 | \\========= Expected this stderr: ========= |
| 256 | 255 | \\{s} |
| ... | ... | @@ -264,7 +263,7 @@ fn make(step: *Step) !void { |
| 264 | 263 | }, |
| 265 | 264 | .expect_matches => |matches| for (matches) |match| { |
| 266 | 265 | if (mem.indexOf(u8, stderr.?, match) == null) { |
| 267 | warn( | |
| 266 | std.debug.print( | |
| 268 | 267 | \\ |
| 269 | 268 | \\========= Expected to find in stderr: ========= |
| 270 | 269 | \\{s} |
| ... | ... | @@ -282,7 +281,7 @@ fn make(step: *Step) !void { |
| 282 | 281 | .inherit, .ignore => {}, |
| 283 | 282 | .expect_exact => |expected_bytes| { |
| 284 | 283 | if (!mem.eql(u8, expected_bytes, stdout.?)) { |
| 285 | warn( | |
| 284 | std.debug.print( | |
| 286 | 285 | \\ |
| 287 | 286 | \\========= Expected this stdout: ========= |
| 288 | 287 | \\{s} |
| ... | ... | @@ -296,7 +295,7 @@ fn make(step: *Step) !void { |
| 296 | 295 | }, |
| 297 | 296 | .expect_matches => |matches| for (matches) |match| { |
| 298 | 297 | if (mem.indexOf(u8, stdout.?, match) == null) { |
| 299 | warn( | |
| 298 | std.debug.print( | |
| 300 | 299 | \\ |
| 301 | 300 | \\========= Expected to find in stdout: ========= |
| 302 | 301 | \\{s} |
| ... | ... | @@ -312,11 +311,11 @@ fn make(step: *Step) !void { |
| 312 | 311 | } |
| 313 | 312 | |
| 314 | 313 | fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void { |
| 315 | if (cwd) |yes_cwd| warn("cd {s} && ", .{yes_cwd}); | |
| 314 | if (cwd) |yes_cwd| std.debug.print("cd {s} && ", .{yes_cwd}); | |
| 316 | 315 | for (argv) |arg| { |
| 317 | warn("{s} ", .{arg}); | |
| 316 | std.debug.print("{s} ", .{arg}); | |
| 318 | 317 | } |
| 319 | warn("\n", .{}); | |
| 318 | std.debug.print("\n", .{}); | |
| 320 | 319 | } |
| 321 | 320 | |
| 322 | 321 | fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void { |
lib/std/build/WriteFileStep.zig+2-3| ... | ... | @@ -3,7 +3,6 @@ const build = @import("../build.zig"); |
| 3 | 3 | const Step = build.Step; |
| 4 | 4 | const Builder = build.Builder; |
| 5 | 5 | const fs = std.fs; |
| 6 | const warn = std.debug.warn; | |
| 7 | 6 | const ArrayList = std.ArrayList; |
| 8 | 7 | |
| 9 | 8 | const WriteFileStep = @This(); |
| ... | ... | @@ -91,7 +90,7 @@ fn make(step: *Step) !void { |
| 91 | 90 | }); |
| 92 | 91 | // TODO replace with something like fs.makePathAndOpenDir |
| 93 | 92 | fs.cwd().makePath(self.output_dir) catch |err| { |
| 94 | warn("unable to make path {s}: {s}\n", .{ self.output_dir, @errorName(err) }); | |
| 93 | std.debug.print("unable to make path {s}: {s}\n", .{ self.output_dir, @errorName(err) }); | |
| 95 | 94 | return err; |
| 96 | 95 | }; |
| 97 | 96 | var dir = try fs.cwd().openDir(self.output_dir, .{}); |
| ... | ... | @@ -100,7 +99,7 @@ fn make(step: *Step) !void { |
| 100 | 99 | var it = self.files.first; |
| 101 | 100 | while (it) |node| : (it = node.next) { |
| 102 | 101 | dir.writeFile(node.data.basename, node.data.bytes) catch |err| { |
| 103 | warn("unable to write {s} into {s}: {s}\n", .{ | |
| 102 | std.debug.print("unable to write {s} into {s}: {s}\n", .{ | |
| 104 | 103 | node.data.basename, |
| 105 | 104 | self.output_dir, |
| 106 | 105 | @errorName(err), |
lib/std/builtin.zig+1-1| ... | ... | @@ -707,7 +707,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn |
| 707 | 707 | } |
| 708 | 708 | }, |
| 709 | 709 | .wasi => { |
| 710 | std.debug.warn("{s}", .{msg}); | |
| 710 | std.debug.print("{s}", .{msg}); | |
| 711 | 711 | std.os.abort(); |
| 712 | 712 | }, |
| 713 | 713 | .uefi => { |
lib/std/c/tokenizer.zig+2-2| ... | ... | @@ -126,7 +126,7 @@ pub const Token = struct { |
| 126 | 126 | Keyword_error, |
| 127 | 127 | Keyword_pragma, |
| 128 | 128 | |
| 129 | pub fn symbol(id: std.meta.TagType(Id)) []const u8 { | |
| 129 | pub fn symbol(id: std.meta.Tag(Id)) []const u8 { | |
| 130 | 130 | return switch (id) { |
| 131 | 131 | .Invalid => "Invalid", |
| 132 | 132 | .Eof => "Eof", |
| ... | ... | @@ -342,7 +342,7 @@ pub const Token = struct { |
| 342 | 342 | pub const Tokenizer = struct { |
| 343 | 343 | buffer: []const u8, |
| 344 | 344 | index: usize = 0, |
| 345 | prev_tok_id: std.meta.TagType(Token.Id) = .Invalid, | |
| 345 | prev_tok_id: std.meta.Tag(Token.Id) = .Invalid, | |
| 346 | 346 | pp_directive: bool = false, |
| 347 | 347 | |
| 348 | 348 | pub fn next(self: *Tokenizer) Token { |
lib/std/child_process.zig-2| ... | ... | @@ -181,8 +181,6 @@ pub const ChildProcess = struct { |
| 181 | 181 | stderr: []u8, |
| 182 | 182 | }; |
| 183 | 183 | |
| 184 | pub const exec2 = @compileError("deprecated: exec2 is renamed to exec"); | |
| 185 | ||
| 186 | 184 | fn collectOutputPosix( |
| 187 | 185 | child: *const ChildProcess, |
| 188 | 186 | stdout: *std.ArrayList(u8), |
lib/std/crypto/benchmark.zig+1-1| ... | ... | @@ -343,7 +343,7 @@ fn benchmarkPwhash( |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | fn usage() void { |
| 346 | std.debug.warn( | |
| 346 | std.debug.print( | |
| 347 | 347 | \\throughput_test [options] |
| 348 | 348 | \\ |
| 349 | 349 | \\Options: |
lib/std/debug.zig+6-8| ... | ... | @@ -55,9 +55,7 @@ const PdbOrDwarf = union(enum) { |
| 55 | 55 | |
| 56 | 56 | var stderr_mutex = std.Thread.Mutex{}; |
| 57 | 57 | |
| 58 | /// Deprecated. Use `std.log` functions for logging or `std.debug.print` for | |
| 59 | /// "printf debugging". | |
| 60 | pub const warn = print; | |
| 58 | pub const warn = @compileError("deprecated; use `std.log` functions for logging or `std.debug.print` for 'printf debugging'"); | |
| 61 | 59 | |
| 62 | 60 | /// Print to stderr, unbuffered, and silently returning on failure. Intended |
| 63 | 61 | /// for use in "printf debugging." Use `std.log` functions for proper logging. |
| ... | ... | @@ -1052,7 +1050,7 @@ pub const DebugInfo = struct { |
| 1052 | 1050 | const obj_di = try self.allocator.create(ModuleDebugInfo); |
| 1053 | 1051 | errdefer self.allocator.destroy(obj_di); |
| 1054 | 1052 | |
| 1055 | const macho_path = mem.spanZ(std.c._dyld_get_image_name(i)); | |
| 1053 | const macho_path = mem.sliceTo(std.c._dyld_get_image_name(i), 0); | |
| 1056 | 1054 | const macho_file = fs.cwd().openFile(macho_path, .{ .intended_io_mode = .blocking }) catch |err| switch (err) { |
| 1057 | 1055 | error.FileNotFound => return error.MissingDebugInfo, |
| 1058 | 1056 | else => return err, |
| ... | ... | @@ -1178,7 +1176,7 @@ pub const DebugInfo = struct { |
| 1178 | 1176 | if (context.address >= seg_start and context.address < seg_end) { |
| 1179 | 1177 | // Android libc uses NULL instead of an empty string to mark the |
| 1180 | 1178 | // main program |
| 1181 | context.name = mem.spanZ(info.dlpi_name) orelse ""; | |
| 1179 | context.name = mem.sliceTo(info.dlpi_name, 0) orelse ""; | |
| 1182 | 1180 | context.base_address = info.dlpi_addr; |
| 1183 | 1181 | // Stop the iteration |
| 1184 | 1182 | return error.Found; |
| ... | ... | @@ -1341,12 +1339,12 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1341 | 1339 | |
| 1342 | 1340 | // Take the symbol name from the N_FUN STAB entry, we're going to |
| 1343 | 1341 | // use it if we fail to find the DWARF infos |
| 1344 | const stab_symbol = mem.spanZ(self.strings[symbol.nlist.n_strx..]); | |
| 1342 | const stab_symbol = mem.sliceTo(self.strings[symbol.nlist.n_strx..], 0); | |
| 1345 | 1343 | |
| 1346 | 1344 | if (symbol.ofile == null) |
| 1347 | 1345 | return SymbolInfo{ .symbol_name = stab_symbol }; |
| 1348 | 1346 | |
| 1349 | const o_file_path = mem.spanZ(self.strings[symbol.ofile.?.n_strx..]); | |
| 1347 | const o_file_path = mem.sliceTo(self.strings[symbol.ofile.?.n_strx..], 0); | |
| 1350 | 1348 | |
| 1351 | 1349 | // Check if its debug infos are already in the cache |
| 1352 | 1350 | var o_file_di = self.ofiles.get(o_file_path) orelse |
| ... | ... | @@ -1668,5 +1666,5 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void { |
| 1668 | 1666 | const sp = asm ("" |
| 1669 | 1667 | : [argc] "={rsp}" (-> usize), |
| 1670 | 1668 | ); |
| 1671 | std.debug.warn("{} sp = 0x{x}\n", .{ prefix, sp }); | |
| 1669 | std.debug.print("{} sp = 0x{x}\n", .{ prefix, sp }); | |
| 1672 | 1670 | } |
lib/std/dynamic_library.zig+3-9| ... | ... | @@ -248,11 +248,9 @@ pub const ElfDynLib = struct { |
| 248 | 248 | }; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | pub const openC = @compileError("deprecated: renamed to openZ"); | |
| 252 | ||
| 253 | 251 | /// Trusts the file. Malicious file will be able to execute arbitrary code. |
| 254 | 252 | pub fn openZ(path_c: [*:0]const u8) !ElfDynLib { |
| 255 | return open(mem.spanZ(path_c)); | |
| 253 | return open(mem.sliceTo(path_c, 0)); | |
| 256 | 254 | } |
| 257 | 255 | |
| 258 | 256 | /// Trusts the file |
| ... | ... | @@ -281,7 +279,7 @@ pub const ElfDynLib = struct { |
| 281 | 279 | if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue; |
| 282 | 280 | if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue; |
| 283 | 281 | if (0 == self.syms[i].st_shndx) continue; |
| 284 | if (!mem.eql(u8, name, mem.spanZ(self.strings + self.syms[i].st_name))) continue; | |
| 282 | if (!mem.eql(u8, name, mem.sliceTo(self.strings + self.syms[i].st_name, 0))) continue; | |
| 285 | 283 | if (maybe_versym) |versym| { |
| 286 | 284 | if (!checkver(self.verdef.?, versym[i], vername, self.strings)) |
| 287 | 285 | continue; |
| ... | ... | @@ -312,7 +310,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [ |
| 312 | 310 | def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next); |
| 313 | 311 | } |
| 314 | 312 | const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux); |
| 315 | return mem.eql(u8, vername, mem.spanZ(strings + aux.vda_name)); | |
| 313 | return mem.eql(u8, vername, mem.sliceTo(strings + aux.vda_name, 0)); | |
| 316 | 314 | } |
| 317 | 315 | |
| 318 | 316 | pub const WindowsDynLib = struct { |
| ... | ... | @@ -325,8 +323,6 @@ pub const WindowsDynLib = struct { |
| 325 | 323 | return openW(path_w.span().ptr); |
| 326 | 324 | } |
| 327 | 325 | |
| 328 | pub const openC = @compileError("deprecated: renamed to openZ"); | |
| 329 | ||
| 330 | 326 | pub fn openZ(path_c: [*:0]const u8) !WindowsDynLib { |
| 331 | 327 | const path_w = try windows.cStrToPrefixedFileW(path_c); |
| 332 | 328 | return openW(path_w.span().ptr); |
| ... | ... | @@ -368,8 +364,6 @@ pub const DlDynlib = struct { |
| 368 | 364 | return openZ(&path_c); |
| 369 | 365 | } |
| 370 | 366 | |
| 371 | pub const openC = @compileError("deprecated: renamed to openZ"); | |
| 372 | ||
| 373 | 367 | pub fn openZ(path_c: [*:0]const u8) !DlDynlib { |
| 374 | 368 | return DlDynlib{ |
| 375 | 369 | .handle = system.dlopen(path_c, system.RTLD.LAZY) orelse { |
lib/std/fifo.zig+1-2| ... | ... | @@ -119,8 +119,7 @@ pub fn LinearFifo( |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. | |
| 123 | pub const ensureCapacity = ensureTotalCapacity; | |
| 122 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); | |
| 124 | 123 | |
| 125 | 124 | /// Ensure that the buffer can fit at least `size` items |
| 126 | 125 | pub fn ensureTotalCapacity(self: *Self, size: usize) !void { |
lib/std/fmt.zig+1-5| ... | ... | @@ -1814,8 +1814,7 @@ pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: any |
| 1814 | 1814 | }; |
| 1815 | 1815 | } |
| 1816 | 1816 | |
| 1817 | /// Deprecated, use allocPrintZ | |
| 1818 | pub const allocPrint0 = allocPrintZ; | |
| 1817 | pub const allocPrint0 = @compileError("deprecated; use allocPrintZ"); | |
| 1819 | 1818 | |
| 1820 | 1819 | pub fn allocPrintZ(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 { |
| 1821 | 1820 | const result = try allocPrint(allocator, fmt ++ "\x00", args); |
| ... | ... | @@ -2367,9 +2366,6 @@ test "bytes.hex" { |
| 2367 | 2366 | try expectFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{fmtSliceHexLower(bytes_with_zeros)}); |
| 2368 | 2367 | } |
| 2369 | 2368 | |
| 2370 | pub const trim = @compileError("deprecated; use std.mem.trim with std.ascii.spaces instead"); | |
| 2371 | pub const isWhiteSpace = @compileError("deprecated; use std.ascii.isSpace instead"); | |
| 2372 | ||
| 2373 | 2369 | /// Decodes the sequence of bytes represented by the specified string of |
| 2374 | 2370 | /// hexadecimal characters. |
| 2375 | 2371 | /// Returns a slice of the output buffer containing the decoded bytes. |
lib/std/fs.zig+7-42| ... | ... | @@ -19,7 +19,6 @@ pub const wasi = @import("fs/wasi.zig"); |
| 19 | 19 | |
| 20 | 20 | pub const realpath = os.realpath; |
| 21 | 21 | pub const realpathZ = os.realpathZ; |
| 22 | pub const realpathC = @compileError("deprecated: renamed to realpathZ"); | |
| 23 | 22 | pub const realpathW = os.realpathW; |
| 24 | 23 | |
| 25 | 24 | pub const getAppDataDir = @import("fs/get_app_data_dir.zig").getAppDataDir; |
| ... | ... | @@ -227,10 +226,6 @@ pub fn makeDirAbsoluteW(absolute_path_w: [*:0]const u16) !void { |
| 227 | 226 | return os.mkdirW(absolute_path_w, default_new_dir_mode); |
| 228 | 227 | } |
| 229 | 228 | |
| 230 | pub const deleteDir = @compileError("deprecated; use dir.deleteDir or deleteDirAbsolute"); | |
| 231 | pub const deleteDirC = @compileError("deprecated; use dir.deleteDirZ or deleteDirAbsoluteZ"); | |
| 232 | pub const deleteDirW = @compileError("deprecated; use dir.deleteDirW or deleteDirAbsoluteW"); | |
| 233 | ||
| 234 | 229 | /// Same as `Dir.deleteDir` except the path is absolute. |
| 235 | 230 | pub fn deleteDirAbsolute(dir_path: []const u8) !void { |
| 236 | 231 | assert(path.isAbsolute(dir_path)); |
| ... | ... | @@ -249,8 +244,6 @@ pub fn deleteDirAbsoluteW(dir_path: [*:0]const u16) !void { |
| 249 | 244 | return os.rmdirW(dir_path); |
| 250 | 245 | } |
| 251 | 246 | |
| 252 | pub const renameC = @compileError("deprecated: use renameZ, dir.renameZ, or renameAbsoluteZ"); | |
| 253 | ||
| 254 | 247 | /// Same as `Dir.rename` except the paths are absolute. |
| 255 | 248 | pub fn renameAbsolute(old_path: []const u8, new_path: []const u8) !void { |
| 256 | 249 | assert(path.isAbsolute(old_path)); |
| ... | ... | @@ -393,7 +386,7 @@ pub const Dir = struct { |
| 393 | 386 | const next_index = self.index + entry.reclen(); |
| 394 | 387 | self.index = next_index; |
| 395 | 388 | |
| 396 | const name = mem.spanZ(@ptrCast([*:0]u8, &entry.d_name)); | |
| 389 | const name = mem.sliceTo(@ptrCast([*:0]u8, &entry.d_name), 0); | |
| 397 | 390 | if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) |
| 398 | 391 | continue :start_over; |
| 399 | 392 | |
| ... | ... | @@ -520,7 +513,7 @@ pub const Dir = struct { |
| 520 | 513 | const haiku_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]); |
| 521 | 514 | const next_index = self.index + haiku_entry.reclen(); |
| 522 | 515 | self.index = next_index; |
| 523 | const name = mem.spanZ(@ptrCast([*:0]u8, &haiku_entry.d_name)); | |
| 516 | const name = mem.sliceTo(@ptrCast([*:0]u8, &haiku_entry.d_name), 0); | |
| 524 | 517 | |
| 525 | 518 | if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (haiku_entry.d_ino == 0)) { |
| 526 | 519 | continue :start_over; |
| ... | ... | @@ -598,7 +591,7 @@ pub const Dir = struct { |
| 598 | 591 | const next_index = self.index + linux_entry.reclen(); |
| 599 | 592 | self.index = next_index; |
| 600 | 593 | |
| 601 | const name = mem.spanZ(@ptrCast([*:0]u8, &linux_entry.d_name)); | |
| 594 | const name = mem.sliceTo(@ptrCast([*:0]u8, &linux_entry.d_name), 0); | |
| 602 | 595 | |
| 603 | 596 | // skip . and .. entries |
| 604 | 597 | if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) { |
| ... | ... | @@ -965,8 +958,6 @@ pub const Dir = struct { |
| 965 | 958 | return File{ .handle = fd }; |
| 966 | 959 | } |
| 967 | 960 | |
| 968 | pub const openFileC = @compileError("deprecated: renamed to openFileZ"); | |
| 969 | ||
| 970 | 961 | /// Same as `openFile` but the path parameter is null-terminated. |
| 971 | 962 | pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { |
| 972 | 963 | if (builtin.os.tag == .windows) { |
| ... | ... | @@ -1100,8 +1091,6 @@ pub const Dir = struct { |
| 1100 | 1091 | return self.createFileZ(&path_c, flags); |
| 1101 | 1092 | } |
| 1102 | 1093 | |
| 1103 | pub const createFileC = @compileError("deprecated: renamed to createFileZ"); | |
| 1104 | ||
| 1105 | 1094 | /// Same as `createFile` but WASI only. |
| 1106 | 1095 | pub fn createFileWasi(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File { |
| 1107 | 1096 | const w = os.wasi; |
| ... | ... | @@ -1243,10 +1232,6 @@ pub const Dir = struct { |
| 1243 | 1232 | return file; |
| 1244 | 1233 | } |
| 1245 | 1234 | |
| 1246 | pub const openRead = @compileError("deprecated in favor of openFile"); | |
| 1247 | pub const openReadC = @compileError("deprecated in favor of openFileZ"); | |
| 1248 | pub const openReadW = @compileError("deprecated in favor of openFileW"); | |
| 1249 | ||
| 1250 | 1235 | pub fn makeDir(self: Dir, sub_path: []const u8) !void { |
| 1251 | 1236 | try os.mkdirat(self.fd, sub_path, default_new_dir_mode); |
| 1252 | 1237 | } |
| ... | ... | @@ -1463,8 +1448,6 @@ pub const Dir = struct { |
| 1463 | 1448 | } |
| 1464 | 1449 | } |
| 1465 | 1450 | |
| 1466 | pub const openDirC = @compileError("deprecated: renamed to openDirZ"); | |
| 1467 | ||
| 1468 | 1451 | /// Same as `openDir` except only WASI. |
| 1469 | 1452 | pub fn openDirWasi(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir { |
| 1470 | 1453 | const w = os.wasi; |
| ... | ... | @@ -1554,7 +1537,7 @@ pub const Dir = struct { |
| 1554 | 1537 | .fd = undefined, |
| 1555 | 1538 | }; |
| 1556 | 1539 | |
| 1557 | const path_len_bytes = @intCast(u16, mem.lenZ(sub_path_w) * 2); | |
| 1540 | const path_len_bytes = @intCast(u16, mem.sliceTo(sub_path_w, 0).len * 2); | |
| 1558 | 1541 | var nt_name = w.UNICODE_STRING{ |
| 1559 | 1542 | .Length = path_len_bytes, |
| 1560 | 1543 | .MaximumLength = path_len_bytes, |
| ... | ... | @@ -1613,8 +1596,6 @@ pub const Dir = struct { |
| 1613 | 1596 | } |
| 1614 | 1597 | } |
| 1615 | 1598 | |
| 1616 | pub const deleteFileC = @compileError("deprecated: renamed to deleteFileZ"); | |
| 1617 | ||
| 1618 | 1599 | /// Same as `deleteFile` except the parameter is null-terminated. |
| 1619 | 1600 | pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void { |
| 1620 | 1601 | os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) { |
| ... | ... | @@ -1788,8 +1769,6 @@ pub const Dir = struct { |
| 1788 | 1769 | return self.readLinkZ(&sub_path_c, buffer); |
| 1789 | 1770 | } |
| 1790 | 1771 | |
| 1791 | pub const readLinkC = @compileError("deprecated: renamed to readLinkZ"); | |
| 1792 | ||
| 1793 | 1772 | /// WASI-only. Same as `readLink` except targeting WASI. |
| 1794 | 1773 | pub fn readLinkWasi(self: Dir, sub_path: []const u8, buffer: []u8) ![]u8 { |
| 1795 | 1774 | return os.readlinkatWasi(self.fd, sub_path, buffer); |
| ... | ... | @@ -2275,8 +2254,6 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O |
| 2275 | 2254 | return cwd().openFile(absolute_path, flags); |
| 2276 | 2255 | } |
| 2277 | 2256 | |
| 2278 | pub const openFileAbsoluteC = @compileError("deprecated: renamed to openFileAbsoluteZ"); | |
| 2279 | ||
| 2280 | 2257 | /// Same as `openFileAbsolute` but the path parameter is null-terminated. |
| 2281 | 2258 | pub fn openFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { |
| 2282 | 2259 | assert(path.isAbsoluteZ(absolute_path_c)); |
| ... | ... | @@ -2330,8 +2307,6 @@ pub fn createFileAbsolute(absolute_path: []const u8, flags: File.CreateFlags) Fi |
| 2330 | 2307 | return cwd().createFile(absolute_path, flags); |
| 2331 | 2308 | } |
| 2332 | 2309 | |
| 2333 | pub const createFileAbsoluteC = @compileError("deprecated: renamed to createFileAbsoluteZ"); | |
| 2334 | ||
| 2335 | 2310 | /// Same as `createFileAbsolute` but the path parameter is null-terminated. |
| 2336 | 2311 | pub fn createFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File { |
| 2337 | 2312 | assert(path.isAbsoluteZ(absolute_path_c)); |
| ... | ... | @@ -2353,8 +2328,6 @@ pub fn deleteFileAbsolute(absolute_path: []const u8) Dir.DeleteFileError!void { |
| 2353 | 2328 | return cwd().deleteFile(absolute_path); |
| 2354 | 2329 | } |
| 2355 | 2330 | |
| 2356 | pub const deleteFileAbsoluteC = @compileError("deprecated: renamed to deleteFileAbsoluteZ"); | |
| 2357 | ||
| 2358 | 2331 | /// Same as `deleteFileAbsolute` except the parameter is null-terminated. |
| 2359 | 2332 | pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) Dir.DeleteFileError!void { |
| 2360 | 2333 | assert(path.isAbsoluteZ(absolute_path_c)); |
| ... | ... | @@ -2405,9 +2378,6 @@ pub fn readLinkAbsoluteZ(pathname_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8) |
| 2405 | 2378 | return os.readlinkZ(pathname_c, buffer); |
| 2406 | 2379 | } |
| 2407 | 2380 | |
| 2408 | pub const readLink = @compileError("deprecated; use Dir.readLink or readLinkAbsolute"); | |
| 2409 | pub const readLinkC = @compileError("deprecated; use Dir.readLinkZ or readLinkAbsoluteZ"); | |
| 2410 | ||
| 2411 | 2381 | /// Use with `Dir.symLink` and `symLinkAbsolute` to specify whether the symlink |
| 2412 | 2382 | /// will point to a file or a directory. This value is ignored on all hosts |
| 2413 | 2383 | /// except Windows where creating symlinks to different resource types, requires |
| ... | ... | @@ -2458,11 +2428,6 @@ pub fn symLinkAbsoluteZ(target_path_c: [*:0]const u8, sym_link_path_c: [*:0]cons |
| 2458 | 2428 | return os.symlinkZ(target_path_c, sym_link_path_c); |
| 2459 | 2429 | } |
| 2460 | 2430 | |
| 2461 | pub const symLink = @compileError("deprecated: use Dir.symLink or symLinkAbsolute"); | |
| 2462 | pub const symLinkC = @compileError("deprecated: use Dir.symLinkZ or symLinkAbsoluteZ"); | |
| 2463 | ||
| 2464 | pub const walkPath = @compileError("deprecated: use Dir.walk"); | |
| 2465 | ||
| 2466 | 2431 | pub const OpenSelfExeError = error{ |
| 2467 | 2432 | SharingViolation, |
| 2468 | 2433 | PathAlreadyExists, |
| ... | ... | @@ -2544,14 +2509,14 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { |
| 2544 | 2509 | var out_len: usize = out_buffer.len; |
| 2545 | 2510 | try os.sysctl(&mib, out_buffer.ptr, &out_len, null, 0); |
| 2546 | 2511 | // TODO could this slice from 0 to out_len instead? |
| 2547 | return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)); | |
| 2512 | return mem.sliceTo(std.meta.assumeSentinel(out_buffer.ptr, 0), 0); | |
| 2548 | 2513 | }, |
| 2549 | 2514 | .netbsd => { |
| 2550 | 2515 | var mib = [4]c_int{ os.CTL.KERN, os.KERN.PROC_ARGS, -1, os.KERN.PROC_PATHNAME }; |
| 2551 | 2516 | var out_len: usize = out_buffer.len; |
| 2552 | 2517 | try os.sysctl(&mib, out_buffer.ptr, &out_len, null, 0); |
| 2553 | 2518 | // TODO could this slice from 0 to out_len instead? |
| 2554 | return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)); | |
| 2519 | return mem.sliceTo(std.meta.assumeSentinel(out_buffer.ptr, 0), 0); | |
| 2555 | 2520 | }, |
| 2556 | 2521 | .openbsd, .haiku => { |
| 2557 | 2522 | // OpenBSD doesn't support getting the path of a running process, so try to guess it |
| ... | ... | @@ -2603,7 +2568,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { |
| 2603 | 2568 | /// The result is UTF16LE-encoded. |
| 2604 | 2569 | pub fn selfExePathW() [:0]const u16 { |
| 2605 | 2570 | const image_path_name = &os.windows.peb().ProcessParameters.ImagePathName; |
| 2606 | return mem.spanZ(std.meta.assumeSentinel(image_path_name.Buffer, 0)); | |
| 2571 | return mem.sliceTo(std.meta.assumeSentinel(image_path_name.Buffer, 0), 0); | |
| 2607 | 2572 | } |
| 2608 | 2573 | |
| 2609 | 2574 | /// `selfExeDirPath` except allocates the result on the heap. |
lib/std/fs/get_app_data_dir.zig+2-2| ... | ... | @@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD |
| 24 | 24 | )) { |
| 25 | 25 | os.windows.S_OK => { |
| 26 | 26 | defer os.windows.ole32.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr)); |
| 27 | const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.spanZ(dir_path_ptr)) catch |err| switch (err) { | |
| 27 | const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.sliceTo(dir_path_ptr, 0)) catch |err| switch (err) { | |
| 28 | 28 | error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable, |
| 29 | 29 | error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable, |
| 30 | 30 | error.DanglingSurrogateHalf => return error.AppDataDirUnavailable, |
| ... | ... | @@ -56,7 +56,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD |
| 56 | 56 | // TODO look into directory_which |
| 57 | 57 | const be_user_settings = 0xbbe; |
| 58 | 58 | const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1); |
| 59 | const settings_dir = try allocator.dupeZ(u8, mem.spanZ(dir_path_ptr)); | |
| 59 | const settings_dir = try allocator.dupeZ(u8, mem.sliceTo(dir_path_ptr, 0)); | |
| 60 | 60 | defer allocator.free(settings_dir); |
| 61 | 61 | switch (rc) { |
| 62 | 62 | 0 => return fs.path.join(allocator, &[_][]const u8{ settings_dir, appname }), |
lib/std/fs/path.zig+3-9| ... | ... | @@ -187,8 +187,6 @@ test "join" { |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ"); | |
| 191 | ||
| 192 | 190 | pub fn isAbsoluteZ(path_c: [*:0]const u8) bool { |
| 193 | 191 | if (native_os == .windows) { |
| 194 | 192 | return isAbsoluteWindowsZ(path_c); |
| ... | ... | @@ -233,27 +231,23 @@ pub fn isAbsoluteWindows(path: []const u8) bool { |
| 233 | 231 | } |
| 234 | 232 | |
| 235 | 233 | pub fn isAbsoluteWindowsW(path_w: [*:0]const u16) bool { |
| 236 | return isAbsoluteWindowsImpl(u16, mem.spanZ(path_w)); | |
| 234 | return isAbsoluteWindowsImpl(u16, mem.sliceTo(path_w, 0)); | |
| 237 | 235 | } |
| 238 | 236 | |
| 239 | 237 | pub fn isAbsoluteWindowsWTF16(path: []const u16) bool { |
| 240 | 238 | return isAbsoluteWindowsImpl(u16, path); |
| 241 | 239 | } |
| 242 | 240 | |
| 243 | pub const isAbsoluteWindowsC = @compileError("deprecated: renamed to isAbsoluteWindowsZ"); | |
| 244 | ||
| 245 | 241 | pub fn isAbsoluteWindowsZ(path_c: [*:0]const u8) bool { |
| 246 | return isAbsoluteWindowsImpl(u8, mem.spanZ(path_c)); | |
| 242 | return isAbsoluteWindowsImpl(u8, mem.sliceTo(path_c, 0)); | |
| 247 | 243 | } |
| 248 | 244 | |
| 249 | 245 | pub fn isAbsolutePosix(path: []const u8) bool { |
| 250 | 246 | return path.len > 0 and path[0] == sep_posix; |
| 251 | 247 | } |
| 252 | 248 | |
| 253 | pub const isAbsolutePosixC = @compileError("deprecated: renamed to isAbsolutePosixZ"); | |
| 254 | ||
| 255 | 249 | pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool { |
| 256 | return isAbsolutePosix(mem.spanZ(path_c)); | |
| 250 | return isAbsolutePosix(mem.sliceTo(path_c, 0)); | |
| 257 | 251 | } |
| 258 | 252 | |
| 259 | 253 | test "isAbsoluteWindows" { |
lib/std/hash/benchmark.zig+1-1| ... | ... | @@ -142,7 +142,7 @@ pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | fn usage() void { |
| 145 | std.debug.warn( | |
| 145 | std.debug.print( | |
| 146 | 146 | \\throughput_test [options] |
| 147 | 147 | \\ |
| 148 | 148 | \\Options: |
lib/std/hash_map.zig+5-20| ... | ... | @@ -2,7 +2,6 @@ const std = @import("std.zig"); |
| 2 | 2 | const assert = debug.assert; |
| 3 | 3 | const autoHash = std.hash.autoHash; |
| 4 | 4 | const debug = std.debug; |
| 5 | const warn = debug.warn; | |
| 6 | 5 | const math = std.math; |
| 7 | 6 | const mem = std.mem; |
| 8 | 7 | const meta = std.meta; |
| ... | ... | @@ -101,7 +100,7 @@ pub const StringIndexContext = struct { |
| 101 | 100 | } |
| 102 | 101 | |
| 103 | 102 | pub fn hash(self: @This(), x: u32) u64 { |
| 104 | const x_slice = mem.spanZ(@ptrCast([*:0]const u8, self.bytes.items.ptr) + x); | |
| 103 | const x_slice = mem.sliceTo(@ptrCast([*:0]const u8, self.bytes.items.ptr) + x, 0); | |
| 105 | 104 | return hashString(x_slice); |
| 106 | 105 | } |
| 107 | 106 | }; |
| ... | ... | @@ -110,7 +109,7 @@ pub const StringIndexAdapter = struct { |
| 110 | 109 | bytes: *std.ArrayListUnmanaged(u8), |
| 111 | 110 | |
| 112 | 111 | pub fn eql(self: @This(), a_slice: []const u8, b: u32) bool { |
| 113 | const b_slice = mem.spanZ(@ptrCast([*:0]const u8, self.bytes.items.ptr) + b); | |
| 112 | const b_slice = mem.sliceTo(@ptrCast([*:0]const u8, self.bytes.items.ptr) + b, 0); | |
| 114 | 113 | return mem.eql(u8, a_slice, b_slice); |
| 115 | 114 | } |
| 116 | 115 | |
| ... | ... | @@ -120,8 +119,7 @@ pub const StringIndexAdapter = struct { |
| 120 | 119 | } |
| 121 | 120 | }; |
| 122 | 121 | |
| 123 | /// Deprecated use `default_max_load_percentage` | |
| 124 | pub const DefaultMaxLoadPercentage = default_max_load_percentage; | |
| 122 | pub const DefaultMaxLoadPercentage = @compileError("deprecated; use `default_max_load_percentage`"); | |
| 125 | 123 | |
| 126 | 124 | pub const default_max_load_percentage = 80; |
| 127 | 125 | |
| ... | ... | @@ -506,8 +504,7 @@ pub fn HashMap( |
| 506 | 504 | return self.unmanaged.getOrPutValueContext(self.allocator, key, value, self.ctx); |
| 507 | 505 | } |
| 508 | 506 | |
| 509 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. | |
| 510 | pub const ensureCapacity = ensureTotalCapacity; | |
| 507 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); | |
| 511 | 508 | |
| 512 | 509 | /// Increases capacity, guaranteeing that insertions up until the |
| 513 | 510 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| ... | ... | @@ -873,8 +870,7 @@ pub fn HashMapUnmanaged( |
| 873 | 870 | return new_cap; |
| 874 | 871 | } |
| 875 | 872 | |
| 876 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. | |
| 877 | pub const ensureCapacity = ensureTotalCapacity; | |
| 873 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); | |
| 878 | 874 | |
| 879 | 875 | pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_size: Size) !void { |
| 880 | 876 | if (@sizeOf(Context) != 0) |
| ... | ... | @@ -2045,14 +2041,3 @@ test "std.hash_map ensureUnusedCapacity" { |
| 2045 | 2041 | // should not change the capacity. |
| 2046 | 2042 | try testing.expectEqual(capacity, map.capacity()); |
| 2047 | 2043 | } |
| 2048 | ||
| 2049 | test "compile everything" { | |
| 2050 | std.testing.refAllDecls(AutoHashMap(i32, i32)); | |
| 2051 | std.testing.refAllDecls(StringHashMap([]const u8)); | |
| 2052 | std.testing.refAllDecls(AutoHashMap(i32, void)); | |
| 2053 | std.testing.refAllDecls(StringHashMap(u0)); | |
| 2054 | std.testing.refAllDecls(AutoHashMapUnmanaged(i32, i32)); | |
| 2055 | std.testing.refAllDecls(StringHashMapUnmanaged([]const u8)); | |
| 2056 | std.testing.refAllDecls(AutoHashMapUnmanaged(i32, void)); | |
| 2057 | std.testing.refAllDecls(StringHashMapUnmanaged(u0)); | |
| 2058 | } |
lib/std/io.zig+3-7| ... | ... | @@ -142,10 +142,9 @@ pub const changeDetectionStream = @import("io/change_detection_stream.zig").chan |
| 142 | 142 | |
| 143 | 143 | pub const FindByteWriter = @import("io/find_byte_writer.zig").FindByteWriter; |
| 144 | 144 | pub const findByteWriter = @import("io/find_byte_writer.zig").findByteWriter; |
| 145 | /// Deprecated: use `FindByteWriter`. | |
| 146 | pub const FindByteOutStream = FindByteWriter; | |
| 147 | /// Deprecated: use `findByteWriter`. | |
| 148 | pub const findByteOutStream = findByteWriter; | |
| 145 | ||
| 146 | pub const FindByteOutStream = @compileError("deprecated; use `FindByteWriter`"); | |
| 147 | pub const findByteOutStream = @compileError("deprecated; use `findByteWriter`"); | |
| 149 | 148 | |
| 150 | 149 | pub const BufferedAtomicFile = @import("io/buffered_atomic_file.zig").BufferedAtomicFile; |
| 151 | 150 | |
| ... | ... | @@ -181,6 +180,3 @@ test { |
| 181 | 180 | _ = @import("io/stream_source.zig"); |
| 182 | 181 | _ = @import("io/test.zig"); |
| 183 | 182 | } |
| 184 | ||
| 185 | pub const writeFile = @compileError("deprecated: use std.fs.Dir.writeFile with math.maxInt(usize)"); | |
| 186 | pub const readFileAlloc = @compileError("deprecated: use std.fs.Dir.readFileAlloc"); |
lib/std/io/reader.zig+4-4| ... | ... | @@ -45,10 +45,10 @@ pub fn Reader( |
| 45 | 45 | if (amt_read < buf.len) return error.EndOfStream; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | pub const readAllBuffer = @compileError("deprecated; use readAllArrayList()"); | |
| 49 | ||
| 50 | /// Appends to the `std.ArrayList` contents by reading from the stream until end of stream is found. | |
| 51 | /// If the number of bytes appended would exceed `max_append_size`, `error.StreamTooLong` is returned | |
| 48 | /// Appends to the `std.ArrayList` contents by reading from the stream | |
| 49 | /// until end of stream is found. | |
| 50 | /// If the number of bytes appended would exceed `max_append_size`, | |
| 51 | /// `error.StreamTooLong` is returned | |
| 52 | 52 | /// and the `std.ArrayList` has exactly `max_append_size` bytes appended. |
| 53 | 53 | pub fn readAllArrayList(self: Self, array_list: *std.ArrayList(u8), max_append_size: usize) !void { |
| 54 | 54 | return self.readAllArrayListAligned(null, array_list, max_append_size); |
lib/std/json.zig+2-2| ... | ... | @@ -3135,7 +3135,7 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions |
| 3135 | 3135 | |
| 3136 | 3136 | fn write(self: *Self, bytes: []const u8) Error!usize { |
| 3137 | 3137 | if (self.expected_remaining.len < bytes.len) { |
| 3138 | std.debug.warn( | |
| 3138 | std.debug.print( | |
| 3139 | 3139 | \\====== expected this output: ========= |
| 3140 | 3140 | \\{s} |
| 3141 | 3141 | \\======== instead found this: ========= |
| ... | ... | @@ -3148,7 +3148,7 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions |
| 3148 | 3148 | return error.TooMuchData; |
| 3149 | 3149 | } |
| 3150 | 3150 | if (!mem.eql(u8, self.expected_remaining[0..bytes.len], bytes)) { |
| 3151 | std.debug.warn( | |
| 3151 | std.debug.print( | |
| 3152 | 3152 | \\====== expected this output: ========= |
| 3153 | 3153 | \\{s} |
| 3154 | 3154 | \\======== instead found this: ========= |
lib/std/log.zig+8-20| ... | ... | @@ -174,14 +174,9 @@ pub fn defaultLog( |
| 174 | 174 | /// provided here. |
| 175 | 175 | pub fn scoped(comptime scope: @Type(.EnumLiteral)) type { |
| 176 | 176 | return struct { |
| 177 | /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released | |
| 178 | pub const emerg = @This().err; | |
| 179 | ||
| 180 | /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released | |
| 181 | pub const alert = @This().err; | |
| 182 | ||
| 183 | /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released | |
| 184 | pub const crit = @This().err; | |
| 177 | pub const emerg = @compileError("deprecated; use err instead of emerg"); | |
| 178 | pub const alert = @compileError("deprecated; use err instead of alert"); | |
| 179 | pub const crit = @compileError("deprecated; use err instead of crit"); | |
| 185 | 180 | |
| 186 | 181 | /// Log an error message. This log level is intended to be used |
| 187 | 182 | /// when something has gone wrong. This might be recoverable or might |
| ... | ... | @@ -204,8 +199,7 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type { |
| 204 | 199 | log(.warn, scope, format, args); |
| 205 | 200 | } |
| 206 | 201 | |
| 207 | /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released | |
| 208 | pub const notice = @This().info; | |
| 202 | pub const notice = @compileError("deprecated; use info instead of notice"); | |
| 209 | 203 | |
| 210 | 204 | /// Log an info message. This log level is intended to be used for |
| 211 | 205 | /// general messages about the state of the program. |
| ... | ... | @@ -230,14 +224,9 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type { |
| 230 | 224 | /// The default scoped logging namespace. |
| 231 | 225 | pub const default = scoped(.default); |
| 232 | 226 | |
| 233 | /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released | |
| 234 | pub const emerg = default.err; | |
| 235 | ||
| 236 | /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released | |
| 237 | pub const alert = default.err; | |
| 238 | ||
| 239 | /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released | |
| 240 | pub const crit = default.err; | |
| 227 | pub const emerg = @compileError("deprecated; use err instead of emerg"); | |
| 228 | pub const alert = @compileError("deprecated; use err instead of alert"); | |
| 229 | pub const crit = @compileError("deprecated; use err instead of crit"); | |
| 241 | 230 | |
| 242 | 231 | /// Log an error message using the default scope. This log level is intended to |
| 243 | 232 | /// be used when something has gone wrong. This might be recoverable or might |
| ... | ... | @@ -249,8 +238,7 @@ pub const err = default.err; |
| 249 | 238 | /// the circumstances would be worth investigating. |
| 250 | 239 | pub const warn = default.warn; |
| 251 | 240 | |
| 252 | /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released | |
| 253 | pub const notice = default.info; | |
| 241 | pub const notice = @compileError("deprecated; use info instead of notice"); | |
| 254 | 242 | |
| 255 | 243 | /// Log an info message using the default scope. This log level is intended to |
| 256 | 244 | /// be used for general messages about the state of the program. |
lib/std/math.zig+7-2| ... | ... | @@ -158,8 +158,13 @@ pub fn approxEqRel(comptime T: type, x: T, y: T, tolerance: T) bool { |
| 158 | 158 | return fabs(x - y) <= max(fabs(x), fabs(y)) * tolerance; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | /// Deprecated, use `approxEqAbs` or `approxEqRel`. | |
| 162 | pub const approxEq = approxEqAbs; | |
| 161 | pub fn approxEq(comptime T: type, x: T, y: T, tolerance: T) bool { | |
| 162 | _ = T; | |
| 163 | _ = x; | |
| 164 | _ = y; | |
| 165 | _ = tolerance; | |
| 166 | @compileError("deprecated; use `approxEqAbs` or `approxEqRel`"); | |
| 167 | } | |
| 163 | 168 | |
| 164 | 169 | test "approxEqAbs and approxEqRel" { |
| 165 | 170 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { |
lib/std/math/big/int.zig+6-6| ... | ... | @@ -185,9 +185,9 @@ pub const Mutable = struct { |
| 185 | 185 | |
| 186 | 186 | pub fn dump(self: Mutable) void { |
| 187 | 187 | for (self.limbs[0..self.len]) |limb| { |
| 188 | std.debug.warn("{x} ", .{limb}); | |
| 188 | std.debug.print("{x} ", .{limb}); | |
| 189 | 189 | } |
| 190 | std.debug.warn("capacity={} positive={}\n", .{ self.limbs.len, self.positive }); | |
| 190 | std.debug.print("capacity={} positive={}\n", .{ self.limbs.len, self.positive }); | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /// Clones an Mutable and returns a new Mutable with the same value. The new Mutable is a deep copy and |
| ... | ... | @@ -1685,9 +1685,9 @@ pub const Const = struct { |
| 1685 | 1685 | |
| 1686 | 1686 | pub fn dump(self: Const) void { |
| 1687 | 1687 | for (self.limbs[0..self.limbs.len]) |limb| { |
| 1688 | std.debug.warn("{x} ", .{limb}); | |
| 1688 | std.debug.print("{x} ", .{limb}); | |
| 1689 | 1689 | } |
| 1690 | std.debug.warn("positive={}\n", .{self.positive}); | |
| 1690 | std.debug.print("positive={}\n", .{self.positive}); | |
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | 1693 | pub fn abs(self: Const) Const { |
| ... | ... | @@ -2237,9 +2237,9 @@ pub const Managed = struct { |
| 2237 | 2237 | /// Debugging tool: prints the state to stderr. |
| 2238 | 2238 | pub fn dump(self: Managed) void { |
| 2239 | 2239 | for (self.limbs[0..self.len()]) |limb| { |
| 2240 | std.debug.warn("{x} ", .{limb}); | |
| 2240 | std.debug.print("{x} ", .{limb}); | |
| 2241 | 2241 | } |
| 2242 | std.debug.warn("capacity={} positive={}\n", .{ self.limbs.len, self.isPositive() }); | |
| 2242 | std.debug.print("capacity={} positive={}\n", .{ self.limbs.len, self.isPositive() }); | |
| 2243 | 2243 | } |
| 2244 | 2244 | |
| 2245 | 2245 | /// Negate the sign. |
lib/std/math/complex.zig+1-2| ... | ... | @@ -34,8 +34,7 @@ pub fn Complex(comptime T: type) type { |
| 34 | 34 | /// Imaginary part. |
| 35 | 35 | im: T, |
| 36 | 36 | |
| 37 | /// Deprecated, use init() | |
| 38 | pub const new = init; | |
| 37 | pub const new = @compileError("deprecated; use init()"); | |
| 39 | 38 | |
| 40 | 39 | /// Create a new Complex number from the given real and imaginary parts. |
| 41 | 40 | pub fn init(re: T, im: T) Self { |
lib/std/mem.zig+5-98| ... | ... | @@ -553,9 +553,6 @@ test "indexOfDiff" { |
| 553 | 553 | try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0); |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ"); | |
| 557 | pub const toSlice = @compileError("deprecated; use std.mem.spanZ"); | |
| 558 | ||
| 559 | 556 | /// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and |
| 560 | 557 | /// returns a slice. If there is a sentinel on the input type, there will be a |
| 561 | 558 | /// sentinel on the output type. The constness of the output type matches |
| ... | ... | @@ -644,34 +641,7 @@ test "span" { |
| 644 | 641 | try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null))); |
| 645 | 642 | } |
| 646 | 643 | |
| 647 | /// Deprecated: use std.mem.span() or std.mem.sliceTo() | |
| 648 | /// Same as `span`, except when there is both a sentinel and an array | |
| 649 | /// length or slice length, scans the memory for the sentinel value | |
| 650 | /// rather than using the length. | |
| 651 | pub fn spanZ(ptr: anytype) Span(@TypeOf(ptr)) { | |
| 652 | if (@typeInfo(@TypeOf(ptr)) == .Optional) { | |
| 653 | if (ptr) |non_null| { | |
| 654 | return spanZ(non_null); | |
| 655 | } else { | |
| 656 | return null; | |
| 657 | } | |
| 658 | } | |
| 659 | const Result = Span(@TypeOf(ptr)); | |
| 660 | const l = lenZ(ptr); | |
| 661 | if (@typeInfo(Result).Pointer.sentinel) |s| { | |
| 662 | return ptr[0..l :s]; | |
| 663 | } else { | |
| 664 | return ptr[0..l]; | |
| 665 | } | |
| 666 | } | |
| 667 | ||
| 668 | test "spanZ" { | |
| 669 | var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 }; | |
| 670 | const ptr = @as([*:3]u16, array[0..2 :3]); | |
| 671 | try testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 })); | |
| 672 | try testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 })); | |
| 673 | try testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null))); | |
| 674 | } | |
| 644 | pub const spanZ = @compileError("deprecated; use use std.mem.span() or std.mem.sliceTo()"); | |
| 675 | 645 | |
| 676 | 646 | /// Helper for the return type of sliceTo() |
| 677 | 647 | fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type { |
| ... | ... | @@ -917,61 +887,7 @@ test "len" { |
| 917 | 887 | } |
| 918 | 888 | } |
| 919 | 889 | |
| 920 | /// Deprecated: use std.mem.len() or std.mem.sliceTo().len | |
| 921 | /// Takes a pointer to an array, an array, a sentinel-terminated pointer, | |
| 922 | /// or a slice, and returns the length. | |
| 923 | /// In the case of a sentinel-terminated array, it scans the array | |
| 924 | /// for a sentinel and uses that for the length, rather than using the array length. | |
| 925 | /// For C pointers it assumes it is a pointer-to-many with a 0 sentinel. | |
| 926 | pub fn lenZ(ptr: anytype) usize { | |
| 927 | return switch (@typeInfo(@TypeOf(ptr))) { | |
| 928 | .Array => |info| if (info.sentinel) |sentinel| | |
| 929 | indexOfSentinel(info.child, sentinel, &ptr) | |
| 930 | else | |
| 931 | info.len, | |
| 932 | .Pointer => |info| switch (info.size) { | |
| 933 | .One => switch (@typeInfo(info.child)) { | |
| 934 | .Array => |x| if (x.sentinel) |sentinel| | |
| 935 | indexOfSentinel(x.child, sentinel, ptr) | |
| 936 | else | |
| 937 | ptr.len, | |
| 938 | else => @compileError("invalid type given to std.mem.lenZ"), | |
| 939 | }, | |
| 940 | .Many => if (info.sentinel) |sentinel| | |
| 941 | indexOfSentinel(info.child, sentinel, ptr) | |
| 942 | else | |
| 943 | @compileError("length of pointer with no sentinel"), | |
| 944 | .C => { | |
| 945 | assert(ptr != null); | |
| 946 | return indexOfSentinel(info.child, 0, ptr); | |
| 947 | }, | |
| 948 | .Slice => if (info.sentinel) |sentinel| | |
| 949 | indexOfSentinel(info.child, sentinel, ptr.ptr) | |
| 950 | else | |
| 951 | ptr.len, | |
| 952 | }, | |
| 953 | else => @compileError("invalid type given to std.mem.lenZ"), | |
| 954 | }; | |
| 955 | } | |
| 956 | ||
| 957 | test "lenZ" { | |
| 958 | try testing.expect(lenZ("aoeu") == 4); | |
| 959 | ||
| 960 | { | |
| 961 | var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 }; | |
| 962 | try testing.expect(lenZ(&array) == 5); | |
| 963 | try testing.expect(lenZ(array[0..3]) == 3); | |
| 964 | array[2] = 0; | |
| 965 | const ptr = @as([*:0]u16, array[0..2 :0]); | |
| 966 | try testing.expect(lenZ(ptr) == 2); | |
| 967 | } | |
| 968 | { | |
| 969 | var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 }; | |
| 970 | try testing.expect(lenZ(&array) == 5); | |
| 971 | array[2] = 0; | |
| 972 | try testing.expect(lenZ(&array) == 2); | |
| 973 | } | |
| 974 | } | |
| 890 | pub const lenZ = @compileError("deprecated; use std.mem.len() or std.mem.sliceTo().len"); | |
| 975 | 891 | |
| 976 | 892 | pub fn indexOfSentinel(comptime Elem: type, comptime sentinel: Elem, ptr: [*:sentinel]const Elem) usize { |
| 977 | 893 | var i: usize = 0; |
| ... | ... | @@ -989,15 +905,8 @@ pub fn allEqual(comptime T: type, slice: []const T, scalar: T) bool { |
| 989 | 905 | return true; |
| 990 | 906 | } |
| 991 | 907 | |
| 992 | /// Deprecated, use `Allocator.dupe`. | |
| 993 | pub fn dupe(allocator: *Allocator, comptime T: type, m: []const T) ![]T { | |
| 994 | return allocator.dupe(T, m); | |
| 995 | } | |
| 996 | ||
| 997 | /// Deprecated, use `Allocator.dupeZ`. | |
| 998 | pub fn dupeZ(allocator: *Allocator, comptime T: type, m: []const T) ![:0]T { | |
| 999 | return allocator.dupeZ(T, m); | |
| 1000 | } | |
| 908 | pub const dupe = @compileError("deprecated; use `Allocator.dupe`"); | |
| 909 | pub const dupeZ = @compileError("deprecated; use `Allocator.dupeZ`"); | |
| 1001 | 910 | |
| 1002 | 911 | /// Remove values from the beginning of a slice. |
| 1003 | 912 | pub fn trimLeft(comptime T: type, slice: []const T, values_to_strip: []const T) []const T { |
| ... | ... | @@ -1727,8 +1636,6 @@ pub fn split(comptime T: type, buffer: []const T, delimiter: []const T) SplitIte |
| 1727 | 1636 | }; |
| 1728 | 1637 | } |
| 1729 | 1638 | |
| 1730 | pub const separate = @compileError("deprecated: renamed to split (behavior remains unchanged)"); | |
| 1731 | ||
| 1732 | 1639 | test "mem.split" { |
| 1733 | 1640 | var it = split(u8, "abc|def||ghi", "|"); |
| 1734 | 1641 | try testing.expect(eql(u8, it.next().?, "abc")); |
| ... | ... | @@ -3024,7 +2931,7 @@ test "isAligned" { |
| 3024 | 2931 | } |
| 3025 | 2932 | |
| 3026 | 2933 | test "freeing empty string with null-terminated sentinel" { |
| 3027 | const empty_string = try dupeZ(testing.allocator, u8, ""); | |
| 2934 | const empty_string = try testing.allocator.dupeZ(u8, ""); | |
| 3028 | 2935 | testing.allocator.free(empty_string); |
| 3029 | 2936 | } |
| 3030 | 2937 |
lib/std/mem/Allocator.zig-1| ... | ... | @@ -235,7 +235,6 @@ pub fn allocSentinel( |
| 235 | 235 | return self.allocWithOptionsRetAddr(Elem, n, null, sentinel, @returnAddress()); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | /// Deprecated: use `allocAdvanced` | |
| 239 | 238 | pub fn alignedAlloc( |
| 240 | 239 | self: *Allocator, |
| 241 | 240 | comptime T: type, |
lib/std/meta.zig+1-2| ... | ... | @@ -594,8 +594,7 @@ test "std.meta.FieldEnum" { |
| 594 | 594 | try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 })); |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | // Deprecated: use Tag | |
| 598 | pub const TagType = Tag; | |
| 597 | pub const TagType = @compileError("deprecated; use Tag"); | |
| 599 | 598 | |
| 600 | 599 | pub fn Tag(comptime T: type) type { |
| 601 | 600 | return switch (@typeInfo(T)) { |
lib/std/meta/trait.zig-1| ... | ... | @@ -2,7 +2,6 @@ const std = @import("../std.zig"); |
| 2 | 2 | const mem = std.mem; |
| 3 | 3 | const debug = std.debug; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = debug.warn; | |
| 6 | 5 | |
| 7 | 6 | const meta = @import("../meta.zig"); |
| 8 | 7 |
lib/std/multi_array_list.zig+1-2| ... | ... | @@ -309,8 +309,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 309 | 309 | self.len = new_len; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. | |
| 313 | pub const ensureCapacity = ensureTotalCapacity; | |
| 312 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); | |
| 314 | 313 | |
| 315 | 314 | /// Modify the array so that it can hold at least `new_capacity` items. |
| 316 | 315 | /// Implements super-linear growth to achieve amortized O(1) append operations. |
lib/std/net.zig+2-2| ... | ... | @@ -785,7 +785,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !* |
| 785 | 785 | |
| 786 | 786 | if (info.canonname) |n| { |
| 787 | 787 | if (result.canon_name == null) { |
| 788 | result.canon_name = try arena.dupe(u8, mem.spanZ(n)); | |
| 788 | result.canon_name = try arena.dupe(u8, mem.sliceTo(n, 0)); | |
| 789 | 789 | } |
| 790 | 790 | } |
| 791 | 791 | i += 1; |
| ... | ... | @@ -1588,7 +1588,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8) |
| 1588 | 1588 | var tmp: [256]u8 = undefined; |
| 1589 | 1589 | // Returns len of compressed name. strlen to get canon name. |
| 1590 | 1590 | _ = try os.dn_expand(packet, data, &tmp); |
| 1591 | const canon_name = mem.spanZ(std.meta.assumeSentinel(&tmp, 0)); | |
| 1591 | const canon_name = mem.sliceTo(std.meta.assumeSentinel(&tmp, 0), 0); | |
| 1592 | 1592 | if (isValidHostName(canon_name)) { |
| 1593 | 1593 | ctx.canon.items.len = 0; |
| 1594 | 1594 | try ctx.canon.appendSlice(canon_name); |
lib/std/os.zig+10-52| ... | ... | @@ -1289,8 +1289,6 @@ pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t { |
| 1289 | 1289 | return openZ(&file_path_c, flags, perm); |
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | pub const openC = @compileError("deprecated: renamed to openZ"); | |
| 1293 | ||
| 1294 | 1292 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 1295 | 1293 | /// See also `open`. |
| 1296 | 1294 | pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t { |
| ... | ... | @@ -1429,8 +1427,6 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, lookup_flags: lookupflags |
| 1429 | 1427 | } |
| 1430 | 1428 | } |
| 1431 | 1429 | |
| 1432 | pub const openatC = @compileError("deprecated: renamed to openatZ"); | |
| 1433 | ||
| 1434 | 1430 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 1435 | 1431 | /// `file_path` is relative to the open directory handle `dir_fd`. |
| 1436 | 1432 | /// See also `openat`. |
| ... | ... | @@ -1529,8 +1525,6 @@ pub const ExecveError = error{ |
| 1529 | 1525 | NameTooLong, |
| 1530 | 1526 | } || UnexpectedError; |
| 1531 | 1527 | |
| 1532 | pub const execveC = @compileError("deprecated: use execveZ"); | |
| 1533 | ||
| 1534 | 1528 | /// Like `execve` except the parameters are null-terminated, |
| 1535 | 1529 | /// matching the syscall API on all targets. This removes the need for an allocator. |
| 1536 | 1530 | /// This function ignores PATH environment variable. See `execvpeZ` for that. |
| ... | ... | @@ -1561,8 +1555,6 @@ pub fn execveZ( |
| 1561 | 1555 | } |
| 1562 | 1556 | } |
| 1563 | 1557 | |
| 1564 | pub const execvpeC = @compileError("deprecated in favor of execvpeZ"); | |
| 1565 | ||
| 1566 | 1558 | pub const Arg0Expand = enum { |
| 1567 | 1559 | expand, |
| 1568 | 1560 | no_expand, |
| ... | ... | @@ -1580,7 +1572,7 @@ pub fn execvpeZ_expandArg0( |
| 1580 | 1572 | }, |
| 1581 | 1573 | envp: [*:null]const ?[*:0]const u8, |
| 1582 | 1574 | ) ExecveError { |
| 1583 | const file_slice = mem.spanZ(file); | |
| 1575 | const file_slice = mem.sliceTo(file, 0); | |
| 1584 | 1576 | if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp); |
| 1585 | 1577 | |
| 1586 | 1578 | const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin"; |
| ... | ... | @@ -1680,19 +1672,17 @@ pub fn getenv(key: []const u8) ?[]const u8 { |
| 1680 | 1672 | return null; |
| 1681 | 1673 | } |
| 1682 | 1674 | |
| 1683 | pub const getenvC = @compileError("Deprecated in favor of `getenvZ`"); | |
| 1684 | ||
| 1685 | 1675 | /// Get an environment variable with a null-terminated name. |
| 1686 | 1676 | /// See also `getenv`. |
| 1687 | 1677 | pub fn getenvZ(key: [*:0]const u8) ?[]const u8 { |
| 1688 | 1678 | if (builtin.link_libc) { |
| 1689 | 1679 | const value = system.getenv(key) orelse return null; |
| 1690 | return mem.spanZ(value); | |
| 1680 | return mem.sliceTo(value, 0); | |
| 1691 | 1681 | } |
| 1692 | 1682 | if (builtin.os.tag == .windows) { |
| 1693 | 1683 | @compileError("std.os.getenvZ is unavailable for Windows because environment string is in WTF-16 format. See std.process.getEnvVarOwned for cross-platform API or std.os.getenvW for Windows-specific API."); |
| 1694 | 1684 | } |
| 1695 | return getenv(mem.spanZ(key)); | |
| 1685 | return getenv(mem.sliceTo(key, 0)); | |
| 1696 | 1686 | } |
| 1697 | 1687 | |
| 1698 | 1688 | /// Windows-only. Get an environment variable with a null-terminated, WTF-16 encoded name. |
| ... | ... | @@ -1703,7 +1693,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 { |
| 1703 | 1693 | if (builtin.os.tag != .windows) { |
| 1704 | 1694 | @compileError("std.os.getenvW is a Windows-only API"); |
| 1705 | 1695 | } |
| 1706 | const key_slice = mem.spanZ(key); | |
| 1696 | const key_slice = mem.sliceTo(key, 0); | |
| 1707 | 1697 | const ptr = windows.peb().ProcessParameters.Environment; |
| 1708 | 1698 | var ascii_match: ?[:0]const u16 = null; |
| 1709 | 1699 | var i: usize = 0; |
| ... | ... | @@ -1758,7 +1748,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { |
| 1758 | 1748 | break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len)); |
| 1759 | 1749 | }; |
| 1760 | 1750 | switch (err) { |
| 1761 | .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)), | |
| 1751 | .SUCCESS => return mem.sliceTo(std.meta.assumeSentinel(out_buffer.ptr, 0), 0), | |
| 1762 | 1752 | .FAULT => unreachable, |
| 1763 | 1753 | .INVAL => unreachable, |
| 1764 | 1754 | .NOENT => return error.CurrentWorkingDirectoryUnlinked, |
| ... | ... | @@ -1802,8 +1792,6 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError! |
| 1802 | 1792 | return symlinkZ(&target_path_c, &sym_link_path_c); |
| 1803 | 1793 | } |
| 1804 | 1794 | |
| 1805 | pub const symlinkC = @compileError("deprecated: renamed to symlinkZ"); | |
| 1806 | ||
| 1807 | 1795 | /// This is the same as `symlink` except the parameters are null-terminated pointers. |
| 1808 | 1796 | /// See also `symlink`. |
| 1809 | 1797 | pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void { |
| ... | ... | @@ -1848,8 +1836,6 @@ pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const |
| 1848 | 1836 | return symlinkatZ(&target_path_c, newdirfd, &sym_link_path_c); |
| 1849 | 1837 | } |
| 1850 | 1838 | |
| 1851 | pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ"); | |
| 1852 | ||
| 1853 | 1839 | /// WASI-only. The same as `symlinkat` but targeting WASI. |
| 1854 | 1840 | /// See also `symlinkat`. |
| 1855 | 1841 | pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void { |
| ... | ... | @@ -2023,8 +2009,6 @@ pub fn unlink(file_path: []const u8) UnlinkError!void { |
| 2023 | 2009 | } |
| 2024 | 2010 | } |
| 2025 | 2011 | |
| 2026 | pub const unlinkC = @compileError("deprecated: renamed to unlinkZ"); | |
| 2027 | ||
| 2028 | 2012 | /// Same as `unlink` except the parameter is a null terminated UTF8-encoded string. |
| 2029 | 2013 | pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void { |
| 2030 | 2014 | if (builtin.os.tag == .windows) { |
| ... | ... | @@ -2074,8 +2058,6 @@ pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!vo |
| 2074 | 2058 | } |
| 2075 | 2059 | } |
| 2076 | 2060 | |
| 2077 | pub const unlinkatC = @compileError("deprecated: renamed to unlinkatZ"); | |
| 2078 | ||
| 2079 | 2061 | /// WASI-only. Same as `unlinkat` but targeting WASI. |
| 2080 | 2062 | /// See also `unlinkat`. |
| 2081 | 2063 | pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!void { |
| ... | ... | @@ -2183,8 +2165,6 @@ pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void { |
| 2183 | 2165 | } |
| 2184 | 2166 | } |
| 2185 | 2167 | |
| 2186 | pub const renameC = @compileError("deprecated: renamed to renameZ"); | |
| 2187 | ||
| 2188 | 2168 | /// Same as `rename` except the parameters are null-terminated byte arrays. |
| 2189 | 2169 | pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void { |
| 2190 | 2170 | if (builtin.os.tag == .windows) { |
| ... | ... | @@ -2378,8 +2358,6 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!v |
| 2378 | 2358 | } |
| 2379 | 2359 | } |
| 2380 | 2360 | |
| 2381 | pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ"); | |
| 2382 | ||
| 2383 | 2361 | pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void { |
| 2384 | 2362 | _ = mode; |
| 2385 | 2363 | switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) { |
| ... | ... | @@ -2548,8 +2526,6 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void { |
| 2548 | 2526 | } |
| 2549 | 2527 | } |
| 2550 | 2528 | |
| 2551 | pub const rmdirC = @compileError("deprecated: renamed to rmdirZ"); | |
| 2552 | ||
| 2553 | 2529 | /// Same as `rmdir` except the parameter is null-terminated. |
| 2554 | 2530 | pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void { |
| 2555 | 2531 | if (builtin.os.tag == .windows) { |
| ... | ... | @@ -2613,8 +2589,6 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { |
| 2613 | 2589 | } |
| 2614 | 2590 | } |
| 2615 | 2591 | |
| 2616 | pub const chdirC = @compileError("deprecated: renamed to chdirZ"); | |
| 2617 | ||
| 2618 | 2592 | /// Same as `chdir` except the parameter is null-terminated. |
| 2619 | 2593 | pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void { |
| 2620 | 2594 | if (builtin.os.tag == .windows) { |
| ... | ... | @@ -2697,8 +2671,6 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 2697 | 2671 | } |
| 2698 | 2672 | } |
| 2699 | 2673 | |
| 2700 | pub const readlinkC = @compileError("deprecated: renamed to readlinkZ"); | |
| 2701 | ||
| 2702 | 2674 | /// Windows-only. Same as `readlink` except `file_path` is WTF16 encoded. |
| 2703 | 2675 | /// See also `readlinkZ`. |
| 2704 | 2676 | pub fn readlinkW(file_path: []const u16, out_buffer: []u8) ReadLinkError![]u8 { |
| ... | ... | @@ -2742,8 +2714,6 @@ pub fn readlinkat(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLink |
| 2742 | 2714 | return readlinkatZ(dirfd, &file_path_c, out_buffer); |
| 2743 | 2715 | } |
| 2744 | 2716 | |
| 2745 | pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ"); | |
| 2746 | ||
| 2747 | 2717 | /// WASI-only. Same as `readlinkat` but targets WASI. |
| 2748 | 2718 | /// See also `readlinkat`. |
| 2749 | 2719 | pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| ... | ... | @@ -3737,8 +3707,6 @@ pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat |
| 3737 | 3707 | } |
| 3738 | 3708 | } |
| 3739 | 3709 | |
| 3740 | pub const fstatatC = @compileError("deprecated: renamed to fstatatZ"); | |
| 3741 | ||
| 3742 | 3710 | /// WASI-only. Same as `fstatat` but targeting WASI. |
| 3743 | 3711 | /// See also `fstatat`. |
| 3744 | 3712 | pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat { |
| ... | ... | @@ -3883,8 +3851,6 @@ pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INoti |
| 3883 | 3851 | return inotify_add_watchZ(inotify_fd, &pathname_c, mask); |
| 3884 | 3852 | } |
| 3885 | 3853 | |
| 3886 | pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add_watchZ"); | |
| 3887 | ||
| 3888 | 3854 | /// Same as `inotify_add_watch` except pathname is null-terminated. |
| 3889 | 3855 | pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 { |
| 3890 | 3856 | const rc = system.inotify_add_watch(inotify_fd, pathname, mask); |
| ... | ... | @@ -4053,8 +4019,6 @@ pub fn access(path: []const u8, mode: u32) AccessError!void { |
| 4053 | 4019 | return accessZ(&path_c, mode); |
| 4054 | 4020 | } |
| 4055 | 4021 | |
| 4056 | pub const accessC = @compileError("Deprecated in favor of `accessZ`"); | |
| 4057 | ||
| 4058 | 4022 | /// Same as `access` except `path` is null-terminated. |
| 4059 | 4023 | pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void { |
| 4060 | 4024 | if (builtin.os.tag == .windows) { |
| ... | ... | @@ -4143,7 +4107,7 @@ pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32 |
| 4143 | 4107 | return; |
| 4144 | 4108 | } |
| 4145 | 4109 | |
| 4146 | const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) { | |
| 4110 | const path_len_bytes = math.cast(u16, mem.sliceTo(sub_path_w, 0).len * 2) catch |err| switch (err) { | |
| 4147 | 4111 | error.Overflow => return error.NameTooLong, |
| 4148 | 4112 | }; |
| 4149 | 4113 | var nt_name = windows.UNICODE_STRING{ |
| ... | ... | @@ -4273,8 +4237,6 @@ pub fn sysctl( |
| 4273 | 4237 | } |
| 4274 | 4238 | } |
| 4275 | 4239 | |
| 4276 | pub const sysctlbynameC = @compileError("deprecated: renamed to sysctlbynameZ"); | |
| 4277 | ||
| 4278 | 4240 | pub fn sysctlbynameZ( |
| 4279 | 4241 | name: [*:0]const u8, |
| 4280 | 4242 | oldp: ?*c_void, |
| ... | ... | @@ -4651,8 +4613,6 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE |
| 4651 | 4613 | return realpathZ(&pathname_c, out_buffer); |
| 4652 | 4614 | } |
| 4653 | 4615 | |
| 4654 | pub const realpathC = @compileError("deprecated: renamed realpathZ"); | |
| 4655 | ||
| 4656 | 4616 | /// Same as `realpath` except `pathname` is null-terminated. |
| 4657 | 4617 | pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { |
| 4658 | 4618 | if (builtin.os.tag == .windows) { |
| ... | ... | @@ -4684,7 +4644,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP |
| 4684 | 4644 | .IO => return error.InputOutput, |
| 4685 | 4645 | else => |err| return unexpectedErrno(err), |
| 4686 | 4646 | }; |
| 4687 | return mem.spanZ(result_path); | |
| 4647 | return mem.sliceTo(result_path, 0); | |
| 4688 | 4648 | } |
| 4689 | 4649 | |
| 4690 | 4650 | /// Same as `realpath` except `pathname` is UTF16LE-encoded. |
| ... | ... | @@ -4997,7 +4957,7 @@ pub const UnexpectedError = error{ |
| 4997 | 4957 | /// and you get an unexpected error. |
| 4998 | 4958 | pub fn unexpectedErrno(err: E) UnexpectedError { |
| 4999 | 4959 | if (unexpected_error_tracing) { |
| 5000 | std.debug.warn("unexpected errno: {d}\n", .{@enumToInt(err)}); | |
| 4960 | std.debug.print("unexpected errno: {d}\n", .{@enumToInt(err)}); | |
| 5001 | 4961 | std.debug.dumpCurrentStackTrace(null); |
| 5002 | 4962 | } |
| 5003 | 4963 | return error.Unexpected; |
| ... | ... | @@ -5092,7 +5052,7 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError; |
| 5092 | 5052 | pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { |
| 5093 | 5053 | if (builtin.link_libc) { |
| 5094 | 5054 | switch (errno(system.gethostname(name_buffer, name_buffer.len))) { |
| 5095 | .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(name_buffer, 0)), | |
| 5055 | .SUCCESS => return mem.sliceTo(std.meta.assumeSentinel(name_buffer, 0), 0), | |
| 5096 | 5056 | .FAULT => unreachable, |
| 5097 | 5057 | .NAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this |
| 5098 | 5058 | .PERM => return error.PermissionDenied, |
| ... | ... | @@ -5101,7 +5061,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { |
| 5101 | 5061 | } |
| 5102 | 5062 | if (builtin.os.tag == .linux) { |
| 5103 | 5063 | const uts = uname(); |
| 5104 | const hostname = mem.spanZ(std.meta.assumeSentinel(&uts.nodename, 0)); | |
| 5064 | const hostname = mem.sliceTo(std.meta.assumeSentinel(&uts.nodename, 0), 0); | |
| 5105 | 5065 | mem.copy(u8, name_buffer, hostname); |
| 5106 | 5066 | return name_buffer[0..hostname.len]; |
| 5107 | 5067 | } |
| ... | ... | @@ -6130,8 +6090,6 @@ pub const MemFdCreateError = error{ |
| 6130 | 6090 | SystemOutdated, |
| 6131 | 6091 | } || UnexpectedError; |
| 6132 | 6092 | |
| 6133 | pub const memfd_createC = @compileError("deprecated: renamed to memfd_createZ"); | |
| 6134 | ||
| 6135 | 6093 | pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t { |
| 6136 | 6094 | // memfd_create is available only in glibc versions starting with 2.27. |
| 6137 | 6095 | const use_c = std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok; |
lib/std/os/linux/vdso.zig+2-2| ... | ... | @@ -69,7 +69,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 69 | 69 | if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue; |
| 70 | 70 | if (0 == syms[i].st_shndx) continue; |
| 71 | 71 | const sym_name = std.meta.assumeSentinel(strings + syms[i].st_name, 0); |
| 72 | if (!mem.eql(u8, name, mem.spanZ(sym_name))) continue; | |
| 72 | if (!mem.eql(u8, name, mem.sliceTo(sym_name, 0))) continue; | |
| 73 | 73 | if (maybe_versym) |versym| { |
| 74 | 74 | if (!checkver(maybe_verdef.?, versym[i], vername, strings)) |
| 75 | 75 | continue; |
| ... | ... | @@ -92,5 +92,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [ |
| 92 | 92 | } |
| 93 | 93 | const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux); |
| 94 | 94 | const vda_name = std.meta.assumeSentinel(strings + aux.vda_name, 0); |
| 95 | return mem.eql(u8, vername, mem.spanZ(vda_name)); | |
| 95 | return mem.eql(u8, vername, mem.sliceTo(vda_name, 0)); | |
| 96 | 96 | } |
lib/std/os/windows.zig+4-4| ... | ... | @@ -813,7 +813,7 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin |
| 813 | 813 | return parseReadlinkPath(path_buf[offset .. offset + len], false, out_buffer); |
| 814 | 814 | }, |
| 815 | 815 | else => |value| { |
| 816 | std.debug.warn("unsupported symlink type: {}", .{value}); | |
| 816 | std.debug.print("unsupported symlink type: {}", .{value}); | |
| 817 | 817 | return error.UnsupportedReparsePointType; |
| 818 | 818 | }, |
| 819 | 819 | } |
| ... | ... | @@ -1862,7 +1862,7 @@ pub fn normalizePath(comptime T: type, path: []T) RemoveDotDirsError!usize { |
| 1862 | 1862 | /// Same as `sliceToPrefixedFileW` but accepts a pointer |
| 1863 | 1863 | /// to a null-terminated path. |
| 1864 | 1864 | pub fn cStrToPrefixedFileW(s: [*:0]const u8) !PathSpace { |
| 1865 | return sliceToPrefixedFileW(mem.spanZ(s)); | |
| 1865 | return sliceToPrefixedFileW(mem.sliceTo(s, 0)); | |
| 1866 | 1866 | } |
| 1867 | 1867 | |
| 1868 | 1868 | /// Converts the path `s` to WTF16, null-terminated. If the path is absolute, |
| ... | ... | @@ -1995,7 +1995,7 @@ pub fn unexpectedError(err: Win32Error) std.os.UnexpectedError { |
| 1995 | 1995 | null, |
| 1996 | 1996 | ); |
| 1997 | 1997 | _ = std.unicode.utf16leToUtf8(&buf_utf8, buf_wstr[0..len]) catch unreachable; |
| 1998 | std.debug.warn("error.Unexpected: GetLastError({}): {s}\n", .{ @enumToInt(err), buf_utf8[0..len] }); | |
| 1998 | std.debug.print("error.Unexpected: GetLastError({}): {s}\n", .{ @enumToInt(err), buf_utf8[0..len] }); | |
| 1999 | 1999 | std.debug.dumpCurrentStackTrace(null); |
| 2000 | 2000 | } |
| 2001 | 2001 | return error.Unexpected; |
| ... | ... | @@ -2009,7 +2009,7 @@ pub fn unexpectedWSAError(err: ws2_32.WinsockError) std.os.UnexpectedError { |
| 2009 | 2009 | /// and you get an unexpected status. |
| 2010 | 2010 | pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError { |
| 2011 | 2011 | if (std.os.unexpected_error_tracing) { |
| 2012 | std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", .{@enumToInt(status)}); | |
| 2012 | std.debug.print("error.Unexpected NTSTATUS=0x{x}\n", .{@enumToInt(status)}); | |
| 2013 | 2013 | std.debug.dumpCurrentStackTrace(null); |
| 2014 | 2014 | } |
| 2015 | 2015 | return error.Unexpected; |
lib/std/pdb.zig+2-3| ... | ... | @@ -3,7 +3,6 @@ const io = std.io; |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const mem = std.mem; |
| 5 | 5 | const os = std.os; |
| 6 | const warn = std.debug.warn; | |
| 7 | 6 | const coff = std.coff; |
| 8 | 7 | const fs = std.fs; |
| 9 | 8 | const File = std.fs.File; |
| ... | ... | @@ -656,7 +655,7 @@ pub const Pdb = struct { |
| 656 | 655 | const name_index = try reader.readIntLittle(u32); |
| 657 | 656 | if (name_offset > name_bytes.len) |
| 658 | 657 | return error.InvalidDebugInfo; |
| 659 | const name = mem.spanZ(std.meta.assumeSentinel(name_bytes.ptr + name_offset, 0)); | |
| 658 | const name = mem.sliceTo(std.meta.assumeSentinel(name_bytes.ptr + name_offset, 0), 0); | |
| 660 | 659 | if (mem.eql(u8, name, "/names")) { |
| 661 | 660 | break :str_tab_index name_index; |
| 662 | 661 | } |
| ... | ... | @@ -681,7 +680,7 @@ pub const Pdb = struct { |
| 681 | 680 | .S_LPROC32, .S_GPROC32 => { |
| 682 | 681 | const proc_sym = @ptrCast(*ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]); |
| 683 | 682 | if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) { |
| 684 | return mem.spanZ(@ptrCast([*:0]u8, proc_sym) + @sizeOf(ProcSym)); | |
| 683 | return mem.sliceTo(@ptrCast([*:0]u8, proc_sym) + @sizeOf(ProcSym), 0); | |
| 685 | 684 | } |
| 686 | 685 | }, |
| 687 | 686 | else => {}, |
lib/std/priority_dequeue.zig+10-11| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const std = @import("std.zig"); |
| 2 | 2 | const Allocator = std.mem.Allocator; |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const warn = std.debug.warn; | |
| 5 | 4 | const Order = std.math.Order; |
| 6 | 5 | const testing = std.testing; |
| 7 | 6 | const expect = testing.expect; |
| ... | ... | @@ -355,8 +354,7 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty |
| 355 | 354 | return queue; |
| 356 | 355 | } |
| 357 | 356 | |
| 358 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. | |
| 359 | pub const ensureCapacity = ensureTotalCapacity; | |
| 357 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); | |
| 360 | 358 | |
| 361 | 359 | /// Ensure that the dequeue can fit at least `new_capacity` items. |
| 362 | 360 | pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void { |
| ... | ... | @@ -421,19 +419,20 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty |
| 421 | 419 | } |
| 422 | 420 | |
| 423 | 421 | fn dump(self: *Self) void { |
| 424 | warn("{{ ", .{}); | |
| 425 | warn("items: ", .{}); | |
| 422 | const print = std.debug.print; | |
| 423 | print("{{ ", .{}); | |
| 424 | print("items: ", .{}); | |
| 426 | 425 | for (self.items) |e, i| { |
| 427 | 426 | if (i >= self.len) break; |
| 428 | warn("{}, ", .{e}); | |
| 427 | print("{}, ", .{e}); | |
| 429 | 428 | } |
| 430 | warn("array: ", .{}); | |
| 429 | print("array: ", .{}); | |
| 431 | 430 | for (self.items) |e| { |
| 432 | warn("{}, ", .{e}); | |
| 431 | print("{}, ", .{e}); | |
| 433 | 432 | } |
| 434 | warn("len: {} ", .{self.len}); | |
| 435 | warn("capacity: {}", .{self.capacity()}); | |
| 436 | warn(" }}\n", .{}); | |
| 433 | print("len: {} ", .{self.len}); | |
| 434 | print("capacity: {}", .{self.capacity()}); | |
| 435 | print(" }}\n", .{}); | |
| 437 | 436 | } |
| 438 | 437 | |
| 439 | 438 | fn parentIndex(index: usize) usize { |
lib/std/priority_queue.zig+10-11| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const std = @import("std.zig"); |
| 2 | 2 | const Allocator = std.mem.Allocator; |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const warn = std.debug.warn; | |
| 5 | 4 | const Order = std.math.Order; |
| 6 | 5 | const testing = std.testing; |
| 7 | 6 | const expect = testing.expect; |
| ... | ... | @@ -171,8 +170,7 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order |
| 171 | 170 | return queue; |
| 172 | 171 | } |
| 173 | 172 | |
| 174 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. | |
| 175 | pub const ensureCapacity = ensureTotalCapacity; | |
| 173 | pub const ensureCapacity = @compileError("deprecated; use ensureUnusedCapacity or ensureTotalCapacity"); | |
| 176 | 174 | |
| 177 | 175 | /// Ensure that the queue can fit at least `new_capacity` items. |
| 178 | 176 | pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void { |
| ... | ... | @@ -242,19 +240,20 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order |
| 242 | 240 | } |
| 243 | 241 | |
| 244 | 242 | fn dump(self: *Self) void { |
| 245 | warn("{{ ", .{}); | |
| 246 | warn("items: ", .{}); | |
| 243 | const print = std.debug.print; | |
| 244 | print("{{ ", .{}); | |
| 245 | print("items: ", .{}); | |
| 247 | 246 | for (self.items) |e, i| { |
| 248 | 247 | if (i >= self.len) break; |
| 249 | warn("{}, ", .{e}); | |
| 248 | print("{}, ", .{e}); | |
| 250 | 249 | } |
| 251 | warn("array: ", .{}); | |
| 250 | print("array: ", .{}); | |
| 252 | 251 | for (self.items) |e| { |
| 253 | warn("{}, ", .{e}); | |
| 252 | print("{}, ", .{e}); | |
| 254 | 253 | } |
| 255 | warn("len: {} ", .{self.len}); | |
| 256 | warn("capacity: {}", .{self.capacity()}); | |
| 257 | warn(" }}\n", .{}); | |
| 254 | print("len: {} ", .{self.len}); | |
| 255 | print("capacity: {}", .{self.capacity()}); | |
| 256 | print(" }}\n", .{}); | |
| 258 | 257 | } |
| 259 | 258 | }; |
| 260 | 259 | } |
lib/std/process.zig+6-6| ... | ... | @@ -103,7 +103,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap { |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | for (environ) |env| { |
| 106 | const pair = mem.spanZ(env); | |
| 106 | const pair = mem.sliceTo(env, 0); | |
| 107 | 107 | var parts = mem.split(u8, pair, "="); |
| 108 | 108 | const key = parts.next().?; |
| 109 | 109 | const value = parts.next().?; |
| ... | ... | @@ -215,7 +215,7 @@ pub const ArgIteratorPosix = struct { |
| 215 | 215 | |
| 216 | 216 | const s = os.argv[self.index]; |
| 217 | 217 | self.index += 1; |
| 218 | return mem.spanZ(s); | |
| 218 | return mem.sliceTo(s, 0); | |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | pub fn skip(self: *ArgIteratorPosix) bool { |
| ... | ... | @@ -267,7 +267,7 @@ pub const ArgIteratorWasi = struct { |
| 267 | 267 | var result_args = try allocator.alloc([:0]u8, count); |
| 268 | 268 | var i: usize = 0; |
| 269 | 269 | while (i < count) : (i += 1) { |
| 270 | result_args[i] = mem.spanZ(argv[i]); | |
| 270 | result_args[i] = mem.sliceTo(argv[i], 0); | |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | return result_args; |
| ... | ... | @@ -768,7 +768,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] |
| 768 | 768 | _ = size; |
| 769 | 769 | const name = info.dlpi_name orelse return; |
| 770 | 770 | if (name[0] == '/') { |
| 771 | const item = try list.allocator.dupeZ(u8, mem.spanZ(name)); | |
| 771 | const item = try list.allocator.dupeZ(u8, mem.sliceTo(name, 0)); | |
| 772 | 772 | errdefer list.allocator.free(item); |
| 773 | 773 | try list.append(item); |
| 774 | 774 | } |
| ... | ... | @@ -789,7 +789,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] |
| 789 | 789 | var i: u32 = 0; |
| 790 | 790 | while (i < img_count) : (i += 1) { |
| 791 | 791 | const name = std.c._dyld_get_image_name(i); |
| 792 | const item = try allocator.dupeZ(u8, mem.spanZ(name)); | |
| 792 | const item = try allocator.dupeZ(u8, mem.sliceTo(name, 0)); | |
| 793 | 793 | errdefer allocator.free(item); |
| 794 | 794 | try paths.append(item); |
| 795 | 795 | } |
| ... | ... | @@ -807,7 +807,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] |
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | var b = "/boot/system/runtime_loader"; |
| 810 | const item = try allocator.dupeZ(u8, mem.spanZ(b)); | |
| 810 | const item = try allocator.dupeZ(u8, mem.sliceTo(b, 0)); | |
| 811 | 811 | errdefer allocator.free(item); |
| 812 | 812 | try paths.append(item); |
| 813 | 813 |
lib/std/rand.zig-4| ... | ... | @@ -245,10 +245,6 @@ pub const Random = struct { |
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | pub const scalar = @compileError("deprecated; use boolean() or int() instead"); | |
| 249 | ||
| 250 | pub const range = @compileError("deprecated; use intRangeLessThan()"); | |
| 251 | ||
| 252 | 248 | /// Return a floating point value evenly distributed in the range [0, 1). |
| 253 | 249 | pub fn float(r: Random, comptime T: type) T { |
| 254 | 250 | // Generate a uniform value between [1, 2) and scale down to [0, 1). |
lib/std/special/build_runner.zig+17-18| ... | ... | @@ -7,7 +7,6 @@ const Builder = std.build.Builder; |
| 7 | 7 | const mem = std.mem; |
| 8 | 8 | const process = std.process; |
| 9 | 9 | const ArrayList = std.ArrayList; |
| 10 | const warn = std.debug.warn; | |
| 11 | 10 | const File = std.fs.File; |
| 12 | 11 | |
| 13 | 12 | pub fn main() !void { |
| ... | ... | @@ -25,19 +24,19 @@ pub fn main() !void { |
| 25 | 24 | var arg_idx: usize = 1; |
| 26 | 25 | |
| 27 | 26 | const zig_exe = nextArg(args, &arg_idx) orelse { |
| 28 | warn("Expected first argument to be path to zig compiler\n", .{}); | |
| 27 | std.debug.print("Expected first argument to be path to zig compiler\n", .{}); | |
| 29 | 28 | return error.InvalidArgs; |
| 30 | 29 | }; |
| 31 | 30 | const build_root = nextArg(args, &arg_idx) orelse { |
| 32 | warn("Expected second argument to be build root directory path\n", .{}); | |
| 31 | std.debug.print("Expected second argument to be build root directory path\n", .{}); | |
| 33 | 32 | return error.InvalidArgs; |
| 34 | 33 | }; |
| 35 | 34 | const cache_root = nextArg(args, &arg_idx) orelse { |
| 36 | warn("Expected third argument to be cache root directory path\n", .{}); | |
| 35 | std.debug.print("Expected third argument to be cache root directory path\n", .{}); | |
| 37 | 36 | return error.InvalidArgs; |
| 38 | 37 | }; |
| 39 | 38 | const global_cache_root = nextArg(args, &arg_idx) orelse { |
| 40 | warn("Expected third argument to be global cache root directory path\n", .{}); | |
| 39 | std.debug.print("Expected third argument to be global cache root directory path\n", .{}); | |
| 41 | 40 | return error.InvalidArgs; |
| 42 | 41 | }; |
| 43 | 42 | |
| ... | ... | @@ -68,7 +67,7 @@ pub fn main() !void { |
| 68 | 67 | if (mem.startsWith(u8, arg, "-D")) { |
| 69 | 68 | const option_contents = arg[2..]; |
| 70 | 69 | if (option_contents.len == 0) { |
| 71 | warn("Expected option name after '-D'\n\n", .{}); | |
| 70 | std.debug.print("Expected option name after '-D'\n\n", .{}); | |
| 72 | 71 | return usageAndErr(builder, false, stderr_stream); |
| 73 | 72 | } |
| 74 | 73 | if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| { |
| ... | ... | @@ -87,59 +86,59 @@ pub fn main() !void { |
| 87 | 86 | return usage(builder, false, stdout_stream); |
| 88 | 87 | } else if (mem.eql(u8, arg, "-p") or mem.eql(u8, arg, "--prefix")) { |
| 89 | 88 | install_prefix = nextArg(args, &arg_idx) orelse { |
| 90 | warn("Expected argument after {s}\n\n", .{arg}); | |
| 89 | std.debug.print("Expected argument after {s}\n\n", .{arg}); | |
| 91 | 90 | return usageAndErr(builder, false, stderr_stream); |
| 92 | 91 | }; |
| 93 | 92 | } else if (mem.eql(u8, arg, "--prefix-lib-dir")) { |
| 94 | 93 | dir_list.lib_dir = nextArg(args, &arg_idx) orelse { |
| 95 | warn("Expected argument after {s}\n\n", .{arg}); | |
| 94 | std.debug.print("Expected argument after {s}\n\n", .{arg}); | |
| 96 | 95 | return usageAndErr(builder, false, stderr_stream); |
| 97 | 96 | }; |
| 98 | 97 | } else if (mem.eql(u8, arg, "--prefix-exe-dir")) { |
| 99 | 98 | dir_list.exe_dir = nextArg(args, &arg_idx) orelse { |
| 100 | warn("Expected argument after {s}\n\n", .{arg}); | |
| 99 | std.debug.print("Expected argument after {s}\n\n", .{arg}); | |
| 101 | 100 | return usageAndErr(builder, false, stderr_stream); |
| 102 | 101 | }; |
| 103 | 102 | } else if (mem.eql(u8, arg, "--prefix-include-dir")) { |
| 104 | 103 | dir_list.include_dir = nextArg(args, &arg_idx) orelse { |
| 105 | warn("Expected argument after {s}\n\n", .{arg}); | |
| 104 | std.debug.print("Expected argument after {s}\n\n", .{arg}); | |
| 106 | 105 | return usageAndErr(builder, false, stderr_stream); |
| 107 | 106 | }; |
| 108 | 107 | } else if (mem.eql(u8, arg, "--sysroot")) { |
| 109 | 108 | const sysroot = nextArg(args, &arg_idx) orelse { |
| 110 | warn("Expected argument after --sysroot\n\n", .{}); | |
| 109 | std.debug.print("Expected argument after --sysroot\n\n", .{}); | |
| 111 | 110 | return usageAndErr(builder, false, stderr_stream); |
| 112 | 111 | }; |
| 113 | 112 | builder.sysroot = sysroot; |
| 114 | 113 | } else if (mem.eql(u8, arg, "--search-prefix")) { |
| 115 | 114 | const search_prefix = nextArg(args, &arg_idx) orelse { |
| 116 | warn("Expected argument after --search-prefix\n\n", .{}); | |
| 115 | std.debug.print("Expected argument after --search-prefix\n\n", .{}); | |
| 117 | 116 | return usageAndErr(builder, false, stderr_stream); |
| 118 | 117 | }; |
| 119 | 118 | builder.addSearchPrefix(search_prefix); |
| 120 | 119 | } else if (mem.eql(u8, arg, "--libc")) { |
| 121 | 120 | const libc_file = nextArg(args, &arg_idx) orelse { |
| 122 | warn("Expected argument after --libc\n\n", .{}); | |
| 121 | std.debug.print("Expected argument after --libc\n\n", .{}); | |
| 123 | 122 | return usageAndErr(builder, false, stderr_stream); |
| 124 | 123 | }; |
| 125 | 124 | builder.libc_file = libc_file; |
| 126 | 125 | } else if (mem.eql(u8, arg, "--color")) { |
| 127 | 126 | const next_arg = nextArg(args, &arg_idx) orelse { |
| 128 | warn("expected [auto|on|off] after --color", .{}); | |
| 127 | std.debug.print("expected [auto|on|off] after --color", .{}); | |
| 129 | 128 | return usageAndErr(builder, false, stderr_stream); |
| 130 | 129 | }; |
| 131 | 130 | builder.color = std.meta.stringToEnum(@TypeOf(builder.color), next_arg) orelse { |
| 132 | warn("expected [auto|on|off] after --color, found '{s}'", .{next_arg}); | |
| 131 | std.debug.print("expected [auto|on|off] after --color, found '{s}'", .{next_arg}); | |
| 133 | 132 | return usageAndErr(builder, false, stderr_stream); |
| 134 | 133 | }; |
| 135 | 134 | } else if (mem.eql(u8, arg, "--zig-lib-dir")) { |
| 136 | 135 | builder.override_lib_dir = nextArg(args, &arg_idx) orelse { |
| 137 | warn("Expected argument after --zig-lib-dir\n\n", .{}); | |
| 136 | std.debug.print("Expected argument after --zig-lib-dir\n\n", .{}); | |
| 138 | 137 | return usageAndErr(builder, false, stderr_stream); |
| 139 | 138 | }; |
| 140 | 139 | } else if (mem.eql(u8, arg, "--debug-log")) { |
| 141 | 140 | const next_arg = nextArg(args, &arg_idx) orelse { |
| 142 | warn("Expected argument after {s}\n\n", .{arg}); | |
| 141 | std.debug.print("Expected argument after {s}\n\n", .{arg}); | |
| 143 | 142 | return usageAndErr(builder, false, stderr_stream); |
| 144 | 143 | }; |
| 145 | 144 | try debug_log_scopes.append(next_arg); |
| ... | ... | @@ -165,7 +164,7 @@ pub fn main() !void { |
| 165 | 164 | builder.args = argsRest(args, arg_idx); |
| 166 | 165 | break; |
| 167 | 166 | } else { |
| 168 | warn("Unrecognized argument: {s}\n\n", .{arg}); | |
| 167 | std.debug.print("Unrecognized argument: {s}\n\n", .{arg}); | |
| 169 | 168 | return usageAndErr(builder, false, stderr_stream); |
| 170 | 169 | } |
| 171 | 170 | } else { |
lib/std/special/c_stage1.zig+4-4| ... | ... | @@ -59,7 +59,7 @@ test "strcpy" { |
| 59 | 59 | |
| 60 | 60 | s1[0] = 0; |
| 61 | 61 | _ = strcpy(&s1, "foobarbaz"); |
| 62 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 62 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0)); | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 { |
| ... | ... | @@ -79,7 +79,7 @@ test "strncpy" { |
| 79 | 79 | |
| 80 | 80 | s1[0] = 0; |
| 81 | 81 | _ = strncpy(&s1, "foobarbaz", @sizeOf(@TypeOf(s1))); |
| 82 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 82 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0)); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 { |
| ... | ... | @@ -102,7 +102,7 @@ test "strcat" { |
| 102 | 102 | _ = strcat(&s1, "foo"); |
| 103 | 103 | _ = strcat(&s1, "bar"); |
| 104 | 104 | _ = strcat(&s1, "baz"); |
| 105 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 105 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0)); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 { |
| ... | ... | @@ -125,7 +125,7 @@ test "strncat" { |
| 125 | 125 | _ = strncat(&s1, "foo1111", 3); |
| 126 | 126 | _ = strncat(&s1, "bar1111", 3); |
| 127 | 127 | _ = strncat(&s1, "baz1111", 3); |
| 128 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 128 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0)); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) callconv(.C) c_int { |
lib/std/special/compiler_rt/fixdfdi_test.zig-3| ... | ... | @@ -2,16 +2,13 @@ const __fixdfdi = @import("fixdfdi.zig").__fixdfdi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = std.debug.warn; | |
| 6 | 5 | |
| 7 | 6 | fn test__fixdfdi(a: f64, expected: i64) !void { |
| 8 | 7 | const x = __fixdfdi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)}); | |
| 10 | 8 | try testing.expect(x == expected); |
| 11 | 9 | } |
| 12 | 10 | |
| 13 | 11 | test "fixdfdi" { |
| 14 | //warn("\n", .{}); | |
| 15 | 12 | try test__fixdfdi(-math.f64_max, math.minInt(i64)); |
| 16 | 13 | |
| 17 | 14 | try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); |
lib/std/special/compiler_rt/fixdfsi_test.zig-3| ... | ... | @@ -2,16 +2,13 @@ const __fixdfsi = @import("fixdfsi.zig").__fixdfsi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = std.debug.warn; | |
| 6 | 5 | |
| 7 | 6 | fn test__fixdfsi(a: f64, expected: i32) !void { |
| 8 | 7 | const x = __fixdfsi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)}); | |
| 10 | 8 | try testing.expect(x == expected); |
| 11 | 9 | } |
| 12 | 10 | |
| 13 | 11 | test "fixdfsi" { |
| 14 | //warn("\n", .{}); | |
| 15 | 12 | try test__fixdfsi(-math.f64_max, math.minInt(i32)); |
| 16 | 13 | |
| 17 | 14 | try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); |
lib/std/special/compiler_rt/fixdfti_test.zig-3| ... | ... | @@ -2,16 +2,13 @@ const __fixdfti = @import("fixdfti.zig").__fixdfti; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = std.debug.warn; | |
| 6 | 5 | |
| 7 | 6 | fn test__fixdfti(a: f64, expected: i128) !void { |
| 8 | 7 | const x = __fixdfti(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)}); | |
| 10 | 8 | try testing.expect(x == expected); |
| 11 | 9 | } |
| 12 | 10 | |
| 13 | 11 | test "fixdfti" { |
| 14 | //warn("\n", .{}); | |
| 15 | 12 | try test__fixdfti(-math.f64_max, math.minInt(i128)); |
| 16 | 13 | |
| 17 | 14 | try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); |
lib/std/special/compiler_rt/fixint_test.zig-2| ... | ... | @@ -2,13 +2,11 @@ const is_test = @import("builtin").is_test; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = std.debug.warn; | |
| 6 | 5 | |
| 7 | 6 | const fixint = @import("fixint.zig").fixint; |
| 8 | 7 | |
| 9 | 8 | fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) !void { |
| 10 | 9 | const x = fixint(fp_t, fixint_t, a); |
| 11 | //warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected}); | |
| 12 | 10 | try testing.expect(x == expected); |
| 13 | 11 | } |
| 14 | 12 |
lib/std/special/compiler_rt/fixsfdi_test.zig-3| ... | ... | @@ -2,16 +2,13 @@ const __fixsfdi = @import("fixsfdi.zig").__fixsfdi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = std.debug.warn; | |
| 6 | 5 | |
| 7 | 6 | fn test__fixsfdi(a: f32, expected: i64) !void { |
| 8 | 7 | const x = __fixsfdi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)}); | |
| 10 | 8 | try testing.expect(x == expected); |
| 11 | 9 | } |
| 12 | 10 | |
| 13 | 11 | test "fixsfdi" { |
| 14 | //warn("\n", .{}); | |
| 15 | 12 | try test__fixsfdi(-math.f32_max, math.minInt(i64)); |
| 16 | 13 | |
| 17 | 14 | try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); |
lib/std/special/compiler_rt/fixsfsi_test.zig-3| ... | ... | @@ -2,16 +2,13 @@ const __fixsfsi = @import("fixsfsi.zig").__fixsfsi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = std.debug.warn; | |
| 6 | 5 | |
| 7 | 6 | fn test__fixsfsi(a: f32, expected: i32) !void { |
| 8 | 7 | const x = __fixsfsi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)}); | |
| 10 | 8 | try testing.expect(x == expected); |
| 11 | 9 | } |
| 12 | 10 | |
| 13 | 11 | test "fixsfsi" { |
| 14 | //warn("\n", .{}); | |
| 15 | 12 | try test__fixsfsi(-math.f32_max, math.minInt(i32)); |
| 16 | 13 | |
| 17 | 14 | try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); |
lib/std/special/compiler_rt/fixsfti_test.zig-3| ... | ... | @@ -2,16 +2,13 @@ const __fixsfti = @import("fixsfti.zig").__fixsfti; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = std.debug.warn; | |
| 6 | 5 | |
| 7 | 6 | fn test__fixsfti(a: f32, expected: i128) !void { |
| 8 | 7 | const x = __fixsfti(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)}); | |
| 10 | 8 | try testing.expect(x == expected); |
| 11 | 9 | } |
| 12 | 10 | |
| 13 | 11 | test "fixsfti" { |
| 14 | //warn("\n", .{}); | |
| 15 | 12 | try test__fixsfti(-math.f32_max, math.minInt(i128)); |
| 16 | 13 | |
| 17 | 14 | try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); |
lib/std/special/compiler_rt/fixtfdi_test.zig-3| ... | ... | @@ -2,16 +2,13 @@ const __fixtfdi = @import("fixtfdi.zig").__fixtfdi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = std.debug.warn; | |
| 6 | 5 | |
| 7 | 6 | fn test__fixtfdi(a: f128, expected: i64) !void { |
| 8 | 7 | const x = __fixtfdi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)}); | |
| 10 | 8 | try testing.expect(x == expected); |
| 11 | 9 | } |
| 12 | 10 | |
| 13 | 11 | test "fixtfdi" { |
| 14 | //warn("\n", .{}); | |
| 15 | 12 | try test__fixtfdi(-math.f128_max, math.minInt(i64)); |
| 16 | 13 | |
| 17 | 14 | try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); |
lib/std/special/compiler_rt/fixtfsi_test.zig-3| ... | ... | @@ -2,16 +2,13 @@ const __fixtfsi = @import("fixtfsi.zig").__fixtfsi; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = std.debug.warn; | |
| 6 | 5 | |
| 7 | 6 | fn test__fixtfsi(a: f128, expected: i32) !void { |
| 8 | 7 | const x = __fixtfsi(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)}); | |
| 10 | 8 | try testing.expect(x == expected); |
| 11 | 9 | } |
| 12 | 10 | |
| 13 | 11 | test "fixtfsi" { |
| 14 | //warn("\n", .{}); | |
| 15 | 12 | try test__fixtfsi(-math.f128_max, math.minInt(i32)); |
| 16 | 13 | |
| 17 | 14 | try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); |
lib/std/special/compiler_rt/fixtfti_test.zig-3| ... | ... | @@ -2,16 +2,13 @@ const __fixtfti = @import("fixtfti.zig").__fixtfti; |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const testing = std.testing; |
| 5 | const warn = std.debug.warn; | |
| 6 | 5 | |
| 7 | 6 | fn test__fixtfti(a: f128, expected: i128) !void { |
| 8 | 7 | const x = __fixtfti(a); |
| 9 | //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)}); | |
| 10 | 8 | try testing.expect(x == expected); |
| 11 | 9 | } |
| 12 | 10 | |
| 13 | 11 | test "fixtfti" { |
| 14 | //warn("\n", .{}); | |
| 15 | 12 | try test__fixtfti(-math.f128_max, math.minInt(i128)); |
| 16 | 13 | |
| 17 | 14 | try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); |
lib/std/special/compiler_rt/truncXfYf2_test.zig+2-2| ... | ... | @@ -217,7 +217,7 @@ fn test__truncdfsf2(a: f64, expected: u32) void { |
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | @import("std").debug.warn("got 0x{x} wanted 0x{x}\n", .{ rep, expected }); | |
| 220 | @import("std").debug.print("got 0x{x} wanted 0x{x}\n", .{ rep, expected }); | |
| 221 | 221 | |
| 222 | 222 | @panic("__trunctfsf2 test failure"); |
| 223 | 223 | } |
| ... | ... | @@ -248,7 +248,7 @@ fn test__trunctfhf2(a: f128, expected: u16) void { |
| 248 | 248 | return; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | @import("std").debug.warn("got 0x{x} wanted 0x{x}\n", .{ rep, expected }); | |
| 251 | @import("std").debug.print("got 0x{x} wanted 0x{x}\n", .{ rep, expected }); | |
| 252 | 252 | |
| 253 | 253 | @panic("__trunctfhf2 test failure"); |
| 254 | 254 | } |
lib/std/testing.zig-3| ... | ... | @@ -208,9 +208,6 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt |
| 208 | 208 | return error.TestExpectedFmt; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | pub const expectWithinMargin = @compileError("expectWithinMargin is deprecated, use expectApproxEqAbs or expectApproxEqRel"); | |
| 212 | pub const expectWithinEpsilon = @compileError("expectWithinEpsilon is deprecated, use expectApproxEqAbs or expectApproxEqRel"); | |
| 213 | ||
| 214 | 211 | /// This function is intended to be used only in tests. When the actual value is |
| 215 | 212 | /// not approximately equal to the expected value, prints diagnostics to stderr |
| 216 | 213 | /// to show exactly how they are not equal, then aborts. |
lib/std/unicode.zig+1-1| ... | ... | @@ -216,7 +216,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool { |
| 216 | 216 | /// ``` |
| 217 | 217 | /// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator(); |
| 218 | 218 | /// while (utf8.nextCodepointSlice()) |codepoint| { |
| 219 | /// std.debug.warn("got codepoint {}\n", .{codepoint}); | |
| 219 | /// std.debug.print("got codepoint {}\n", .{codepoint}); | |
| 220 | 220 | /// } |
| 221 | 221 | /// ``` |
| 222 | 222 | pub const Utf8View = struct { |
lib/std/zig.zig+1-1| ... | ... | @@ -12,7 +12,7 @@ pub const parse = @import("zig/parse.zig").parse; |
| 12 | 12 | pub const string_literal = @import("zig/string_literal.zig"); |
| 13 | 13 | pub const Ast = @import("zig/Ast.zig"); |
| 14 | 14 | pub const system = @import("zig/system.zig"); |
| 15 | pub const CrossTarget = @import("zig/cross_target.zig").CrossTarget; | |
| 15 | pub const CrossTarget = @import("zig/CrossTarget.zig"); | |
| 16 | 16 | |
| 17 | 17 | // Files needed by translate-c. |
| 18 | 18 | pub const c_builtins = @import("zig/c_builtins.zig"); |
lib/std/zig/CrossTarget.zig created+909| ... | ... | @@ -0,0 +1,909 @@ |
| 1 | //! Contains all the same data as `Target`, additionally introducing the concept of "the native target". | |
| 2 | //! The purpose of this abstraction is to provide meaningful and unsurprising defaults. | |
| 3 | //! This struct does reference any resources and it is copyable. | |
| 4 | ||
| 5 | const CrossTarget = @This(); | |
| 6 | const std = @import("../std.zig"); | |
| 7 | const builtin = @import("builtin"); | |
| 8 | const assert = std.debug.assert; | |
| 9 | const Target = std.Target; | |
| 10 | const mem = std.mem; | |
| 11 | ||
| 12 | /// `null` means native. | |
| 13 | cpu_arch: ?Target.Cpu.Arch = null, | |
| 14 | ||
| 15 | cpu_model: CpuModel = CpuModel.determined_by_cpu_arch, | |
| 16 | ||
| 17 | /// Sparse set of CPU features to add to the set from `cpu_model`. | |
| 18 | cpu_features_add: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty, | |
| 19 | ||
| 20 | /// Sparse set of CPU features to remove from the set from `cpu_model`. | |
| 21 | cpu_features_sub: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty, | |
| 22 | ||
| 23 | /// `null` means native. | |
| 24 | os_tag: ?Target.Os.Tag = null, | |
| 25 | ||
| 26 | /// `null` means the default version range for `os_tag`. If `os_tag` is `null` (native) | |
| 27 | /// then `null` for this field means native. | |
| 28 | os_version_min: ?OsVersion = null, | |
| 29 | ||
| 30 | /// When cross compiling, `null` means default (latest known OS version). | |
| 31 | /// When `os_tag` is native, `null` means equal to the native OS version. | |
| 32 | os_version_max: ?OsVersion = null, | |
| 33 | ||
| 34 | /// `null` means default when cross compiling, or native when os_tag is native. | |
| 35 | /// If `isGnuLibC()` is `false`, this must be `null` and is ignored. | |
| 36 | glibc_version: ?SemVer = null, | |
| 37 | ||
| 38 | /// `null` means the native C ABI, if `os_tag` is native, otherwise it means the default C ABI. | |
| 39 | abi: ?Target.Abi = null, | |
| 40 | ||
| 41 | /// When `os_tag` is `null`, then `null` means native. Otherwise it means the standard path | |
| 42 | /// based on the `os_tag`. | |
| 43 | dynamic_linker: DynamicLinker = DynamicLinker{}, | |
| 44 | ||
| 45 | pub const CpuModel = union(enum) { | |
| 46 | /// Always native | |
| 47 | native, | |
| 48 | ||
| 49 | /// Always baseline | |
| 50 | baseline, | |
| 51 | ||
| 52 | /// If CPU Architecture is native, then the CPU model will be native. Otherwise, | |
| 53 | /// it will be baseline. | |
| 54 | determined_by_cpu_arch, | |
| 55 | ||
| 56 | explicit: *const Target.Cpu.Model, | |
| 57 | }; | |
| 58 | ||
| 59 | pub const OsVersion = union(enum) { | |
| 60 | none: void, | |
| 61 | semver: SemVer, | |
| 62 | windows: Target.Os.WindowsVersion, | |
| 63 | }; | |
| 64 | ||
| 65 | pub const SemVer = std.builtin.Version; | |
| 66 | ||
| 67 | pub const DynamicLinker = Target.DynamicLinker; | |
| 68 | ||
| 69 | pub fn fromTarget(target: Target) CrossTarget { | |
| 70 | var result: CrossTarget = .{ | |
| 71 | .cpu_arch = target.cpu.arch, | |
| 72 | .cpu_model = .{ .explicit = target.cpu.model }, | |
| 73 | .os_tag = target.os.tag, | |
| 74 | .os_version_min = undefined, | |
| 75 | .os_version_max = undefined, | |
| 76 | .abi = target.abi, | |
| 77 | .glibc_version = if (target.isGnuLibC()) | |
| 78 | target.os.version_range.linux.glibc | |
| 79 | else | |
| 80 | null, | |
| 81 | }; | |
| 82 | result.updateOsVersionRange(target.os); | |
| 83 | ||
| 84 | const all_features = target.cpu.arch.allFeaturesList(); | |
| 85 | var cpu_model_set = target.cpu.model.features; | |
| 86 | cpu_model_set.populateDependencies(all_features); | |
| 87 | { | |
| 88 | // The "add" set is the full set with the CPU Model set removed. | |
| 89 | const add_set = &result.cpu_features_add; | |
| 90 | add_set.* = target.cpu.features; | |
| 91 | add_set.removeFeatureSet(cpu_model_set); | |
| 92 | } | |
| 93 | { | |
| 94 | // The "sub" set is the features that are on in CPU Model set and off in the full set. | |
| 95 | const sub_set = &result.cpu_features_sub; | |
| 96 | sub_set.* = cpu_model_set; | |
| 97 | sub_set.removeFeatureSet(target.cpu.features); | |
| 98 | } | |
| 99 | return result; | |
| 100 | } | |
| 101 | ||
| 102 | fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void { | |
| 103 | switch (os.tag) { | |
| 104 | .freestanding, | |
| 105 | .ananas, | |
| 106 | .cloudabi, | |
| 107 | .fuchsia, | |
| 108 | .kfreebsd, | |
| 109 | .lv2, | |
| 110 | .solaris, | |
| 111 | .zos, | |
| 112 | .haiku, | |
| 113 | .minix, | |
| 114 | .rtems, | |
| 115 | .nacl, | |
| 116 | .aix, | |
| 117 | .cuda, | |
| 118 | .nvcl, | |
| 119 | .amdhsa, | |
| 120 | .ps4, | |
| 121 | .elfiamcu, | |
| 122 | .mesa3d, | |
| 123 | .contiki, | |
| 124 | .amdpal, | |
| 125 | .hermit, | |
| 126 | .hurd, | |
| 127 | .wasi, | |
| 128 | .emscripten, | |
| 129 | .uefi, | |
| 130 | .opencl, | |
| 131 | .glsl450, | |
| 132 | .vulkan, | |
| 133 | .plan9, | |
| 134 | .other, | |
| 135 | => { | |
| 136 | self.os_version_min = .{ .none = {} }; | |
| 137 | self.os_version_max = .{ .none = {} }; | |
| 138 | }, | |
| 139 | ||
| 140 | .freebsd, | |
| 141 | .macos, | |
| 142 | .ios, | |
| 143 | .tvos, | |
| 144 | .watchos, | |
| 145 | .netbsd, | |
| 146 | .openbsd, | |
| 147 | .dragonfly, | |
| 148 | => { | |
| 149 | self.os_version_min = .{ .semver = os.version_range.semver.min }; | |
| 150 | self.os_version_max = .{ .semver = os.version_range.semver.max }; | |
| 151 | }, | |
| 152 | ||
| 153 | .linux => { | |
| 154 | self.os_version_min = .{ .semver = os.version_range.linux.range.min }; | |
| 155 | self.os_version_max = .{ .semver = os.version_range.linux.range.max }; | |
| 156 | }, | |
| 157 | ||
| 158 | .windows => { | |
| 159 | self.os_version_min = .{ .windows = os.version_range.windows.min }; | |
| 160 | self.os_version_max = .{ .windows = os.version_range.windows.max }; | |
| 161 | }, | |
| 162 | } | |
| 163 | } | |
| 164 | ||
| 165 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 166 | pub fn toTarget(self: CrossTarget) Target { | |
| 167 | return .{ | |
| 168 | .cpu = self.getCpu(), | |
| 169 | .os = self.getOs(), | |
| 170 | .abi = self.getAbi(), | |
| 171 | }; | |
| 172 | } | |
| 173 | ||
| 174 | pub const ParseOptions = struct { | |
| 175 | /// This is sometimes called a "triple". It looks roughly like this: | |
| 176 | /// riscv64-linux-musl | |
| 177 | /// The fields are, respectively: | |
| 178 | /// * CPU Architecture | |
| 179 | /// * Operating System (and optional version range) | |
| 180 | /// * C ABI (optional, with optional glibc version) | |
| 181 | /// The string "native" can be used for CPU architecture as well as Operating System. | |
| 182 | /// If the CPU Architecture is specified as "native", then the Operating System and C ABI may be omitted. | |
| 183 | arch_os_abi: []const u8 = "native", | |
| 184 | ||
| 185 | /// Looks like "name+a+b-c-d+e", where "name" is a CPU Model name, "a", "b", and "e" | |
| 186 | /// are examples of CPU features to add to the set, and "c" and "d" are examples of CPU features | |
| 187 | /// to remove from the set. | |
| 188 | /// The following special strings are recognized for CPU Model name: | |
| 189 | /// * "baseline" - The "default" set of CPU features for cross-compiling. A conservative set | |
| 190 | /// of features that is expected to be supported on most available hardware. | |
| 191 | /// * "native" - The native CPU model is to be detected when compiling. | |
| 192 | /// If this field is not provided (`null`), then the value will depend on the | |
| 193 | /// parsed CPU Architecture. If native, then this will be "native". Otherwise, it will be "baseline". | |
| 194 | cpu_features: ?[]const u8 = null, | |
| 195 | ||
| 196 | /// Absolute path to dynamic linker, to override the default, which is either a natively | |
| 197 | /// detected path, or a standard path. | |
| 198 | dynamic_linker: ?[]const u8 = null, | |
| 199 | ||
| 200 | /// If this is provided, the function will populate some information about parsing failures, | |
| 201 | /// so that user-friendly error messages can be delivered. | |
| 202 | diagnostics: ?*Diagnostics = null, | |
| 203 | ||
| 204 | pub const Diagnostics = struct { | |
| 205 | /// If the architecture was determined, this will be populated. | |
| 206 | arch: ?Target.Cpu.Arch = null, | |
| 207 | ||
| 208 | /// If the OS name was determined, this will be populated. | |
| 209 | os_name: ?[]const u8 = null, | |
| 210 | ||
| 211 | /// If the OS tag was determined, this will be populated. | |
| 212 | os_tag: ?Target.Os.Tag = null, | |
| 213 | ||
| 214 | /// If the ABI was determined, this will be populated. | |
| 215 | abi: ?Target.Abi = null, | |
| 216 | ||
| 217 | /// If the CPU name was determined, this will be populated. | |
| 218 | cpu_name: ?[]const u8 = null, | |
| 219 | ||
| 220 | /// If error.UnknownCpuFeature is returned, this will be populated. | |
| 221 | unknown_feature_name: ?[]const u8 = null, | |
| 222 | }; | |
| 223 | }; | |
| 224 | ||
| 225 | pub fn parse(args: ParseOptions) !CrossTarget { | |
| 226 | var dummy_diags: ParseOptions.Diagnostics = undefined; | |
| 227 | const diags = args.diagnostics orelse &dummy_diags; | |
| 228 | ||
| 229 | var result: CrossTarget = .{ | |
| 230 | .dynamic_linker = DynamicLinker.init(args.dynamic_linker), | |
| 231 | }; | |
| 232 | ||
| 233 | var it = mem.split(u8, args.arch_os_abi, "-"); | |
| 234 | const arch_name = it.next().?; | |
| 235 | const arch_is_native = mem.eql(u8, arch_name, "native"); | |
| 236 | if (!arch_is_native) { | |
| 237 | result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse | |
| 238 | return error.UnknownArchitecture; | |
| 239 | } | |
| 240 | const arch = result.getCpuArch(); | |
| 241 | diags.arch = arch; | |
| 242 | ||
| 243 | if (it.next()) |os_text| { | |
| 244 | try parseOs(&result, diags, os_text); | |
| 245 | } else if (!arch_is_native) { | |
| 246 | return error.MissingOperatingSystem; | |
| 247 | } | |
| 248 | ||
| 249 | const opt_abi_text = it.next(); | |
| 250 | if (opt_abi_text) |abi_text| { | |
| 251 | var abi_it = mem.split(u8, abi_text, "."); | |
| 252 | const abi = std.meta.stringToEnum(Target.Abi, abi_it.next().?) orelse | |
| 253 | return error.UnknownApplicationBinaryInterface; | |
| 254 | result.abi = abi; | |
| 255 | diags.abi = abi; | |
| 256 | ||
| 257 | const abi_ver_text = abi_it.rest(); | |
| 258 | if (abi_it.next() != null) { | |
| 259 | if (result.isGnuLibC()) { | |
| 260 | result.glibc_version = SemVer.parse(abi_ver_text) catch |err| switch (err) { | |
| 261 | error.Overflow => return error.InvalidAbiVersion, | |
| 262 | error.InvalidCharacter => return error.InvalidAbiVersion, | |
| 263 | error.InvalidVersion => return error.InvalidAbiVersion, | |
| 264 | }; | |
| 265 | } else { | |
| 266 | return error.InvalidAbiVersion; | |
| 267 | } | |
| 268 | } | |
| 269 | } | |
| 270 | ||
| 271 | if (it.next() != null) return error.UnexpectedExtraField; | |
| 272 | ||
| 273 | if (args.cpu_features) |cpu_features| { | |
| 274 | const all_features = arch.allFeaturesList(); | |
| 275 | var index: usize = 0; | |
| 276 | while (index < cpu_features.len and | |
| 277 | cpu_features[index] != '+' and | |
| 278 | cpu_features[index] != '-') | |
| 279 | { | |
| 280 | index += 1; | |
| 281 | } | |
| 282 | const cpu_name = cpu_features[0..index]; | |
| 283 | diags.cpu_name = cpu_name; | |
| 284 | ||
| 285 | const add_set = &result.cpu_features_add; | |
| 286 | const sub_set = &result.cpu_features_sub; | |
| 287 | if (mem.eql(u8, cpu_name, "native")) { | |
| 288 | result.cpu_model = .native; | |
| 289 | } else if (mem.eql(u8, cpu_name, "baseline")) { | |
| 290 | result.cpu_model = .baseline; | |
| 291 | } else { | |
| 292 | result.cpu_model = .{ .explicit = try arch.parseCpuModel(cpu_name) }; | |
| 293 | } | |
| 294 | ||
| 295 | while (index < cpu_features.len) { | |
| 296 | const op = cpu_features[index]; | |
| 297 | const set = switch (op) { | |
| 298 | '+' => add_set, | |
| 299 | '-' => sub_set, | |
| 300 | else => unreachable, | |
| 301 | }; | |
| 302 | index += 1; | |
| 303 | const start = index; | |
| 304 | while (index < cpu_features.len and | |
| 305 | cpu_features[index] != '+' and | |
| 306 | cpu_features[index] != '-') | |
| 307 | { | |
| 308 | index += 1; | |
| 309 | } | |
| 310 | const feature_name = cpu_features[start..index]; | |
| 311 | for (all_features) |feature, feat_index_usize| { | |
| 312 | const feat_index = @intCast(Target.Cpu.Feature.Set.Index, feat_index_usize); | |
| 313 | if (mem.eql(u8, feature_name, feature.name)) { | |
| 314 | set.addFeature(feat_index); | |
| 315 | break; | |
| 316 | } | |
| 317 | } else { | |
| 318 | diags.unknown_feature_name = feature_name; | |
| 319 | return error.UnknownCpuFeature; | |
| 320 | } | |
| 321 | } | |
| 322 | } | |
| 323 | ||
| 324 | return result; | |
| 325 | } | |
| 326 | ||
| 327 | /// Similar to `parse` except instead of fully parsing, it only determines the CPU | |
| 328 | /// architecture and returns it if it can be determined, and returns `null` otherwise. | |
| 329 | /// This is intended to be used if the API user of CrossTarget needs to learn the | |
| 330 | /// target CPU architecture in order to fully populate `ParseOptions`. | |
| 331 | pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch { | |
| 332 | var it = mem.split(u8, args.arch_os_abi, "-"); | |
| 333 | const arch_name = it.next().?; | |
| 334 | const arch_is_native = mem.eql(u8, arch_name, "native"); | |
| 335 | if (arch_is_native) { | |
| 336 | return builtin.cpu.arch; | |
| 337 | } else { | |
| 338 | return std.meta.stringToEnum(Target.Cpu.Arch, arch_name); | |
| 339 | } | |
| 340 | } | |
| 341 | ||
| 342 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 343 | pub fn getCpu(self: CrossTarget) Target.Cpu { | |
| 344 | switch (self.cpu_model) { | |
| 345 | .native => { | |
| 346 | // This works when doing `zig build` because Zig generates a build executable using | |
| 347 | // native CPU model & features. However this will not be accurate otherwise, and | |
| 348 | // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. | |
| 349 | return builtin.cpu; | |
| 350 | }, | |
| 351 | .baseline => { | |
| 352 | var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch()); | |
| 353 | self.updateCpuFeatures(&adjusted_baseline.features); | |
| 354 | return adjusted_baseline; | |
| 355 | }, | |
| 356 | .determined_by_cpu_arch => if (self.cpu_arch == null) { | |
| 357 | // This works when doing `zig build` because Zig generates a build executable using | |
| 358 | // native CPU model & features. However this will not be accurate otherwise, and | |
| 359 | // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. | |
| 360 | return builtin.cpu; | |
| 361 | } else { | |
| 362 | var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch()); | |
| 363 | self.updateCpuFeatures(&adjusted_baseline.features); | |
| 364 | return adjusted_baseline; | |
| 365 | }, | |
| 366 | .explicit => |model| { | |
| 367 | var adjusted_model = model.toCpu(self.getCpuArch()); | |
| 368 | self.updateCpuFeatures(&adjusted_model.features); | |
| 369 | return adjusted_model; | |
| 370 | }, | |
| 371 | } | |
| 372 | } | |
| 373 | ||
| 374 | pub fn getCpuArch(self: CrossTarget) Target.Cpu.Arch { | |
| 375 | return self.cpu_arch orelse builtin.cpu.arch; | |
| 376 | } | |
| 377 | ||
| 378 | pub fn getCpuModel(self: CrossTarget) *const Target.Cpu.Model { | |
| 379 | return switch (self.cpu_model) { | |
| 380 | .explicit => |cpu_model| cpu_model, | |
| 381 | else => self.getCpu().model, | |
| 382 | }; | |
| 383 | } | |
| 384 | ||
| 385 | pub fn getCpuFeatures(self: CrossTarget) Target.Cpu.Feature.Set { | |
| 386 | return self.getCpu().features; | |
| 387 | } | |
| 388 | ||
| 389 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 390 | pub fn getOs(self: CrossTarget) Target.Os { | |
| 391 | // `builtin.os` works when doing `zig build` because Zig generates a build executable using | |
| 392 | // native OS version range. However this will not be accurate otherwise, and | |
| 393 | // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. | |
| 394 | var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange(self.getCpuArch()) else builtin.os; | |
| 395 | ||
| 396 | if (self.os_version_min) |min| switch (min) { | |
| 397 | .none => {}, | |
| 398 | .semver => |semver| switch (self.getOsTag()) { | |
| 399 | .linux => adjusted_os.version_range.linux.range.min = semver, | |
| 400 | else => adjusted_os.version_range.semver.min = semver, | |
| 401 | }, | |
| 402 | .windows => |win_ver| adjusted_os.version_range.windows.min = win_ver, | |
| 403 | }; | |
| 404 | ||
| 405 | if (self.os_version_max) |max| switch (max) { | |
| 406 | .none => {}, | |
| 407 | .semver => |semver| switch (self.getOsTag()) { | |
| 408 | .linux => adjusted_os.version_range.linux.range.max = semver, | |
| 409 | else => adjusted_os.version_range.semver.max = semver, | |
| 410 | }, | |
| 411 | .windows => |win_ver| adjusted_os.version_range.windows.max = win_ver, | |
| 412 | }; | |
| 413 | ||
| 414 | if (self.glibc_version) |glibc| { | |
| 415 | assert(self.isGnuLibC()); | |
| 416 | adjusted_os.version_range.linux.glibc = glibc; | |
| 417 | } | |
| 418 | ||
| 419 | return adjusted_os; | |
| 420 | } | |
| 421 | ||
| 422 | pub fn getOsTag(self: CrossTarget) Target.Os.Tag { | |
| 423 | return self.os_tag orelse builtin.os.tag; | |
| 424 | } | |
| 425 | ||
| 426 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 427 | pub fn getOsVersionMin(self: CrossTarget) OsVersion { | |
| 428 | if (self.os_version_min) |version_min| return version_min; | |
| 429 | var tmp: CrossTarget = undefined; | |
| 430 | tmp.updateOsVersionRange(self.getOs()); | |
| 431 | return tmp.os_version_min.?; | |
| 432 | } | |
| 433 | ||
| 434 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 435 | pub fn getOsVersionMax(self: CrossTarget) OsVersion { | |
| 436 | if (self.os_version_max) |version_max| return version_max; | |
| 437 | var tmp: CrossTarget = undefined; | |
| 438 | tmp.updateOsVersionRange(self.getOs()); | |
| 439 | return tmp.os_version_max.?; | |
| 440 | } | |
| 441 | ||
| 442 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 443 | pub fn getAbi(self: CrossTarget) Target.Abi { | |
| 444 | if (self.abi) |abi| return abi; | |
| 445 | ||
| 446 | if (self.os_tag == null) { | |
| 447 | // This works when doing `zig build` because Zig generates a build executable using | |
| 448 | // native CPU model & features. However this will not be accurate otherwise, and | |
| 449 | // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. | |
| 450 | return builtin.abi; | |
| 451 | } | |
| 452 | ||
| 453 | return Target.Abi.default(self.getCpuArch(), self.getOs()); | |
| 454 | } | |
| 455 | ||
| 456 | pub fn isFreeBSD(self: CrossTarget) bool { | |
| 457 | return self.getOsTag() == .freebsd; | |
| 458 | } | |
| 459 | ||
| 460 | pub fn isDarwin(self: CrossTarget) bool { | |
| 461 | return self.getOsTag().isDarwin(); | |
| 462 | } | |
| 463 | ||
| 464 | pub fn isNetBSD(self: CrossTarget) bool { | |
| 465 | return self.getOsTag() == .netbsd; | |
| 466 | } | |
| 467 | ||
| 468 | pub fn isOpenBSD(self: CrossTarget) bool { | |
| 469 | return self.getOsTag() == .openbsd; | |
| 470 | } | |
| 471 | ||
| 472 | pub fn isUefi(self: CrossTarget) bool { | |
| 473 | return self.getOsTag() == .uefi; | |
| 474 | } | |
| 475 | ||
| 476 | pub fn isDragonFlyBSD(self: CrossTarget) bool { | |
| 477 | return self.getOsTag() == .dragonfly; | |
| 478 | } | |
| 479 | ||
| 480 | pub fn isLinux(self: CrossTarget) bool { | |
| 481 | return self.getOsTag() == .linux; | |
| 482 | } | |
| 483 | ||
| 484 | pub fn isWindows(self: CrossTarget) bool { | |
| 485 | return self.getOsTag() == .windows; | |
| 486 | } | |
| 487 | ||
| 488 | pub fn exeFileExt(self: CrossTarget) [:0]const u8 { | |
| 489 | return Target.exeFileExtSimple(self.getCpuArch(), self.getOsTag()); | |
| 490 | } | |
| 491 | ||
| 492 | pub fn staticLibSuffix(self: CrossTarget) [:0]const u8 { | |
| 493 | return Target.staticLibSuffix_os_abi(self.getOsTag(), self.getAbi()); | |
| 494 | } | |
| 495 | ||
| 496 | pub fn dynamicLibSuffix(self: CrossTarget) [:0]const u8 { | |
| 497 | return self.getOsTag().dynamicLibSuffix(); | |
| 498 | } | |
| 499 | ||
| 500 | pub fn libPrefix(self: CrossTarget) [:0]const u8 { | |
| 501 | return Target.libPrefix_os_abi(self.getOsTag(), self.getAbi()); | |
| 502 | } | |
| 503 | ||
| 504 | pub fn isNativeCpu(self: CrossTarget) bool { | |
| 505 | return self.cpu_arch == null and | |
| 506 | (self.cpu_model == .native or self.cpu_model == .determined_by_cpu_arch) and | |
| 507 | self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty(); | |
| 508 | } | |
| 509 | ||
| 510 | pub fn isNativeOs(self: CrossTarget) bool { | |
| 511 | return self.os_tag == null and self.os_version_min == null and self.os_version_max == null and | |
| 512 | self.dynamic_linker.get() == null and self.glibc_version == null; | |
| 513 | } | |
| 514 | ||
| 515 | pub fn isNativeAbi(self: CrossTarget) bool { | |
| 516 | return self.os_tag == null and self.abi == null; | |
| 517 | } | |
| 518 | ||
| 519 | pub fn isNative(self: CrossTarget) bool { | |
| 520 | return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi(); | |
| 521 | } | |
| 522 | ||
| 523 | pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 { | |
| 524 | if (self.isNative()) { | |
| 525 | return allocator.dupe(u8, "native"); | |
| 526 | } | |
| 527 | ||
| 528 | const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native"; | |
| 529 | const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native"; | |
| 530 | ||
| 531 | var result = std.ArrayList(u8).init(allocator); | |
| 532 | defer result.deinit(); | |
| 533 | ||
| 534 | try result.writer().print("{s}-{s}", .{ arch_name, os_name }); | |
| 535 | ||
| 536 | // The zig target syntax does not allow specifying a max os version with no min, so | |
| 537 | // if either are present, we need the min. | |
| 538 | if (self.os_version_min != null or self.os_version_max != null) { | |
| 539 | switch (self.getOsVersionMin()) { | |
| 540 | .none => {}, | |
| 541 | .semver => |v| try result.writer().print(".{}", .{v}), | |
| 542 | .windows => |v| try result.writer().print("{s}", .{v}), | |
| 543 | } | |
| 544 | } | |
| 545 | if (self.os_version_max) |max| { | |
| 546 | switch (max) { | |
| 547 | .none => {}, | |
| 548 | .semver => |v| try result.writer().print("...{}", .{v}), | |
| 549 | .windows => |v| try result.writer().print("..{s}", .{v}), | |
| 550 | } | |
| 551 | } | |
| 552 | ||
| 553 | if (self.glibc_version) |v| { | |
| 554 | try result.writer().print("-{s}.{}", .{ @tagName(self.getAbi()), v }); | |
| 555 | } else if (self.abi) |abi| { | |
| 556 | try result.writer().print("-{s}", .{@tagName(abi)}); | |
| 557 | } | |
| 558 | ||
| 559 | return result.toOwnedSlice(); | |
| 560 | } | |
| 561 | ||
| 562 | pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![]u8 { | |
| 563 | // TODO is there anything else worthy of the description that is not | |
| 564 | // already captured in the triple? | |
| 565 | return self.zigTriple(allocator); | |
| 566 | } | |
| 567 | ||
| 568 | pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 { | |
| 569 | return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi()); | |
| 570 | } | |
| 571 | ||
| 572 | pub fn wantSharedLibSymLinks(self: CrossTarget) bool { | |
| 573 | return self.getOsTag() != .windows; | |
| 574 | } | |
| 575 | ||
| 576 | pub const VcpkgLinkage = std.builtin.LinkMode; | |
| 577 | ||
| 578 | /// Returned slice must be freed by the caller. | |
| 579 | pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![]u8 { | |
| 580 | const arch = switch (self.getCpuArch()) { | |
| 581 | .i386 => "x86", | |
| 582 | .x86_64 => "x64", | |
| 583 | ||
| 584 | .arm, | |
| 585 | .armeb, | |
| 586 | .thumb, | |
| 587 | .thumbeb, | |
| 588 | .aarch64_32, | |
| 589 | => "arm", | |
| 590 | ||
| 591 | .aarch64, | |
| 592 | .aarch64_be, | |
| 593 | => "arm64", | |
| 594 | ||
| 595 | else => return error.UnsupportedVcpkgArchitecture, | |
| 596 | }; | |
| 597 | ||
| 598 | const os = switch (self.getOsTag()) { | |
| 599 | .windows => "windows", | |
| 600 | .linux => "linux", | |
| 601 | .macos => "macos", | |
| 602 | else => return error.UnsupportedVcpkgOperatingSystem, | |
| 603 | }; | |
| 604 | ||
| 605 | const static_suffix = switch (linkage) { | |
| 606 | .Static => "-static", | |
| 607 | .Dynamic => "", | |
| 608 | }; | |
| 609 | ||
| 610 | return std.fmt.allocPrint(allocator, "{s}-{s}{s}", .{ arch, os, static_suffix }); | |
| 611 | } | |
| 612 | ||
| 613 | pub const Executor = union(enum) { | |
| 614 | native, | |
| 615 | qemu: []const u8, | |
| 616 | wine: []const u8, | |
| 617 | wasmtime: []const u8, | |
| 618 | darling: []const u8, | |
| 619 | unavailable, | |
| 620 | }; | |
| 621 | ||
| 622 | /// Note that even a `CrossTarget` which returns `false` for `isNative` could still be natively executed. | |
| 623 | /// For example `-target arm-native` running on an aarch64 host. | |
| 624 | pub fn getExternalExecutor(self: CrossTarget) Executor { | |
| 625 | const cpu_arch = self.getCpuArch(); | |
| 626 | const os_tag = self.getOsTag(); | |
| 627 | const os_match = os_tag == builtin.os.tag; | |
| 628 | ||
| 629 | // If the OS and CPU arch match, the binary can be considered native. | |
| 630 | // TODO additionally match the CPU features. This `getExternalExecutor` function should | |
| 631 | // be moved to std.Target and match any chosen target against the native target. | |
| 632 | if (os_match and cpu_arch == builtin.cpu.arch) { | |
| 633 | // However, we also need to verify that the dynamic linker path is valid. | |
| 634 | if (self.os_tag == null) { | |
| 635 | return .native; | |
| 636 | } | |
| 637 | // TODO here we call toTarget, a deprecated function, because of the above TODO about moving | |
| 638 | // this code to std.Target. | |
| 639 | const opt_dl = self.dynamic_linker.get() orelse self.toTarget().standardDynamicLinkerPath().get(); | |
| 640 | if (opt_dl) |dl| blk: { | |
| 641 | std.fs.cwd().access(dl, .{}) catch break :blk; | |
| 642 | return .native; | |
| 643 | } | |
| 644 | } | |
| 645 | ||
| 646 | // If the OS matches, we can use QEMU to emulate a foreign architecture. | |
| 647 | if (os_match) { | |
| 648 | return switch (cpu_arch) { | |
| 649 | .aarch64 => Executor{ .qemu = "qemu-aarch64" }, | |
| 650 | .aarch64_be => Executor{ .qemu = "qemu-aarch64_be" }, | |
| 651 | .arm => Executor{ .qemu = "qemu-arm" }, | |
| 652 | .armeb => Executor{ .qemu = "qemu-armeb" }, | |
| 653 | .i386 => Executor{ .qemu = "qemu-i386" }, | |
| 654 | .mips => Executor{ .qemu = "qemu-mips" }, | |
| 655 | .mipsel => Executor{ .qemu = "qemu-mipsel" }, | |
| 656 | .mips64 => Executor{ .qemu = "qemu-mips64" }, | |
| 657 | .mips64el => Executor{ .qemu = "qemu-mips64el" }, | |
| 658 | .powerpc => Executor{ .qemu = "qemu-ppc" }, | |
| 659 | .powerpc64 => Executor{ .qemu = "qemu-ppc64" }, | |
| 660 | .powerpc64le => Executor{ .qemu = "qemu-ppc64le" }, | |
| 661 | .riscv32 => Executor{ .qemu = "qemu-riscv32" }, | |
| 662 | .riscv64 => Executor{ .qemu = "qemu-riscv64" }, | |
| 663 | .s390x => Executor{ .qemu = "qemu-s390x" }, | |
| 664 | .sparc => Executor{ .qemu = "qemu-sparc" }, | |
| 665 | .x86_64 => Executor{ .qemu = "qemu-x86_64" }, | |
| 666 | else => return .unavailable, | |
| 667 | }; | |
| 668 | } | |
| 669 | ||
| 670 | switch (os_tag) { | |
| 671 | .windows => switch (cpu_arch.ptrBitWidth()) { | |
| 672 | 32 => return Executor{ .wine = "wine" }, | |
| 673 | 64 => return Executor{ .wine = "wine64" }, | |
| 674 | else => return .unavailable, | |
| 675 | }, | |
| 676 | .wasi => switch (cpu_arch.ptrBitWidth()) { | |
| 677 | 32 => return Executor{ .wasmtime = "wasmtime" }, | |
| 678 | else => return .unavailable, | |
| 679 | }, | |
| 680 | .macos => { | |
| 681 | // TODO loosen this check once upstream adds QEMU-based emulation | |
| 682 | // layer for non-host architectures: | |
| 683 | // https://github.com/darlinghq/darling/issues/863 | |
| 684 | if (cpu_arch != builtin.cpu.arch) { | |
| 685 | return .unavailable; | |
| 686 | } | |
| 687 | return Executor{ .darling = "darling" }; | |
| 688 | }, | |
| 689 | else => return .unavailable, | |
| 690 | } | |
| 691 | } | |
| 692 | ||
| 693 | pub fn isGnuLibC(self: CrossTarget) bool { | |
| 694 | return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi()); | |
| 695 | } | |
| 696 | ||
| 697 | pub fn setGnuLibCVersion(self: *CrossTarget, major: u32, minor: u32, patch: u32) void { | |
| 698 | assert(self.isGnuLibC()); | |
| 699 | self.glibc_version = SemVer{ .major = major, .minor = minor, .patch = patch }; | |
| 700 | } | |
| 701 | ||
| 702 | pub fn getObjectFormat(self: CrossTarget) Target.ObjectFormat { | |
| 703 | return Target.getObjectFormatSimple(self.getOsTag(), self.getCpuArch()); | |
| 704 | } | |
| 705 | ||
| 706 | pub fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void { | |
| 707 | set.removeFeatureSet(self.cpu_features_sub); | |
| 708 | set.addFeatureSet(self.cpu_features_add); | |
| 709 | set.populateDependencies(self.getCpuArch().allFeaturesList()); | |
| 710 | set.removeFeatureSet(self.cpu_features_sub); | |
| 711 | } | |
| 712 | ||
| 713 | fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void { | |
| 714 | var it = mem.split(u8, text, "."); | |
| 715 | const os_name = it.next().?; | |
| 716 | diags.os_name = os_name; | |
| 717 | const os_is_native = mem.eql(u8, os_name, "native"); | |
| 718 | if (!os_is_native) { | |
| 719 | result.os_tag = std.meta.stringToEnum(Target.Os.Tag, os_name) orelse | |
| 720 | return error.UnknownOperatingSystem; | |
| 721 | } | |
| 722 | const tag = result.getOsTag(); | |
| 723 | diags.os_tag = tag; | |
| 724 | ||
| 725 | const version_text = it.rest(); | |
| 726 | if (it.next() == null) return; | |
| 727 | ||
| 728 | switch (tag) { | |
| 729 | .freestanding, | |
| 730 | .ananas, | |
| 731 | .cloudabi, | |
| 732 | .fuchsia, | |
| 733 | .kfreebsd, | |
| 734 | .lv2, | |
| 735 | .solaris, | |
| 736 | .zos, | |
| 737 | .haiku, | |
| 738 | .minix, | |
| 739 | .rtems, | |
| 740 | .nacl, | |
| 741 | .aix, | |
| 742 | .cuda, | |
| 743 | .nvcl, | |
| 744 | .amdhsa, | |
| 745 | .ps4, | |
| 746 | .elfiamcu, | |
| 747 | .mesa3d, | |
| 748 | .contiki, | |
| 749 | .amdpal, | |
| 750 | .hermit, | |
| 751 | .hurd, | |
| 752 | .wasi, | |
| 753 | .emscripten, | |
| 754 | .uefi, | |
| 755 | .opencl, | |
| 756 | .glsl450, | |
| 757 | .vulkan, | |
| 758 | .plan9, | |
| 759 | .other, | |
| 760 | => return error.InvalidOperatingSystemVersion, | |
| 761 | ||
| 762 | .freebsd, | |
| 763 | .macos, | |
| 764 | .ios, | |
| 765 | .tvos, | |
| 766 | .watchos, | |
| 767 | .netbsd, | |
| 768 | .openbsd, | |
| 769 | .linux, | |
| 770 | .dragonfly, | |
| 771 | => { | |
| 772 | var range_it = mem.split(u8, version_text, "..."); | |
| 773 | ||
| 774 | const min_text = range_it.next().?; | |
| 775 | const min_ver = SemVer.parse(min_text) catch |err| switch (err) { | |
| 776 | error.Overflow => return error.InvalidOperatingSystemVersion, | |
| 777 | error.InvalidCharacter => return error.InvalidOperatingSystemVersion, | |
| 778 | error.InvalidVersion => return error.InvalidOperatingSystemVersion, | |
| 779 | }; | |
| 780 | result.os_version_min = .{ .semver = min_ver }; | |
| 781 | ||
| 782 | const max_text = range_it.next() orelse return; | |
| 783 | const max_ver = SemVer.parse(max_text) catch |err| switch (err) { | |
| 784 | error.Overflow => return error.InvalidOperatingSystemVersion, | |
| 785 | error.InvalidCharacter => return error.InvalidOperatingSystemVersion, | |
| 786 | error.InvalidVersion => return error.InvalidOperatingSystemVersion, | |
| 787 | }; | |
| 788 | result.os_version_max = .{ .semver = max_ver }; | |
| 789 | }, | |
| 790 | ||
| 791 | .windows => { | |
| 792 | var range_it = mem.split(u8, version_text, "..."); | |
| 793 | ||
| 794 | const min_text = range_it.next().?; | |
| 795 | const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse | |
| 796 | return error.InvalidOperatingSystemVersion; | |
| 797 | result.os_version_min = .{ .windows = min_ver }; | |
| 798 | ||
| 799 | const max_text = range_it.next() orelse return; | |
| 800 | const max_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, max_text) orelse | |
| 801 | return error.InvalidOperatingSystemVersion; | |
| 802 | result.os_version_max = .{ .windows = max_ver }; | |
| 803 | }, | |
| 804 | } | |
| 805 | } | |
| 806 | ||
| 807 | test "CrossTarget.parse" { | |
| 808 | if (builtin.target.isGnuLibC()) { | |
| 809 | var cross_target = try CrossTarget.parse(.{}); | |
| 810 | cross_target.setGnuLibCVersion(2, 1, 1); | |
| 811 | ||
| 812 | const text = try cross_target.zigTriple(std.testing.allocator); | |
| 813 | defer std.testing.allocator.free(text); | |
| 814 | ||
| 815 | var buf: [256]u8 = undefined; | |
| 816 | const triple = std.fmt.bufPrint( | |
| 817 | buf[0..], | |
| 818 | "native-native-{s}.2.1.1", | |
| 819 | .{@tagName(builtin.abi)}, | |
| 820 | ) catch unreachable; | |
| 821 | ||
| 822 | try std.testing.expectEqualSlices(u8, triple, text); | |
| 823 | } | |
| 824 | { | |
| 825 | const cross_target = try CrossTarget.parse(.{ | |
| 826 | .arch_os_abi = "aarch64-linux", | |
| 827 | .cpu_features = "native", | |
| 828 | }); | |
| 829 | ||
| 830 | try std.testing.expect(cross_target.cpu_arch.? == .aarch64); | |
| 831 | try std.testing.expect(cross_target.cpu_model == .native); | |
| 832 | } | |
| 833 | { | |
| 834 | const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" }); | |
| 835 | ||
| 836 | try std.testing.expect(cross_target.cpu_arch == null); | |
| 837 | try std.testing.expect(cross_target.isNative()); | |
| 838 | ||
| 839 | const text = try cross_target.zigTriple(std.testing.allocator); | |
| 840 | defer std.testing.allocator.free(text); | |
| 841 | try std.testing.expectEqualSlices(u8, "native", text); | |
| 842 | } | |
| 843 | { | |
| 844 | const cross_target = try CrossTarget.parse(.{ | |
| 845 | .arch_os_abi = "x86_64-linux-gnu", | |
| 846 | .cpu_features = "x86_64-sse-sse2-avx-cx8", | |
| 847 | }); | |
| 848 | const target = cross_target.toTarget(); | |
| 849 | ||
| 850 | try std.testing.expect(target.os.tag == .linux); | |
| 851 | try std.testing.expect(target.abi == .gnu); | |
| 852 | try std.testing.expect(target.cpu.arch == .x86_64); | |
| 853 | try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse)); | |
| 854 | try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx)); | |
| 855 | try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8)); | |
| 856 | try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov)); | |
| 857 | try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr)); | |
| 858 | ||
| 859 | try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov })); | |
| 860 | try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx })); | |
| 861 | try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 })); | |
| 862 | try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse })); | |
| 863 | ||
| 864 | const text = try cross_target.zigTriple(std.testing.allocator); | |
| 865 | defer std.testing.allocator.free(text); | |
| 866 | try std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text); | |
| 867 | } | |
| 868 | { | |
| 869 | const cross_target = try CrossTarget.parse(.{ | |
| 870 | .arch_os_abi = "arm-linux-musleabihf", | |
| 871 | .cpu_features = "generic+v8a", | |
| 872 | }); | |
| 873 | const target = cross_target.toTarget(); | |
| 874 | ||
| 875 | try std.testing.expect(target.os.tag == .linux); | |
| 876 | try std.testing.expect(target.abi == .musleabihf); | |
| 877 | try std.testing.expect(target.cpu.arch == .arm); | |
| 878 | try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic); | |
| 879 | try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a)); | |
| 880 | ||
| 881 | const text = try cross_target.zigTriple(std.testing.allocator); | |
| 882 | defer std.testing.allocator.free(text); | |
| 883 | try std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text); | |
| 884 | } | |
| 885 | { | |
| 886 | const cross_target = try CrossTarget.parse(.{ | |
| 887 | .arch_os_abi = "aarch64-linux.3.10...4.4.1-gnu.2.27", | |
| 888 | .cpu_features = "generic+v8a", | |
| 889 | }); | |
| 890 | const target = cross_target.toTarget(); | |
| 891 | ||
| 892 | try std.testing.expect(target.cpu.arch == .aarch64); | |
| 893 | try std.testing.expect(target.os.tag == .linux); | |
| 894 | try std.testing.expect(target.os.version_range.linux.range.min.major == 3); | |
| 895 | try std.testing.expect(target.os.version_range.linux.range.min.minor == 10); | |
| 896 | try std.testing.expect(target.os.version_range.linux.range.min.patch == 0); | |
| 897 | try std.testing.expect(target.os.version_range.linux.range.max.major == 4); | |
| 898 | try std.testing.expect(target.os.version_range.linux.range.max.minor == 4); | |
| 899 | try std.testing.expect(target.os.version_range.linux.range.max.patch == 1); | |
| 900 | try std.testing.expect(target.os.version_range.linux.glibc.major == 2); | |
| 901 | try std.testing.expect(target.os.version_range.linux.glibc.minor == 27); | |
| 902 | try std.testing.expect(target.os.version_range.linux.glibc.patch == 0); | |
| 903 | try std.testing.expect(target.abi == .gnu); | |
| 904 | ||
| 905 | const text = try cross_target.zigTriple(std.testing.allocator); | |
| 906 | defer std.testing.allocator.free(text); | |
| 907 | try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text); | |
| 908 | } | |
| 909 | } |
lib/std/zig/c_builtins.zig+1-1| ... | ... | @@ -123,7 +123,7 @@ pub inline fn __builtin_roundf(val: f32) f32 { |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | pub inline fn __builtin_strlen(s: [*c]const u8) usize { |
| 126 | return std.mem.lenZ(s); | |
| 126 | return std.mem.sliceTo(s, 0).len; | |
| 127 | 127 | } |
| 128 | 128 | pub inline fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) c_int { |
| 129 | 129 | return @as(c_int, std.cstr.cmp(s1, s2)); |
lib/std/zig/cross_target.zig deleted-909| ... | ... | @@ -1,909 +0,0 @@ |
| 1 | const std = @import("../std.zig"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const assert = std.debug.assert; | |
| 4 | const Target = std.Target; | |
| 5 | const mem = std.mem; | |
| 6 | ||
| 7 | /// Contains all the same data as `Target`, additionally introducing the concept of "the native target". | |
| 8 | /// The purpose of this abstraction is to provide meaningful and unsurprising defaults. | |
| 9 | /// This struct does reference any resources and it is copyable. | |
| 10 | pub const CrossTarget = struct { | |
| 11 | /// `null` means native. | |
| 12 | cpu_arch: ?Target.Cpu.Arch = null, | |
| 13 | ||
| 14 | cpu_model: CpuModel = CpuModel.determined_by_cpu_arch, | |
| 15 | ||
| 16 | /// Sparse set of CPU features to add to the set from `cpu_model`. | |
| 17 | cpu_features_add: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty, | |
| 18 | ||
| 19 | /// Sparse set of CPU features to remove from the set from `cpu_model`. | |
| 20 | cpu_features_sub: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty, | |
| 21 | ||
| 22 | /// `null` means native. | |
| 23 | os_tag: ?Target.Os.Tag = null, | |
| 24 | ||
| 25 | /// `null` means the default version range for `os_tag`. If `os_tag` is `null` (native) | |
| 26 | /// then `null` for this field means native. | |
| 27 | os_version_min: ?OsVersion = null, | |
| 28 | ||
| 29 | /// When cross compiling, `null` means default (latest known OS version). | |
| 30 | /// When `os_tag` is native, `null` means equal to the native OS version. | |
| 31 | os_version_max: ?OsVersion = null, | |
| 32 | ||
| 33 | /// `null` means default when cross compiling, or native when os_tag is native. | |
| 34 | /// If `isGnuLibC()` is `false`, this must be `null` and is ignored. | |
| 35 | glibc_version: ?SemVer = null, | |
| 36 | ||
| 37 | /// `null` means the native C ABI, if `os_tag` is native, otherwise it means the default C ABI. | |
| 38 | abi: ?Target.Abi = null, | |
| 39 | ||
| 40 | /// When `os_tag` is `null`, then `null` means native. Otherwise it means the standard path | |
| 41 | /// based on the `os_tag`. | |
| 42 | dynamic_linker: DynamicLinker = DynamicLinker{}, | |
| 43 | ||
| 44 | pub const CpuModel = union(enum) { | |
| 45 | /// Always native | |
| 46 | native, | |
| 47 | ||
| 48 | /// Always baseline | |
| 49 | baseline, | |
| 50 | ||
| 51 | /// If CPU Architecture is native, then the CPU model will be native. Otherwise, | |
| 52 | /// it will be baseline. | |
| 53 | determined_by_cpu_arch, | |
| 54 | ||
| 55 | explicit: *const Target.Cpu.Model, | |
| 56 | }; | |
| 57 | ||
| 58 | pub const OsVersion = union(enum) { | |
| 59 | none: void, | |
| 60 | semver: SemVer, | |
| 61 | windows: Target.Os.WindowsVersion, | |
| 62 | }; | |
| 63 | ||
| 64 | pub const SemVer = std.builtin.Version; | |
| 65 | ||
| 66 | pub const DynamicLinker = Target.DynamicLinker; | |
| 67 | ||
| 68 | pub fn fromTarget(target: Target) CrossTarget { | |
| 69 | var result: CrossTarget = .{ | |
| 70 | .cpu_arch = target.cpu.arch, | |
| 71 | .cpu_model = .{ .explicit = target.cpu.model }, | |
| 72 | .os_tag = target.os.tag, | |
| 73 | .os_version_min = undefined, | |
| 74 | .os_version_max = undefined, | |
| 75 | .abi = target.abi, | |
| 76 | .glibc_version = if (target.isGnuLibC()) | |
| 77 | target.os.version_range.linux.glibc | |
| 78 | else | |
| 79 | null, | |
| 80 | }; | |
| 81 | result.updateOsVersionRange(target.os); | |
| 82 | ||
| 83 | const all_features = target.cpu.arch.allFeaturesList(); | |
| 84 | var cpu_model_set = target.cpu.model.features; | |
| 85 | cpu_model_set.populateDependencies(all_features); | |
| 86 | { | |
| 87 | // The "add" set is the full set with the CPU Model set removed. | |
| 88 | const add_set = &result.cpu_features_add; | |
| 89 | add_set.* = target.cpu.features; | |
| 90 | add_set.removeFeatureSet(cpu_model_set); | |
| 91 | } | |
| 92 | { | |
| 93 | // The "sub" set is the features that are on in CPU Model set and off in the full set. | |
| 94 | const sub_set = &result.cpu_features_sub; | |
| 95 | sub_set.* = cpu_model_set; | |
| 96 | sub_set.removeFeatureSet(target.cpu.features); | |
| 97 | } | |
| 98 | return result; | |
| 99 | } | |
| 100 | ||
| 101 | fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void { | |
| 102 | switch (os.tag) { | |
| 103 | .freestanding, | |
| 104 | .ananas, | |
| 105 | .cloudabi, | |
| 106 | .fuchsia, | |
| 107 | .kfreebsd, | |
| 108 | .lv2, | |
| 109 | .solaris, | |
| 110 | .zos, | |
| 111 | .haiku, | |
| 112 | .minix, | |
| 113 | .rtems, | |
| 114 | .nacl, | |
| 115 | .aix, | |
| 116 | .cuda, | |
| 117 | .nvcl, | |
| 118 | .amdhsa, | |
| 119 | .ps4, | |
| 120 | .elfiamcu, | |
| 121 | .mesa3d, | |
| 122 | .contiki, | |
| 123 | .amdpal, | |
| 124 | .hermit, | |
| 125 | .hurd, | |
| 126 | .wasi, | |
| 127 | .emscripten, | |
| 128 | .uefi, | |
| 129 | .opencl, | |
| 130 | .glsl450, | |
| 131 | .vulkan, | |
| 132 | .plan9, | |
| 133 | .other, | |
| 134 | => { | |
| 135 | self.os_version_min = .{ .none = {} }; | |
| 136 | self.os_version_max = .{ .none = {} }; | |
| 137 | }, | |
| 138 | ||
| 139 | .freebsd, | |
| 140 | .macos, | |
| 141 | .ios, | |
| 142 | .tvos, | |
| 143 | .watchos, | |
| 144 | .netbsd, | |
| 145 | .openbsd, | |
| 146 | .dragonfly, | |
| 147 | => { | |
| 148 | self.os_version_min = .{ .semver = os.version_range.semver.min }; | |
| 149 | self.os_version_max = .{ .semver = os.version_range.semver.max }; | |
| 150 | }, | |
| 151 | ||
| 152 | .linux => { | |
| 153 | self.os_version_min = .{ .semver = os.version_range.linux.range.min }; | |
| 154 | self.os_version_max = .{ .semver = os.version_range.linux.range.max }; | |
| 155 | }, | |
| 156 | ||
| 157 | .windows => { | |
| 158 | self.os_version_min = .{ .windows = os.version_range.windows.min }; | |
| 159 | self.os_version_max = .{ .windows = os.version_range.windows.max }; | |
| 160 | }, | |
| 161 | } | |
| 162 | } | |
| 163 | ||
| 164 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 165 | pub fn toTarget(self: CrossTarget) Target { | |
| 166 | return .{ | |
| 167 | .cpu = self.getCpu(), | |
| 168 | .os = self.getOs(), | |
| 169 | .abi = self.getAbi(), | |
| 170 | }; | |
| 171 | } | |
| 172 | ||
| 173 | pub const ParseOptions = struct { | |
| 174 | /// This is sometimes called a "triple". It looks roughly like this: | |
| 175 | /// riscv64-linux-musl | |
| 176 | /// The fields are, respectively: | |
| 177 | /// * CPU Architecture | |
| 178 | /// * Operating System (and optional version range) | |
| 179 | /// * C ABI (optional, with optional glibc version) | |
| 180 | /// The string "native" can be used for CPU architecture as well as Operating System. | |
| 181 | /// If the CPU Architecture is specified as "native", then the Operating System and C ABI may be omitted. | |
| 182 | arch_os_abi: []const u8 = "native", | |
| 183 | ||
| 184 | /// Looks like "name+a+b-c-d+e", where "name" is a CPU Model name, "a", "b", and "e" | |
| 185 | /// are examples of CPU features to add to the set, and "c" and "d" are examples of CPU features | |
| 186 | /// to remove from the set. | |
| 187 | /// The following special strings are recognized for CPU Model name: | |
| 188 | /// * "baseline" - The "default" set of CPU features for cross-compiling. A conservative set | |
| 189 | /// of features that is expected to be supported on most available hardware. | |
| 190 | /// * "native" - The native CPU model is to be detected when compiling. | |
| 191 | /// If this field is not provided (`null`), then the value will depend on the | |
| 192 | /// parsed CPU Architecture. If native, then this will be "native". Otherwise, it will be "baseline". | |
| 193 | cpu_features: ?[]const u8 = null, | |
| 194 | ||
| 195 | /// Absolute path to dynamic linker, to override the default, which is either a natively | |
| 196 | /// detected path, or a standard path. | |
| 197 | dynamic_linker: ?[]const u8 = null, | |
| 198 | ||
| 199 | /// If this is provided, the function will populate some information about parsing failures, | |
| 200 | /// so that user-friendly error messages can be delivered. | |
| 201 | diagnostics: ?*Diagnostics = null, | |
| 202 | ||
| 203 | pub const Diagnostics = struct { | |
| 204 | /// If the architecture was determined, this will be populated. | |
| 205 | arch: ?Target.Cpu.Arch = null, | |
| 206 | ||
| 207 | /// If the OS name was determined, this will be populated. | |
| 208 | os_name: ?[]const u8 = null, | |
| 209 | ||
| 210 | /// If the OS tag was determined, this will be populated. | |
| 211 | os_tag: ?Target.Os.Tag = null, | |
| 212 | ||
| 213 | /// If the ABI was determined, this will be populated. | |
| 214 | abi: ?Target.Abi = null, | |
| 215 | ||
| 216 | /// If the CPU name was determined, this will be populated. | |
| 217 | cpu_name: ?[]const u8 = null, | |
| 218 | ||
| 219 | /// If error.UnknownCpuFeature is returned, this will be populated. | |
| 220 | unknown_feature_name: ?[]const u8 = null, | |
| 221 | }; | |
| 222 | }; | |
| 223 | ||
| 224 | pub fn parse(args: ParseOptions) !CrossTarget { | |
| 225 | var dummy_diags: ParseOptions.Diagnostics = undefined; | |
| 226 | const diags = args.diagnostics orelse &dummy_diags; | |
| 227 | ||
| 228 | var result: CrossTarget = .{ | |
| 229 | .dynamic_linker = DynamicLinker.init(args.dynamic_linker), | |
| 230 | }; | |
| 231 | ||
| 232 | var it = mem.split(u8, args.arch_os_abi, "-"); | |
| 233 | const arch_name = it.next().?; | |
| 234 | const arch_is_native = mem.eql(u8, arch_name, "native"); | |
| 235 | if (!arch_is_native) { | |
| 236 | result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse | |
| 237 | return error.UnknownArchitecture; | |
| 238 | } | |
| 239 | const arch = result.getCpuArch(); | |
| 240 | diags.arch = arch; | |
| 241 | ||
| 242 | if (it.next()) |os_text| { | |
| 243 | try parseOs(&result, diags, os_text); | |
| 244 | } else if (!arch_is_native) { | |
| 245 | return error.MissingOperatingSystem; | |
| 246 | } | |
| 247 | ||
| 248 | const opt_abi_text = it.next(); | |
| 249 | if (opt_abi_text) |abi_text| { | |
| 250 | var abi_it = mem.split(u8, abi_text, "."); | |
| 251 | const abi = std.meta.stringToEnum(Target.Abi, abi_it.next().?) orelse | |
| 252 | return error.UnknownApplicationBinaryInterface; | |
| 253 | result.abi = abi; | |
| 254 | diags.abi = abi; | |
| 255 | ||
| 256 | const abi_ver_text = abi_it.rest(); | |
| 257 | if (abi_it.next() != null) { | |
| 258 | if (result.isGnuLibC()) { | |
| 259 | result.glibc_version = SemVer.parse(abi_ver_text) catch |err| switch (err) { | |
| 260 | error.Overflow => return error.InvalidAbiVersion, | |
| 261 | error.InvalidCharacter => return error.InvalidAbiVersion, | |
| 262 | error.InvalidVersion => return error.InvalidAbiVersion, | |
| 263 | }; | |
| 264 | } else { | |
| 265 | return error.InvalidAbiVersion; | |
| 266 | } | |
| 267 | } | |
| 268 | } | |
| 269 | ||
| 270 | if (it.next() != null) return error.UnexpectedExtraField; | |
| 271 | ||
| 272 | if (args.cpu_features) |cpu_features| { | |
| 273 | const all_features = arch.allFeaturesList(); | |
| 274 | var index: usize = 0; | |
| 275 | while (index < cpu_features.len and | |
| 276 | cpu_features[index] != '+' and | |
| 277 | cpu_features[index] != '-') | |
| 278 | { | |
| 279 | index += 1; | |
| 280 | } | |
| 281 | const cpu_name = cpu_features[0..index]; | |
| 282 | diags.cpu_name = cpu_name; | |
| 283 | ||
| 284 | const add_set = &result.cpu_features_add; | |
| 285 | const sub_set = &result.cpu_features_sub; | |
| 286 | if (mem.eql(u8, cpu_name, "native")) { | |
| 287 | result.cpu_model = .native; | |
| 288 | } else if (mem.eql(u8, cpu_name, "baseline")) { | |
| 289 | result.cpu_model = .baseline; | |
| 290 | } else { | |
| 291 | result.cpu_model = .{ .explicit = try arch.parseCpuModel(cpu_name) }; | |
| 292 | } | |
| 293 | ||
| 294 | while (index < cpu_features.len) { | |
| 295 | const op = cpu_features[index]; | |
| 296 | const set = switch (op) { | |
| 297 | '+' => add_set, | |
| 298 | '-' => sub_set, | |
| 299 | else => unreachable, | |
| 300 | }; | |
| 301 | index += 1; | |
| 302 | const start = index; | |
| 303 | while (index < cpu_features.len and | |
| 304 | cpu_features[index] != '+' and | |
| 305 | cpu_features[index] != '-') | |
| 306 | { | |
| 307 | index += 1; | |
| 308 | } | |
| 309 | const feature_name = cpu_features[start..index]; | |
| 310 | for (all_features) |feature, feat_index_usize| { | |
| 311 | const feat_index = @intCast(Target.Cpu.Feature.Set.Index, feat_index_usize); | |
| 312 | if (mem.eql(u8, feature_name, feature.name)) { | |
| 313 | set.addFeature(feat_index); | |
| 314 | break; | |
| 315 | } | |
| 316 | } else { | |
| 317 | diags.unknown_feature_name = feature_name; | |
| 318 | return error.UnknownCpuFeature; | |
| 319 | } | |
| 320 | } | |
| 321 | } | |
| 322 | ||
| 323 | return result; | |
| 324 | } | |
| 325 | ||
| 326 | /// Similar to `parse` except instead of fully parsing, it only determines the CPU | |
| 327 | /// architecture and returns it if it can be determined, and returns `null` otherwise. | |
| 328 | /// This is intended to be used if the API user of CrossTarget needs to learn the | |
| 329 | /// target CPU architecture in order to fully populate `ParseOptions`. | |
| 330 | pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch { | |
| 331 | var it = mem.split(u8, args.arch_os_abi, "-"); | |
| 332 | const arch_name = it.next().?; | |
| 333 | const arch_is_native = mem.eql(u8, arch_name, "native"); | |
| 334 | if (arch_is_native) { | |
| 335 | return builtin.cpu.arch; | |
| 336 | } else { | |
| 337 | return std.meta.stringToEnum(Target.Cpu.Arch, arch_name); | |
| 338 | } | |
| 339 | } | |
| 340 | ||
| 341 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 342 | pub fn getCpu(self: CrossTarget) Target.Cpu { | |
| 343 | switch (self.cpu_model) { | |
| 344 | .native => { | |
| 345 | // This works when doing `zig build` because Zig generates a build executable using | |
| 346 | // native CPU model & features. However this will not be accurate otherwise, and | |
| 347 | // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. | |
| 348 | return builtin.cpu; | |
| 349 | }, | |
| 350 | .baseline => { | |
| 351 | var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch()); | |
| 352 | self.updateCpuFeatures(&adjusted_baseline.features); | |
| 353 | return adjusted_baseline; | |
| 354 | }, | |
| 355 | .determined_by_cpu_arch => if (self.cpu_arch == null) { | |
| 356 | // This works when doing `zig build` because Zig generates a build executable using | |
| 357 | // native CPU model & features. However this will not be accurate otherwise, and | |
| 358 | // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. | |
| 359 | return builtin.cpu; | |
| 360 | } else { | |
| 361 | var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch()); | |
| 362 | self.updateCpuFeatures(&adjusted_baseline.features); | |
| 363 | return adjusted_baseline; | |
| 364 | }, | |
| 365 | .explicit => |model| { | |
| 366 | var adjusted_model = model.toCpu(self.getCpuArch()); | |
| 367 | self.updateCpuFeatures(&adjusted_model.features); | |
| 368 | return adjusted_model; | |
| 369 | }, | |
| 370 | } | |
| 371 | } | |
| 372 | ||
| 373 | pub fn getCpuArch(self: CrossTarget) Target.Cpu.Arch { | |
| 374 | return self.cpu_arch orelse builtin.cpu.arch; | |
| 375 | } | |
| 376 | ||
| 377 | pub fn getCpuModel(self: CrossTarget) *const Target.Cpu.Model { | |
| 378 | return switch (self.cpu_model) { | |
| 379 | .explicit => |cpu_model| cpu_model, | |
| 380 | else => self.getCpu().model, | |
| 381 | }; | |
| 382 | } | |
| 383 | ||
| 384 | pub fn getCpuFeatures(self: CrossTarget) Target.Cpu.Feature.Set { | |
| 385 | return self.getCpu().features; | |
| 386 | } | |
| 387 | ||
| 388 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 389 | pub fn getOs(self: CrossTarget) Target.Os { | |
| 390 | // `builtin.os` works when doing `zig build` because Zig generates a build executable using | |
| 391 | // native OS version range. However this will not be accurate otherwise, and | |
| 392 | // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. | |
| 393 | var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange(self.getCpuArch()) else builtin.os; | |
| 394 | ||
| 395 | if (self.os_version_min) |min| switch (min) { | |
| 396 | .none => {}, | |
| 397 | .semver => |semver| switch (self.getOsTag()) { | |
| 398 | .linux => adjusted_os.version_range.linux.range.min = semver, | |
| 399 | else => adjusted_os.version_range.semver.min = semver, | |
| 400 | }, | |
| 401 | .windows => |win_ver| adjusted_os.version_range.windows.min = win_ver, | |
| 402 | }; | |
| 403 | ||
| 404 | if (self.os_version_max) |max| switch (max) { | |
| 405 | .none => {}, | |
| 406 | .semver => |semver| switch (self.getOsTag()) { | |
| 407 | .linux => adjusted_os.version_range.linux.range.max = semver, | |
| 408 | else => adjusted_os.version_range.semver.max = semver, | |
| 409 | }, | |
| 410 | .windows => |win_ver| adjusted_os.version_range.windows.max = win_ver, | |
| 411 | }; | |
| 412 | ||
| 413 | if (self.glibc_version) |glibc| { | |
| 414 | assert(self.isGnuLibC()); | |
| 415 | adjusted_os.version_range.linux.glibc = glibc; | |
| 416 | } | |
| 417 | ||
| 418 | return adjusted_os; | |
| 419 | } | |
| 420 | ||
| 421 | pub fn getOsTag(self: CrossTarget) Target.Os.Tag { | |
| 422 | return self.os_tag orelse builtin.os.tag; | |
| 423 | } | |
| 424 | ||
| 425 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 426 | pub fn getOsVersionMin(self: CrossTarget) OsVersion { | |
| 427 | if (self.os_version_min) |version_min| return version_min; | |
| 428 | var tmp: CrossTarget = undefined; | |
| 429 | tmp.updateOsVersionRange(self.getOs()); | |
| 430 | return tmp.os_version_min.?; | |
| 431 | } | |
| 432 | ||
| 433 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 434 | pub fn getOsVersionMax(self: CrossTarget) OsVersion { | |
| 435 | if (self.os_version_max) |version_max| return version_max; | |
| 436 | var tmp: CrossTarget = undefined; | |
| 437 | tmp.updateOsVersionRange(self.getOs()); | |
| 438 | return tmp.os_version_max.?; | |
| 439 | } | |
| 440 | ||
| 441 | /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. | |
| 442 | pub fn getAbi(self: CrossTarget) Target.Abi { | |
| 443 | if (self.abi) |abi| return abi; | |
| 444 | ||
| 445 | if (self.os_tag == null) { | |
| 446 | // This works when doing `zig build` because Zig generates a build executable using | |
| 447 | // native CPU model & features. However this will not be accurate otherwise, and | |
| 448 | // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. | |
| 449 | return builtin.abi; | |
| 450 | } | |
| 451 | ||
| 452 | return Target.Abi.default(self.getCpuArch(), self.getOs()); | |
| 453 | } | |
| 454 | ||
| 455 | pub fn isFreeBSD(self: CrossTarget) bool { | |
| 456 | return self.getOsTag() == .freebsd; | |
| 457 | } | |
| 458 | ||
| 459 | pub fn isDarwin(self: CrossTarget) bool { | |
| 460 | return self.getOsTag().isDarwin(); | |
| 461 | } | |
| 462 | ||
| 463 | pub fn isNetBSD(self: CrossTarget) bool { | |
| 464 | return self.getOsTag() == .netbsd; | |
| 465 | } | |
| 466 | ||
| 467 | pub fn isOpenBSD(self: CrossTarget) bool { | |
| 468 | return self.getOsTag() == .openbsd; | |
| 469 | } | |
| 470 | ||
| 471 | pub fn isUefi(self: CrossTarget) bool { | |
| 472 | return self.getOsTag() == .uefi; | |
| 473 | } | |
| 474 | ||
| 475 | pub fn isDragonFlyBSD(self: CrossTarget) bool { | |
| 476 | return self.getOsTag() == .dragonfly; | |
| 477 | } | |
| 478 | ||
| 479 | pub fn isLinux(self: CrossTarget) bool { | |
| 480 | return self.getOsTag() == .linux; | |
| 481 | } | |
| 482 | ||
| 483 | pub fn isWindows(self: CrossTarget) bool { | |
| 484 | return self.getOsTag() == .windows; | |
| 485 | } | |
| 486 | ||
| 487 | pub fn exeFileExt(self: CrossTarget) [:0]const u8 { | |
| 488 | return Target.exeFileExtSimple(self.getCpuArch(), self.getOsTag()); | |
| 489 | } | |
| 490 | ||
| 491 | pub fn staticLibSuffix(self: CrossTarget) [:0]const u8 { | |
| 492 | return Target.staticLibSuffix_os_abi(self.getOsTag(), self.getAbi()); | |
| 493 | } | |
| 494 | ||
| 495 | pub fn dynamicLibSuffix(self: CrossTarget) [:0]const u8 { | |
| 496 | return self.getOsTag().dynamicLibSuffix(); | |
| 497 | } | |
| 498 | ||
| 499 | pub fn libPrefix(self: CrossTarget) [:0]const u8 { | |
| 500 | return Target.libPrefix_os_abi(self.getOsTag(), self.getAbi()); | |
| 501 | } | |
| 502 | ||
| 503 | pub fn isNativeCpu(self: CrossTarget) bool { | |
| 504 | return self.cpu_arch == null and | |
| 505 | (self.cpu_model == .native or self.cpu_model == .determined_by_cpu_arch) and | |
| 506 | self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty(); | |
| 507 | } | |
| 508 | ||
| 509 | pub fn isNativeOs(self: CrossTarget) bool { | |
| 510 | return self.os_tag == null and self.os_version_min == null and self.os_version_max == null and | |
| 511 | self.dynamic_linker.get() == null and self.glibc_version == null; | |
| 512 | } | |
| 513 | ||
| 514 | pub fn isNativeAbi(self: CrossTarget) bool { | |
| 515 | return self.os_tag == null and self.abi == null; | |
| 516 | } | |
| 517 | ||
| 518 | pub fn isNative(self: CrossTarget) bool { | |
| 519 | return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi(); | |
| 520 | } | |
| 521 | ||
| 522 | pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 { | |
| 523 | if (self.isNative()) { | |
| 524 | return allocator.dupe(u8, "native"); | |
| 525 | } | |
| 526 | ||
| 527 | const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native"; | |
| 528 | const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native"; | |
| 529 | ||
| 530 | var result = std.ArrayList(u8).init(allocator); | |
| 531 | defer result.deinit(); | |
| 532 | ||
| 533 | try result.writer().print("{s}-{s}", .{ arch_name, os_name }); | |
| 534 | ||
| 535 | // The zig target syntax does not allow specifying a max os version with no min, so | |
| 536 | // if either are present, we need the min. | |
| 537 | if (self.os_version_min != null or self.os_version_max != null) { | |
| 538 | switch (self.getOsVersionMin()) { | |
| 539 | .none => {}, | |
| 540 | .semver => |v| try result.writer().print(".{}", .{v}), | |
| 541 | .windows => |v| try result.writer().print("{s}", .{v}), | |
| 542 | } | |
| 543 | } | |
| 544 | if (self.os_version_max) |max| { | |
| 545 | switch (max) { | |
| 546 | .none => {}, | |
| 547 | .semver => |v| try result.writer().print("...{}", .{v}), | |
| 548 | .windows => |v| try result.writer().print("..{s}", .{v}), | |
| 549 | } | |
| 550 | } | |
| 551 | ||
| 552 | if (self.glibc_version) |v| { | |
| 553 | try result.writer().print("-{s}.{}", .{ @tagName(self.getAbi()), v }); | |
| 554 | } else if (self.abi) |abi| { | |
| 555 | try result.writer().print("-{s}", .{@tagName(abi)}); | |
| 556 | } | |
| 557 | ||
| 558 | return result.toOwnedSlice(); | |
| 559 | } | |
| 560 | ||
| 561 | pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![]u8 { | |
| 562 | // TODO is there anything else worthy of the description that is not | |
| 563 | // already captured in the triple? | |
| 564 | return self.zigTriple(allocator); | |
| 565 | } | |
| 566 | ||
| 567 | pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 { | |
| 568 | return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi()); | |
| 569 | } | |
| 570 | ||
| 571 | pub fn wantSharedLibSymLinks(self: CrossTarget) bool { | |
| 572 | return self.getOsTag() != .windows; | |
| 573 | } | |
| 574 | ||
| 575 | pub const VcpkgLinkage = std.builtin.LinkMode; | |
| 576 | ||
| 577 | /// Returned slice must be freed by the caller. | |
| 578 | pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![]u8 { | |
| 579 | const arch = switch (self.getCpuArch()) { | |
| 580 | .i386 => "x86", | |
| 581 | .x86_64 => "x64", | |
| 582 | ||
| 583 | .arm, | |
| 584 | .armeb, | |
| 585 | .thumb, | |
| 586 | .thumbeb, | |
| 587 | .aarch64_32, | |
| 588 | => "arm", | |
| 589 | ||
| 590 | .aarch64, | |
| 591 | .aarch64_be, | |
| 592 | => "arm64", | |
| 593 | ||
| 594 | else => return error.UnsupportedVcpkgArchitecture, | |
| 595 | }; | |
| 596 | ||
| 597 | const os = switch (self.getOsTag()) { | |
| 598 | .windows => "windows", | |
| 599 | .linux => "linux", | |
| 600 | .macos => "macos", | |
| 601 | else => return error.UnsupportedVcpkgOperatingSystem, | |
| 602 | }; | |
| 603 | ||
| 604 | const static_suffix = switch (linkage) { | |
| 605 | .Static => "-static", | |
| 606 | .Dynamic => "", | |
| 607 | }; | |
| 608 | ||
| 609 | return std.fmt.allocPrint(allocator, "{s}-{s}{s}", .{ arch, os, static_suffix }); | |
| 610 | } | |
| 611 | ||
| 612 | pub const Executor = union(enum) { | |
| 613 | native, | |
| 614 | qemu: []const u8, | |
| 615 | wine: []const u8, | |
| 616 | wasmtime: []const u8, | |
| 617 | darling: []const u8, | |
| 618 | unavailable, | |
| 619 | }; | |
| 620 | ||
| 621 | /// Note that even a `CrossTarget` which returns `false` for `isNative` could still be natively executed. | |
| 622 | /// For example `-target arm-native` running on an aarch64 host. | |
| 623 | pub fn getExternalExecutor(self: CrossTarget) Executor { | |
| 624 | const cpu_arch = self.getCpuArch(); | |
| 625 | const os_tag = self.getOsTag(); | |
| 626 | const os_match = os_tag == builtin.os.tag; | |
| 627 | ||
| 628 | // If the OS and CPU arch match, the binary can be considered native. | |
| 629 | // TODO additionally match the CPU features. This `getExternalExecutor` function should | |
| 630 | // be moved to std.Target and match any chosen target against the native target. | |
| 631 | if (os_match and cpu_arch == builtin.cpu.arch) { | |
| 632 | // However, we also need to verify that the dynamic linker path is valid. | |
| 633 | if (self.os_tag == null) { | |
| 634 | return .native; | |
| 635 | } | |
| 636 | // TODO here we call toTarget, a deprecated function, because of the above TODO about moving | |
| 637 | // this code to std.Target. | |
| 638 | const opt_dl = self.dynamic_linker.get() orelse self.toTarget().standardDynamicLinkerPath().get(); | |
| 639 | if (opt_dl) |dl| blk: { | |
| 640 | std.fs.cwd().access(dl, .{}) catch break :blk; | |
| 641 | return .native; | |
| 642 | } | |
| 643 | } | |
| 644 | ||
| 645 | // If the OS matches, we can use QEMU to emulate a foreign architecture. | |
| 646 | if (os_match) { | |
| 647 | return switch (cpu_arch) { | |
| 648 | .aarch64 => Executor{ .qemu = "qemu-aarch64" }, | |
| 649 | .aarch64_be => Executor{ .qemu = "qemu-aarch64_be" }, | |
| 650 | .arm => Executor{ .qemu = "qemu-arm" }, | |
| 651 | .armeb => Executor{ .qemu = "qemu-armeb" }, | |
| 652 | .i386 => Executor{ .qemu = "qemu-i386" }, | |
| 653 | .mips => Executor{ .qemu = "qemu-mips" }, | |
| 654 | .mipsel => Executor{ .qemu = "qemu-mipsel" }, | |
| 655 | .mips64 => Executor{ .qemu = "qemu-mips64" }, | |
| 656 | .mips64el => Executor{ .qemu = "qemu-mips64el" }, | |
| 657 | .powerpc => Executor{ .qemu = "qemu-ppc" }, | |
| 658 | .powerpc64 => Executor{ .qemu = "qemu-ppc64" }, | |
| 659 | .powerpc64le => Executor{ .qemu = "qemu-ppc64le" }, | |
| 660 | .riscv32 => Executor{ .qemu = "qemu-riscv32" }, | |
| 661 | .riscv64 => Executor{ .qemu = "qemu-riscv64" }, | |
| 662 | .s390x => Executor{ .qemu = "qemu-s390x" }, | |
| 663 | .sparc => Executor{ .qemu = "qemu-sparc" }, | |
| 664 | .x86_64 => Executor{ .qemu = "qemu-x86_64" }, | |
| 665 | else => return .unavailable, | |
| 666 | }; | |
| 667 | } | |
| 668 | ||
| 669 | switch (os_tag) { | |
| 670 | .windows => switch (cpu_arch.ptrBitWidth()) { | |
| 671 | 32 => return Executor{ .wine = "wine" }, | |
| 672 | 64 => return Executor{ .wine = "wine64" }, | |
| 673 | else => return .unavailable, | |
| 674 | }, | |
| 675 | .wasi => switch (cpu_arch.ptrBitWidth()) { | |
| 676 | 32 => return Executor{ .wasmtime = "wasmtime" }, | |
| 677 | else => return .unavailable, | |
| 678 | }, | |
| 679 | .macos => { | |
| 680 | // TODO loosen this check once upstream adds QEMU-based emulation | |
| 681 | // layer for non-host architectures: | |
| 682 | // https://github.com/darlinghq/darling/issues/863 | |
| 683 | if (cpu_arch != builtin.cpu.arch) { | |
| 684 | return .unavailable; | |
| 685 | } | |
| 686 | return Executor{ .darling = "darling" }; | |
| 687 | }, | |
| 688 | else => return .unavailable, | |
| 689 | } | |
| 690 | } | |
| 691 | ||
| 692 | pub fn isGnuLibC(self: CrossTarget) bool { | |
| 693 | return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi()); | |
| 694 | } | |
| 695 | ||
| 696 | pub fn setGnuLibCVersion(self: *CrossTarget, major: u32, minor: u32, patch: u32) void { | |
| 697 | assert(self.isGnuLibC()); | |
| 698 | self.glibc_version = SemVer{ .major = major, .minor = minor, .patch = patch }; | |
| 699 | } | |
| 700 | ||
| 701 | pub fn getObjectFormat(self: CrossTarget) Target.ObjectFormat { | |
| 702 | return Target.getObjectFormatSimple(self.getOsTag(), self.getCpuArch()); | |
| 703 | } | |
| 704 | ||
| 705 | pub fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void { | |
| 706 | set.removeFeatureSet(self.cpu_features_sub); | |
| 707 | set.addFeatureSet(self.cpu_features_add); | |
| 708 | set.populateDependencies(self.getCpuArch().allFeaturesList()); | |
| 709 | set.removeFeatureSet(self.cpu_features_sub); | |
| 710 | } | |
| 711 | ||
| 712 | fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void { | |
| 713 | var it = mem.split(u8, text, "."); | |
| 714 | const os_name = it.next().?; | |
| 715 | diags.os_name = os_name; | |
| 716 | const os_is_native = mem.eql(u8, os_name, "native"); | |
| 717 | if (!os_is_native) { | |
| 718 | result.os_tag = std.meta.stringToEnum(Target.Os.Tag, os_name) orelse | |
| 719 | return error.UnknownOperatingSystem; | |
| 720 | } | |
| 721 | const tag = result.getOsTag(); | |
| 722 | diags.os_tag = tag; | |
| 723 | ||
| 724 | const version_text = it.rest(); | |
| 725 | if (it.next() == null) return; | |
| 726 | ||
| 727 | switch (tag) { | |
| 728 | .freestanding, | |
| 729 | .ananas, | |
| 730 | .cloudabi, | |
| 731 | .fuchsia, | |
| 732 | .kfreebsd, | |
| 733 | .lv2, | |
| 734 | .solaris, | |
| 735 | .zos, | |
| 736 | .haiku, | |
| 737 | .minix, | |
| 738 | .rtems, | |
| 739 | .nacl, | |
| 740 | .aix, | |
| 741 | .cuda, | |
| 742 | .nvcl, | |
| 743 | .amdhsa, | |
| 744 | .ps4, | |
| 745 | .elfiamcu, | |
| 746 | .mesa3d, | |
| 747 | .contiki, | |
| 748 | .amdpal, | |
| 749 | .hermit, | |
| 750 | .hurd, | |
| 751 | .wasi, | |
| 752 | .emscripten, | |
| 753 | .uefi, | |
| 754 | .opencl, | |
| 755 | .glsl450, | |
| 756 | .vulkan, | |
| 757 | .plan9, | |
| 758 | .other, | |
| 759 | => return error.InvalidOperatingSystemVersion, | |
| 760 | ||
| 761 | .freebsd, | |
| 762 | .macos, | |
| 763 | .ios, | |
| 764 | .tvos, | |
| 765 | .watchos, | |
| 766 | .netbsd, | |
| 767 | .openbsd, | |
| 768 | .linux, | |
| 769 | .dragonfly, | |
| 770 | => { | |
| 771 | var range_it = mem.split(u8, version_text, "..."); | |
| 772 | ||
| 773 | const min_text = range_it.next().?; | |
| 774 | const min_ver = SemVer.parse(min_text) catch |err| switch (err) { | |
| 775 | error.Overflow => return error.InvalidOperatingSystemVersion, | |
| 776 | error.InvalidCharacter => return error.InvalidOperatingSystemVersion, | |
| 777 | error.InvalidVersion => return error.InvalidOperatingSystemVersion, | |
| 778 | }; | |
| 779 | result.os_version_min = .{ .semver = min_ver }; | |
| 780 | ||
| 781 | const max_text = range_it.next() orelse return; | |
| 782 | const max_ver = SemVer.parse(max_text) catch |err| switch (err) { | |
| 783 | error.Overflow => return error.InvalidOperatingSystemVersion, | |
| 784 | error.InvalidCharacter => return error.InvalidOperatingSystemVersion, | |
| 785 | error.InvalidVersion => return error.InvalidOperatingSystemVersion, | |
| 786 | }; | |
| 787 | result.os_version_max = .{ .semver = max_ver }; | |
| 788 | }, | |
| 789 | ||
| 790 | .windows => { | |
| 791 | var range_it = mem.split(u8, version_text, "..."); | |
| 792 | ||
| 793 | const min_text = range_it.next().?; | |
| 794 | const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse | |
| 795 | return error.InvalidOperatingSystemVersion; | |
| 796 | result.os_version_min = .{ .windows = min_ver }; | |
| 797 | ||
| 798 | const max_text = range_it.next() orelse return; | |
| 799 | const max_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, max_text) orelse | |
| 800 | return error.InvalidOperatingSystemVersion; | |
| 801 | result.os_version_max = .{ .windows = max_ver }; | |
| 802 | }, | |
| 803 | } | |
| 804 | } | |
| 805 | }; | |
| 806 | ||
| 807 | test "CrossTarget.parse" { | |
| 808 | if (builtin.target.isGnuLibC()) { | |
| 809 | var cross_target = try CrossTarget.parse(.{}); | |
| 810 | cross_target.setGnuLibCVersion(2, 1, 1); | |
| 811 | ||
| 812 | const text = try cross_target.zigTriple(std.testing.allocator); | |
| 813 | defer std.testing.allocator.free(text); | |
| 814 | ||
| 815 | var buf: [256]u8 = undefined; | |
| 816 | const triple = std.fmt.bufPrint( | |
| 817 | buf[0..], | |
| 818 | "native-native-{s}.2.1.1", | |
| 819 | .{@tagName(builtin.abi)}, | |
| 820 | ) catch unreachable; | |
| 821 | ||
| 822 | try std.testing.expectEqualSlices(u8, triple, text); | |
| 823 | } | |
| 824 | { | |
| 825 | const cross_target = try CrossTarget.parse(.{ | |
| 826 | .arch_os_abi = "aarch64-linux", | |
| 827 | .cpu_features = "native", | |
| 828 | }); | |
| 829 | ||
| 830 | try std.testing.expect(cross_target.cpu_arch.? == .aarch64); | |
| 831 | try std.testing.expect(cross_target.cpu_model == .native); | |
| 832 | } | |
| 833 | { | |
| 834 | const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" }); | |
| 835 | ||
| 836 | try std.testing.expect(cross_target.cpu_arch == null); | |
| 837 | try std.testing.expect(cross_target.isNative()); | |
| 838 | ||
| 839 | const text = try cross_target.zigTriple(std.testing.allocator); | |
| 840 | defer std.testing.allocator.free(text); | |
| 841 | try std.testing.expectEqualSlices(u8, "native", text); | |
| 842 | } | |
| 843 | { | |
| 844 | const cross_target = try CrossTarget.parse(.{ | |
| 845 | .arch_os_abi = "x86_64-linux-gnu", | |
| 846 | .cpu_features = "x86_64-sse-sse2-avx-cx8", | |
| 847 | }); | |
| 848 | const target = cross_target.toTarget(); | |
| 849 | ||
| 850 | try std.testing.expect(target.os.tag == .linux); | |
| 851 | try std.testing.expect(target.abi == .gnu); | |
| 852 | try std.testing.expect(target.cpu.arch == .x86_64); | |
| 853 | try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse)); | |
| 854 | try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx)); | |
| 855 | try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8)); | |
| 856 | try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov)); | |
| 857 | try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr)); | |
| 858 | ||
| 859 | try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov })); | |
| 860 | try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx })); | |
| 861 | try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 })); | |
| 862 | try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse })); | |
| 863 | ||
| 864 | const text = try cross_target.zigTriple(std.testing.allocator); | |
| 865 | defer std.testing.allocator.free(text); | |
| 866 | try std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text); | |
| 867 | } | |
| 868 | { | |
| 869 | const cross_target = try CrossTarget.parse(.{ | |
| 870 | .arch_os_abi = "arm-linux-musleabihf", | |
| 871 | .cpu_features = "generic+v8a", | |
| 872 | }); | |
| 873 | const target = cross_target.toTarget(); | |
| 874 | ||
| 875 | try std.testing.expect(target.os.tag == .linux); | |
| 876 | try std.testing.expect(target.abi == .musleabihf); | |
| 877 | try std.testing.expect(target.cpu.arch == .arm); | |
| 878 | try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic); | |
| 879 | try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a)); | |
| 880 | ||
| 881 | const text = try cross_target.zigTriple(std.testing.allocator); | |
| 882 | defer std.testing.allocator.free(text); | |
| 883 | try std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text); | |
| 884 | } | |
| 885 | { | |
| 886 | const cross_target = try CrossTarget.parse(.{ | |
| 887 | .arch_os_abi = "aarch64-linux.3.10...4.4.1-gnu.2.27", | |
| 888 | .cpu_features = "generic+v8a", | |
| 889 | }); | |
| 890 | const target = cross_target.toTarget(); | |
| 891 | ||
| 892 | try std.testing.expect(target.cpu.arch == .aarch64); | |
| 893 | try std.testing.expect(target.os.tag == .linux); | |
| 894 | try std.testing.expect(target.os.version_range.linux.range.min.major == 3); | |
| 895 | try std.testing.expect(target.os.version_range.linux.range.min.minor == 10); | |
| 896 | try std.testing.expect(target.os.version_range.linux.range.min.patch == 0); | |
| 897 | try std.testing.expect(target.os.version_range.linux.range.max.major == 4); | |
| 898 | try std.testing.expect(target.os.version_range.linux.range.max.minor == 4); | |
| 899 | try std.testing.expect(target.os.version_range.linux.range.max.patch == 1); | |
| 900 | try std.testing.expect(target.os.version_range.linux.glibc.major == 2); | |
| 901 | try std.testing.expect(target.os.version_range.linux.glibc.minor == 27); | |
| 902 | try std.testing.expect(target.os.version_range.linux.glibc.patch == 0); | |
| 903 | try std.testing.expect(target.abi == .gnu); | |
| 904 | ||
| 905 | const text = try cross_target.zigTriple(std.testing.allocator); | |
| 906 | defer std.testing.allocator.free(text); | |
| 907 | try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text); | |
| 908 | } | |
| 909 | } |
lib/std/zig/perf_test.zig-1| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const mem = std.mem; |
| 3 | const warn = std.debug.warn; | |
| 4 | 3 | const Tokenizer = std.zig.Tokenizer; |
| 5 | 4 | const Parser = std.zig.Parser; |
| 6 | 5 | const io = std.io; |
lib/std/zig/system.zig+8-8| ... | ... | @@ -165,7 +165,7 @@ pub const NativePaths = struct { |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | pub fn addIncludeDirFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void { |
| 168 | const item = try std.fmt.allocPrint0(self.include_dirs.allocator, fmt, args); | |
| 168 | const item = try std.fmt.allocPrintZ(self.include_dirs.allocator, fmt, args); | |
| 169 | 169 | errdefer self.include_dirs.allocator.free(item); |
| 170 | 170 | try self.include_dirs.append(item); |
| 171 | 171 | } |
| ... | ... | @@ -175,7 +175,7 @@ pub const NativePaths = struct { |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | pub fn addLibDirFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void { |
| 178 | const item = try std.fmt.allocPrint0(self.lib_dirs.allocator, fmt, args); | |
| 178 | const item = try std.fmt.allocPrintZ(self.lib_dirs.allocator, fmt, args); | |
| 179 | 179 | errdefer self.lib_dirs.allocator.free(item); |
| 180 | 180 | try self.lib_dirs.append(item); |
| 181 | 181 | } |
| ... | ... | @@ -189,13 +189,13 @@ pub const NativePaths = struct { |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | pub fn addFrameworkDirFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void { |
| 192 | const item = try std.fmt.allocPrint0(self.framework_dirs.allocator, fmt, args); | |
| 192 | const item = try std.fmt.allocPrintZ(self.framework_dirs.allocator, fmt, args); | |
| 193 | 193 | errdefer self.framework_dirs.allocator.free(item); |
| 194 | 194 | try self.framework_dirs.append(item); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | pub fn addWarningFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void { |
| 198 | const item = try std.fmt.allocPrint0(self.warnings.allocator, fmt, args); | |
| 198 | const item = try std.fmt.allocPrintZ(self.warnings.allocator, fmt, args); | |
| 199 | 199 | errdefer self.warnings.allocator.free(item); |
| 200 | 200 | try self.warnings.append(item); |
| 201 | 201 | } |
| ... | ... | @@ -243,7 +243,7 @@ pub const NativeTargetInfo = struct { |
| 243 | 243 | switch (builtin.target.os.tag) { |
| 244 | 244 | .linux => { |
| 245 | 245 | const uts = std.os.uname(); |
| 246 | const release = mem.spanZ(&uts.release); | |
| 246 | const release = mem.sliceTo(&uts.release, 0); | |
| 247 | 247 | // The release field sometimes has a weird format, |
| 248 | 248 | // `Version.parse` will attempt to find some meaningful interpretation. |
| 249 | 249 | if (std.builtin.Version.parse(release)) |ver| { |
| ... | ... | @@ -257,7 +257,7 @@ pub const NativeTargetInfo = struct { |
| 257 | 257 | }, |
| 258 | 258 | .solaris => { |
| 259 | 259 | const uts = std.os.uname(); |
| 260 | const release = mem.spanZ(&uts.release); | |
| 260 | const release = mem.sliceTo(&uts.release, 0); | |
| 261 | 261 | if (std.builtin.Version.parse(release)) |ver| { |
| 262 | 262 | os.version_range.semver.min = ver; |
| 263 | 263 | os.version_range.semver.max = ver; |
| ... | ... | @@ -838,7 +838,7 @@ pub const NativeTargetInfo = struct { |
| 838 | 838 | ); |
| 839 | 839 | const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name); |
| 840 | 840 | // TODO this pointer cast should not be necessary |
| 841 | const sh_name = mem.spanZ(std.meta.assumeSentinel(shstrtab[sh_name_off..].ptr, 0)); | |
| 841 | const sh_name = mem.sliceTo(std.meta.assumeSentinel(shstrtab[sh_name_off..].ptr, 0), 0); | |
| 842 | 842 | if (mem.eql(u8, sh_name, ".dynstr")) { |
| 843 | 843 | break :find_dyn_str .{ |
| 844 | 844 | .offset = elfInt(is_64, need_bswap, sh32.sh_offset, sh64.sh_offset), |
| ... | ... | @@ -856,7 +856,7 @@ pub const NativeTargetInfo = struct { |
| 856 | 856 | const rpoff_usize = std.math.cast(usize, rpoff) catch |err| switch (err) { |
| 857 | 857 | error.Overflow => return error.InvalidElfFile, |
| 858 | 858 | }; |
| 859 | const rpath_list = mem.spanZ(std.meta.assumeSentinel(strtab[rpoff_usize..].ptr, 0)); | |
| 859 | const rpath_list = mem.sliceTo(std.meta.assumeSentinel(strtab[rpoff_usize..].ptr, 0), 0); | |
| 860 | 860 | var it = mem.tokenize(u8, rpath_list, ":"); |
| 861 | 861 | while (it.next()) |rpath| { |
| 862 | 862 | var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) { |
lib/std/zig/tokenizer.zig+1-1| ... | ... | @@ -334,7 +334,7 @@ pub const Tokenizer = struct { |
| 334 | 334 | |
| 335 | 335 | /// For debugging purposes |
| 336 | 336 | pub fn dump(self: *Tokenizer, token: *const Token) void { |
| 337 | std.debug.warn("{s} \"{s}\"\n", .{ @tagName(token.tag), self.buffer[token.start..token.end] }); | |
| 337 | std.debug.print("{s} \"{s}\"\n", .{ @tagName(token.tag), self.buffer[token.start..token.end] }); | |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | pub fn init(buffer: [:0]const u8) Tokenizer { |
src/AstGen.zig+6-26| ... | ... | @@ -8399,7 +8399,7 @@ fn parseStrLit( |
| 8399 | 8399 | const raw_string = bytes[offset..]; |
| 8400 | 8400 | var buf_managed = buf.toManaged(astgen.gpa); |
| 8401 | 8401 | const result = std.zig.string_literal.parseAppend(&buf_managed, raw_string); |
| 8402 | buf.* = buf_managed.toUnmanaged(); | |
| 8402 | buf.* = buf_managed.moveToUnmanaged(); | |
| 8403 | 8403 | switch (try result) { |
| 8404 | 8404 | .success => return, |
| 8405 | 8405 | .invalid_character => |bad_index| { |
| ... | ... | @@ -8472,11 +8472,7 @@ fn failNodeNotes( |
| 8472 | 8472 | @setCold(true); |
| 8473 | 8473 | const string_bytes = &astgen.string_bytes; |
| 8474 | 8474 | const msg = @intCast(u32, string_bytes.items.len); |
| 8475 | { | |
| 8476 | var managed = string_bytes.toManaged(astgen.gpa); | |
| 8477 | defer string_bytes.* = managed.toUnmanaged(); | |
| 8478 | try managed.writer().print(format ++ "\x00", args); | |
| 8479 | } | |
| 8475 | try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args); | |
| 8480 | 8476 | const notes_index: u32 = if (notes.len != 0) blk: { |
| 8481 | 8477 | const notes_start = astgen.extra.items.len; |
| 8482 | 8478 | try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len); |
| ... | ... | @@ -8513,11 +8509,7 @@ fn failTokNotes( |
| 8513 | 8509 | @setCold(true); |
| 8514 | 8510 | const string_bytes = &astgen.string_bytes; |
| 8515 | 8511 | const msg = @intCast(u32, string_bytes.items.len); |
| 8516 | { | |
| 8517 | var managed = string_bytes.toManaged(astgen.gpa); | |
| 8518 | defer string_bytes.* = managed.toUnmanaged(); | |
| 8519 | try managed.writer().print(format ++ "\x00", args); | |
| 8520 | } | |
| 8512 | try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args); | |
| 8521 | 8513 | const notes_index: u32 = if (notes.len != 0) blk: { |
| 8522 | 8514 | const notes_start = astgen.extra.items.len; |
| 8523 | 8515 | try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len); |
| ... | ... | @@ -8546,11 +8538,7 @@ fn failOff( |
| 8546 | 8538 | @setCold(true); |
| 8547 | 8539 | const string_bytes = &astgen.string_bytes; |
| 8548 | 8540 | const msg = @intCast(u32, string_bytes.items.len); |
| 8549 | { | |
| 8550 | var managed = string_bytes.toManaged(astgen.gpa); | |
| 8551 | defer string_bytes.* = managed.toUnmanaged(); | |
| 8552 | try managed.writer().print(format ++ "\x00", args); | |
| 8553 | } | |
| 8541 | try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args); | |
| 8554 | 8542 | try astgen.compile_errors.append(astgen.gpa, .{ |
| 8555 | 8543 | .msg = msg, |
| 8556 | 8544 | .node = 0, |
| ... | ... | @@ -8570,11 +8558,7 @@ fn errNoteTok( |
| 8570 | 8558 | @setCold(true); |
| 8571 | 8559 | const string_bytes = &astgen.string_bytes; |
| 8572 | 8560 | const msg = @intCast(u32, string_bytes.items.len); |
| 8573 | { | |
| 8574 | var managed = string_bytes.toManaged(astgen.gpa); | |
| 8575 | defer string_bytes.* = managed.toUnmanaged(); | |
| 8576 | try managed.writer().print(format ++ "\x00", args); | |
| 8577 | } | |
| 8561 | try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args); | |
| 8578 | 8562 | return astgen.addExtra(Zir.Inst.CompileErrors.Item{ |
| 8579 | 8563 | .msg = msg, |
| 8580 | 8564 | .node = 0, |
| ... | ... | @@ -8593,11 +8577,7 @@ fn errNoteNode( |
| 8593 | 8577 | @setCold(true); |
| 8594 | 8578 | const string_bytes = &astgen.string_bytes; |
| 8595 | 8579 | const msg = @intCast(u32, string_bytes.items.len); |
| 8596 | { | |
| 8597 | var managed = string_bytes.toManaged(astgen.gpa); | |
| 8598 | defer string_bytes.* = managed.toUnmanaged(); | |
| 8599 | try managed.writer().print(format ++ "\x00", args); | |
| 8600 | } | |
| 8580 | try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args); | |
| 8601 | 8581 | return astgen.addExtra(Zir.Inst.CompileErrors.Item{ |
| 8602 | 8582 | .msg = msg, |
| 8603 | 8583 | .node = node, |
src/Module.zig+9-9| ... | ... | @@ -470,7 +470,7 @@ pub const Decl = struct { |
| 470 | 470 | pub const DepsTable = std.AutoArrayHashMapUnmanaged(*Decl, void); |
| 471 | 471 | |
| 472 | 472 | pub fn clearName(decl: *Decl, gpa: *Allocator) void { |
| 473 | gpa.free(mem.spanZ(decl.name)); | |
| 473 | gpa.free(mem.sliceTo(decl.name, 0)); | |
| 474 | 474 | decl.name = undefined; |
| 475 | 475 | } |
| 476 | 476 | |
| ... | ... | @@ -627,12 +627,12 @@ pub const Decl = struct { |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | pub fn renderFullyQualifiedName(decl: Decl, writer: anytype) !void { |
| 630 | const unqualified_name = mem.spanZ(decl.name); | |
| 630 | const unqualified_name = mem.sliceTo(decl.name, 0); | |
| 631 | 631 | return decl.src_namespace.renderFullyQualifiedName(unqualified_name, writer); |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | pub fn renderFullyQualifiedDebugName(decl: Decl, writer: anytype) !void { |
| 635 | const unqualified_name = mem.spanZ(decl.name); | |
| 635 | const unqualified_name = mem.sliceTo(decl.name, 0); | |
| 636 | 636 | return decl.src_namespace.renderFullyQualifiedDebugName(unqualified_name, writer); |
| 637 | 637 | } |
| 638 | 638 | |
| ... | ... | @@ -737,7 +737,7 @@ pub const Decl = struct { |
| 737 | 737 | decl.scope.sub_file_path, |
| 738 | 738 | loc.line + 1, |
| 739 | 739 | loc.column + 1, |
| 740 | mem.spanZ(decl.name), | |
| 740 | mem.sliceTo(decl.name, 0), | |
| 741 | 741 | @tagName(decl.analysis), |
| 742 | 742 | }); |
| 743 | 743 | if (decl.has_tv) { |
| ... | ... | @@ -1342,7 +1342,7 @@ pub const Namespace = struct { |
| 1342 | 1342 | ) @TypeOf(writer).Error!void { |
| 1343 | 1343 | if (ns.parent) |parent| { |
| 1344 | 1344 | const decl = ns.getDecl(); |
| 1345 | try parent.renderFullyQualifiedName(mem.spanZ(decl.name), writer); | |
| 1345 | try parent.renderFullyQualifiedName(mem.sliceTo(decl.name, 0), writer); | |
| 1346 | 1346 | } else { |
| 1347 | 1347 | try ns.file_scope.renderFullyQualifiedName(writer); |
| 1348 | 1348 | } |
| ... | ... | @@ -1361,7 +1361,7 @@ pub const Namespace = struct { |
| 1361 | 1361 | var separator_char: u8 = '.'; |
| 1362 | 1362 | if (ns.parent) |parent| { |
| 1363 | 1363 | const decl = ns.getDecl(); |
| 1364 | try parent.renderFullyQualifiedDebugName(mem.spanZ(decl.name), writer); | |
| 1364 | try parent.renderFullyQualifiedDebugName(mem.sliceTo(decl.name, 0), writer); | |
| 1365 | 1365 | } else { |
| 1366 | 1366 | try ns.file_scope.renderFullyQualifiedDebugName(writer); |
| 1367 | 1367 | separator_char = ':'; |
| ... | ... | @@ -3432,7 +3432,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { |
| 3432 | 3432 | return sema.fail(&block_scope, export_src, "export of inline function", .{}); |
| 3433 | 3433 | } |
| 3434 | 3434 | // The scope needs to have the decl in it. |
| 3435 | const options: std.builtin.ExportOptions = .{ .name = mem.spanZ(decl.name) }; | |
| 3435 | const options: std.builtin.ExportOptions = .{ .name = mem.sliceTo(decl.name, 0) }; | |
| 3436 | 3436 | try sema.analyzeExport(&block_scope, export_src, options, decl); |
| 3437 | 3437 | } |
| 3438 | 3438 | return type_changed or is_inline != prev_is_inline; |
| ... | ... | @@ -3501,7 +3501,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { |
| 3501 | 3501 | if (decl.is_exported) { |
| 3502 | 3502 | const export_src = src; // TODO point to the export token |
| 3503 | 3503 | // The scope needs to have the decl in it. |
| 3504 | const options: std.builtin.ExportOptions = .{ .name = mem.spanZ(decl.name) }; | |
| 3504 | const options: std.builtin.ExportOptions = .{ .name = mem.sliceTo(decl.name, 0) }; | |
| 3505 | 3505 | try sema.analyzeExport(&block_scope, export_src, options, decl); |
| 3506 | 3506 | } |
| 3507 | 3507 | |
| ... | ... | @@ -4675,7 +4675,7 @@ pub fn processOutdatedAndDeletedDecls(mod: *Module) !void { |
| 4675 | 4675 | |
| 4676 | 4676 | // Remove from the namespace it resides in, preserving declaration order. |
| 4677 | 4677 | assert(decl.zir_decl_index != 0); |
| 4678 | _ = decl.src_namespace.decls.orderedRemove(mem.spanZ(decl.name)); | |
| 4678 | _ = decl.src_namespace.decls.orderedRemove(mem.sliceTo(decl.name, 0)); | |
| 4679 | 4679 | |
| 4680 | 4680 | try mod.clearDecl(decl, &outdated_decls); |
| 4681 | 4681 | decl.destroy(mod); |
src/Package.zig+1-1| ... | ... | @@ -115,7 +115,7 @@ pub fn deinitTable(pkg: *Package, gpa: *Allocator) void { |
| 115 | 115 | |
| 116 | 116 | pub fn add(pkg: *Package, gpa: *Allocator, name: []const u8, package: *Package) !void { |
| 117 | 117 | try pkg.table.ensureUnusedCapacity(gpa, 1); |
| 118 | const name_dupe = try mem.dupe(gpa, u8, name); | |
| 118 | const name_dupe = try gpa.dupe(u8, name); | |
| 119 | 119 | pkg.table.putAssumeCapacityNoClobber(name_dupe, package); |
| 120 | 120 | } |
| 121 | 121 |
src/Sema.zig+1-1| ... | ... | @@ -1639,7 +1639,7 @@ fn createTypeName(sema: *Sema, block: *Block, name_strategy: Zir.Inst.NameStrate |
| 1639 | 1639 | block.src_decl.name, name_index, |
| 1640 | 1640 | }); |
| 1641 | 1641 | }, |
| 1642 | .parent => return sema.gpa.dupeZ(u8, mem.spanZ(block.src_decl.name)), | |
| 1642 | .parent => return sema.gpa.dupeZ(u8, mem.sliceTo(block.src_decl.name, 0)), | |
| 1643 | 1643 | .func => { |
| 1644 | 1644 | const name_index = sema.mod.getNextAnonNameIndex(); |
| 1645 | 1645 | const name = try std.fmt.allocPrintZ(sema.gpa, "{s}__anon_{d}", .{ |
src/arch/aarch64/CodeGen.zig+1-1| ... | ... | @@ -1501,7 +1501,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void { |
| 1501 | 1501 | }); |
| 1502 | 1502 | } else if (func_value.castTag(.extern_fn)) |func_payload| { |
| 1503 | 1503 | const decl = func_payload.data; |
| 1504 | const n_strx = try macho_file.addExternFn(mem.spanZ(decl.name)); | |
| 1504 | const n_strx = try macho_file.addExternFn(mem.sliceTo(decl.name, 0)); | |
| 1505 | 1505 | |
| 1506 | 1506 | _ = try self.addInst(.{ |
| 1507 | 1507 | .tag = .call_extern, |
src/arch/x86_64/CodeGen.zig+1-1| ... | ... | @@ -1966,7 +1966,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void { |
| 1966 | 1966 | }); |
| 1967 | 1967 | } else if (func_value.castTag(.extern_fn)) |func_payload| { |
| 1968 | 1968 | const decl = func_payload.data; |
| 1969 | const n_strx = try macho_file.addExternFn(mem.spanZ(decl.name)); | |
| 1969 | const n_strx = try macho_file.addExternFn(mem.sliceTo(decl.name, 0)); | |
| 1970 | 1970 | _ = try self.addInst(.{ |
| 1971 | 1971 | .tag = .call_extern, |
| 1972 | 1972 | .ops = undefined, |
src/codegen/c.zig+1-1| ... | ... | @@ -981,7 +981,7 @@ pub const DeclGen = struct { |
| 981 | 981 | if (dg.module.decl_exports.get(decl)) |exports| { |
| 982 | 982 | return writer.writeAll(exports[0].options.name); |
| 983 | 983 | } else if (decl.val.tag() == .extern_fn) { |
| 984 | return writer.writeAll(mem.spanZ(decl.name)); | |
| 984 | return writer.writeAll(mem.sliceTo(decl.name, 0)); | |
| 985 | 985 | } else { |
| 986 | 986 | const gpa = dg.module.gpa; |
| 987 | 987 | const name = try decl.getFullyQualifiedName(gpa); |
src/libc_installation.zig+15-15| ... | ... | @@ -76,7 +76,7 @@ pub const LibCInstallation = struct { |
| 76 | 76 | if (value.len == 0) { |
| 77 | 77 | @field(self, field.name) = null; |
| 78 | 78 | } else { |
| 79 | found_keys[i].allocated = try std.mem.dupeZ(allocator, u8, value); | |
| 79 | found_keys[i].allocated = try allocator.dupeZ(u8, value); | |
| 80 | 80 | @field(self, field.name) = found_keys[i].allocated; |
| 81 | 81 | } |
| 82 | 82 | break; |
| ... | ... | @@ -213,7 +213,7 @@ pub const LibCInstallation = struct { |
| 213 | 213 | errdefer batch.wait() catch {}; |
| 214 | 214 | batch.add(&async self.findNativeIncludeDirPosix(args)); |
| 215 | 215 | batch.add(&async self.findNativeCrtBeginDirHaiku(args)); |
| 216 | self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/system/develop/lib"); | |
| 216 | self.crt_dir = try args.allocator.dupeZ(u8, "/system/develop/lib"); | |
| 217 | 217 | break :blk batch.wait(); |
| 218 | 218 | }; |
| 219 | 219 | } else { |
| ... | ... | @@ -222,8 +222,8 @@ pub const LibCInstallation = struct { |
| 222 | 222 | errdefer batch.wait() catch {}; |
| 223 | 223 | batch.add(&async self.findNativeIncludeDirPosix(args)); |
| 224 | 224 | switch (builtin.target.os.tag) { |
| 225 | .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"), | |
| 226 | .solaris => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib/64"), | |
| 225 | .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib"), | |
| 226 | .solaris => self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib/64"), | |
| 227 | 227 | .linux => batch.add(&async self.findNativeCrtDirPosix(args)), |
| 228 | 228 | else => {}, |
| 229 | 229 | } |
| ... | ... | @@ -344,7 +344,7 @@ pub const LibCInstallation = struct { |
| 344 | 344 | |
| 345 | 345 | if (self.include_dir == null) { |
| 346 | 346 | if (search_dir.accessZ(include_dir_example_file, .{})) |_| { |
| 347 | self.include_dir = try std.mem.dupeZ(allocator, u8, search_path); | |
| 347 | self.include_dir = try allocator.dupeZ(u8, search_path); | |
| 348 | 348 | } else |err| switch (err) { |
| 349 | 349 | error.FileNotFound => {}, |
| 350 | 350 | else => return error.FileSystem, |
| ... | ... | @@ -353,7 +353,7 @@ pub const LibCInstallation = struct { |
| 353 | 353 | |
| 354 | 354 | if (self.sys_include_dir == null) { |
| 355 | 355 | if (search_dir.accessZ(sys_include_dir_example_file, .{})) |_| { |
| 356 | self.sys_include_dir = try std.mem.dupeZ(allocator, u8, search_path); | |
| 356 | self.sys_include_dir = try allocator.dupeZ(u8, search_path); | |
| 357 | 357 | } else |err| switch (err) { |
| 358 | 358 | error.FileNotFound => {}, |
| 359 | 359 | else => return error.FileSystem, |
| ... | ... | @@ -557,7 +557,7 @@ pub const LibCInstallation = struct { |
| 557 | 557 | ) FindError!void { |
| 558 | 558 | const allocator = args.allocator; |
| 559 | 559 | const msvc_lib_dir_ptr = sdk.msvc_lib_dir_ptr orelse return error.LibCRuntimeNotFound; |
| 560 | self.msvc_lib_dir = try std.mem.dupeZ(allocator, u8, msvc_lib_dir_ptr[0..sdk.msvc_lib_dir_len]); | |
| 560 | self.msvc_lib_dir = try allocator.dupeZ(u8, msvc_lib_dir_ptr[0..sdk.msvc_lib_dir_len]); | |
| 561 | 561 | } |
| 562 | 562 | }; |
| 563 | 563 | |
| ... | ... | @@ -631,10 +631,10 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 { |
| 631 | 631 | // So we detect failure by checking if the output matches exactly the input. |
| 632 | 632 | if (std.mem.eql(u8, line, args.search_basename)) return error.LibCRuntimeNotFound; |
| 633 | 633 | switch (args.want_dirname) { |
| 634 | .full_path => return std.mem.dupeZ(allocator, u8, line), | |
| 634 | .full_path => return allocator.dupeZ(u8, line), | |
| 635 | 635 | .only_dir => { |
| 636 | 636 | const dirname = fs.path.dirname(line) orelse return error.LibCRuntimeNotFound; |
| 637 | return std.mem.dupeZ(allocator, u8, dirname); | |
| 637 | return allocator.dupeZ(u8, dirname); | |
| 638 | 638 | }, |
| 639 | 639 | } |
| 640 | 640 | } |
| ... | ... | @@ -648,17 +648,17 @@ fn printVerboseInvocation( |
| 648 | 648 | if (!verbose) return; |
| 649 | 649 | |
| 650 | 650 | if (search_basename) |s| { |
| 651 | std.debug.warn("Zig attempted to find the file '{s}' by executing this command:\n", .{s}); | |
| 651 | std.debug.print("Zig attempted to find the file '{s}' by executing this command:\n", .{s}); | |
| 652 | 652 | } else { |
| 653 | std.debug.warn("Zig attempted to find the path to native system libc headers by executing this command:\n", .{}); | |
| 653 | std.debug.print("Zig attempted to find the path to native system libc headers by executing this command:\n", .{}); | |
| 654 | 654 | } |
| 655 | 655 | for (argv) |arg, i| { |
| 656 | if (i != 0) std.debug.warn(" ", .{}); | |
| 657 | std.debug.warn("{s}", .{arg}); | |
| 656 | if (i != 0) std.debug.print(" ", .{}); | |
| 657 | std.debug.print("{s}", .{arg}); | |
| 658 | 658 | } |
| 659 | std.debug.warn("\n", .{}); | |
| 659 | std.debug.print("\n", .{}); | |
| 660 | 660 | if (stderr) |s| { |
| 661 | std.debug.warn("Output:\n==========\n{s}\n==========\n", .{s}); | |
| 661 | std.debug.print("Output:\n==========\n{s}\n==========\n", .{s}); | |
| 662 | 662 | } |
| 663 | 663 | } |
| 664 | 664 |
src/link/Coff.zig+1-1| ... | ... | @@ -752,7 +752,7 @@ fn finishUpdateDecl(self: *Coff, module: *Module, decl: *Module.Decl, code: []co |
| 752 | 752 | } else { |
| 753 | 753 | const vaddr = try self.allocateTextBlock(&decl.link.coff, code.len, required_alignment); |
| 754 | 754 | log.debug("allocated text block for {s} at 0x{x} (size: {Bi})\n", .{ |
| 755 | mem.spanZ(decl.name), | |
| 755 | mem.sliceTo(decl.name, 0), | |
| 756 | 756 | vaddr, |
| 757 | 757 | std.fmt.fmtIntSizeDec(code.len), |
| 758 | 758 | }); |
src/link/Elf.zig+4-4| ... | ... | @@ -429,7 +429,7 @@ fn makeDebugString(self: *Elf, bytes: []const u8) !u32 { |
| 429 | 429 | |
| 430 | 430 | fn getString(self: *Elf, str_off: u32) []const u8 { |
| 431 | 431 | assert(str_off < self.shstrtab.items.len); |
| 432 | return mem.spanZ(@ptrCast([*:0]const u8, self.shstrtab.items.ptr + str_off)); | |
| 432 | return mem.sliceTo(@ptrCast([*:0]const u8, self.shstrtab.items.ptr + str_off), 0); | |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | fn updateString(self: *Elf, old_str_off: u32, new_name: []const u8) !u32 { |
| ... | ... | @@ -2236,14 +2236,14 @@ fn updateDeclCode(self: *Elf, decl: *Module.Decl, code: []const u8, stt_bits: u8 |
| 2236 | 2236 | self.shrinkTextBlock(&decl.link.elf, code.len); |
| 2237 | 2237 | } |
| 2238 | 2238 | local_sym.st_size = code.len; |
| 2239 | local_sym.st_name = try self.updateString(local_sym.st_name, mem.spanZ(decl.name)); | |
| 2239 | local_sym.st_name = try self.updateString(local_sym.st_name, mem.sliceTo(decl.name, 0)); | |
| 2240 | 2240 | local_sym.st_info = (elf.STB_LOCAL << 4) | stt_bits; |
| 2241 | 2241 | local_sym.st_other = 0; |
| 2242 | 2242 | local_sym.st_shndx = self.text_section_index.?; |
| 2243 | 2243 | // TODO this write could be avoided if no fields of the symbol were changed. |
| 2244 | 2244 | try self.writeSymbol(decl.link.elf.local_sym_index); |
| 2245 | 2245 | } else { |
| 2246 | const decl_name = mem.spanZ(decl.name); | |
| 2246 | const decl_name = mem.sliceTo(decl.name, 0); | |
| 2247 | 2247 | const name_str_index = try self.makeString(decl_name); |
| 2248 | 2248 | const vaddr = try self.allocateTextBlock(&decl.link.elf, code.len, required_alignment); |
| 2249 | 2249 | log.debug("allocated text block for {s} at 0x{x}", .{ decl_name, vaddr }); |
| ... | ... | @@ -2371,7 +2371,7 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven |
| 2371 | 2371 | dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy); |
| 2372 | 2372 | |
| 2373 | 2373 | // .debug_info subprogram |
| 2374 | const decl_name_with_null = decl.name[0 .. mem.lenZ(decl.name) + 1]; | |
| 2374 | const decl_name_with_null = decl.name[0 .. mem.sliceTo(decl.name, 0).len + 1]; | |
| 2375 | 2375 | try dbg_info_buffer.ensureUnusedCapacity(25 + decl_name_with_null.len); |
| 2376 | 2376 | |
| 2377 | 2377 | const fn_ret_type = decl.ty.fnReturnType(); |
src/link/MachO.zig+9-5| ... | ... | @@ -3439,7 +3439,9 @@ fn placeDecl(self: *MachO, decl: *Module.Decl, code_len: usize) !*macho.nlist_64 |
| 3439 | 3439 | decl.link.macho.size = code_len; |
| 3440 | 3440 | decl.link.macho.dirty = true; |
| 3441 | 3441 | |
| 3442 | const new_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{mem.spanZ(decl.name)}); | |
| 3442 | const new_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{ | |
| 3443 | mem.sliceTo(decl.name, 0), | |
| 3444 | }); | |
| 3443 | 3445 | defer self.base.allocator.free(new_name); |
| 3444 | 3446 | |
| 3445 | 3447 | symbol.n_strx = try self.makeString(new_name); |
| ... | ... | @@ -3447,7 +3449,9 @@ fn placeDecl(self: *MachO, decl: *Module.Decl, code_len: usize) !*macho.nlist_64 |
| 3447 | 3449 | symbol.n_sect = @intCast(u8, self.text_section_index.?) + 1; |
| 3448 | 3450 | symbol.n_desc = 0; |
| 3449 | 3451 | } else { |
| 3450 | const decl_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{mem.spanZ(decl.name)}); | |
| 3452 | const decl_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{ | |
| 3453 | mem.sliceTo(decl.name, 0), | |
| 3454 | }); | |
| 3451 | 3455 | defer self.base.allocator.free(decl_name); |
| 3452 | 3456 | |
| 3453 | 3457 | const name_str_index = try self.makeString(decl_name); |
| ... | ... | @@ -4045,7 +4049,7 @@ pub fn populateMissingMetadata(self: *MachO) !void { |
| 4045 | 4049 | self.dylinker_cmd_index = @intCast(u16, self.load_commands.items.len); |
| 4046 | 4050 | const cmdsize = @intCast(u32, mem.alignForwardGeneric( |
| 4047 | 4051 | u64, |
| 4048 | @sizeOf(macho.dylinker_command) + mem.lenZ(default_dyld_path), | |
| 4052 | @sizeOf(macho.dylinker_command) + mem.sliceTo(default_dyld_path, 0).len, | |
| 4049 | 4053 | @sizeOf(u64), |
| 4050 | 4054 | )); |
| 4051 | 4055 | var dylinker_cmd = commands.emptyGenericCommandWithData(macho.dylinker_command{ |
| ... | ... | @@ -4055,7 +4059,7 @@ pub fn populateMissingMetadata(self: *MachO) !void { |
| 4055 | 4059 | }); |
| 4056 | 4060 | dylinker_cmd.data = try self.base.allocator.alloc(u8, cmdsize - dylinker_cmd.inner.name); |
| 4057 | 4061 | mem.set(u8, dylinker_cmd.data, 0); |
| 4058 | mem.copy(u8, dylinker_cmd.data, mem.spanZ(default_dyld_path)); | |
| 4062 | mem.copy(u8, dylinker_cmd.data, mem.sliceTo(default_dyld_path, 0)); | |
| 4059 | 4063 | try self.load_commands.append(self.base.allocator, .{ .Dylinker = dylinker_cmd }); |
| 4060 | 4064 | self.load_commands_dirty = true; |
| 4061 | 4065 | } |
| ... | ... | @@ -5292,7 +5296,7 @@ pub fn makeString(self: *MachO, string: []const u8) !u32 { |
| 5292 | 5296 | |
| 5293 | 5297 | pub fn getString(self: *MachO, off: u32) []const u8 { |
| 5294 | 5298 | assert(off < self.strtab.items.len); |
| 5295 | return mem.spanZ(@ptrCast([*:0]const u8, self.strtab.items.ptr + off)); | |
| 5299 | return mem.sliceTo(@ptrCast([*:0]const u8, self.strtab.items.ptr + off), 0); | |
| 5296 | 5300 | } |
| 5297 | 5301 | |
| 5298 | 5302 | pub fn symbolIsStab(sym: macho.nlist_64) bool { |
src/link/MachO/Archive.zig+1-1| ... | ... | @@ -175,7 +175,7 @@ fn parseTableOfContents(self: *Archive, allocator: *Allocator, reader: anytype) |
| 175 | 175 | }; |
| 176 | 176 | const object_offset = try symtab_reader.readIntLittle(u32); |
| 177 | 177 | |
| 178 | const sym_name = mem.spanZ(@ptrCast([*:0]const u8, strtab.ptr + n_strx)); | |
| 178 | const sym_name = mem.sliceTo(@ptrCast([*:0]const u8, strtab.ptr + n_strx), 0); | |
| 179 | 179 | const owned_name = try allocator.dupe(u8, sym_name); |
| 180 | 180 | const res = try self.toc.getOrPut(allocator, owned_name); |
| 181 | 181 | defer if (res.found_existing) allocator.free(owned_name); |
src/link/MachO/DebugSymbols.zig+1-1| ... | ... | @@ -884,7 +884,7 @@ pub fn initDeclDebugBuffers( |
| 884 | 884 | dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy); |
| 885 | 885 | |
| 886 | 886 | // .debug_info subprogram |
| 887 | const decl_name_with_null = decl.name[0 .. mem.lenZ(decl.name) + 1]; | |
| 887 | const decl_name_with_null = decl.name[0 .. mem.sliceTo(decl.name, 0).len + 1]; | |
| 888 | 888 | try dbg_info_buffer.ensureUnusedCapacity(27 + decl_name_with_null.len); |
| 889 | 889 | |
| 890 | 890 | const fn_ret_type = decl.ty.fnReturnType(); |
src/link/MachO/Dylib.zig+2-2| ... | ... | @@ -56,7 +56,7 @@ pub const Id = struct { |
| 56 | 56 | pub fn fromLoadCommand(allocator: *Allocator, lc: commands.GenericCommandWithData(macho.dylib_command)) !Id { |
| 57 | 57 | const dylib = lc.inner.dylib; |
| 58 | 58 | const dylib_name = @ptrCast([*:0]const u8, lc.data[dylib.name - @sizeOf(macho.dylib_command) ..]); |
| 59 | const name = try allocator.dupe(u8, mem.spanZ(dylib_name)); | |
| 59 | const name = try allocator.dupe(u8, mem.sliceTo(dylib_name, 0)); | |
| 60 | 60 | |
| 61 | 61 | return Id{ |
| 62 | 62 | .name = name, |
| ... | ... | @@ -230,7 +230,7 @@ fn parseSymbols(self: *Dylib, allocator: *Allocator) !void { |
| 230 | 230 | |
| 231 | 231 | if (!add_to_symtab) continue; |
| 232 | 232 | |
| 233 | const sym_name = mem.spanZ(@ptrCast([*:0]const u8, strtab.ptr + sym.n_strx)); | |
| 233 | const sym_name = mem.sliceTo(@ptrCast([*:0]const u8, strtab.ptr + sym.n_strx), 0); | |
| 234 | 234 | const name = try allocator.dupe(u8, sym_name); |
| 235 | 235 | try self.symbols.putNoClobber(allocator, name, {}); |
| 236 | 236 | } |
src/link/MachO/Object.zig+1-1| ... | ... | @@ -633,5 +633,5 @@ fn readSection(self: Object, allocator: *Allocator, index: u16) ![]u8 { |
| 633 | 633 | |
| 634 | 634 | pub fn getString(self: Object, off: u32) []const u8 { |
| 635 | 635 | assert(off < self.strtab.items.len); |
| 636 | return mem.spanZ(@ptrCast([*:0]const u8, self.strtab.items.ptr + off)); | |
| 636 | return mem.sliceTo(@ptrCast([*:0]const u8, self.strtab.items.ptr + off), 0); | |
| 637 | 637 | } |
src/link/Plan9.zig+1-1| ... | ... | @@ -299,7 +299,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl: *Module.Decl) !void { |
| 299 | 299 | return; |
| 300 | 300 | }, |
| 301 | 301 | }; |
| 302 | var duped_code = try std.mem.dupe(self.base.allocator, u8, code); | |
| 302 | var duped_code = try self.base.allocator.dupe(u8, code); | |
| 303 | 303 | errdefer self.base.allocator.free(duped_code); |
| 304 | 304 | try self.data_decl_table.put(self.base.allocator, decl, duped_code); |
| 305 | 305 | return self.updateFinish(decl); |
src/main.zig+2-2| ... | ... | @@ -1282,7 +1282,7 @@ fn buildOutputType( |
| 1282 | 1282 | try clang_argv.appendSlice(it.other_args); |
| 1283 | 1283 | }, |
| 1284 | 1284 | .positional => { |
| 1285 | const file_ext = Compilation.classifyFileExt(mem.spanZ(it.only_arg)); | |
| 1285 | const file_ext = Compilation.classifyFileExt(mem.sliceTo(it.only_arg, 0)); | |
| 1286 | 1286 | switch (file_ext) { |
| 1287 | 1287 | .assembly, .c, .cpp, .ll, .bc, .h, .m, .mm => try c_source_files.append(.{ .src_path = it.only_arg }), |
| 1288 | 1288 | .unknown, .shared_library, .object, .static_library => { |
| ... | ... | @@ -4117,7 +4117,7 @@ pub const ClangArgIterator = struct { |
| 4117 | 4117 | } |
| 4118 | 4118 | } |
| 4119 | 4119 | while (it.next()) |token| { |
| 4120 | const dupe_token = try mem.dupeZ(allocator, u8, token); | |
| 4120 | const dupe_token = try allocator.dupeZ(u8, token); | |
| 4121 | 4121 | errdefer allocator.free(dupe_token); |
| 4122 | 4122 | try resp_arg_list.append(dupe_token); |
| 4123 | 4123 | } |
src/stage1.zig+3-3| ... | ... | @@ -42,7 +42,7 @@ pub fn main(argc: c_int, argv: [*][*:0]u8) callconv(.C) c_int { |
| 42 | 42 | |
| 43 | 43 | const args = arena.alloc([]const u8, @intCast(usize, argc)) catch fatal("{s}", .{"OutOfMemory"}); |
| 44 | 44 | for (args) |*arg, i| { |
| 45 | arg.* = mem.spanZ(argv[i]); | |
| 45 | arg.* = mem.sliceTo(argv[i], 0); | |
| 46 | 46 | } |
| 47 | 47 | if (builtin.mode == .Debug) { |
| 48 | 48 | stage2.mainArgs(gpa, arena, args) catch unreachable; |
| ... | ... | @@ -434,14 +434,14 @@ export fn stage2_add_link_lib( |
| 434 | 434 | return null; |
| 435 | 435 | } |
| 436 | 436 | if (!target.isWasm() and !comp.bin_file.options.pic) { |
| 437 | return std.fmt.allocPrint0( | |
| 437 | return std.fmt.allocPrintZ( | |
| 438 | 438 | comp.gpa, |
| 439 | 439 | "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.", |
| 440 | 440 | .{ lib_name, lib_name }, |
| 441 | 441 | ) catch "out of memory"; |
| 442 | 442 | } |
| 443 | 443 | comp.stage1AddLinkLib(lib_name) catch |err| { |
| 444 | return std.fmt.allocPrint0(comp.gpa, "unable to add link lib '{s}': {s}", .{ | |
| 444 | return std.fmt.allocPrintZ(comp.gpa, "unable to add link lib '{s}': {s}", .{ | |
| 445 | 445 | lib_name, @errorName(err), |
| 446 | 446 | }) catch "out of memory"; |
| 447 | 447 | }; |
src/translate_c.zig+3-3| ... | ... | @@ -335,7 +335,7 @@ pub const Context = struct { |
| 335 | 335 | |
| 336 | 336 | /// Convert a null-terminated C string to a slice allocated in the arena |
| 337 | 337 | fn str(c: *Context, s: [*:0]const u8) ![]u8 { |
| 338 | return mem.dupe(c.arena, u8, mem.spanZ(s)); | |
| 338 | return c.arena.dupe(u8, mem.sliceTo(s, 0)); | |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /// Convert a clang source location to a file:line:column string |
| ... | ... | @@ -2553,7 +2553,7 @@ fn transInitListExprRecord( |
| 2553 | 2553 | var raw_name = try c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin()); |
| 2554 | 2554 | if (field_decl.isAnonymousStructOrUnion()) { |
| 2555 | 2555 | const name = c.decl_table.get(@ptrToInt(field_decl.getCanonicalDecl())).?; |
| 2556 | raw_name = try mem.dupe(c.arena, u8, name); | |
| 2556 | raw_name = try c.arena.dupe(u8, name); | |
| 2557 | 2557 | } |
| 2558 | 2558 | |
| 2559 | 2559 | var init_expr = try transExpr(c, scope, elem_expr, .used); |
| ... | ... | @@ -3318,7 +3318,7 @@ fn transMemberExpr(c: *Context, scope: *Scope, stmt: *const clang.MemberExpr, re |
| 3318 | 3318 | const field_decl = @ptrCast(*const clang.FieldDecl, member_decl); |
| 3319 | 3319 | if (field_decl.isAnonymousStructOrUnion()) { |
| 3320 | 3320 | const name = c.decl_table.get(@ptrToInt(field_decl.getCanonicalDecl())).?; |
| 3321 | break :blk try mem.dupe(c.arena, u8, name); | |
| 3321 | break :blk try c.arena.dupe(u8, name); | |
| 3322 | 3322 | } |
| 3323 | 3323 | } |
| 3324 | 3324 | const decl = @ptrCast(*const clang.NamedDecl, member_decl); |
src/type.zig+1-1| ... | ... | @@ -1179,7 +1179,7 @@ pub const Type = extern union { |
| 1179 | 1179 | }, |
| 1180 | 1180 | .error_set => { |
| 1181 | 1181 | const error_set = ty.castTag(.error_set).?.data; |
| 1182 | return writer.writeAll(std.mem.spanZ(error_set.owner_decl.name)); | |
| 1182 | return writer.writeAll(std.mem.sliceTo(error_set.owner_decl.name, 0)); | |
| 1183 | 1183 | }, |
| 1184 | 1184 | .error_set_inferred => { |
| 1185 | 1185 | const func = ty.castTag(.error_set_inferred).?.data.func; |
src/value.zig+2-2| ... | ... | @@ -753,9 +753,9 @@ pub const Value = extern union { |
| 753 | 753 | const bytes = val.castTag(.bytes).?.data; |
| 754 | 754 | const adjusted_len = bytes.len - @boolToInt(ty.sentinel() != null); |
| 755 | 755 | const adjusted_bytes = bytes[0..adjusted_len]; |
| 756 | return std.mem.dupe(allocator, u8, adjusted_bytes); | |
| 756 | return allocator.dupe(u8, adjusted_bytes); | |
| 757 | 757 | }, |
| 758 | .enum_literal => return std.mem.dupe(allocator, u8, val.castTag(.enum_literal).?.data), | |
| 758 | .enum_literal => return allocator.dupe(u8, val.castTag(.enum_literal).?.data), | |
| 759 | 759 | .repeated => @panic("TODO implement toAllocatedBytes for this Value tag"), |
| 760 | 760 | .decl_ref => { |
| 761 | 761 | const decl = val.castTag(.decl_ref).?.data; |
test/behavior/async_fn.zig+2-2| ... | ... | @@ -715,7 +715,7 @@ fn testAsyncAwaitTypicalUsage( |
| 715 | 715 | var global_download_frame: anyframe = undefined; |
| 716 | 716 | fn fetchUrl(allocator: *std.mem.Allocator, url: []const u8) anyerror![]u8 { |
| 717 | 717 | _ = url; |
| 718 | const result = try std.mem.dupe(allocator, u8, "expected download text"); | |
| 718 | const result = try allocator.dupe(u8, "expected download text"); | |
| 719 | 719 | errdefer allocator.free(result); |
| 720 | 720 | if (suspend_download) { |
| 721 | 721 | suspend { |
| ... | ... | @@ -729,7 +729,7 @@ fn testAsyncAwaitTypicalUsage( |
| 729 | 729 | var global_file_frame: anyframe = undefined; |
| 730 | 730 | fn readFile(allocator: *std.mem.Allocator, filename: []const u8) anyerror![]u8 { |
| 731 | 731 | _ = filename; |
| 732 | const result = try std.mem.dupe(allocator, u8, "expected file text"); | |
| 732 | const result = try allocator.dupe(u8, "expected file text"); | |
| 733 | 733 | errdefer allocator.free(result); |
| 734 | 734 | if (suspend_file) { |
| 735 | 735 | suspend { |
test/behavior/cast_stage1.zig+1-1| ... | ... | @@ -171,7 +171,7 @@ fn testCastPtrOfArrayToSliceAndPtr() !void { |
| 171 | 171 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 172 | 172 | const window_name = [1][*]const u8{"window name"}; |
| 173 | 173 | const x: [*]const ?[*]const u8 = &window_name; |
| 174 | try expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name")); | |
| 174 | try expect(mem.eql(u8, std.mem.sliceTo(@ptrCast([*:0]const u8, x[0].?), 0), "window name")); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | test "cast f16 to wider types" { |
test/behavior/pointers_stage1.zig+1-1| ... | ... | @@ -142,7 +142,7 @@ test "null terminated pointer" { |
| 142 | 142 | var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); |
| 143 | 143 | var no_zero_ptr: [*]const u8 = zero_ptr; |
| 144 | 144 | var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr); |
| 145 | try expect(std.mem.eql(u8, std.mem.spanZ(zero_ptr_again), "hello")); | |
| 145 | try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello")); | |
| 146 | 146 | } |
| 147 | 147 | }; |
| 148 | 148 | try S.doTheTest(); |
test/cli.zig+10-10| ... | ... | @@ -19,11 +19,11 @@ pub fn main() !void { |
| 19 | 19 | a = &arena.allocator; |
| 20 | 20 | |
| 21 | 21 | const zig_exe_rel = try (arg_it.next(a) orelse { |
| 22 | std.debug.warn("Expected first argument to be path to zig compiler\n", .{}); | |
| 22 | std.debug.print("Expected first argument to be path to zig compiler\n", .{}); | |
| 23 | 23 | return error.InvalidArgs; |
| 24 | 24 | }); |
| 25 | 25 | const cache_root = try (arg_it.next(a) orelse { |
| 26 | std.debug.warn("Expected second argument to be cache root directory path\n", .{}); | |
| 26 | std.debug.print("Expected second argument to be cache root directory path\n", .{}); | |
| 27 | 27 | return error.InvalidArgs; |
| 28 | 28 | }); |
| 29 | 29 | const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel}); |
| ... | ... | @@ -47,11 +47,11 @@ pub fn main() !void { |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | fn printCmd(cwd: []const u8, argv: []const []const u8) void { |
| 50 | std.debug.warn("cd {s} && ", .{cwd}); | |
| 50 | std.debug.print("cd {s} && ", .{cwd}); | |
| 51 | 51 | for (argv) |arg| { |
| 52 | std.debug.warn("{s} ", .{arg}); | |
| 52 | std.debug.print("{s} ", .{arg}); | |
| 53 | 53 | } |
| 54 | std.debug.warn("\n", .{}); | |
| 54 | std.debug.print("\n", .{}); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess.ExecResult { |
| ... | ... | @@ -62,23 +62,23 @@ fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess |
| 62 | 62 | .cwd = cwd, |
| 63 | 63 | .max_output_bytes = max_output_size, |
| 64 | 64 | }) catch |err| { |
| 65 | std.debug.warn("The following command failed:\n", .{}); | |
| 65 | std.debug.print("The following command failed:\n", .{}); | |
| 66 | 66 | printCmd(cwd, argv); |
| 67 | 67 | return err; |
| 68 | 68 | }; |
| 69 | 69 | switch (result.term) { |
| 70 | 70 | .Exited => |code| { |
| 71 | 71 | if ((code != 0) == expect_0) { |
| 72 | std.debug.warn("The following command exited with error code {}:\n", .{code}); | |
| 72 | std.debug.print("The following command exited with error code {}:\n", .{code}); | |
| 73 | 73 | printCmd(cwd, argv); |
| 74 | std.debug.warn("stderr:\n{s}\n", .{result.stderr}); | |
| 74 | std.debug.print("stderr:\n{s}\n", .{result.stderr}); | |
| 75 | 75 | return error.CommandFailed; |
| 76 | 76 | } |
| 77 | 77 | }, |
| 78 | 78 | else => { |
| 79 | std.debug.warn("The following command terminated unexpectedly:\n", .{}); | |
| 79 | std.debug.print("The following command terminated unexpectedly:\n", .{}); | |
| 80 | 80 | printCmd(cwd, argv); |
| 81 | std.debug.warn("stderr:\n{s}\n", .{result.stderr}); | |
| 81 | std.debug.print("stderr:\n{s}\n", .{result.stderr}); | |
| 82 | 82 | return error.CommandFailed; |
| 83 | 83 | }, |
| 84 | 84 | } |
test/src/compare_output.zig-1| ... | ... | @@ -6,7 +6,6 @@ const ArrayList = std.ArrayList; |
| 6 | 6 | const fmt = std.fmt; |
| 7 | 7 | const mem = std.mem; |
| 8 | 8 | const fs = std.fs; |
| 9 | const warn = std.debug.warn; | |
| 10 | 9 | const Mode = std.builtin.Mode; |
| 11 | 10 | |
| 12 | 11 | pub const CompareOutputContext = struct { |
test/src/run_translated_c.zig-1| ... | ... | @@ -6,7 +6,6 @@ const ArrayList = std.ArrayList; |
| 6 | 6 | const fmt = std.fmt; |
| 7 | 7 | const mem = std.mem; |
| 8 | 8 | const fs = std.fs; |
| 9 | const warn = std.debug.warn; | |
| 10 | 9 | |
| 11 | 10 | pub const RunTranslatedCContext = struct { |
| 12 | 11 | b: *build.Builder, |
test/src/translate_c.zig-1| ... | ... | @@ -6,7 +6,6 @@ const ArrayList = std.ArrayList; |
| 6 | 6 | const fmt = std.fmt; |
| 7 | 7 | const mem = std.mem; |
| 8 | 8 | const fs = std.fs; |
| 9 | const warn = std.debug.warn; | |
| 10 | 9 | const CrossTarget = std.zig.CrossTarget; |
| 11 | 10 | |
| 12 | 11 | pub const TranslateCContext = struct { |
test/tests.zig+12-13| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const debug = std.debug; |
| 4 | const warn = debug.warn; | |
| 5 | 4 | const build = std.build; |
| 6 | 5 | const CrossTarget = std.zig.CrossTarget; |
| 7 | 6 | const io = std.io; |
| ... | ... | @@ -716,7 +715,7 @@ pub const StackTracesContext = struct { |
| 716 | 715 | defer args.deinit(); |
| 717 | 716 | args.append(full_exe_path) catch unreachable; |
| 718 | 717 | |
| 719 | warn("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name }); | |
| 718 | std.debug.print("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name }); | |
| 720 | 719 | |
| 721 | 720 | const child = std.ChildProcess.init(args.items, b.allocator) catch unreachable; |
| 722 | 721 | defer child.deinit(); |
| ... | ... | @@ -745,7 +744,7 @@ pub const StackTracesContext = struct { |
| 745 | 744 | .Exited => |code| { |
| 746 | 745 | const expect_code: u32 = 1; |
| 747 | 746 | if (code != expect_code) { |
| 748 | warn("Process {s} exited with error code {d} but expected code {d}\n", .{ | |
| 747 | std.debug.print("Process {s} exited with error code {d} but expected code {d}\n", .{ | |
| 749 | 748 | full_exe_path, |
| 750 | 749 | code, |
| 751 | 750 | expect_code, |
| ... | ... | @@ -755,17 +754,17 @@ pub const StackTracesContext = struct { |
| 755 | 754 | } |
| 756 | 755 | }, |
| 757 | 756 | .Signal => |signum| { |
| 758 | warn("Process {s} terminated on signal {d}\n", .{ full_exe_path, signum }); | |
| 757 | std.debug.print("Process {s} terminated on signal {d}\n", .{ full_exe_path, signum }); | |
| 759 | 758 | printInvocation(args.items); |
| 760 | 759 | return error.TestFailed; |
| 761 | 760 | }, |
| 762 | 761 | .Stopped => |signum| { |
| 763 | warn("Process {s} stopped on signal {d}\n", .{ full_exe_path, signum }); | |
| 762 | std.debug.print("Process {s} stopped on signal {d}\n", .{ full_exe_path, signum }); | |
| 764 | 763 | printInvocation(args.items); |
| 765 | 764 | return error.TestFailed; |
| 766 | 765 | }, |
| 767 | 766 | .Unknown => |code| { |
| 768 | warn("Process {s} terminated unexpectedly with error code {d}\n", .{ full_exe_path, code }); | |
| 767 | std.debug.print("Process {s} terminated unexpectedly with error code {d}\n", .{ full_exe_path, code }); | |
| 769 | 768 | printInvocation(args.items); |
| 770 | 769 | return error.TestFailed; |
| 771 | 770 | }, |
| ... | ... | @@ -829,7 +828,7 @@ pub const StackTracesContext = struct { |
| 829 | 828 | }; |
| 830 | 829 | |
| 831 | 830 | if (!mem.eql(u8, self.expect_output, got)) { |
| 832 | warn( | |
| 831 | std.debug.print( | |
| 833 | 832 | \\ |
| 834 | 833 | \\========= Expected this output: ========= |
| 835 | 834 | \\{s} |
| ... | ... | @@ -839,7 +838,7 @@ pub const StackTracesContext = struct { |
| 839 | 838 | , .{ self.expect_output, got }); |
| 840 | 839 | return error.TestFailed; |
| 841 | 840 | } |
| 842 | warn("OK\n", .{}); | |
| 841 | std.debug.print("OK\n", .{}); | |
| 843 | 842 | } |
| 844 | 843 | }; |
| 845 | 844 | }; |
| ... | ... | @@ -1003,14 +1002,14 @@ pub const GenHContext = struct { |
| 1003 | 1002 | const self = @fieldParentPtr(GenHCmpOutputStep, "step", step); |
| 1004 | 1003 | const b = self.context.b; |
| 1005 | 1004 | |
| 1006 | warn("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name }); | |
| 1005 | std.debug.print("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name }); | |
| 1007 | 1006 | |
| 1008 | 1007 | const full_h_path = self.obj.getOutputHPath(); |
| 1009 | 1008 | const actual_h = try io.readFileAlloc(b.allocator, full_h_path); |
| 1010 | 1009 | |
| 1011 | 1010 | for (self.case.expected_lines.items) |expected_line| { |
| 1012 | 1011 | if (mem.indexOf(u8, actual_h, expected_line) == null) { |
| 1013 | warn( | |
| 1012 | std.debug.print( | |
| 1014 | 1013 | \\ |
| 1015 | 1014 | \\========= Expected this output: ================ |
| 1016 | 1015 | \\{s} |
| ... | ... | @@ -1021,7 +1020,7 @@ pub const GenHContext = struct { |
| 1021 | 1020 | return error.TestFailed; |
| 1022 | 1021 | } |
| 1023 | 1022 | } |
| 1024 | warn("OK\n", .{}); | |
| 1023 | std.debug.print("OK\n", .{}); | |
| 1025 | 1024 | } |
| 1026 | 1025 | }; |
| 1027 | 1026 | |
| ... | ... | @@ -1077,7 +1076,7 @@ pub const GenHContext = struct { |
| 1077 | 1076 | |
| 1078 | 1077 | fn printInvocation(args: []const []const u8) void { |
| 1079 | 1078 | for (args) |arg| { |
| 1080 | warn("{s} ", .{arg}); | |
| 1079 | std.debug.print("{s} ", .{arg}); | |
| 1081 | 1080 | } |
| 1082 | warn("\n", .{}); | |
| 1081 | std.debug.print("\n", .{}); | |
| 1083 | 1082 | } |
tools/process_headers.zig+13-13| ... | ... | @@ -295,7 +295,7 @@ pub fn main() !void { |
| 295 | 295 | if (std.mem.eql(u8, args[arg_i], "--help")) |
| 296 | 296 | usageAndExit(args[0]); |
| 297 | 297 | if (arg_i + 1 >= args.len) { |
| 298 | std.debug.warn("expected argument after '{s}'\n", .{args[arg_i]}); | |
| 298 | std.debug.print("expected argument after '{s}'\n", .{args[arg_i]}); | |
| 299 | 299 | usageAndExit(args[0]); |
| 300 | 300 | } |
| 301 | 301 | |
| ... | ... | @@ -308,7 +308,7 @@ pub fn main() !void { |
| 308 | 308 | assert(opt_abi == null); |
| 309 | 309 | opt_abi = args[arg_i + 1]; |
| 310 | 310 | } else { |
| 311 | std.debug.warn("unrecognized argument: {s}\n", .{args[arg_i]}); | |
| 311 | std.debug.print("unrecognized argument: {s}\n", .{args[arg_i]}); | |
| 312 | 312 | usageAndExit(args[0]); |
| 313 | 313 | } |
| 314 | 314 | |
| ... | ... | @@ -322,7 +322,7 @@ pub fn main() !void { |
| 322 | 322 | else if (std.mem.eql(u8, abi_name, "glibc")) |
| 323 | 323 | LibCVendor.glibc |
| 324 | 324 | else { |
| 325 | std.debug.warn("unrecognized C ABI: {s}\n", .{abi_name}); | |
| 325 | std.debug.print("unrecognized C ABI: {s}\n", .{abi_name}); | |
| 326 | 326 | usageAndExit(args[0]); |
| 327 | 327 | }; |
| 328 | 328 | const generic_name = try std.fmt.allocPrint(allocator, "generic-{s}", .{abi_name}); |
| ... | ... | @@ -393,7 +393,7 @@ pub fn main() !void { |
| 393 | 393 | if (gop.found_existing) { |
| 394 | 394 | max_bytes_saved += raw_bytes.len; |
| 395 | 395 | gop.value_ptr.hit_count += 1; |
| 396 | std.debug.warn("duplicate: {s} {s} ({:2})\n", .{ | |
| 396 | std.debug.print("duplicate: {s} {s} ({:2})\n", .{ | |
| 397 | 397 | libc_target.name, |
| 398 | 398 | rel_path, |
| 399 | 399 | std.fmt.fmtIntSizeDec(raw_bytes.len), |
| ... | ... | @@ -415,16 +415,16 @@ pub fn main() !void { |
| 415 | 415 | }; |
| 416 | 416 | try target_to_hash.putNoClobber(dest_target, hash); |
| 417 | 417 | }, |
| 418 | else => std.debug.warn("warning: weird file: {s}\n", .{full_path}), | |
| 418 | else => std.debug.print("warning: weird file: {s}\n", .{full_path}), | |
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | break; |
| 423 | 423 | } else { |
| 424 | std.debug.warn("warning: libc target not found: {s}\n", .{libc_target.name}); | |
| 424 | std.debug.print("warning: libc target not found: {s}\n", .{libc_target.name}); | |
| 425 | 425 | } |
| 426 | 426 | } |
| 427 | std.debug.warn("summary: {:2} could be reduced to {:2}\n", .{ | |
| 427 | std.debug.print("summary: {:2} could be reduced to {:2}\n", .{ | |
| 428 | 428 | std.fmt.fmtIntSizeDec(total_bytes), |
| 429 | 429 | std.fmt.fmtIntSizeDec(total_bytes - max_bytes_saved), |
| 430 | 430 | }); |
| ... | ... | @@ -456,7 +456,7 @@ pub fn main() !void { |
| 456 | 456 | if (contender.hit_count > 1) { |
| 457 | 457 | const this_missed_bytes = contender.hit_count * contender.bytes.len; |
| 458 | 458 | missed_opportunity_bytes += this_missed_bytes; |
| 459 | std.debug.warn("Missed opportunity ({:2}): {s}\n", .{ | |
| 459 | std.debug.print("Missed opportunity ({:2}): {s}\n", .{ | |
| 460 | 460 | std.fmt.fmtIntSizeDec(this_missed_bytes), |
| 461 | 461 | path_kv.key_ptr.*, |
| 462 | 462 | }); |
| ... | ... | @@ -486,10 +486,10 @@ pub fn main() !void { |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | fn usageAndExit(arg0: []const u8) noreturn { |
| 489 | std.debug.warn("Usage: {s} [--search-path <dir>] --out <dir> --abi <name>\n", .{arg0}); | |
| 490 | std.debug.warn("--search-path can be used any number of times.\n", .{}); | |
| 491 | std.debug.warn(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{}); | |
| 492 | std.debug.warn("--out is a dir that will be created, and populated with the results\n", .{}); | |
| 493 | std.debug.warn("--abi is either musl or glibc\n", .{}); | |
| 489 | std.debug.print("Usage: {s} [--search-path <dir>] --out <dir> --abi <name>\n", .{arg0}); | |
| 490 | std.debug.print("--search-path can be used any number of times.\n", .{}); | |
| 491 | std.debug.print(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{}); | |
| 492 | std.debug.print("--out is a dir that will be created, and populated with the results\n", .{}); | |
| 493 | std.debug.print("--abi is either musl or glibc\n", .{}); | |
| 494 | 494 | std.process.exit(1); |
| 495 | 495 | } |
tools/update-linux-headers.zig+11-11| ... | ... | @@ -141,7 +141,7 @@ pub fn main() !void { |
| 141 | 141 | if (std.mem.eql(u8, args[arg_i], "--help")) |
| 142 | 142 | usageAndExit(args[0]); |
| 143 | 143 | if (arg_i + 1 >= args.len) { |
| 144 | std.debug.warn("expected argument after '{s}'\n", .{args[arg_i]}); | |
| 144 | std.debug.print("expected argument after '{s}'\n", .{args[arg_i]}); | |
| 145 | 145 | usageAndExit(args[0]); |
| 146 | 146 | } |
| 147 | 147 | |
| ... | ... | @@ -151,7 +151,7 @@ pub fn main() !void { |
| 151 | 151 | assert(opt_out_dir == null); |
| 152 | 152 | opt_out_dir = args[arg_i + 1]; |
| 153 | 153 | } else { |
| 154 | std.debug.warn("unrecognized argument: {s}\n", .{args[arg_i]}); | |
| 154 | std.debug.print("unrecognized argument: {s}\n", .{args[arg_i]}); | |
| 155 | 155 | usageAndExit(args[0]); |
| 156 | 156 | } |
| 157 | 157 | |
| ... | ... | @@ -208,7 +208,7 @@ pub fn main() !void { |
| 208 | 208 | if (gop.found_existing) { |
| 209 | 209 | max_bytes_saved += raw_bytes.len; |
| 210 | 210 | gop.value_ptr.hit_count += 1; |
| 211 | std.debug.warn("duplicate: {s} {s} ({:2})\n", .{ | |
| 211 | std.debug.print("duplicate: {s} {s} ({:2})\n", .{ | |
| 212 | 212 | linux_target.name, |
| 213 | 213 | rel_path, |
| 214 | 214 | std.fmt.fmtIntSizeDec(raw_bytes.len), |
| ... | ... | @@ -230,16 +230,16 @@ pub fn main() !void { |
| 230 | 230 | }; |
| 231 | 231 | try target_to_hash.putNoClobber(dest_target, hash); |
| 232 | 232 | }, |
| 233 | else => std.debug.warn("warning: weird file: {s}\n", .{full_path}), | |
| 233 | else => std.debug.print("warning: weird file: {s}\n", .{full_path}), | |
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | 237 | break; |
| 238 | 238 | } else { |
| 239 | std.debug.warn("warning: libc target not found: {s}\n", .{linux_target.name}); | |
| 239 | std.debug.print("warning: libc target not found: {s}\n", .{linux_target.name}); | |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | std.debug.warn("summary: {:2} could be reduced to {:2}\n", .{ | |
| 242 | std.debug.print("summary: {:2} could be reduced to {:2}\n", .{ | |
| 243 | 243 | std.fmt.fmtIntSizeDec(total_bytes), |
| 244 | 244 | std.fmt.fmtIntSizeDec(total_bytes - max_bytes_saved), |
| 245 | 245 | }); |
| ... | ... | @@ -271,7 +271,7 @@ pub fn main() !void { |
| 271 | 271 | if (contender.hit_count > 1) { |
| 272 | 272 | const this_missed_bytes = contender.hit_count * contender.bytes.len; |
| 273 | 273 | missed_opportunity_bytes += this_missed_bytes; |
| 274 | std.debug.warn("Missed opportunity ({:2}): {s}\n", .{ | |
| 274 | std.debug.print("Missed opportunity ({:2}): {s}\n", .{ | |
| 275 | 275 | std.fmt.fmtIntSizeDec(this_missed_bytes), |
| 276 | 276 | path_kv.key_ptr.*, |
| 277 | 277 | }); |
| ... | ... | @@ -297,9 +297,9 @@ pub fn main() !void { |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | fn usageAndExit(arg0: []const u8) noreturn { |
| 300 | std.debug.warn("Usage: {s} [--search-path <dir>] --out <dir> --abi <name>\n", .{arg0}); | |
| 301 | std.debug.warn("--search-path can be used any number of times.\n", .{}); | |
| 302 | std.debug.warn(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{}); | |
| 303 | std.debug.warn("--out is a dir that will be created, and populated with the results\n", .{}); | |
| 300 | std.debug.print("Usage: {s} [--search-path <dir>] --out <dir> --abi <name>\n", .{arg0}); | |
| 301 | std.debug.print("--search-path can be used any number of times.\n", .{}); | |
| 302 | std.debug.print(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{}); | |
| 303 | std.debug.print("--out is a dir that will be created, and populated with the results\n", .{}); | |
| 304 | 304 | std.process.exit(1); |
| 305 | 305 | } |
tools/update_cpu_features.zig+3-3| ... | ... | @@ -875,16 +875,16 @@ fn processOneTarget(job: Job) anyerror!void { |
| 875 | 875 | }); |
| 876 | 876 | tblgen_progress.end(); |
| 877 | 877 | if (child_result.stderr.len != 0) { |
| 878 | std.debug.warn("{s}\n", .{child_result.stderr}); | |
| 878 | std.debug.print("{s}\n", .{child_result.stderr}); | |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | const json_text = switch (child_result.term) { |
| 882 | 882 | .Exited => |code| if (code == 0) child_result.stdout else { |
| 883 | std.debug.warn("llvm-tblgen exited with code {d}\n", .{code}); | |
| 883 | std.debug.print("llvm-tblgen exited with code {d}\n", .{code}); | |
| 884 | 884 | std.process.exit(1); |
| 885 | 885 | }, |
| 886 | 886 | else => { |
| 887 | std.debug.warn("llvm-tblgen crashed\n", .{}); | |
| 887 | std.debug.print("llvm-tblgen crashed\n", .{}); | |
| 888 | 888 | std.process.exit(1); |
| 889 | 889 | }, |
| 890 | 890 | }; |
tools/update_glibc.zig+1-1| ... | ... | @@ -185,7 +185,7 @@ pub fn main() !void { |
| 185 | 185 | }; |
| 186 | 186 | const max_bytes = 10 * 1024 * 1024; |
| 187 | 187 | const contents = std.fs.cwd().readFileAlloc(allocator, abi_list_filename, max_bytes) catch |err| { |
| 188 | std.debug.warn("unable to open {s}: {}\n", .{ abi_list_filename, err }); | |
| 188 | std.debug.print("unable to open {s}: {}\n", .{ abi_list_filename, err }); | |
| 189 | 189 | std.process.exit(1); |
| 190 | 190 | }; |
| 191 | 191 | var lines_it = std.mem.tokenize(u8, contents, "\n"); |