authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-30 00:13:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-30 00:13:07-07:00
log902df103c6151c257c90de9ba5f29f7f4b9dbea2
tree16a522f3c8bbe34b56038d4810bf2487e32e2d85
parent173d56213b60fc570b6ba3922ee1d40bbf0d0e36

std lib API deprecations for the upcoming 0.9.0 release

See #3811

101 files changed, 1225 insertions(+), 1561 deletions(-)

CMakeLists.txt+1-1
......@@ -534,7 +534,7 @@ set(ZIG_STAGE2_SOURCES
534534 "${CMAKE_SOURCE_DIR}/lib/std/unicode.zig"
535535 "${CMAKE_SOURCE_DIR}/lib/std/zig.zig"
536536 "${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"
538538 "${CMAKE_SOURCE_DIR}/lib/std/zig/parse.zig"
539539 "${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"
540540 "${CMAKE_SOURCE_DIR}/lib/std/zig/string_literal.zig"
build.zig+3-4
......@@ -3,7 +3,6 @@ const builtin = std.builtin;
33const Builder = std.build.Builder;
44const tests = @import("test/tests.zig");
55const BufMap = std.BufMap;
6const warn = std.debug.warn;
76const mem = std.mem;
87const ArrayList = std.ArrayList;
98const io = std.io;
......@@ -558,9 +557,9 @@ fn addCxxKnownPath(
558557 const path_unpadded = mem.tokenize(u8, path_padded, "\r\n").next().?;
559558 if (mem.eql(u8, path_unpadded, objname)) {
560559 if (errtxt) |msg| {
561 warn("{s}", .{msg});
560 std.debug.print("{s}", .{msg});
562561 } else {
563 warn("Unable to determine path to {s}\n", .{objname});
562 std.debug.print("Unable to determine path to {s}\n", .{objname});
564563 }
565564 return error.RequiredLibraryNotFound;
566565 }
......@@ -687,7 +686,7 @@ fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeCon
687686}
688687
689688fn 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;
691690 for (duplicated) |*byte| switch (byte.*) {
692691 '/' => byte.* = fs.path.sep,
693692 else => {},
doc/langref.html.in+5-5
......@@ -5708,7 +5708,7 @@ const mem = std.mem;
57085708test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
57095709 const window_name = [1][*]const u8{"window name"};
57105710 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"));
57125712}
57135713 {#code_end#}
57145714 {#header_close#}
......@@ -7364,7 +7364,7 @@ fn amain() !void {
73647364var global_download_frame: anyframe = undefined;
73657365fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
73667366 _ = 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");
73687368 errdefer allocator.free(result);
73697369 suspend {
73707370 global_download_frame = @frame();
......@@ -7376,7 +7376,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
73767376var global_file_frame: anyframe = undefined;
73777377fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
73787378 _ = 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");
73807380 errdefer allocator.free(result);
73817381 suspend {
73827382 global_file_frame = @frame();
......@@ -7435,7 +7435,7 @@ fn amain() !void {
74357435
74367436fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
74377437 _ = 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");
74397439 errdefer allocator.free(result);
74407440 std.debug.print("fetchUrl returning\n", .{});
74417441 return result;
......@@ -7443,7 +7443,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
74437443
74447444fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
74457445 _ = 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");
74477447 errdefer allocator.free(result);
74487448 std.debug.print("readFile returning\n", .{});
74497449 return result;
lib/std/Thread.zig+1-3
......@@ -17,8 +17,6 @@ pub const Mutex = @import("Thread/Mutex.zig");
1717pub const Semaphore = @import("Thread/Semaphore.zig");
1818pub const Condition = @import("Thread/Condition.zig");
1919
20pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint");
21
2220pub const use_pthreads = target.os.tag != .windows and target.os.tag != .wasi and builtin.link_libc;
2321const is_gnu = target.abi.isGnu();
2422
......@@ -361,7 +359,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
361359 }
362360
363361 @call(.{}, f, args) catch |err| {
364 std.debug.warn("error: {s}\n", .{@errorName(err)});
362 std.debug.print("error: {s}\n", .{@errorName(err)});
365363 if (@errorReturnTrace()) |trace| {
366364 std.debug.dumpStackTrace(trace.*);
367365 }
lib/std/array_hash_map.zig+2-15
......@@ -201,8 +201,7 @@ pub fn ArrayHashMap(
201201 return self.unmanaged.getOrPutValueContext(self.allocator, key, value, self.ctx);
202202 }
203203
204 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
205 pub const ensureCapacity = ensureTotalCapacity;
204 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
206205
207206 /// Increases capacity, guaranteeing that insertions up until the
208207 /// `expected_count` will not cause an allocation, and therefore cannot fail.
......@@ -746,8 +745,7 @@ pub fn ArrayHashMapUnmanaged(
746745 return res;
747746 }
748747
749 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
750 pub const ensureCapacity = ensureTotalCapacity;
748 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
751749
752750 /// Increases capacity, guaranteeing that insertions up until the
753751 /// `expected_count` will not cause an allocation, and therefore cannot fail.
......@@ -2217,17 +2215,6 @@ test "auto store_hash" {
22172215 try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Data, .hash).field_type != void);
22182216}
22192217
2220test "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
22312218pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {
22322219 return struct {
22332220 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 {
7171 }
7272 }
7373
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
8374 /// ArrayList takes ownership of the passed in slice. The slice must have been
8475 /// allocated with `allocator`.
8576 /// Deinitialize with `deinit` or use `toOwnedSlice`.
......@@ -91,12 +82,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
9182 };
9283 }
9384
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.");
10086
10187 /// Initializes an ArrayListUnmanaged with the `items` and `capacity` fields
10288 /// of this ArrayList. Empties this ArrayList.
......@@ -307,8 +293,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
307293 self.capacity = 0;
308294 }
309295
310 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
311 pub const ensureCapacity = ensureTotalCapacity;
296 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
312297
313298 /// Modify the array so that it can hold at least `new_capacity` items.
314299 /// Invalidates pointers if additional memory is needed.
......@@ -533,7 +518,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
533518 pub fn replaceRange(self: *Self, allocator: *Allocator, start: usize, len: usize, new_items: []const T) !void {
534519 var managed = self.toManaged(allocator);
535520 try managed.replaceRange(start, len, new_items);
536 self.* = managed.toUnmanaged();
521 self.* = managed.moveToUnmanaged();
537522 }
538523
539524 /// 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
674659 self.capacity = 0;
675660 }
676661
677 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
678 pub const ensureCapacity = ensureTotalCapacity;
662 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
679663
680664 /// Modify the array so that it can hold at least `new_capacity` items.
681665 /// Invalidates pointers if additional memory is needed.
......@@ -1337,7 +1321,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
13371321
13381322 const result = try list.toOwnedSliceSentinel(0);
13391323 defer a.free(result);
1340 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1324 try testing.expectEqualStrings(result, mem.sliceTo(result.ptr, 0));
13411325 }
13421326 {
13431327 var list = ArrayListUnmanaged(u8){};
......@@ -1347,7 +1331,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
13471331
13481332 const result = try list.toOwnedSliceSentinel(a, 0);
13491333 defer a.free(result);
1350 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1334 try testing.expectEqualStrings(result, mem.sliceTo(result.ptr, 0));
13511335 }
13521336}
13531337
lib/std/base64.zig+3-8
......@@ -64,14 +64,9 @@ pub const url_safe_no_pad = Codecs{
6464 .Decoder = Base64Decoder.init(url_safe_alphabet_chars, null),
6565};
6666
67// Backwards compatibility
68
69/// Deprecated - Use `standard.pad_char`
70pub const standard_pad_char = standard.pad_char;
71/// Deprecated - Use `standard.Encoder`
72pub const standard_encoder = standard.Encoder;
73/// Deprecated - Use `standard.Decoder`
74pub const standard_decoder = standard.Decoder;
67pub const standard_pad_char = @compileError("deprecated; use standard.pad_char");
68pub const standard_encoder = @compileError("deprecated; use standard.Encoder");
69pub const standard_decoder = @compileError("deprecated; use standard.Decoder");
7570
7671pub const Base64Encoder = struct {
7772 alphabet_chars: [64]u8,
lib/std/build.zig+7-19
......@@ -6,7 +6,7 @@ const mem = std.mem;
66const debug = std.debug;
77const panic = std.debug.panic;
88const assert = debug.assert;
9const warn = std.debug.warn;
9const warn = std.debug.print; // TODO use the log system instead of this
1010const ArrayList = std.ArrayList;
1111const StringHashMap = std.StringHashMap;
1212const Allocator = mem.Allocator;
......@@ -1295,11 +1295,12 @@ test "builder.findProgram compiles" {
12951295 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
12961296}
12971297
1298/// Deprecated. Use `std.builtin.Version`.
1299pub const Version = std.builtin.Version;
1300
1301/// Deprecated. Use `std.zig.CrossTarget`.
1302pub 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.
1302pub const Version = @compileError("deprecated; Use `std.builtin.Version`");
1303pub const Target = @compileError("deprecated; Use `std.zig.CrossTarget`");
13031304
13041305pub const Pkg = struct {
13051306 name: []const u8,
......@@ -3277,16 +3278,3 @@ test "LibExeObjStep.addPackage" {
32773278 const dupe = exe.packages.items[0];
32783279 try std.testing.expectEqualStrings(pkg_top.name, dupe.name);
32793280}
3280
3281test {
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;
44const Builder = build.Builder;
55const fs = std.fs;
66const mem = std.mem;
7const warn = std.debug.warn;
87
98const CheckFileStep = @This();
109
......@@ -40,7 +39,7 @@ fn make(step: *Step) !void {
4039
4140 for (self.expected_matches) |expected_match| {
4241 if (mem.indexOf(u8, contents, expected_match) == null) {
43 warn(
42 std.debug.print(
4443 \\
4544 \\========= Expected to find: ===================
4645 \\{s}
lib/std/build/InstallRawStep.zig+1-2
......@@ -12,7 +12,6 @@ const elf = std.elf;
1212const fs = std.fs;
1313const io = std.io;
1414const sort = std.sort;
15const warn = std.debug.warn;
1615
1716const BinaryElfSection = struct {
1817 elfOffset: u64,
......@@ -387,7 +386,7 @@ fn make(step: *Step) !void {
387386 const builder = self.builder;
388387
389388 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", .{});
391390 return error.InvalidObjectFormat;
392391 }
393392
lib/std/build/RunStep.zig+12-13
......@@ -10,7 +10,6 @@ const mem = std.mem;
1010const process = std.process;
1111const ArrayList = std.ArrayList;
1212const BufMap = std.BufMap;
13const warn = std.debug.warn;
1413
1514const max_stdout_size = 1 * 1024 * 1024; // 1 MiB
1615
......@@ -189,7 +188,7 @@ fn make(step: *Step) !void {
189188 printCmd(cwd, argv);
190189
191190 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) });
193192 return err;
194193 };
195194
......@@ -216,7 +215,7 @@ fn make(step: *Step) !void {
216215 }
217216
218217 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) });
220219 return err;
221220 };
222221
......@@ -224,12 +223,12 @@ fn make(step: *Step) !void {
224223 .Exited => |code| {
225224 if (code != self.expected_exit_code) {
226225 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", .{
228227 code,
229228 self.expected_exit_code,
230229 });
231230 } 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", .{
233232 code,
234233 self.expected_exit_code,
235234 });
......@@ -240,7 +239,7 @@ fn make(step: *Step) !void {
240239 }
241240 },
242241 else => {
243 warn("The following command terminated unexpectedly:\n", .{});
242 std.debug.print("The following command terminated unexpectedly:\n", .{});
244243 printCmd(cwd, argv);
245244 return error.UncleanExit;
246245 },
......@@ -250,7 +249,7 @@ fn make(step: *Step) !void {
250249 .inherit, .ignore => {},
251250 .expect_exact => |expected_bytes| {
252251 if (!mem.eql(u8, expected_bytes, stderr.?)) {
253 warn(
252 std.debug.print(
254253 \\
255254 \\========= Expected this stderr: =========
256255 \\{s}
......@@ -264,7 +263,7 @@ fn make(step: *Step) !void {
264263 },
265264 .expect_matches => |matches| for (matches) |match| {
266265 if (mem.indexOf(u8, stderr.?, match) == null) {
267 warn(
266 std.debug.print(
268267 \\
269268 \\========= Expected to find in stderr: =========
270269 \\{s}
......@@ -282,7 +281,7 @@ fn make(step: *Step) !void {
282281 .inherit, .ignore => {},
283282 .expect_exact => |expected_bytes| {
284283 if (!mem.eql(u8, expected_bytes, stdout.?)) {
285 warn(
284 std.debug.print(
286285 \\
287286 \\========= Expected this stdout: =========
288287 \\{s}
......@@ -296,7 +295,7 @@ fn make(step: *Step) !void {
296295 },
297296 .expect_matches => |matches| for (matches) |match| {
298297 if (mem.indexOf(u8, stdout.?, match) == null) {
299 warn(
298 std.debug.print(
300299 \\
301300 \\========= Expected to find in stdout: =========
302301 \\{s}
......@@ -312,11 +311,11 @@ fn make(step: *Step) !void {
312311}
313312
314313fn 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});
316315 for (argv) |arg| {
317 warn("{s} ", .{arg});
316 std.debug.print("{s} ", .{arg});
318317 }
319 warn("\n", .{});
318 std.debug.print("\n", .{});
320319}
321320
322321fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void {
lib/std/build/WriteFileStep.zig+2-3
......@@ -3,7 +3,6 @@ const build = @import("../build.zig");
33const Step = build.Step;
44const Builder = build.Builder;
55const fs = std.fs;
6const warn = std.debug.warn;
76const ArrayList = std.ArrayList;
87
98const WriteFileStep = @This();
......@@ -91,7 +90,7 @@ fn make(step: *Step) !void {
9190 });
9291 // TODO replace with something like fs.makePathAndOpenDir
9392 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) });
9594 return err;
9695 };
9796 var dir = try fs.cwd().openDir(self.output_dir, .{});
......@@ -100,7 +99,7 @@ fn make(step: *Step) !void {
10099 var it = self.files.first;
101100 while (it) |node| : (it = node.next) {
102101 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", .{
104103 node.data.basename,
105104 self.output_dir,
106105 @errorName(err),
lib/std/builtin.zig+1-1
......@@ -707,7 +707,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
707707 }
708708 },
709709 .wasi => {
710 std.debug.warn("{s}", .{msg});
710 std.debug.print("{s}", .{msg});
711711 std.os.abort();
712712 },
713713 .uefi => {
lib/std/c/tokenizer.zig+2-2
......@@ -126,7 +126,7 @@ pub const Token = struct {
126126 Keyword_error,
127127 Keyword_pragma,
128128
129 pub fn symbol(id: std.meta.TagType(Id)) []const u8 {
129 pub fn symbol(id: std.meta.Tag(Id)) []const u8 {
130130 return switch (id) {
131131 .Invalid => "Invalid",
132132 .Eof => "Eof",
......@@ -342,7 +342,7 @@ pub const Token = struct {
342342pub const Tokenizer = struct {
343343 buffer: []const u8,
344344 index: usize = 0,
345 prev_tok_id: std.meta.TagType(Token.Id) = .Invalid,
345 prev_tok_id: std.meta.Tag(Token.Id) = .Invalid,
346346 pp_directive: bool = false,
347347
348348 pub fn next(self: *Tokenizer) Token {
lib/std/child_process.zig-2
......@@ -181,8 +181,6 @@ pub const ChildProcess = struct {
181181 stderr: []u8,
182182 };
183183
184 pub const exec2 = @compileError("deprecated: exec2 is renamed to exec");
185
186184 fn collectOutputPosix(
187185 child: *const ChildProcess,
188186 stdout: *std.ArrayList(u8),
lib/std/crypto/benchmark.zig+1-1
......@@ -343,7 +343,7 @@ fn benchmarkPwhash(
343343}
344344
345345fn usage() void {
346 std.debug.warn(
346 std.debug.print(
347347 \\throughput_test [options]
348348 \\
349349 \\Options:
lib/std/debug.zig+6-8
......@@ -55,9 +55,7 @@ const PdbOrDwarf = union(enum) {
5555
5656var stderr_mutex = std.Thread.Mutex{};
5757
58/// Deprecated. Use `std.log` functions for logging or `std.debug.print` for
59/// "printf debugging".
60pub const warn = print;
58pub const warn = @compileError("deprecated; use `std.log` functions for logging or `std.debug.print` for 'printf debugging'");
6159
6260/// Print to stderr, unbuffered, and silently returning on failure. Intended
6361/// for use in "printf debugging." Use `std.log` functions for proper logging.
......@@ -1052,7 +1050,7 @@ pub const DebugInfo = struct {
10521050 const obj_di = try self.allocator.create(ModuleDebugInfo);
10531051 errdefer self.allocator.destroy(obj_di);
10541052
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);
10561054 const macho_file = fs.cwd().openFile(macho_path, .{ .intended_io_mode = .blocking }) catch |err| switch (err) {
10571055 error.FileNotFound => return error.MissingDebugInfo,
10581056 else => return err,
......@@ -1178,7 +1176,7 @@ pub const DebugInfo = struct {
11781176 if (context.address >= seg_start and context.address < seg_end) {
11791177 // Android libc uses NULL instead of an empty string to mark the
11801178 // main program
1181 context.name = mem.spanZ(info.dlpi_name) orelse "";
1179 context.name = mem.sliceTo(info.dlpi_name, 0) orelse "";
11821180 context.base_address = info.dlpi_addr;
11831181 // Stop the iteration
11841182 return error.Found;
......@@ -1341,12 +1339,12 @@ pub const ModuleDebugInfo = switch (native_os) {
13411339
13421340 // Take the symbol name from the N_FUN STAB entry, we're going to
13431341 // 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);
13451343
13461344 if (symbol.ofile == null)
13471345 return SymbolInfo{ .symbol_name = stab_symbol };
13481346
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);
13501348
13511349 // Check if its debug infos are already in the cache
13521350 var o_file_di = self.ofiles.get(o_file_path) orelse
......@@ -1668,5 +1666,5 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {
16681666 const sp = asm (""
16691667 : [argc] "={rsp}" (-> usize),
16701668 );
1671 std.debug.warn("{} sp = 0x{x}\n", .{ prefix, sp });
1669 std.debug.print("{} sp = 0x{x}\n", .{ prefix, sp });
16721670}
lib/std/dynamic_library.zig+3-9
......@@ -248,11 +248,9 @@ pub const ElfDynLib = struct {
248248 };
249249 }
250250
251 pub const openC = @compileError("deprecated: renamed to openZ");
252
253251 /// Trusts the file. Malicious file will be able to execute arbitrary code.
254252 pub fn openZ(path_c: [*:0]const u8) !ElfDynLib {
255 return open(mem.spanZ(path_c));
253 return open(mem.sliceTo(path_c, 0));
256254 }
257255
258256 /// Trusts the file
......@@ -281,7 +279,7 @@ pub const ElfDynLib = struct {
281279 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
282280 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
283281 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;
285283 if (maybe_versym) |versym| {
286284 if (!checkver(self.verdef.?, versym[i], vername, self.strings))
287285 continue;
......@@ -312,7 +310,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
312310 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
313311 }
314312 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));
316314}
317315
318316pub const WindowsDynLib = struct {
......@@ -325,8 +323,6 @@ pub const WindowsDynLib = struct {
325323 return openW(path_w.span().ptr);
326324 }
327325
328 pub const openC = @compileError("deprecated: renamed to openZ");
329
330326 pub fn openZ(path_c: [*:0]const u8) !WindowsDynLib {
331327 const path_w = try windows.cStrToPrefixedFileW(path_c);
332328 return openW(path_w.span().ptr);
......@@ -368,8 +364,6 @@ pub const DlDynlib = struct {
368364 return openZ(&path_c);
369365 }
370366
371 pub const openC = @compileError("deprecated: renamed to openZ");
372
373367 pub fn openZ(path_c: [*:0]const u8) !DlDynlib {
374368 return DlDynlib{
375369 .handle = system.dlopen(path_c, system.RTLD.LAZY) orelse {
lib/std/fifo.zig+1-2
......@@ -119,8 +119,7 @@ pub fn LinearFifo(
119119 }
120120 }
121121
122 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
123 pub const ensureCapacity = ensureTotalCapacity;
122 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
124123
125124 /// Ensure that the buffer can fit at least `size` items
126125 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
18141814 };
18151815}
18161816
1817/// Deprecated, use allocPrintZ
1818pub const allocPrint0 = allocPrintZ;
1817pub const allocPrint0 = @compileError("deprecated; use allocPrintZ");
18191818
18201819pub fn allocPrintZ(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 {
18211820 const result = try allocPrint(allocator, fmt ++ "\x00", args);
......@@ -2367,9 +2366,6 @@ test "bytes.hex" {
23672366 try expectFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{fmtSliceHexLower(bytes_with_zeros)});
23682367}
23692368
2370pub const trim = @compileError("deprecated; use std.mem.trim with std.ascii.spaces instead");
2371pub const isWhiteSpace = @compileError("deprecated; use std.ascii.isSpace instead");
2372
23732369/// Decodes the sequence of bytes represented by the specified string of
23742370/// hexadecimal characters.
23752371/// 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");
1919
2020pub const realpath = os.realpath;
2121pub const realpathZ = os.realpathZ;
22pub const realpathC = @compileError("deprecated: renamed to realpathZ");
2322pub const realpathW = os.realpathW;
2423
2524pub const getAppDataDir = @import("fs/get_app_data_dir.zig").getAppDataDir;
......@@ -227,10 +226,6 @@ pub fn makeDirAbsoluteW(absolute_path_w: [*:0]const u16) !void {
227226 return os.mkdirW(absolute_path_w, default_new_dir_mode);
228227}
229228
230pub const deleteDir = @compileError("deprecated; use dir.deleteDir or deleteDirAbsolute");
231pub const deleteDirC = @compileError("deprecated; use dir.deleteDirZ or deleteDirAbsoluteZ");
232pub const deleteDirW = @compileError("deprecated; use dir.deleteDirW or deleteDirAbsoluteW");
233
234229/// Same as `Dir.deleteDir` except the path is absolute.
235230pub fn deleteDirAbsolute(dir_path: []const u8) !void {
236231 assert(path.isAbsolute(dir_path));
......@@ -249,8 +244,6 @@ pub fn deleteDirAbsoluteW(dir_path: [*:0]const u16) !void {
249244 return os.rmdirW(dir_path);
250245}
251246
252pub const renameC = @compileError("deprecated: use renameZ, dir.renameZ, or renameAbsoluteZ");
253
254247/// Same as `Dir.rename` except the paths are absolute.
255248pub fn renameAbsolute(old_path: []const u8, new_path: []const u8) !void {
256249 assert(path.isAbsolute(old_path));
......@@ -393,7 +386,7 @@ pub const Dir = struct {
393386 const next_index = self.index + entry.reclen();
394387 self.index = next_index;
395388
396 const name = mem.spanZ(@ptrCast([*:0]u8, &entry.d_name));
389 const name = mem.sliceTo(@ptrCast([*:0]u8, &entry.d_name), 0);
397390 if (mem.eql(u8, name, ".") or mem.eql(u8, name, ".."))
398391 continue :start_over;
399392
......@@ -520,7 +513,7 @@ pub const Dir = struct {
520513 const haiku_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);
521514 const next_index = self.index + haiku_entry.reclen();
522515 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);
524517
525518 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (haiku_entry.d_ino == 0)) {
526519 continue :start_over;
......@@ -598,7 +591,7 @@ pub const Dir = struct {
598591 const next_index = self.index + linux_entry.reclen();
599592 self.index = next_index;
600593
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);
602595
603596 // skip . and .. entries
604597 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
......@@ -965,8 +958,6 @@ pub const Dir = struct {
965958 return File{ .handle = fd };
966959 }
967960
968 pub const openFileC = @compileError("deprecated: renamed to openFileZ");
969
970961 /// Same as `openFile` but the path parameter is null-terminated.
971962 pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
972963 if (builtin.os.tag == .windows) {
......@@ -1100,8 +1091,6 @@ pub const Dir = struct {
11001091 return self.createFileZ(&path_c, flags);
11011092 }
11021093
1103 pub const createFileC = @compileError("deprecated: renamed to createFileZ");
1104
11051094 /// Same as `createFile` but WASI only.
11061095 pub fn createFileWasi(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File {
11071096 const w = os.wasi;
......@@ -1243,10 +1232,6 @@ pub const Dir = struct {
12431232 return file;
12441233 }
12451234
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
12501235 pub fn makeDir(self: Dir, sub_path: []const u8) !void {
12511236 try os.mkdirat(self.fd, sub_path, default_new_dir_mode);
12521237 }
......@@ -1463,8 +1448,6 @@ pub const Dir = struct {
14631448 }
14641449 }
14651450
1466 pub const openDirC = @compileError("deprecated: renamed to openDirZ");
1467
14681451 /// Same as `openDir` except only WASI.
14691452 pub fn openDirWasi(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir {
14701453 const w = os.wasi;
......@@ -1554,7 +1537,7 @@ pub const Dir = struct {
15541537 .fd = undefined,
15551538 };
15561539
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);
15581541 var nt_name = w.UNICODE_STRING{
15591542 .Length = path_len_bytes,
15601543 .MaximumLength = path_len_bytes,
......@@ -1613,8 +1596,6 @@ pub const Dir = struct {
16131596 }
16141597 }
16151598
1616 pub const deleteFileC = @compileError("deprecated: renamed to deleteFileZ");
1617
16181599 /// Same as `deleteFile` except the parameter is null-terminated.
16191600 pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void {
16201601 os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) {
......@@ -1788,8 +1769,6 @@ pub const Dir = struct {
17881769 return self.readLinkZ(&sub_path_c, buffer);
17891770 }
17901771
1791 pub const readLinkC = @compileError("deprecated: renamed to readLinkZ");
1792
17931772 /// WASI-only. Same as `readLink` except targeting WASI.
17941773 pub fn readLinkWasi(self: Dir, sub_path: []const u8, buffer: []u8) ![]u8 {
17951774 return os.readlinkatWasi(self.fd, sub_path, buffer);
......@@ -2275,8 +2254,6 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O
22752254 return cwd().openFile(absolute_path, flags);
22762255}
22772256
2278pub const openFileAbsoluteC = @compileError("deprecated: renamed to openFileAbsoluteZ");
2279
22802257/// Same as `openFileAbsolute` but the path parameter is null-terminated.
22812258pub fn openFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
22822259 assert(path.isAbsoluteZ(absolute_path_c));
......@@ -2330,8 +2307,6 @@ pub fn createFileAbsolute(absolute_path: []const u8, flags: File.CreateFlags) Fi
23302307 return cwd().createFile(absolute_path, flags);
23312308}
23322309
2333pub const createFileAbsoluteC = @compileError("deprecated: renamed to createFileAbsoluteZ");
2334
23352310/// Same as `createFileAbsolute` but the path parameter is null-terminated.
23362311pub fn createFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {
23372312 assert(path.isAbsoluteZ(absolute_path_c));
......@@ -2353,8 +2328,6 @@ pub fn deleteFileAbsolute(absolute_path: []const u8) Dir.DeleteFileError!void {
23532328 return cwd().deleteFile(absolute_path);
23542329}
23552330
2356pub const deleteFileAbsoluteC = @compileError("deprecated: renamed to deleteFileAbsoluteZ");
2357
23582331/// Same as `deleteFileAbsolute` except the parameter is null-terminated.
23592332pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) Dir.DeleteFileError!void {
23602333 assert(path.isAbsoluteZ(absolute_path_c));
......@@ -2405,9 +2378,6 @@ pub fn readLinkAbsoluteZ(pathname_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8)
24052378 return os.readlinkZ(pathname_c, buffer);
24062379}
24072380
2408pub const readLink = @compileError("deprecated; use Dir.readLink or readLinkAbsolute");
2409pub const readLinkC = @compileError("deprecated; use Dir.readLinkZ or readLinkAbsoluteZ");
2410
24112381/// Use with `Dir.symLink` and `symLinkAbsolute` to specify whether the symlink
24122382/// will point to a file or a directory. This value is ignored on all hosts
24132383/// 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
24582428 return os.symlinkZ(target_path_c, sym_link_path_c);
24592429}
24602430
2461pub const symLink = @compileError("deprecated: use Dir.symLink or symLinkAbsolute");
2462pub const symLinkC = @compileError("deprecated: use Dir.symLinkZ or symLinkAbsoluteZ");
2463
2464pub const walkPath = @compileError("deprecated: use Dir.walk");
2465
24662431pub const OpenSelfExeError = error{
24672432 SharingViolation,
24682433 PathAlreadyExists,
......@@ -2544,14 +2509,14 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
25442509 var out_len: usize = out_buffer.len;
25452510 try os.sysctl(&mib, out_buffer.ptr, &out_len, null, 0);
25462511 // 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);
25482513 },
25492514 .netbsd => {
25502515 var mib = [4]c_int{ os.CTL.KERN, os.KERN.PROC_ARGS, -1, os.KERN.PROC_PATHNAME };
25512516 var out_len: usize = out_buffer.len;
25522517 try os.sysctl(&mib, out_buffer.ptr, &out_len, null, 0);
25532518 // 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);
25552520 },
25562521 .openbsd, .haiku => {
25572522 // 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 {
26032568/// The result is UTF16LE-encoded.
26042569pub fn selfExePathW() [:0]const u16 {
26052570 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);
26072572}
26082573
26092574/// `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
2424 )) {
2525 os.windows.S_OK => {
2626 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) {
2828 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
2929 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
3030 error.DanglingSurrogateHalf => return error.AppDataDirUnavailable,
......@@ -56,7 +56,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
5656 // TODO look into directory_which
5757 const be_user_settings = 0xbbe;
5858 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));
6060 defer allocator.free(settings_dir);
6161 switch (rc) {
6262 0 => return fs.path.join(allocator, &[_][]const u8{ settings_dir, appname }),
lib/std/fs/path.zig+3-9
......@@ -187,8 +187,6 @@ test "join" {
187187 }
188188}
189189
190pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ");
191
192190pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {
193191 if (native_os == .windows) {
194192 return isAbsoluteWindowsZ(path_c);
......@@ -233,27 +231,23 @@ pub fn isAbsoluteWindows(path: []const u8) bool {
233231}
234232
235233pub 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));
237235}
238236
239237pub fn isAbsoluteWindowsWTF16(path: []const u16) bool {
240238 return isAbsoluteWindowsImpl(u16, path);
241239}
242240
243pub const isAbsoluteWindowsC = @compileError("deprecated: renamed to isAbsoluteWindowsZ");
244
245241pub 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));
247243}
248244
249245pub fn isAbsolutePosix(path: []const u8) bool {
250246 return path.len > 0 and path[0] == sep_posix;
251247}
252248
253pub const isAbsolutePosixC = @compileError("deprecated: renamed to isAbsolutePosixZ");
254
255249pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {
256 return isAbsolutePosix(mem.spanZ(path_c));
250 return isAbsolutePosix(mem.sliceTo(path_c, 0));
257251}
258252
259253test "isAbsoluteWindows" {
lib/std/hash/benchmark.zig+1-1
......@@ -142,7 +142,7 @@ pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize
142142}
143143
144144fn usage() void {
145 std.debug.warn(
145 std.debug.print(
146146 \\throughput_test [options]
147147 \\
148148 \\Options:
lib/std/hash_map.zig+5-20
......@@ -2,7 +2,6 @@ const std = @import("std.zig");
22const assert = debug.assert;
33const autoHash = std.hash.autoHash;
44const debug = std.debug;
5const warn = debug.warn;
65const math = std.math;
76const mem = std.mem;
87const meta = std.meta;
......@@ -101,7 +100,7 @@ pub const StringIndexContext = struct {
101100 }
102101
103102 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);
105104 return hashString(x_slice);
106105 }
107106};
......@@ -110,7 +109,7 @@ pub const StringIndexAdapter = struct {
110109 bytes: *std.ArrayListUnmanaged(u8),
111110
112111 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);
114113 return mem.eql(u8, a_slice, b_slice);
115114 }
116115
......@@ -120,8 +119,7 @@ pub const StringIndexAdapter = struct {
120119 }
121120};
122121
123/// Deprecated use `default_max_load_percentage`
124pub const DefaultMaxLoadPercentage = default_max_load_percentage;
122pub const DefaultMaxLoadPercentage = @compileError("deprecated; use `default_max_load_percentage`");
125123
126124pub const default_max_load_percentage = 80;
127125
......@@ -506,8 +504,7 @@ pub fn HashMap(
506504 return self.unmanaged.getOrPutValueContext(self.allocator, key, value, self.ctx);
507505 }
508506
509 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
510 pub const ensureCapacity = ensureTotalCapacity;
507 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
511508
512509 /// Increases capacity, guaranteeing that insertions up until the
513510 /// `expected_count` will not cause an allocation, and therefore cannot fail.
......@@ -873,8 +870,7 @@ pub fn HashMapUnmanaged(
873870 return new_cap;
874871 }
875872
876 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
877 pub const ensureCapacity = ensureTotalCapacity;
873 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
878874
879875 pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_size: Size) !void {
880876 if (@sizeOf(Context) != 0)
......@@ -2045,14 +2041,3 @@ test "std.hash_map ensureUnusedCapacity" {
20452041 // should not change the capacity.
20462042 try testing.expectEqual(capacity, map.capacity());
20472043}
2048
2049test "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
142142
143143pub const FindByteWriter = @import("io/find_byte_writer.zig").FindByteWriter;
144144pub const findByteWriter = @import("io/find_byte_writer.zig").findByteWriter;
145/// Deprecated: use `FindByteWriter`.
146pub const FindByteOutStream = FindByteWriter;
147/// Deprecated: use `findByteWriter`.
148pub const findByteOutStream = findByteWriter;
145
146pub const FindByteOutStream = @compileError("deprecated; use `FindByteWriter`");
147pub const findByteOutStream = @compileError("deprecated; use `findByteWriter`");
149148
150149pub const BufferedAtomicFile = @import("io/buffered_atomic_file.zig").BufferedAtomicFile;
151150
......@@ -181,6 +180,3 @@ test {
181180 _ = @import("io/stream_source.zig");
182181 _ = @import("io/test.zig");
183182}
184
185pub const writeFile = @compileError("deprecated: use std.fs.Dir.writeFile with math.maxInt(usize)");
186pub const readFileAlloc = @compileError("deprecated: use std.fs.Dir.readFileAlloc");
lib/std/io/reader.zig+4-4
......@@ -45,10 +45,10 @@ pub fn Reader(
4545 if (amt_read < buf.len) return error.EndOfStream;
4646 }
4747
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
5252 /// and the `std.ArrayList` has exactly `max_append_size` bytes appended.
5353 pub fn readAllArrayList(self: Self, array_list: *std.ArrayList(u8), max_append_size: usize) !void {
5454 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
31353135
31363136 fn write(self: *Self, bytes: []const u8) Error!usize {
31373137 if (self.expected_remaining.len < bytes.len) {
3138 std.debug.warn(
3138 std.debug.print(
31393139 \\====== expected this output: =========
31403140 \\{s}
31413141 \\======== instead found this: =========
......@@ -3148,7 +3148,7 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions
31483148 return error.TooMuchData;
31493149 }
31503150 if (!mem.eql(u8, self.expected_remaining[0..bytes.len], bytes)) {
3151 std.debug.warn(
3151 std.debug.print(
31523152 \\====== expected this output: =========
31533153 \\{s}
31543154 \\======== instead found this: =========
lib/std/log.zig+8-20
......@@ -174,14 +174,9 @@ pub fn defaultLog(
174174/// provided here.
175175pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
176176 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");
185180
186181 /// Log an error message. This log level is intended to be used
187182 /// when something has gone wrong. This might be recoverable or might
......@@ -204,8 +199,7 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
204199 log(.warn, scope, format, args);
205200 }
206201
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");
209203
210204 /// Log an info message. This log level is intended to be used for
211205 /// general messages about the state of the program.
......@@ -230,14 +224,9 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
230224/// The default scoped logging namespace.
231225pub const default = scoped(.default);
232226
233/// Deprecated. TODO: replace with @compileError() after 0.9.0 is released
234pub const emerg = default.err;
235
236/// Deprecated. TODO: replace with @compileError() after 0.9.0 is released
237pub const alert = default.err;
238
239/// Deprecated. TODO: replace with @compileError() after 0.9.0 is released
240pub const crit = default.err;
227pub const emerg = @compileError("deprecated; use err instead of emerg");
228pub const alert = @compileError("deprecated; use err instead of alert");
229pub const crit = @compileError("deprecated; use err instead of crit");
241230
242231/// Log an error message using the default scope. This log level is intended to
243232/// be used when something has gone wrong. This might be recoverable or might
......@@ -249,8 +238,7 @@ pub const err = default.err;
249238/// the circumstances would be worth investigating.
250239pub const warn = default.warn;
251240
252/// Deprecated. TODO: replace with @compileError() after 0.9.0 is released
253pub const notice = default.info;
241pub const notice = @compileError("deprecated; use info instead of notice");
254242
255243/// Log an info message using the default scope. This log level is intended to
256244/// 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 {
158158 return fabs(x - y) <= max(fabs(x), fabs(y)) * tolerance;
159159}
160160
161/// Deprecated, use `approxEqAbs` or `approxEqRel`.
162pub const approxEq = approxEqAbs;
161pub 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}
163168
164169test "approxEqAbs and approxEqRel" {
165170 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
lib/std/math/big/int.zig+6-6
......@@ -185,9 +185,9 @@ pub const Mutable = struct {
185185
186186 pub fn dump(self: Mutable) void {
187187 for (self.limbs[0..self.len]) |limb| {
188 std.debug.warn("{x} ", .{limb});
188 std.debug.print("{x} ", .{limb});
189189 }
190 std.debug.warn("capacity={} positive={}\n", .{ self.limbs.len, self.positive });
190 std.debug.print("capacity={} positive={}\n", .{ self.limbs.len, self.positive });
191191 }
192192
193193 /// 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 {
16851685
16861686 pub fn dump(self: Const) void {
16871687 for (self.limbs[0..self.limbs.len]) |limb| {
1688 std.debug.warn("{x} ", .{limb});
1688 std.debug.print("{x} ", .{limb});
16891689 }
1690 std.debug.warn("positive={}\n", .{self.positive});
1690 std.debug.print("positive={}\n", .{self.positive});
16911691 }
16921692
16931693 pub fn abs(self: Const) Const {
......@@ -2237,9 +2237,9 @@ pub const Managed = struct {
22372237 /// Debugging tool: prints the state to stderr.
22382238 pub fn dump(self: Managed) void {
22392239 for (self.limbs[0..self.len()]) |limb| {
2240 std.debug.warn("{x} ", .{limb});
2240 std.debug.print("{x} ", .{limb});
22412241 }
2242 std.debug.warn("capacity={} positive={}\n", .{ self.limbs.len, self.isPositive() });
2242 std.debug.print("capacity={} positive={}\n", .{ self.limbs.len, self.isPositive() });
22432243 }
22442244
22452245 /// Negate the sign.
lib/std/math/complex.zig+1-2
......@@ -34,8 +34,7 @@ pub fn Complex(comptime T: type) type {
3434 /// Imaginary part.
3535 im: T,
3636
37 /// Deprecated, use init()
38 pub const new = init;
37 pub const new = @compileError("deprecated; use init()");
3938
4039 /// Create a new Complex number from the given real and imaginary parts.
4140 pub fn init(re: T, im: T) Self {
lib/std/mem.zig+5-98
......@@ -553,9 +553,6 @@ test "indexOfDiff" {
553553 try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
554554}
555555
556pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");
557pub const toSlice = @compileError("deprecated; use std.mem.spanZ");
558
559556/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and
560557/// returns a slice. If there is a sentinel on the input type, there will be a
561558/// sentinel on the output type. The constness of the output type matches
......@@ -644,34 +641,7 @@ test "span" {
644641 try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
645642}
646643
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.
651pub 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
668test "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}
644pub const spanZ = @compileError("deprecated; use use std.mem.span() or std.mem.sliceTo()");
675645
676646/// Helper for the return type of sliceTo()
677647fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
......@@ -917,61 +887,7 @@ test "len" {
917887 }
918888}
919889
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.
926pub 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
957test "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}
890pub const lenZ = @compileError("deprecated; use std.mem.len() or std.mem.sliceTo().len");
975891
976892pub fn indexOfSentinel(comptime Elem: type, comptime sentinel: Elem, ptr: [*:sentinel]const Elem) usize {
977893 var i: usize = 0;
......@@ -989,15 +905,8 @@ pub fn allEqual(comptime T: type, slice: []const T, scalar: T) bool {
989905 return true;
990906}
991907
992/// Deprecated, use `Allocator.dupe`.
993pub fn dupe(allocator: *Allocator, comptime T: type, m: []const T) ![]T {
994 return allocator.dupe(T, m);
995}
996
997/// Deprecated, use `Allocator.dupeZ`.
998pub fn dupeZ(allocator: *Allocator, comptime T: type, m: []const T) ![:0]T {
999 return allocator.dupeZ(T, m);
1000}
908pub const dupe = @compileError("deprecated; use `Allocator.dupe`");
909pub const dupeZ = @compileError("deprecated; use `Allocator.dupeZ`");
1001910
1002911/// Remove values from the beginning of a slice.
1003912pub 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
17271636 };
17281637}
17291638
1730pub const separate = @compileError("deprecated: renamed to split (behavior remains unchanged)");
1731
17321639test "mem.split" {
17331640 var it = split(u8, "abc|def||ghi", "|");
17341641 try testing.expect(eql(u8, it.next().?, "abc"));
......@@ -3024,7 +2931,7 @@ test "isAligned" {
30242931}
30252932
30262933test "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, "");
30282935 testing.allocator.free(empty_string);
30292936}
30302937
lib/std/mem/Allocator.zig-1
......@@ -235,7 +235,6 @@ pub fn allocSentinel(
235235 return self.allocWithOptionsRetAddr(Elem, n, null, sentinel, @returnAddress());
236236}
237237
238/// Deprecated: use `allocAdvanced`
239238pub fn alignedAlloc(
240239 self: *Allocator,
241240 comptime T: type,
lib/std/meta.zig+1-2
......@@ -594,8 +594,7 @@ test "std.meta.FieldEnum" {
594594 try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
595595}
596596
597// Deprecated: use Tag
598pub const TagType = Tag;
597pub const TagType = @compileError("deprecated; use Tag");
599598
600599pub fn Tag(comptime T: type) type {
601600 return switch (@typeInfo(T)) {
lib/std/meta/trait.zig-1
......@@ -2,7 +2,6 @@ const std = @import("../std.zig");
22const mem = std.mem;
33const debug = std.debug;
44const testing = std.testing;
5const warn = debug.warn;
65
76const meta = @import("../meta.zig");
87
lib/std/multi_array_list.zig+1-2
......@@ -309,8 +309,7 @@ pub fn MultiArrayList(comptime S: type) type {
309309 self.len = new_len;
310310 }
311311
312 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
313 pub const ensureCapacity = ensureTotalCapacity;
312 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
314313
315314 /// Modify the array so that it can hold at least `new_capacity` items.
316315 /// 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) !*
785785
786786 if (info.canonname) |n| {
787787 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));
789789 }
790790 }
791791 i += 1;
......@@ -1588,7 +1588,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)
15881588 var tmp: [256]u8 = undefined;
15891589 // Returns len of compressed name. strlen to get canon name.
15901590 _ = 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);
15921592 if (isValidHostName(canon_name)) {
15931593 ctx.canon.items.len = 0;
15941594 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 {
12891289 return openZ(&file_path_c, flags, perm);
12901290}
12911291
1292pub const openC = @compileError("deprecated: renamed to openZ");
1293
12941292/// Open and possibly create a file. Keeps trying if it gets interrupted.
12951293/// See also `open`.
12961294pub 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
14291427 }
14301428}
14311429
1432pub const openatC = @compileError("deprecated: renamed to openatZ");
1433
14341430/// Open and possibly create a file. Keeps trying if it gets interrupted.
14351431/// `file_path` is relative to the open directory handle `dir_fd`.
14361432/// See also `openat`.
......@@ -1529,8 +1525,6 @@ pub const ExecveError = error{
15291525 NameTooLong,
15301526} || UnexpectedError;
15311527
1532pub const execveC = @compileError("deprecated: use execveZ");
1533
15341528/// Like `execve` except the parameters are null-terminated,
15351529/// matching the syscall API on all targets. This removes the need for an allocator.
15361530/// This function ignores PATH environment variable. See `execvpeZ` for that.
......@@ -1561,8 +1555,6 @@ pub fn execveZ(
15611555 }
15621556}
15631557
1564pub const execvpeC = @compileError("deprecated in favor of execvpeZ");
1565
15661558pub const Arg0Expand = enum {
15671559 expand,
15681560 no_expand,
......@@ -1580,7 +1572,7 @@ pub fn execvpeZ_expandArg0(
15801572 },
15811573 envp: [*:null]const ?[*:0]const u8,
15821574) ExecveError {
1583 const file_slice = mem.spanZ(file);
1575 const file_slice = mem.sliceTo(file, 0);
15841576 if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp);
15851577
15861578 const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin";
......@@ -1680,19 +1672,17 @@ pub fn getenv(key: []const u8) ?[]const u8 {
16801672 return null;
16811673}
16821674
1683pub const getenvC = @compileError("Deprecated in favor of `getenvZ`");
1684
16851675/// Get an environment variable with a null-terminated name.
16861676/// See also `getenv`.
16871677pub fn getenvZ(key: [*:0]const u8) ?[]const u8 {
16881678 if (builtin.link_libc) {
16891679 const value = system.getenv(key) orelse return null;
1690 return mem.spanZ(value);
1680 return mem.sliceTo(value, 0);
16911681 }
16921682 if (builtin.os.tag == .windows) {
16931683 @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.");
16941684 }
1695 return getenv(mem.spanZ(key));
1685 return getenv(mem.sliceTo(key, 0));
16961686}
16971687
16981688/// 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 {
17031693 if (builtin.os.tag != .windows) {
17041694 @compileError("std.os.getenvW is a Windows-only API");
17051695 }
1706 const key_slice = mem.spanZ(key);
1696 const key_slice = mem.sliceTo(key, 0);
17071697 const ptr = windows.peb().ProcessParameters.Environment;
17081698 var ascii_match: ?[:0]const u16 = null;
17091699 var i: usize = 0;
......@@ -1758,7 +1748,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
17581748 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
17591749 };
17601750 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),
17621752 .FAULT => unreachable,
17631753 .INVAL => unreachable,
17641754 .NOENT => return error.CurrentWorkingDirectoryUnlinked,
......@@ -1802,8 +1792,6 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!
18021792 return symlinkZ(&target_path_c, &sym_link_path_c);
18031793}
18041794
1805pub const symlinkC = @compileError("deprecated: renamed to symlinkZ");
1806
18071795/// This is the same as `symlink` except the parameters are null-terminated pointers.
18081796/// See also `symlink`.
18091797pub 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
18481836 return symlinkatZ(&target_path_c, newdirfd, &sym_link_path_c);
18491837}
18501838
1851pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");
1852
18531839/// WASI-only. The same as `symlinkat` but targeting WASI.
18541840/// See also `symlinkat`.
18551841pub 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 {
20232009 }
20242010}
20252011
2026pub const unlinkC = @compileError("deprecated: renamed to unlinkZ");
2027
20282012/// Same as `unlink` except the parameter is a null terminated UTF8-encoded string.
20292013pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {
20302014 if (builtin.os.tag == .windows) {
......@@ -2074,8 +2058,6 @@ pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!vo
20742058 }
20752059}
20762060
2077pub const unlinkatC = @compileError("deprecated: renamed to unlinkatZ");
2078
20792061/// WASI-only. Same as `unlinkat` but targeting WASI.
20802062/// See also `unlinkat`.
20812063pub 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 {
21832165 }
21842166}
21852167
2186pub const renameC = @compileError("deprecated: renamed to renameZ");
2187
21882168/// Same as `rename` except the parameters are null-terminated byte arrays.
21892169pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void {
21902170 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
23782358 }
23792359}
23802360
2381pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
2382
23832361pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
23842362 _ = mode;
23852363 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 {
25482526 }
25492527}
25502528
2551pub const rmdirC = @compileError("deprecated: renamed to rmdirZ");
2552
25532529/// Same as `rmdir` except the parameter is null-terminated.
25542530pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void {
25552531 if (builtin.os.tag == .windows) {
......@@ -2613,8 +2589,6 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
26132589 }
26142590}
26152591
2616pub const chdirC = @compileError("deprecated: renamed to chdirZ");
2617
26182592/// Same as `chdir` except the parameter is null-terminated.
26192593pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void {
26202594 if (builtin.os.tag == .windows) {
......@@ -2697,8 +2671,6 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
26972671 }
26982672}
26992673
2700pub const readlinkC = @compileError("deprecated: renamed to readlinkZ");
2701
27022674/// Windows-only. Same as `readlink` except `file_path` is WTF16 encoded.
27032675/// See also `readlinkZ`.
27042676pub 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
27422714 return readlinkatZ(dirfd, &file_path_c, out_buffer);
27432715}
27442716
2745pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");
2746
27472717/// WASI-only. Same as `readlinkat` but targets WASI.
27482718/// See also `readlinkat`.
27492719pub 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
37373707 }
37383708}
37393709
3740pub const fstatatC = @compileError("deprecated: renamed to fstatatZ");
3741
37423710/// WASI-only. Same as `fstatat` but targeting WASI.
37433711/// See also `fstatat`.
37443712pub 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
38833851 return inotify_add_watchZ(inotify_fd, &pathname_c, mask);
38843852}
38853853
3886pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add_watchZ");
3887
38883854/// Same as `inotify_add_watch` except pathname is null-terminated.
38893855pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
38903856 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);
......@@ -4053,8 +4019,6 @@ pub fn access(path: []const u8, mode: u32) AccessError!void {
40534019 return accessZ(&path_c, mode);
40544020}
40554021
4056pub const accessC = @compileError("Deprecated in favor of `accessZ`");
4057
40584022/// Same as `access` except `path` is null-terminated.
40594023pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
40604024 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
41434107 return;
41444108 }
41454109
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) {
41474111 error.Overflow => return error.NameTooLong,
41484112 };
41494113 var nt_name = windows.UNICODE_STRING{
......@@ -4273,8 +4237,6 @@ pub fn sysctl(
42734237 }
42744238}
42754239
4276pub const sysctlbynameC = @compileError("deprecated: renamed to sysctlbynameZ");
4277
42784240pub fn sysctlbynameZ(
42794241 name: [*:0]const u8,
42804242 oldp: ?*c_void,
......@@ -4651,8 +4613,6 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE
46514613 return realpathZ(&pathname_c, out_buffer);
46524614}
46534615
4654pub const realpathC = @compileError("deprecated: renamed realpathZ");
4655
46564616/// Same as `realpath` except `pathname` is null-terminated.
46574617pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
46584618 if (builtin.os.tag == .windows) {
......@@ -4684,7 +4644,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
46844644 .IO => return error.InputOutput,
46854645 else => |err| return unexpectedErrno(err),
46864646 };
4687 return mem.spanZ(result_path);
4647 return mem.sliceTo(result_path, 0);
46884648}
46894649
46904650/// Same as `realpath` except `pathname` is UTF16LE-encoded.
......@@ -4997,7 +4957,7 @@ pub const UnexpectedError = error{
49974957/// and you get an unexpected error.
49984958pub fn unexpectedErrno(err: E) UnexpectedError {
49994959 if (unexpected_error_tracing) {
5000 std.debug.warn("unexpected errno: {d}\n", .{@enumToInt(err)});
4960 std.debug.print("unexpected errno: {d}\n", .{@enumToInt(err)});
50014961 std.debug.dumpCurrentStackTrace(null);
50024962 }
50034963 return error.Unexpected;
......@@ -5092,7 +5052,7 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError;
50925052pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
50935053 if (builtin.link_libc) {
50945054 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),
50965056 .FAULT => unreachable,
50975057 .NAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this
50985058 .PERM => return error.PermissionDenied,
......@@ -5101,7 +5061,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
51015061 }
51025062 if (builtin.os.tag == .linux) {
51035063 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);
51055065 mem.copy(u8, name_buffer, hostname);
51065066 return name_buffer[0..hostname.len];
51075067 }
......@@ -6130,8 +6090,6 @@ pub const MemFdCreateError = error{
61306090 SystemOutdated,
61316091} || UnexpectedError;
61326092
6133pub const memfd_createC = @compileError("deprecated: renamed to memfd_createZ");
6134
61356093pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
61366094 // memfd_create is available only in glibc versions starting with 2.27.
61376095 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 {
6969 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
7070 if (0 == syms[i].st_shndx) continue;
7171 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;
7373 if (maybe_versym) |versym| {
7474 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
7575 continue;
......@@ -92,5 +92,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
9292 }
9393 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
9494 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));
9696}
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
813813 return parseReadlinkPath(path_buf[offset .. offset + len], false, out_buffer);
814814 },
815815 else => |value| {
816 std.debug.warn("unsupported symlink type: {}", .{value});
816 std.debug.print("unsupported symlink type: {}", .{value});
817817 return error.UnsupportedReparsePointType;
818818 },
819819 }
......@@ -1862,7 +1862,7 @@ pub fn normalizePath(comptime T: type, path: []T) RemoveDotDirsError!usize {
18621862/// Same as `sliceToPrefixedFileW` but accepts a pointer
18631863/// to a null-terminated path.
18641864pub fn cStrToPrefixedFileW(s: [*:0]const u8) !PathSpace {
1865 return sliceToPrefixedFileW(mem.spanZ(s));
1865 return sliceToPrefixedFileW(mem.sliceTo(s, 0));
18661866}
18671867
18681868/// 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 {
19951995 null,
19961996 );
19971997 _ = 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] });
19991999 std.debug.dumpCurrentStackTrace(null);
20002000 }
20012001 return error.Unexpected;
......@@ -2009,7 +2009,7 @@ pub fn unexpectedWSAError(err: ws2_32.WinsockError) std.os.UnexpectedError {
20092009/// and you get an unexpected status.
20102010pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {
20112011 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)});
20132013 std.debug.dumpCurrentStackTrace(null);
20142014 }
20152015 return error.Unexpected;
lib/std/pdb.zig+2-3
......@@ -3,7 +3,6 @@ const io = std.io;
33const math = std.math;
44const mem = std.mem;
55const os = std.os;
6const warn = std.debug.warn;
76const coff = std.coff;
87const fs = std.fs;
98const File = std.fs.File;
......@@ -656,7 +655,7 @@ pub const Pdb = struct {
656655 const name_index = try reader.readIntLittle(u32);
657656 if (name_offset > name_bytes.len)
658657 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);
660659 if (mem.eql(u8, name, "/names")) {
661660 break :str_tab_index name_index;
662661 }
......@@ -681,7 +680,7 @@ pub const Pdb = struct {
681680 .S_LPROC32, .S_GPROC32 => {
682681 const proc_sym = @ptrCast(*ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]);
683682 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);
685684 }
686685 },
687686 else => {},
lib/std/priority_dequeue.zig+10-11
......@@ -1,7 +1,6 @@
11const std = @import("std.zig");
22const Allocator = std.mem.Allocator;
33const assert = std.debug.assert;
4const warn = std.debug.warn;
54const Order = std.math.Order;
65const testing = std.testing;
76const expect = testing.expect;
......@@ -355,8 +354,7 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty
355354 return queue;
356355 }
357356
358 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
359 pub const ensureCapacity = ensureTotalCapacity;
357 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
360358
361359 /// Ensure that the dequeue can fit at least `new_capacity` items.
362360 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
421419 }
422420
423421 fn dump(self: *Self) void {
424 warn("{{ ", .{});
425 warn("items: ", .{});
422 const print = std.debug.print;
423 print("{{ ", .{});
424 print("items: ", .{});
426425 for (self.items) |e, i| {
427426 if (i >= self.len) break;
428 warn("{}, ", .{e});
427 print("{}, ", .{e});
429428 }
430 warn("array: ", .{});
429 print("array: ", .{});
431430 for (self.items) |e| {
432 warn("{}, ", .{e});
431 print("{}, ", .{e});
433432 }
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", .{});
437436 }
438437
439438 fn parentIndex(index: usize) usize {
lib/std/priority_queue.zig+10-11
......@@ -1,7 +1,6 @@
11const std = @import("std.zig");
22const Allocator = std.mem.Allocator;
33const assert = std.debug.assert;
4const warn = std.debug.warn;
54const Order = std.math.Order;
65const testing = std.testing;
76const expect = testing.expect;
......@@ -171,8 +170,7 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order
171170 return queue;
172171 }
173172
174 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
175 pub const ensureCapacity = ensureTotalCapacity;
173 pub const ensureCapacity = @compileError("deprecated; use ensureUnusedCapacity or ensureTotalCapacity");
176174
177175 /// Ensure that the queue can fit at least `new_capacity` items.
178176 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
242240 }
243241
244242 fn dump(self: *Self) void {
245 warn("{{ ", .{});
246 warn("items: ", .{});
243 const print = std.debug.print;
244 print("{{ ", .{});
245 print("items: ", .{});
247246 for (self.items) |e, i| {
248247 if (i >= self.len) break;
249 warn("{}, ", .{e});
248 print("{}, ", .{e});
250249 }
251 warn("array: ", .{});
250 print("array: ", .{});
252251 for (self.items) |e| {
253 warn("{}, ", .{e});
252 print("{}, ", .{e});
254253 }
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", .{});
258257 }
259258 };
260259}
lib/std/process.zig+6-6
......@@ -103,7 +103,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
103103 }
104104
105105 for (environ) |env| {
106 const pair = mem.spanZ(env);
106 const pair = mem.sliceTo(env, 0);
107107 var parts = mem.split(u8, pair, "=");
108108 const key = parts.next().?;
109109 const value = parts.next().?;
......@@ -215,7 +215,7 @@ pub const ArgIteratorPosix = struct {
215215
216216 const s = os.argv[self.index];
217217 self.index += 1;
218 return mem.spanZ(s);
218 return mem.sliceTo(s, 0);
219219 }
220220
221221 pub fn skip(self: *ArgIteratorPosix) bool {
......@@ -267,7 +267,7 @@ pub const ArgIteratorWasi = struct {
267267 var result_args = try allocator.alloc([:0]u8, count);
268268 var i: usize = 0;
269269 while (i < count) : (i += 1) {
270 result_args[i] = mem.spanZ(argv[i]);
270 result_args[i] = mem.sliceTo(argv[i], 0);
271271 }
272272
273273 return result_args;
......@@ -768,7 +768,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
768768 _ = size;
769769 const name = info.dlpi_name orelse return;
770770 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));
772772 errdefer list.allocator.free(item);
773773 try list.append(item);
774774 }
......@@ -789,7 +789,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
789789 var i: u32 = 0;
790790 while (i < img_count) : (i += 1) {
791791 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));
793793 errdefer allocator.free(item);
794794 try paths.append(item);
795795 }
......@@ -807,7 +807,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
807807 }
808808
809809 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));
811811 errdefer allocator.free(item);
812812 try paths.append(item);
813813
lib/std/rand.zig-4
......@@ -245,10 +245,6 @@ pub const Random = struct {
245245 }
246246 }
247247
248 pub const scalar = @compileError("deprecated; use boolean() or int() instead");
249
250 pub const range = @compileError("deprecated; use intRangeLessThan()");
251
252248 /// Return a floating point value evenly distributed in the range [0, 1).
253249 pub fn float(r: Random, comptime T: type) T {
254250 // 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;
77const mem = std.mem;
88const process = std.process;
99const ArrayList = std.ArrayList;
10const warn = std.debug.warn;
1110const File = std.fs.File;
1211
1312pub fn main() !void {
......@@ -25,19 +24,19 @@ pub fn main() !void {
2524 var arg_idx: usize = 1;
2625
2726 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", .{});
2928 return error.InvalidArgs;
3029 };
3130 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", .{});
3332 return error.InvalidArgs;
3433 };
3534 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", .{});
3736 return error.InvalidArgs;
3837 };
3938 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", .{});
4140 return error.InvalidArgs;
4241 };
4342
......@@ -68,7 +67,7 @@ pub fn main() !void {
6867 if (mem.startsWith(u8, arg, "-D")) {
6968 const option_contents = arg[2..];
7069 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", .{});
7271 return usageAndErr(builder, false, stderr_stream);
7372 }
7473 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
......@@ -87,59 +86,59 @@ pub fn main() !void {
8786 return usage(builder, false, stdout_stream);
8887 } else if (mem.eql(u8, arg, "-p") or mem.eql(u8, arg, "--prefix")) {
8988 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});
9190 return usageAndErr(builder, false, stderr_stream);
9291 };
9392 } else if (mem.eql(u8, arg, "--prefix-lib-dir")) {
9493 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});
9695 return usageAndErr(builder, false, stderr_stream);
9796 };
9897 } else if (mem.eql(u8, arg, "--prefix-exe-dir")) {
9998 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});
101100 return usageAndErr(builder, false, stderr_stream);
102101 };
103102 } else if (mem.eql(u8, arg, "--prefix-include-dir")) {
104103 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});
106105 return usageAndErr(builder, false, stderr_stream);
107106 };
108107 } else if (mem.eql(u8, arg, "--sysroot")) {
109108 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", .{});
111110 return usageAndErr(builder, false, stderr_stream);
112111 };
113112 builder.sysroot = sysroot;
114113 } else if (mem.eql(u8, arg, "--search-prefix")) {
115114 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", .{});
117116 return usageAndErr(builder, false, stderr_stream);
118117 };
119118 builder.addSearchPrefix(search_prefix);
120119 } else if (mem.eql(u8, arg, "--libc")) {
121120 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", .{});
123122 return usageAndErr(builder, false, stderr_stream);
124123 };
125124 builder.libc_file = libc_file;
126125 } else if (mem.eql(u8, arg, "--color")) {
127126 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", .{});
129128 return usageAndErr(builder, false, stderr_stream);
130129 };
131130 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});
133132 return usageAndErr(builder, false, stderr_stream);
134133 };
135134 } else if (mem.eql(u8, arg, "--zig-lib-dir")) {
136135 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", .{});
138137 return usageAndErr(builder, false, stderr_stream);
139138 };
140139 } else if (mem.eql(u8, arg, "--debug-log")) {
141140 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});
143142 return usageAndErr(builder, false, stderr_stream);
144143 };
145144 try debug_log_scopes.append(next_arg);
......@@ -165,7 +164,7 @@ pub fn main() !void {
165164 builder.args = argsRest(args, arg_idx);
166165 break;
167166 } else {
168 warn("Unrecognized argument: {s}\n\n", .{arg});
167 std.debug.print("Unrecognized argument: {s}\n\n", .{arg});
169168 return usageAndErr(builder, false, stderr_stream);
170169 }
171170 } else {
lib/std/special/c_stage1.zig+4-4
......@@ -59,7 +59,7 @@ test "strcpy" {
5959
6060 s1[0] = 0;
6161 _ = 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));
6363}
6464
6565fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 {
......@@ -79,7 +79,7 @@ test "strncpy" {
7979
8080 s1[0] = 0;
8181 _ = 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));
8383}
8484
8585fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {
......@@ -102,7 +102,7 @@ test "strcat" {
102102 _ = strcat(&s1, "foo");
103103 _ = strcat(&s1, "bar");
104104 _ = 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));
106106}
107107
108108fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 {
......@@ -125,7 +125,7 @@ test "strncat" {
125125 _ = strncat(&s1, "foo1111", 3);
126126 _ = strncat(&s1, "bar1111", 3);
127127 _ = 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));
129129}
130130
131131fn 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;
22const std = @import("std");
33const math = std.math;
44const testing = std.testing;
5const warn = std.debug.warn;
65
76fn test__fixdfdi(a: f64, expected: i64) !void {
87 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)});
108 try testing.expect(x == expected);
119}
1210
1311test "fixdfdi" {
14 //warn("\n", .{});
1512 try test__fixdfdi(-math.f64_max, math.minInt(i64));
1613
1714 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;
22const std = @import("std");
33const math = std.math;
44const testing = std.testing;
5const warn = std.debug.warn;
65
76fn test__fixdfsi(a: f64, expected: i32) !void {
87 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)});
108 try testing.expect(x == expected);
119}
1210
1311test "fixdfsi" {
14 //warn("\n", .{});
1512 try test__fixdfsi(-math.f64_max, math.minInt(i32));
1613
1714 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;
22const std = @import("std");
33const math = std.math;
44const testing = std.testing;
5const warn = std.debug.warn;
65
76fn test__fixdfti(a: f64, expected: i128) !void {
87 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)});
108 try testing.expect(x == expected);
119}
1210
1311test "fixdfti" {
14 //warn("\n", .{});
1512 try test__fixdfti(-math.f64_max, math.minInt(i128));
1613
1714 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;
22const std = @import("std");
33const math = std.math;
44const testing = std.testing;
5const warn = std.debug.warn;
65
76const fixint = @import("fixint.zig").fixint;
87
98fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) !void {
109 const x = fixint(fp_t, fixint_t, a);
11 //warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected});
1210 try testing.expect(x == expected);
1311}
1412
lib/std/special/compiler_rt/fixsfdi_test.zig-3
......@@ -2,16 +2,13 @@ const __fixsfdi = @import("fixsfdi.zig").__fixsfdi;
22const std = @import("std");
33const math = std.math;
44const testing = std.testing;
5const warn = std.debug.warn;
65
76fn test__fixsfdi(a: f32, expected: i64) !void {
87 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)});
108 try testing.expect(x == expected);
119}
1210
1311test "fixsfdi" {
14 //warn("\n", .{});
1512 try test__fixsfdi(-math.f32_max, math.minInt(i64));
1613
1714 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;
22const std = @import("std");
33const math = std.math;
44const testing = std.testing;
5const warn = std.debug.warn;
65
76fn test__fixsfsi(a: f32, expected: i32) !void {
87 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)});
108 try testing.expect(x == expected);
119}
1210
1311test "fixsfsi" {
14 //warn("\n", .{});
1512 try test__fixsfsi(-math.f32_max, math.minInt(i32));
1613
1714 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;
22const std = @import("std");
33const math = std.math;
44const testing = std.testing;
5const warn = std.debug.warn;
65
76fn test__fixsfti(a: f32, expected: i128) !void {
87 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)});
108 try testing.expect(x == expected);
119}
1210
1311test "fixsfti" {
14 //warn("\n", .{});
1512 try test__fixsfti(-math.f32_max, math.minInt(i128));
1613
1714 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;
22const std = @import("std");
33const math = std.math;
44const testing = std.testing;
5const warn = std.debug.warn;
65
76fn test__fixtfdi(a: f128, expected: i64) !void {
87 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)});
108 try testing.expect(x == expected);
119}
1210
1311test "fixtfdi" {
14 //warn("\n", .{});
1512 try test__fixtfdi(-math.f128_max, math.minInt(i64));
1613
1714 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;
22const std = @import("std");
33const math = std.math;
44const testing = std.testing;
5const warn = std.debug.warn;
65
76fn test__fixtfsi(a: f128, expected: i32) !void {
87 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)});
108 try testing.expect(x == expected);
119}
1210
1311test "fixtfsi" {
14 //warn("\n", .{});
1512 try test__fixtfsi(-math.f128_max, math.minInt(i32));
1613
1714 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;
22const std = @import("std");
33const math = std.math;
44const testing = std.testing;
5const warn = std.debug.warn;
65
76fn test__fixtfti(a: f128, expected: i128) !void {
87 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)});
108 try testing.expect(x == expected);
119}
1210
1311test "fixtfti" {
14 //warn("\n", .{});
1512 try test__fixtfti(-math.f128_max, math.minInt(i128));
1613
1714 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 {
217217 }
218218 }
219219
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 });
221221
222222 @panic("__trunctfsf2 test failure");
223223}
......@@ -248,7 +248,7 @@ fn test__trunctfhf2(a: f128, expected: u16) void {
248248 return;
249249 }
250250
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 });
252252
253253 @panic("__trunctfhf2 test failure");
254254}
lib/std/testing.zig-3
......@@ -208,9 +208,6 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt
208208 return error.TestExpectedFmt;
209209}
210210
211pub const expectWithinMargin = @compileError("expectWithinMargin is deprecated, use expectApproxEqAbs or expectApproxEqRel");
212pub const expectWithinEpsilon = @compileError("expectWithinEpsilon is deprecated, use expectApproxEqAbs or expectApproxEqRel");
213
214211/// This function is intended to be used only in tests. When the actual value is
215212/// not approximately equal to the expected value, prints diagnostics to stderr
216213/// 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 {
216216/// ```
217217/// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator();
218218/// while (utf8.nextCodepointSlice()) |codepoint| {
219/// std.debug.warn("got codepoint {}\n", .{codepoint});
219/// std.debug.print("got codepoint {}\n", .{codepoint});
220220/// }
221221/// ```
222222pub const Utf8View = struct {
lib/std/zig.zig+1-1
......@@ -12,7 +12,7 @@ pub const parse = @import("zig/parse.zig").parse;
1212pub const string_literal = @import("zig/string_literal.zig");
1313pub const Ast = @import("zig/Ast.zig");
1414pub const system = @import("zig/system.zig");
15pub const CrossTarget = @import("zig/cross_target.zig").CrossTarget;
15pub const CrossTarget = @import("zig/CrossTarget.zig");
1616
1717// Files needed by translate-c.
1818pub 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
5const CrossTarget = @This();
6const std = @import("../std.zig");
7const builtin = @import("builtin");
8const assert = std.debug.assert;
9const Target = std.Target;
10const mem = std.mem;
11
12/// `null` means native.
13cpu_arch: ?Target.Cpu.Arch = null,
14
15cpu_model: CpuModel = CpuModel.determined_by_cpu_arch,
16
17/// Sparse set of CPU features to add to the set from `cpu_model`.
18cpu_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`.
21cpu_features_sub: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty,
22
23/// `null` means native.
24os_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.
28os_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.
32os_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.
36glibc_version: ?SemVer = null,
37
38/// `null` means the native C ABI, if `os_tag` is native, otherwise it means the default C ABI.
39abi: ?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`.
43dynamic_linker: DynamicLinker = DynamicLinker{},
44
45pub 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
59pub const OsVersion = union(enum) {
60 none: void,
61 semver: SemVer,
62 windows: Target.Os.WindowsVersion,
63};
64
65pub const SemVer = std.builtin.Version;
66
67pub const DynamicLinker = Target.DynamicLinker;
68
69pub 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
102fn 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`.
166pub fn toTarget(self: CrossTarget) Target {
167 return .{
168 .cpu = self.getCpu(),
169 .os = self.getOs(),
170 .abi = self.getAbi(),
171 };
172}
173
174pub 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
225pub 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`.
331pub 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`.
343pub 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
374pub fn getCpuArch(self: CrossTarget) Target.Cpu.Arch {
375 return self.cpu_arch orelse builtin.cpu.arch;
376}
377
378pub 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
385pub fn getCpuFeatures(self: CrossTarget) Target.Cpu.Feature.Set {
386 return self.getCpu().features;
387}
388
389/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
390pub 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
422pub 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`.
427pub 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`.
435pub 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`.
443pub 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
456pub fn isFreeBSD(self: CrossTarget) bool {
457 return self.getOsTag() == .freebsd;
458}
459
460pub fn isDarwin(self: CrossTarget) bool {
461 return self.getOsTag().isDarwin();
462}
463
464pub fn isNetBSD(self: CrossTarget) bool {
465 return self.getOsTag() == .netbsd;
466}
467
468pub fn isOpenBSD(self: CrossTarget) bool {
469 return self.getOsTag() == .openbsd;
470}
471
472pub fn isUefi(self: CrossTarget) bool {
473 return self.getOsTag() == .uefi;
474}
475
476pub fn isDragonFlyBSD(self: CrossTarget) bool {
477 return self.getOsTag() == .dragonfly;
478}
479
480pub fn isLinux(self: CrossTarget) bool {
481 return self.getOsTag() == .linux;
482}
483
484pub fn isWindows(self: CrossTarget) bool {
485 return self.getOsTag() == .windows;
486}
487
488pub fn exeFileExt(self: CrossTarget) [:0]const u8 {
489 return Target.exeFileExtSimple(self.getCpuArch(), self.getOsTag());
490}
491
492pub fn staticLibSuffix(self: CrossTarget) [:0]const u8 {
493 return Target.staticLibSuffix_os_abi(self.getOsTag(), self.getAbi());
494}
495
496pub fn dynamicLibSuffix(self: CrossTarget) [:0]const u8 {
497 return self.getOsTag().dynamicLibSuffix();
498}
499
500pub fn libPrefix(self: CrossTarget) [:0]const u8 {
501 return Target.libPrefix_os_abi(self.getOsTag(), self.getAbi());
502}
503
504pub 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
510pub 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
515pub fn isNativeAbi(self: CrossTarget) bool {
516 return self.os_tag == null and self.abi == null;
517}
518
519pub fn isNative(self: CrossTarget) bool {
520 return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi();
521}
522
523pub 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
562pub 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
568pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
569 return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi());
570}
571
572pub fn wantSharedLibSymLinks(self: CrossTarget) bool {
573 return self.getOsTag() != .windows;
574}
575
576pub const VcpkgLinkage = std.builtin.LinkMode;
577
578/// Returned slice must be freed by the caller.
579pub 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
613pub 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.
624pub 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
693pub fn isGnuLibC(self: CrossTarget) bool {
694 return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi());
695}
696
697pub 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
702pub fn getObjectFormat(self: CrossTarget) Target.ObjectFormat {
703 return Target.getObjectFormatSimple(self.getOsTag(), self.getCpuArch());
704}
705
706pub 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
713fn 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
807test "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 {
123123}
124124
125125pub inline fn __builtin_strlen(s: [*c]const u8) usize {
126 return std.mem.lenZ(s);
126 return std.mem.sliceTo(s, 0).len;
127127}
128128pub inline fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) c_int {
129129 return @as(c_int, std.cstr.cmp(s1, s2));
lib/std/zig/cross_target.zig deleted-909
......@@ -1,909 +0,0 @@
1const std = @import("../std.zig");
2const builtin = @import("builtin");
3const assert = std.debug.assert;
4const Target = std.Target;
5const 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.
10pub 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
807test "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 @@
11const std = @import("std");
22const mem = std.mem;
3const warn = std.debug.warn;
43const Tokenizer = std.zig.Tokenizer;
54const Parser = std.zig.Parser;
65const io = std.io;
lib/std/zig/system.zig+8-8
......@@ -165,7 +165,7 @@ pub const NativePaths = struct {
165165 }
166166
167167 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);
169169 errdefer self.include_dirs.allocator.free(item);
170170 try self.include_dirs.append(item);
171171 }
......@@ -175,7 +175,7 @@ pub const NativePaths = struct {
175175 }
176176
177177 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);
179179 errdefer self.lib_dirs.allocator.free(item);
180180 try self.lib_dirs.append(item);
181181 }
......@@ -189,13 +189,13 @@ pub const NativePaths = struct {
189189 }
190190
191191 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);
193193 errdefer self.framework_dirs.allocator.free(item);
194194 try self.framework_dirs.append(item);
195195 }
196196
197197 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);
199199 errdefer self.warnings.allocator.free(item);
200200 try self.warnings.append(item);
201201 }
......@@ -243,7 +243,7 @@ pub const NativeTargetInfo = struct {
243243 switch (builtin.target.os.tag) {
244244 .linux => {
245245 const uts = std.os.uname();
246 const release = mem.spanZ(&uts.release);
246 const release = mem.sliceTo(&uts.release, 0);
247247 // The release field sometimes has a weird format,
248248 // `Version.parse` will attempt to find some meaningful interpretation.
249249 if (std.builtin.Version.parse(release)) |ver| {
......@@ -257,7 +257,7 @@ pub const NativeTargetInfo = struct {
257257 },
258258 .solaris => {
259259 const uts = std.os.uname();
260 const release = mem.spanZ(&uts.release);
260 const release = mem.sliceTo(&uts.release, 0);
261261 if (std.builtin.Version.parse(release)) |ver| {
262262 os.version_range.semver.min = ver;
263263 os.version_range.semver.max = ver;
......@@ -838,7 +838,7 @@ pub const NativeTargetInfo = struct {
838838 );
839839 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);
840840 // 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);
842842 if (mem.eql(u8, sh_name, ".dynstr")) {
843843 break :find_dyn_str .{
844844 .offset = elfInt(is_64, need_bswap, sh32.sh_offset, sh64.sh_offset),
......@@ -856,7 +856,7 @@ pub const NativeTargetInfo = struct {
856856 const rpoff_usize = std.math.cast(usize, rpoff) catch |err| switch (err) {
857857 error.Overflow => return error.InvalidElfFile,
858858 };
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);
860860 var it = mem.tokenize(u8, rpath_list, ":");
861861 while (it.next()) |rpath| {
862862 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 {
334334
335335 /// For debugging purposes
336336 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] });
338338 }
339339
340340 pub fn init(buffer: [:0]const u8) Tokenizer {
src/AstGen.zig+6-26
......@@ -8399,7 +8399,7 @@ fn parseStrLit(
83998399 const raw_string = bytes[offset..];
84008400 var buf_managed = buf.toManaged(astgen.gpa);
84018401 const result = std.zig.string_literal.parseAppend(&buf_managed, raw_string);
8402 buf.* = buf_managed.toUnmanaged();
8402 buf.* = buf_managed.moveToUnmanaged();
84038403 switch (try result) {
84048404 .success => return,
84058405 .invalid_character => |bad_index| {
......@@ -8472,11 +8472,7 @@ fn failNodeNotes(
84728472 @setCold(true);
84738473 const string_bytes = &astgen.string_bytes;
84748474 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);
84808476 const notes_index: u32 = if (notes.len != 0) blk: {
84818477 const notes_start = astgen.extra.items.len;
84828478 try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len);
......@@ -8513,11 +8509,7 @@ fn failTokNotes(
85138509 @setCold(true);
85148510 const string_bytes = &astgen.string_bytes;
85158511 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);
85218513 const notes_index: u32 = if (notes.len != 0) blk: {
85228514 const notes_start = astgen.extra.items.len;
85238515 try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len);
......@@ -8546,11 +8538,7 @@ fn failOff(
85468538 @setCold(true);
85478539 const string_bytes = &astgen.string_bytes;
85488540 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);
85548542 try astgen.compile_errors.append(astgen.gpa, .{
85558543 .msg = msg,
85568544 .node = 0,
......@@ -8570,11 +8558,7 @@ fn errNoteTok(
85708558 @setCold(true);
85718559 const string_bytes = &astgen.string_bytes;
85728560 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);
85788562 return astgen.addExtra(Zir.Inst.CompileErrors.Item{
85798563 .msg = msg,
85808564 .node = 0,
......@@ -8593,11 +8577,7 @@ fn errNoteNode(
85938577 @setCold(true);
85948578 const string_bytes = &astgen.string_bytes;
85958579 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);
86018581 return astgen.addExtra(Zir.Inst.CompileErrors.Item{
86028582 .msg = msg,
86038583 .node = node,
src/Module.zig+9-9
......@@ -470,7 +470,7 @@ pub const Decl = struct {
470470 pub const DepsTable = std.AutoArrayHashMapUnmanaged(*Decl, void);
471471
472472 pub fn clearName(decl: *Decl, gpa: *Allocator) void {
473 gpa.free(mem.spanZ(decl.name));
473 gpa.free(mem.sliceTo(decl.name, 0));
474474 decl.name = undefined;
475475 }
476476
......@@ -627,12 +627,12 @@ pub const Decl = struct {
627627 }
628628
629629 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);
631631 return decl.src_namespace.renderFullyQualifiedName(unqualified_name, writer);
632632 }
633633
634634 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);
636636 return decl.src_namespace.renderFullyQualifiedDebugName(unqualified_name, writer);
637637 }
638638
......@@ -737,7 +737,7 @@ pub const Decl = struct {
737737 decl.scope.sub_file_path,
738738 loc.line + 1,
739739 loc.column + 1,
740 mem.spanZ(decl.name),
740 mem.sliceTo(decl.name, 0),
741741 @tagName(decl.analysis),
742742 });
743743 if (decl.has_tv) {
......@@ -1342,7 +1342,7 @@ pub const Namespace = struct {
13421342 ) @TypeOf(writer).Error!void {
13431343 if (ns.parent) |parent| {
13441344 const decl = ns.getDecl();
1345 try parent.renderFullyQualifiedName(mem.spanZ(decl.name), writer);
1345 try parent.renderFullyQualifiedName(mem.sliceTo(decl.name, 0), writer);
13461346 } else {
13471347 try ns.file_scope.renderFullyQualifiedName(writer);
13481348 }
......@@ -1361,7 +1361,7 @@ pub const Namespace = struct {
13611361 var separator_char: u8 = '.';
13621362 if (ns.parent) |parent| {
13631363 const decl = ns.getDecl();
1364 try parent.renderFullyQualifiedDebugName(mem.spanZ(decl.name), writer);
1364 try parent.renderFullyQualifiedDebugName(mem.sliceTo(decl.name, 0), writer);
13651365 } else {
13661366 try ns.file_scope.renderFullyQualifiedDebugName(writer);
13671367 separator_char = ':';
......@@ -3432,7 +3432,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
34323432 return sema.fail(&block_scope, export_src, "export of inline function", .{});
34333433 }
34343434 // 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) };
34363436 try sema.analyzeExport(&block_scope, export_src, options, decl);
34373437 }
34383438 return type_changed or is_inline != prev_is_inline;
......@@ -3501,7 +3501,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
35013501 if (decl.is_exported) {
35023502 const export_src = src; // TODO point to the export token
35033503 // 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) };
35053505 try sema.analyzeExport(&block_scope, export_src, options, decl);
35063506 }
35073507
......@@ -4675,7 +4675,7 @@ pub fn processOutdatedAndDeletedDecls(mod: *Module) !void {
46754675
46764676 // Remove from the namespace it resides in, preserving declaration order.
46774677 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));
46794679
46804680 try mod.clearDecl(decl, &outdated_decls);
46814681 decl.destroy(mod);
src/Package.zig+1-1
......@@ -115,7 +115,7 @@ pub fn deinitTable(pkg: *Package, gpa: *Allocator) void {
115115
116116pub fn add(pkg: *Package, gpa: *Allocator, name: []const u8, package: *Package) !void {
117117 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);
119119 pkg.table.putAssumeCapacityNoClobber(name_dupe, package);
120120}
121121
src/Sema.zig+1-1
......@@ -1639,7 +1639,7 @@ fn createTypeName(sema: *Sema, block: *Block, name_strategy: Zir.Inst.NameStrate
16391639 block.src_decl.name, name_index,
16401640 });
16411641 },
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)),
16431643 .func => {
16441644 const name_index = sema.mod.getNextAnonNameIndex();
16451645 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 {
15011501 });
15021502 } else if (func_value.castTag(.extern_fn)) |func_payload| {
15031503 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));
15051505
15061506 _ = try self.addInst(.{
15071507 .tag = .call_extern,
src/arch/x86_64/CodeGen.zig+1-1
......@@ -1966,7 +1966,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {
19661966 });
19671967 } else if (func_value.castTag(.extern_fn)) |func_payload| {
19681968 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));
19701970 _ = try self.addInst(.{
19711971 .tag = .call_extern,
19721972 .ops = undefined,
src/codegen/c.zig+1-1
......@@ -981,7 +981,7 @@ pub const DeclGen = struct {
981981 if (dg.module.decl_exports.get(decl)) |exports| {
982982 return writer.writeAll(exports[0].options.name);
983983 } else if (decl.val.tag() == .extern_fn) {
984 return writer.writeAll(mem.spanZ(decl.name));
984 return writer.writeAll(mem.sliceTo(decl.name, 0));
985985 } else {
986986 const gpa = dg.module.gpa;
987987 const name = try decl.getFullyQualifiedName(gpa);
src/libc_installation.zig+15-15
......@@ -76,7 +76,7 @@ pub const LibCInstallation = struct {
7676 if (value.len == 0) {
7777 @field(self, field.name) = null;
7878 } else {
79 found_keys[i].allocated = try std.mem.dupeZ(allocator, u8, value);
79 found_keys[i].allocated = try allocator.dupeZ(u8, value);
8080 @field(self, field.name) = found_keys[i].allocated;
8181 }
8282 break;
......@@ -213,7 +213,7 @@ pub const LibCInstallation = struct {
213213 errdefer batch.wait() catch {};
214214 batch.add(&async self.findNativeIncludeDirPosix(args));
215215 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");
217217 break :blk batch.wait();
218218 };
219219 } else {
......@@ -222,8 +222,8 @@ pub const LibCInstallation = struct {
222222 errdefer batch.wait() catch {};
223223 batch.add(&async self.findNativeIncludeDirPosix(args));
224224 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"),
227227 .linux => batch.add(&async self.findNativeCrtDirPosix(args)),
228228 else => {},
229229 }
......@@ -344,7 +344,7 @@ pub const LibCInstallation = struct {
344344
345345 if (self.include_dir == null) {
346346 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);
348348 } else |err| switch (err) {
349349 error.FileNotFound => {},
350350 else => return error.FileSystem,
......@@ -353,7 +353,7 @@ pub const LibCInstallation = struct {
353353
354354 if (self.sys_include_dir == null) {
355355 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);
357357 } else |err| switch (err) {
358358 error.FileNotFound => {},
359359 else => return error.FileSystem,
......@@ -557,7 +557,7 @@ pub const LibCInstallation = struct {
557557 ) FindError!void {
558558 const allocator = args.allocator;
559559 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]);
561561 }
562562};
563563
......@@ -631,10 +631,10 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 {
631631 // So we detect failure by checking if the output matches exactly the input.
632632 if (std.mem.eql(u8, line, args.search_basename)) return error.LibCRuntimeNotFound;
633633 switch (args.want_dirname) {
634 .full_path => return std.mem.dupeZ(allocator, u8, line),
634 .full_path => return allocator.dupeZ(u8, line),
635635 .only_dir => {
636636 const dirname = fs.path.dirname(line) orelse return error.LibCRuntimeNotFound;
637 return std.mem.dupeZ(allocator, u8, dirname);
637 return allocator.dupeZ(u8, dirname);
638638 },
639639 }
640640}
......@@ -648,17 +648,17 @@ fn printVerboseInvocation(
648648 if (!verbose) return;
649649
650650 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});
652652 } 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", .{});
654654 }
655655 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});
658658 }
659 std.debug.warn("\n", .{});
659 std.debug.print("\n", .{});
660660 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});
662662 }
663663}
664664
src/link/Coff.zig+1-1
......@@ -752,7 +752,7 @@ fn finishUpdateDecl(self: *Coff, module: *Module, decl: *Module.Decl, code: []co
752752 } else {
753753 const vaddr = try self.allocateTextBlock(&decl.link.coff, code.len, required_alignment);
754754 log.debug("allocated text block for {s} at 0x{x} (size: {Bi})\n", .{
755 mem.spanZ(decl.name),
755 mem.sliceTo(decl.name, 0),
756756 vaddr,
757757 std.fmt.fmtIntSizeDec(code.len),
758758 });
src/link/Elf.zig+4-4
......@@ -429,7 +429,7 @@ fn makeDebugString(self: *Elf, bytes: []const u8) !u32 {
429429
430430fn getString(self: *Elf, str_off: u32) []const u8 {
431431 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);
433433}
434434
435435fn 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
22362236 self.shrinkTextBlock(&decl.link.elf, code.len);
22372237 }
22382238 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));
22402240 local_sym.st_info = (elf.STB_LOCAL << 4) | stt_bits;
22412241 local_sym.st_other = 0;
22422242 local_sym.st_shndx = self.text_section_index.?;
22432243 // TODO this write could be avoided if no fields of the symbol were changed.
22442244 try self.writeSymbol(decl.link.elf.local_sym_index);
22452245 } else {
2246 const decl_name = mem.spanZ(decl.name);
2246 const decl_name = mem.sliceTo(decl.name, 0);
22472247 const name_str_index = try self.makeString(decl_name);
22482248 const vaddr = try self.allocateTextBlock(&decl.link.elf, code.len, required_alignment);
22492249 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
23712371 dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy);
23722372
23732373 // .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];
23752375 try dbg_info_buffer.ensureUnusedCapacity(25 + decl_name_with_null.len);
23762376
23772377 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
34393439 decl.link.macho.size = code_len;
34403440 decl.link.macho.dirty = true;
34413441
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 });
34433445 defer self.base.allocator.free(new_name);
34443446
34453447 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
34473449 symbol.n_sect = @intCast(u8, self.text_section_index.?) + 1;
34483450 symbol.n_desc = 0;
34493451 } 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 });
34513455 defer self.base.allocator.free(decl_name);
34523456
34533457 const name_str_index = try self.makeString(decl_name);
......@@ -4045,7 +4049,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
40454049 self.dylinker_cmd_index = @intCast(u16, self.load_commands.items.len);
40464050 const cmdsize = @intCast(u32, mem.alignForwardGeneric(
40474051 u64,
4048 @sizeOf(macho.dylinker_command) + mem.lenZ(default_dyld_path),
4052 @sizeOf(macho.dylinker_command) + mem.sliceTo(default_dyld_path, 0).len,
40494053 @sizeOf(u64),
40504054 ));
40514055 var dylinker_cmd = commands.emptyGenericCommandWithData(macho.dylinker_command{
......@@ -4055,7 +4059,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
40554059 });
40564060 dylinker_cmd.data = try self.base.allocator.alloc(u8, cmdsize - dylinker_cmd.inner.name);
40574061 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));
40594063 try self.load_commands.append(self.base.allocator, .{ .Dylinker = dylinker_cmd });
40604064 self.load_commands_dirty = true;
40614065 }
......@@ -5292,7 +5296,7 @@ pub fn makeString(self: *MachO, string: []const u8) !u32 {
52925296
52935297pub fn getString(self: *MachO, off: u32) []const u8 {
52945298 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);
52965300}
52975301
52985302pub 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)
175175 };
176176 const object_offset = try symtab_reader.readIntLittle(u32);
177177
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);
179179 const owned_name = try allocator.dupe(u8, sym_name);
180180 const res = try self.toc.getOrPut(allocator, owned_name);
181181 defer if (res.found_existing) allocator.free(owned_name);
src/link/MachO/DebugSymbols.zig+1-1
......@@ -884,7 +884,7 @@ pub fn initDeclDebugBuffers(
884884 dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy);
885885
886886 // .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];
888888 try dbg_info_buffer.ensureUnusedCapacity(27 + decl_name_with_null.len);
889889
890890 const fn_ret_type = decl.ty.fnReturnType();
src/link/MachO/Dylib.zig+2-2
......@@ -56,7 +56,7 @@ pub const Id = struct {
5656 pub fn fromLoadCommand(allocator: *Allocator, lc: commands.GenericCommandWithData(macho.dylib_command)) !Id {
5757 const dylib = lc.inner.dylib;
5858 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));
6060
6161 return Id{
6262 .name = name,
......@@ -230,7 +230,7 @@ fn parseSymbols(self: *Dylib, allocator: *Allocator) !void {
230230
231231 if (!add_to_symtab) continue;
232232
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);
234234 const name = try allocator.dupe(u8, sym_name);
235235 try self.symbols.putNoClobber(allocator, name, {});
236236 }
src/link/MachO/Object.zig+1-1
......@@ -633,5 +633,5 @@ fn readSection(self: Object, allocator: *Allocator, index: u16) ![]u8 {
633633
634634pub fn getString(self: Object, off: u32) []const u8 {
635635 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);
637637}
src/link/Plan9.zig+1-1
......@@ -299,7 +299,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl: *Module.Decl) !void {
299299 return;
300300 },
301301 };
302 var duped_code = try std.mem.dupe(self.base.allocator, u8, code);
302 var duped_code = try self.base.allocator.dupe(u8, code);
303303 errdefer self.base.allocator.free(duped_code);
304304 try self.data_decl_table.put(self.base.allocator, decl, duped_code);
305305 return self.updateFinish(decl);
src/main.zig+2-2
......@@ -1282,7 +1282,7 @@ fn buildOutputType(
12821282 try clang_argv.appendSlice(it.other_args);
12831283 },
12841284 .positional => {
1285 const file_ext = Compilation.classifyFileExt(mem.spanZ(it.only_arg));
1285 const file_ext = Compilation.classifyFileExt(mem.sliceTo(it.only_arg, 0));
12861286 switch (file_ext) {
12871287 .assembly, .c, .cpp, .ll, .bc, .h, .m, .mm => try c_source_files.append(.{ .src_path = it.only_arg }),
12881288 .unknown, .shared_library, .object, .static_library => {
......@@ -4117,7 +4117,7 @@ pub const ClangArgIterator = struct {
41174117 }
41184118 }
41194119 while (it.next()) |token| {
4120 const dupe_token = try mem.dupeZ(allocator, u8, token);
4120 const dupe_token = try allocator.dupeZ(u8, token);
41214121 errdefer allocator.free(dupe_token);
41224122 try resp_arg_list.append(dupe_token);
41234123 }
src/stage1.zig+3-3
......@@ -42,7 +42,7 @@ pub fn main(argc: c_int, argv: [*][*:0]u8) callconv(.C) c_int {
4242
4343 const args = arena.alloc([]const u8, @intCast(usize, argc)) catch fatal("{s}", .{"OutOfMemory"});
4444 for (args) |*arg, i| {
45 arg.* = mem.spanZ(argv[i]);
45 arg.* = mem.sliceTo(argv[i], 0);
4646 }
4747 if (builtin.mode == .Debug) {
4848 stage2.mainArgs(gpa, arena, args) catch unreachable;
......@@ -434,14 +434,14 @@ export fn stage2_add_link_lib(
434434 return null;
435435 }
436436 if (!target.isWasm() and !comp.bin_file.options.pic) {
437 return std.fmt.allocPrint0(
437 return std.fmt.allocPrintZ(
438438 comp.gpa,
439439 "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.",
440440 .{ lib_name, lib_name },
441441 ) catch "out of memory";
442442 }
443443 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}", .{
445445 lib_name, @errorName(err),
446446 }) catch "out of memory";
447447 };
src/translate_c.zig+3-3
......@@ -335,7 +335,7 @@ pub const Context = struct {
335335
336336 /// Convert a null-terminated C string to a slice allocated in the arena
337337 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));
339339 }
340340
341341 /// Convert a clang source location to a file:line:column string
......@@ -2553,7 +2553,7 @@ fn transInitListExprRecord(
25532553 var raw_name = try c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin());
25542554 if (field_decl.isAnonymousStructOrUnion()) {
25552555 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);
25572557 }
25582558
25592559 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
33183318 const field_decl = @ptrCast(*const clang.FieldDecl, member_decl);
33193319 if (field_decl.isAnonymousStructOrUnion()) {
33203320 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);
33223322 }
33233323 }
33243324 const decl = @ptrCast(*const clang.NamedDecl, member_decl);
src/type.zig+1-1
......@@ -1179,7 +1179,7 @@ pub const Type = extern union {
11791179 },
11801180 .error_set => {
11811181 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));
11831183 },
11841184 .error_set_inferred => {
11851185 const func = ty.castTag(.error_set_inferred).?.data.func;
src/value.zig+2-2
......@@ -753,9 +753,9 @@ pub const Value = extern union {
753753 const bytes = val.castTag(.bytes).?.data;
754754 const adjusted_len = bytes.len - @boolToInt(ty.sentinel() != null);
755755 const adjusted_bytes = bytes[0..adjusted_len];
756 return std.mem.dupe(allocator, u8, adjusted_bytes);
756 return allocator.dupe(u8, adjusted_bytes);
757757 },
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),
759759 .repeated => @panic("TODO implement toAllocatedBytes for this Value tag"),
760760 .decl_ref => {
761761 const decl = val.castTag(.decl_ref).?.data;
test/behavior/async_fn.zig+2-2
......@@ -715,7 +715,7 @@ fn testAsyncAwaitTypicalUsage(
715715 var global_download_frame: anyframe = undefined;
716716 fn fetchUrl(allocator: *std.mem.Allocator, url: []const u8) anyerror![]u8 {
717717 _ = url;
718 const result = try std.mem.dupe(allocator, u8, "expected download text");
718 const result = try allocator.dupe(u8, "expected download text");
719719 errdefer allocator.free(result);
720720 if (suspend_download) {
721721 suspend {
......@@ -729,7 +729,7 @@ fn testAsyncAwaitTypicalUsage(
729729 var global_file_frame: anyframe = undefined;
730730 fn readFile(allocator: *std.mem.Allocator, filename: []const u8) anyerror![]u8 {
731731 _ = filename;
732 const result = try std.mem.dupe(allocator, u8, "expected file text");
732 const result = try allocator.dupe(u8, "expected file text");
733733 errdefer allocator.free(result);
734734 if (suspend_file) {
735735 suspend {
test/behavior/cast_stage1.zig+1-1
......@@ -171,7 +171,7 @@ fn testCastPtrOfArrayToSliceAndPtr() !void {
171171test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
172172 const window_name = [1][*]const u8{"window name"};
173173 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"));
175175}
176176
177177test "cast f16 to wider types" {
test/behavior/pointers_stage1.zig+1-1
......@@ -142,7 +142,7 @@ test "null terminated pointer" {
142142 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);
143143 var no_zero_ptr: [*]const u8 = zero_ptr;
144144 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"));
146146 }
147147 };
148148 try S.doTheTest();
test/cli.zig+10-10
......@@ -19,11 +19,11 @@ pub fn main() !void {
1919 a = &arena.allocator;
2020
2121 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", .{});
2323 return error.InvalidArgs;
2424 });
2525 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", .{});
2727 return error.InvalidArgs;
2828 });
2929 const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel});
......@@ -47,11 +47,11 @@ pub fn main() !void {
4747}
4848
4949fn printCmd(cwd: []const u8, argv: []const []const u8) void {
50 std.debug.warn("cd {s} && ", .{cwd});
50 std.debug.print("cd {s} && ", .{cwd});
5151 for (argv) |arg| {
52 std.debug.warn("{s} ", .{arg});
52 std.debug.print("{s} ", .{arg});
5353 }
54 std.debug.warn("\n", .{});
54 std.debug.print("\n", .{});
5555}
5656
5757fn 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
6262 .cwd = cwd,
6363 .max_output_bytes = max_output_size,
6464 }) catch |err| {
65 std.debug.warn("The following command failed:\n", .{});
65 std.debug.print("The following command failed:\n", .{});
6666 printCmd(cwd, argv);
6767 return err;
6868 };
6969 switch (result.term) {
7070 .Exited => |code| {
7171 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});
7373 printCmd(cwd, argv);
74 std.debug.warn("stderr:\n{s}\n", .{result.stderr});
74 std.debug.print("stderr:\n{s}\n", .{result.stderr});
7575 return error.CommandFailed;
7676 }
7777 },
7878 else => {
79 std.debug.warn("The following command terminated unexpectedly:\n", .{});
79 std.debug.print("The following command terminated unexpectedly:\n", .{});
8080 printCmd(cwd, argv);
81 std.debug.warn("stderr:\n{s}\n", .{result.stderr});
81 std.debug.print("stderr:\n{s}\n", .{result.stderr});
8282 return error.CommandFailed;
8383 },
8484 }
test/src/compare_output.zig-1
......@@ -6,7 +6,6 @@ const ArrayList = std.ArrayList;
66const fmt = std.fmt;
77const mem = std.mem;
88const fs = std.fs;
9const warn = std.debug.warn;
109const Mode = std.builtin.Mode;
1110
1211pub const CompareOutputContext = struct {
test/src/run_translated_c.zig-1
......@@ -6,7 +6,6 @@ const ArrayList = std.ArrayList;
66const fmt = std.fmt;
77const mem = std.mem;
88const fs = std.fs;
9const warn = std.debug.warn;
109
1110pub const RunTranslatedCContext = struct {
1211 b: *build.Builder,
test/src/translate_c.zig-1
......@@ -6,7 +6,6 @@ const ArrayList = std.ArrayList;
66const fmt = std.fmt;
77const mem = std.mem;
88const fs = std.fs;
9const warn = std.debug.warn;
109const CrossTarget = std.zig.CrossTarget;
1110
1211pub const TranslateCContext = struct {
test/tests.zig+12-13
......@@ -1,7 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const debug = std.debug;
4const warn = debug.warn;
54const build = std.build;
65const CrossTarget = std.zig.CrossTarget;
76const io = std.io;
......@@ -716,7 +715,7 @@ pub const StackTracesContext = struct {
716715 defer args.deinit();
717716 args.append(full_exe_path) catch unreachable;
718717
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 });
720719
721720 const child = std.ChildProcess.init(args.items, b.allocator) catch unreachable;
722721 defer child.deinit();
......@@ -745,7 +744,7 @@ pub const StackTracesContext = struct {
745744 .Exited => |code| {
746745 const expect_code: u32 = 1;
747746 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", .{
749748 full_exe_path,
750749 code,
751750 expect_code,
......@@ -755,17 +754,17 @@ pub const StackTracesContext = struct {
755754 }
756755 },
757756 .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 });
759758 printInvocation(args.items);
760759 return error.TestFailed;
761760 },
762761 .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 });
764763 printInvocation(args.items);
765764 return error.TestFailed;
766765 },
767766 .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 });
769768 printInvocation(args.items);
770769 return error.TestFailed;
771770 },
......@@ -829,7 +828,7 @@ pub const StackTracesContext = struct {
829828 };
830829
831830 if (!mem.eql(u8, self.expect_output, got)) {
832 warn(
831 std.debug.print(
833832 \\
834833 \\========= Expected this output: =========
835834 \\{s}
......@@ -839,7 +838,7 @@ pub const StackTracesContext = struct {
839838 , .{ self.expect_output, got });
840839 return error.TestFailed;
841840 }
842 warn("OK\n", .{});
841 std.debug.print("OK\n", .{});
843842 }
844843 };
845844};
......@@ -1003,14 +1002,14 @@ pub const GenHContext = struct {
10031002 const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
10041003 const b = self.context.b;
10051004
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 });
10071006
10081007 const full_h_path = self.obj.getOutputHPath();
10091008 const actual_h = try io.readFileAlloc(b.allocator, full_h_path);
10101009
10111010 for (self.case.expected_lines.items) |expected_line| {
10121011 if (mem.indexOf(u8, actual_h, expected_line) == null) {
1013 warn(
1012 std.debug.print(
10141013 \\
10151014 \\========= Expected this output: ================
10161015 \\{s}
......@@ -1021,7 +1020,7 @@ pub const GenHContext = struct {
10211020 return error.TestFailed;
10221021 }
10231022 }
1024 warn("OK\n", .{});
1023 std.debug.print("OK\n", .{});
10251024 }
10261025 };
10271026
......@@ -1077,7 +1076,7 @@ pub const GenHContext = struct {
10771076
10781077fn printInvocation(args: []const []const u8) void {
10791078 for (args) |arg| {
1080 warn("{s} ", .{arg});
1079 std.debug.print("{s} ", .{arg});
10811080 }
1082 warn("\n", .{});
1081 std.debug.print("\n", .{});
10831082}
tools/process_headers.zig+13-13
......@@ -295,7 +295,7 @@ pub fn main() !void {
295295 if (std.mem.eql(u8, args[arg_i], "--help"))
296296 usageAndExit(args[0]);
297297 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]});
299299 usageAndExit(args[0]);
300300 }
301301
......@@ -308,7 +308,7 @@ pub fn main() !void {
308308 assert(opt_abi == null);
309309 opt_abi = args[arg_i + 1];
310310 } else {
311 std.debug.warn("unrecognized argument: {s}\n", .{args[arg_i]});
311 std.debug.print("unrecognized argument: {s}\n", .{args[arg_i]});
312312 usageAndExit(args[0]);
313313 }
314314
......@@ -322,7 +322,7 @@ pub fn main() !void {
322322 else if (std.mem.eql(u8, abi_name, "glibc"))
323323 LibCVendor.glibc
324324 else {
325 std.debug.warn("unrecognized C ABI: {s}\n", .{abi_name});
325 std.debug.print("unrecognized C ABI: {s}\n", .{abi_name});
326326 usageAndExit(args[0]);
327327 };
328328 const generic_name = try std.fmt.allocPrint(allocator, "generic-{s}", .{abi_name});
......@@ -393,7 +393,7 @@ pub fn main() !void {
393393 if (gop.found_existing) {
394394 max_bytes_saved += raw_bytes.len;
395395 gop.value_ptr.hit_count += 1;
396 std.debug.warn("duplicate: {s} {s} ({:2})\n", .{
396 std.debug.print("duplicate: {s} {s} ({:2})\n", .{
397397 libc_target.name,
398398 rel_path,
399399 std.fmt.fmtIntSizeDec(raw_bytes.len),
......@@ -415,16 +415,16 @@ pub fn main() !void {
415415 };
416416 try target_to_hash.putNoClobber(dest_target, hash);
417417 },
418 else => std.debug.warn("warning: weird file: {s}\n", .{full_path}),
418 else => std.debug.print("warning: weird file: {s}\n", .{full_path}),
419419 }
420420 }
421421 }
422422 break;
423423 } 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});
425425 }
426426 }
427 std.debug.warn("summary: {:2} could be reduced to {:2}\n", .{
427 std.debug.print("summary: {:2} could be reduced to {:2}\n", .{
428428 std.fmt.fmtIntSizeDec(total_bytes),
429429 std.fmt.fmtIntSizeDec(total_bytes - max_bytes_saved),
430430 });
......@@ -456,7 +456,7 @@ pub fn main() !void {
456456 if (contender.hit_count > 1) {
457457 const this_missed_bytes = contender.hit_count * contender.bytes.len;
458458 missed_opportunity_bytes += this_missed_bytes;
459 std.debug.warn("Missed opportunity ({:2}): {s}\n", .{
459 std.debug.print("Missed opportunity ({:2}): {s}\n", .{
460460 std.fmt.fmtIntSizeDec(this_missed_bytes),
461461 path_kv.key_ptr.*,
462462 });
......@@ -486,10 +486,10 @@ pub fn main() !void {
486486}
487487
488488fn 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", .{});
494494 std.process.exit(1);
495495}
tools/update-linux-headers.zig+11-11
......@@ -141,7 +141,7 @@ pub fn main() !void {
141141 if (std.mem.eql(u8, args[arg_i], "--help"))
142142 usageAndExit(args[0]);
143143 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]});
145145 usageAndExit(args[0]);
146146 }
147147
......@@ -151,7 +151,7 @@ pub fn main() !void {
151151 assert(opt_out_dir == null);
152152 opt_out_dir = args[arg_i + 1];
153153 } else {
154 std.debug.warn("unrecognized argument: {s}\n", .{args[arg_i]});
154 std.debug.print("unrecognized argument: {s}\n", .{args[arg_i]});
155155 usageAndExit(args[0]);
156156 }
157157
......@@ -208,7 +208,7 @@ pub fn main() !void {
208208 if (gop.found_existing) {
209209 max_bytes_saved += raw_bytes.len;
210210 gop.value_ptr.hit_count += 1;
211 std.debug.warn("duplicate: {s} {s} ({:2})\n", .{
211 std.debug.print("duplicate: {s} {s} ({:2})\n", .{
212212 linux_target.name,
213213 rel_path,
214214 std.fmt.fmtIntSizeDec(raw_bytes.len),
......@@ -230,16 +230,16 @@ pub fn main() !void {
230230 };
231231 try target_to_hash.putNoClobber(dest_target, hash);
232232 },
233 else => std.debug.warn("warning: weird file: {s}\n", .{full_path}),
233 else => std.debug.print("warning: weird file: {s}\n", .{full_path}),
234234 }
235235 }
236236 }
237237 break;
238238 } 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});
240240 }
241241 }
242 std.debug.warn("summary: {:2} could be reduced to {:2}\n", .{
242 std.debug.print("summary: {:2} could be reduced to {:2}\n", .{
243243 std.fmt.fmtIntSizeDec(total_bytes),
244244 std.fmt.fmtIntSizeDec(total_bytes - max_bytes_saved),
245245 });
......@@ -271,7 +271,7 @@ pub fn main() !void {
271271 if (contender.hit_count > 1) {
272272 const this_missed_bytes = contender.hit_count * contender.bytes.len;
273273 missed_opportunity_bytes += this_missed_bytes;
274 std.debug.warn("Missed opportunity ({:2}): {s}\n", .{
274 std.debug.print("Missed opportunity ({:2}): {s}\n", .{
275275 std.fmt.fmtIntSizeDec(this_missed_bytes),
276276 path_kv.key_ptr.*,
277277 });
......@@ -297,9 +297,9 @@ pub fn main() !void {
297297}
298298
299299fn 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", .{});
304304 std.process.exit(1);
305305}
tools/update_cpu_features.zig+3-3
......@@ -875,16 +875,16 @@ fn processOneTarget(job: Job) anyerror!void {
875875 });
876876 tblgen_progress.end();
877877 if (child_result.stderr.len != 0) {
878 std.debug.warn("{s}\n", .{child_result.stderr});
878 std.debug.print("{s}\n", .{child_result.stderr});
879879 }
880880
881881 const json_text = switch (child_result.term) {
882882 .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});
884884 std.process.exit(1);
885885 },
886886 else => {
887 std.debug.warn("llvm-tblgen crashed\n", .{});
887 std.debug.print("llvm-tblgen crashed\n", .{});
888888 std.process.exit(1);
889889 },
890890 };
tools/update_glibc.zig+1-1
......@@ -185,7 +185,7 @@ pub fn main() !void {
185185 };
186186 const max_bytes = 10 * 1024 * 1024;
187187 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 });
189189 std.process.exit(1);
190190 };
191191 var lines_it = std.mem.tokenize(u8, contents, "\n");