| author | |
| committer | |
| log | bf74827ddb34e36906c5f7615f8b488d90e16be4 |
| tree | e00a03395bbffa6359640093c976c2dde8f775dd |
| parent | 1b56686012c49b34f395c82741b03587633aaa31 |
41 files changed, 346 insertions(+), 416 deletions(-)
lib/compiler/aro/aro/Compilation.zig+11-10| ... | ... | @@ -74,9 +74,7 @@ pub const Environment = struct { |
| 74 | 74 | pub const default: @This() = .{ .provided = 0 }; |
| 75 | 75 | }; |
| 76 | 76 | |
| 77 | /// Load all of the environment variables using the std.process API. Do not use if using Aro as a shared library on Linux without libc | |
| 78 | /// See https://github.com/ziglang/zig/issues/4524 | |
| 79 | pub fn loadAll(allocator: std.mem.Allocator) !Environment { | |
| 77 | pub fn loadAll(allocator: std.mem.Allocator, environ_map: *const std.process.Environ.Map) !Environment { | |
| 80 | 78 | var env: Environment = .{}; |
| 81 | 79 | errdefer env.deinit(allocator); |
| 82 | 80 | |
| ... | ... | @@ -85,11 +83,7 @@ pub const Environment = struct { |
| 85 | 83 | |
| 86 | 84 | var env_var_buf: [field.name.len]u8 = undefined; |
| 87 | 85 | const env_var_name = std.ascii.upperString(&env_var_buf, field.name); |
| 88 | const val: ?[]const u8 = std.process.getEnvVarOwned(allocator, env_var_name) catch |err| switch (err) { | |
| 89 | error.OutOfMemory => |e| return e, | |
| 90 | error.EnvironmentVariableNotFound => null, | |
| 91 | error.InvalidWtf8 => null, | |
| 92 | }; | |
| 86 | const val: ?[]const u8 = if (environ_map.get(env_var_name)) |v| try allocator.dupe(u8, v) else null; | |
| 93 | 87 | @field(env, field.name) = val; |
| 94 | 88 | } |
| 95 | 89 | return env; |
| ... | ... | @@ -193,13 +187,20 @@ pub fn init(gpa: Allocator, arena: Allocator, io: Io, diagnostics: *Diagnostics, |
| 193 | 187 | |
| 194 | 188 | /// Initialize Compilation with default environment, |
| 195 | 189 | /// pragma handlers and emulation mode set to target. |
| 196 | pub fn initDefault(gpa: Allocator, arena: Allocator, io: Io, diagnostics: *Diagnostics, cwd: Io.Dir) !Compilation { | |
| 190 | pub fn initDefault( | |
| 191 | gpa: Allocator, | |
| 192 | arena: Allocator, | |
| 193 | io: Io, | |
| 194 | diagnostics: *Diagnostics, | |
| 195 | cwd: Io.Dir, | |
| 196 | env_map: *const std.process.Environ.Map, | |
| 197 | ) !Compilation { | |
| 197 | 198 | var comp: Compilation = .{ |
| 198 | 199 | .gpa = gpa, |
| 199 | 200 | .arena = arena, |
| 200 | 201 | .io = io, |
| 201 | 202 | .diagnostics = diagnostics, |
| 202 | .environment = try Environment.loadAll(gpa), | |
| 203 | .environment = try Environment.loadAll(gpa, env_map), | |
| 203 | 204 | .cwd = cwd, |
| 204 | 205 | }; |
| 205 | 206 | errdefer comp.deinit(); |
lib/compiler/aro/aro/Driver.zig+24-16| ... | ... | @@ -1250,21 +1250,25 @@ fn getOutFileName(d: *Driver, source: Source, buf: *[std.fs.max_name_bytes]u8) ! |
| 1250 | 1250 | } |
| 1251 | 1251 | |
| 1252 | 1252 | fn invokeAssembler(d: *Driver, tc: *Toolchain, input_path: []const u8, output_path: []const u8) !void { |
| 1253 | const io = d.comp.io; | |
| 1253 | 1254 | var assembler_path_buf: [std.fs.max_path_bytes]u8 = undefined; |
| 1254 | 1255 | const assembler_path = try tc.getAssemblerPath(&assembler_path_buf); |
| 1255 | 1256 | const argv = [_][]const u8{ assembler_path, input_path, "-o", output_path }; |
| 1256 | 1257 | |
| 1257 | var child = std.process.Child.init(&argv, d.comp.gpa); | |
| 1258 | // TODO handle better | |
| 1259 | child.stdin_behavior = .inherit; | |
| 1260 | child.stdout_behavior = .inherit; | |
| 1261 | child.stderr_behavior = .inherit; | |
| 1262 | ||
| 1263 | const term = child.spawnAndWait() catch |er| { | |
| 1258 | var child = std.process.spawn(io, .{ | |
| 1259 | .argv = &argv, | |
| 1260 | // TODO handle better | |
| 1261 | .stdin = .inherit, | |
| 1262 | .stdout = .inherit, | |
| 1263 | .stderr = .inherit, | |
| 1264 | }) catch |er| { | |
| 1264 | 1265 | return d.fatal("unable to spawn linker: {s}", .{errorDescription(er)}); |
| 1265 | 1266 | }; |
| 1267 | const term = child.wait(io) catch |er| { | |
| 1268 | return d.fatal("unable to wait linker: {s}", .{errorDescription(er)}); | |
| 1269 | }; | |
| 1266 | 1270 | switch (term) { |
| 1267 | .Exited => |code| if (code != 0) { | |
| 1271 | .exited => |code| if (code != 0) { | |
| 1268 | 1272 | const e = d.fatal("assembler exited with an error code", .{}); |
| 1269 | 1273 | return e; |
| 1270 | 1274 | }, |
| ... | ... | @@ -1490,6 +1494,7 @@ fn dumpLinkerArgs(w: *std.Io.Writer, items: []const []const u8) !void { |
| 1490 | 1494 | /// **MAY call `exit` if `fast_exit` is set.** |
| 1491 | 1495 | pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) Compilation.Error!void { |
| 1492 | 1496 | const gpa = d.comp.gpa; |
| 1497 | const io = d.comp.io; | |
| 1493 | 1498 | var argv: std.ArrayList([]const u8) = .empty; |
| 1494 | 1499 | defer argv.deinit(gpa); |
| 1495 | 1500 | |
| ... | ... | @@ -1506,17 +1511,20 @@ pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) Compil |
| 1506 | 1511 | return d.fatal("unable to dump linker args: {s}", .{errorDescription(stdout.err.?)}); |
| 1507 | 1512 | }; |
| 1508 | 1513 | } |
| 1509 | var child = std.process.Child.init(argv.items, d.comp.gpa); | |
| 1510 | // TODO handle better | |
| 1511 | child.stdin_behavior = .inherit; | |
| 1512 | child.stdout_behavior = .inherit; | |
| 1513 | child.stderr_behavior = .inherit; | |
| 1514 | ||
| 1515 | const term = child.spawnAndWait() catch |er| { | |
| 1514 | var child = std.process.spawn(io, .{ | |
| 1515 | .argv = argv.items, | |
| 1516 | // TODO handle better | |
| 1517 | .stdin = .inherit, | |
| 1518 | .stdout = .inherit, | |
| 1519 | .stderr = .inherit, | |
| 1520 | }) catch |er| { | |
| 1516 | 1521 | return d.fatal("unable to spawn linker: {s}", .{errorDescription(er)}); |
| 1517 | 1522 | }; |
| 1523 | const term = child.wait(io) catch |er| { | |
| 1524 | return d.fatal("unable to wait linker: {s}", .{errorDescription(er)}); | |
| 1525 | }; | |
| 1518 | 1526 | switch (term) { |
| 1519 | .Exited => |code| if (code != 0) { | |
| 1527 | .exited => |code| if (code != 0) { | |
| 1520 | 1528 | const e = d.fatal("linker exited with an error code", .{}); |
| 1521 | 1529 | if (fast_exit) d.exitWithCleanup(code); |
| 1522 | 1530 | return e; |
lib/compiler/resinator/compile.zig+2-3| ... | ... | @@ -80,7 +80,7 @@ pub const Dependencies = struct { |
| 80 | 80 | } |
| 81 | 81 | }; |
| 82 | 82 | |
| 83 | pub fn compile(allocator: Allocator, io: Io, source: []const u8, writer: *std.Io.Writer, options: CompileOptions) !void { | |
| 83 | pub fn compile(allocator: Allocator, io: Io, source: []const u8, writer: *std.Io.Writer, options: CompileOptions, env_map: *const std.process.Environ.Map) !void { | |
| 84 | 84 | var lexer = lex.Lexer.init(source, .{ |
| 85 | 85 | .default_code_page = options.default_code_page, |
| 86 | 86 | .source_mappings = options.source_mappings, |
| ... | ... | @@ -148,8 +148,7 @@ pub fn compile(allocator: Allocator, io: Io, source: []const u8, writer: *std.Io |
| 148 | 148 | try search_dirs.append(allocator, .{ .dir = dir, .path = try allocator.dupe(u8, system_include_path) }); |
| 149 | 149 | } |
| 150 | 150 | if (!options.ignore_include_env_var) { |
| 151 | const INCLUDE = std.process.getEnvVarOwned(allocator, "INCLUDE") catch ""; | |
| 152 | defer allocator.free(INCLUDE); | |
| 151 | const INCLUDE = env_map.get("INCLUDE") orelse ""; | |
| 153 | 152 | |
| 154 | 153 | // The only precedence here is llvm-rc which also uses the platform-specific |
| 155 | 154 | // delimiter. There's no precedence set by `rc.exe` since it's Windows-only. |
lib/compiler/resinator/main.zig+7-4| ... | ... | @@ -24,6 +24,9 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 24 | 24 | defer std.debug.assert(debug_allocator.deinit() == .ok); |
| 25 | 25 | const gpa = debug_allocator.allocator(); |
| 26 | 26 | |
| 27 | var env_map = try init.environ.createMap(gpa); | |
| 28 | defer env_map.deinit(); | |
| 29 | ||
| 27 | 30 | var threaded: std.Io.Threaded = .init(gpa, .{ |
| 28 | 31 | .environ = init.environ, |
| 29 | 32 | .argv0 = .init(init.args), |
| ... | ... | @@ -148,8 +151,8 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 148 | 151 | defer argv.deinit(aro_arena); |
| 149 | 152 | |
| 150 | 153 | try argv.append(aro_arena, "arocc"); // dummy command name |
| 151 | const resolved_include_paths = try include_paths.get(&error_handler); | |
| 152 | try preprocess.appendAroArgs(aro_arena, &argv, options, resolved_include_paths); | |
| 154 | const resolved_include_paths = try include_paths.get(&error_handler, &env_map); | |
| 155 | try preprocess.appendAroArgs(aro_arena, &argv, options, resolved_include_paths, &env_map); | |
| 153 | 156 | try argv.append(aro_arena, switch (options.input_source) { |
| 154 | 157 | .stdio => "-", |
| 155 | 158 | .filename => |filename| filename, |
| ... | ... | @@ -283,7 +286,7 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 283 | 286 | .dependencies = maybe_dependencies, |
| 284 | 287 | .ignore_include_env_var = options.ignore_include_env_var, |
| 285 | 288 | .extra_include_paths = options.extra_include_paths.items, |
| 286 | .system_include_paths = try include_paths.get(&error_handler), | |
| 289 | .system_include_paths = try include_paths.get(&error_handler, &env_map), | |
| 287 | 290 | .default_language_id = options.default_language_id, |
| 288 | 291 | .default_code_page = default_code_page, |
| 289 | 292 | .disjoint_code_page = has_disjoint_code_page, |
| ... | ... | @@ -292,7 +295,7 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 292 | 295 | .max_string_literal_codepoints = options.max_string_literal_codepoints, |
| 293 | 296 | .silent_duplicate_control_ids = options.silent_duplicate_control_ids, |
| 294 | 297 | .warn_instead_of_error_on_invalid_code_page = options.warn_instead_of_error_on_invalid_code_page, |
| 295 | }) catch |err| switch (err) { | |
| 298 | }, &env_map) catch |err| switch (err) { | |
| 296 | 299 | error.ParseError, error.CompileError => { |
| 297 | 300 | try error_handler.emitDiagnostics(gpa, Io.Dir.cwd(), final_input, &diagnostics, mapping_results.mappings); |
| 298 | 301 | // Delete the output file on error |
lib/compiler/resinator/preprocess.zig+2-2| ... | ... | @@ -86,7 +86,7 @@ fn hasAnyErrors(comp: *aro.Compilation) bool { |
| 86 | 86 | |
| 87 | 87 | /// `arena` is used for temporary -D argument strings and the INCLUDE environment variable. |
| 88 | 88 | /// The arena should be kept alive at least as long as `argv`. |
| 89 | pub fn appendAroArgs(arena: Allocator, argv: *std.ArrayList([]const u8), options: cli.Options, system_include_paths: []const []const u8) !void { | |
| 89 | pub fn appendAroArgs(arena: Allocator, argv: *std.ArrayList([]const u8), options: cli.Options, system_include_paths: []const []const u8, env_map: *const std.process.Environ.Map) !void { | |
| 90 | 90 | try argv.appendSlice(arena, &.{ |
| 91 | 91 | "-E", |
| 92 | 92 | "--comments", |
| ... | ... | @@ -109,7 +109,7 @@ pub fn appendAroArgs(arena: Allocator, argv: *std.ArrayList([]const u8), options |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | if (!options.ignore_include_env_var) { |
| 112 | const INCLUDE = std.process.getEnvVarOwned(arena, "INCLUDE") catch ""; | |
| 112 | const INCLUDE = env_map.get("INCLUDE") orelse ""; | |
| 113 | 113 | |
| 114 | 114 | // The only precedence here is llvm-rc which also uses the platform-specific |
| 115 | 115 | // delimiter. There's no precedence set by `rc.exe` since it's Windows-only. |
lib/compiler/translate-c/main.zig+29-30| ... | ... | @@ -13,6 +13,7 @@ pub fn main(init: std.process.Init) u8 { |
| 13 | 13 | const gpa = init.gpa; |
| 14 | 14 | const arena = init.arena.allocator(); |
| 15 | 15 | const io = init.io; |
| 16 | const env_map = init.env_map; | |
| 16 | 17 | |
| 17 | 18 | const args = init.minimal.args.toSlice(arena) catch { |
| 18 | 19 | std.debug.print("ran out of memory allocating arguments\n", .{}); |
| ... | ... | @@ -25,8 +26,8 @@ pub fn main(init: std.process.Init) u8 { |
| 25 | 26 | zig_integration = true; |
| 26 | 27 | } |
| 27 | 28 | |
| 28 | const NO_COLOR = std.zig.EnvVar.NO_COLOR.isSet(init.env_map); | |
| 29 | const CLICOLOR_FORCE = std.zig.EnvVar.CLICOLOR_FORCE.isSet(init.env_map); | |
| 29 | const NO_COLOR = std.zig.EnvVar.NO_COLOR.isSet(env_map); | |
| 30 | const CLICOLOR_FORCE = std.zig.EnvVar.CLICOLOR_FORCE.isSet(env_map); | |
| 30 | 31 | |
| 31 | 32 | var stderr_buf: [1024]u8 = undefined; |
| 32 | 33 | var stderr = Io.File.stderr().writer(io, &stderr_buf); |
| ... | ... | @@ -41,7 +42,7 @@ pub fn main(init: std.process.Init) u8 { |
| 41 | 42 | }; |
| 42 | 43 | defer diagnostics.deinit(); |
| 43 | 44 | |
| 44 | var comp = aro.Compilation.initDefault(gpa, arena, io, &diagnostics, Io.Dir.cwd()) catch |err| switch (err) { | |
| 45 | var comp = aro.Compilation.initDefault(gpa, arena, io, &diagnostics, .cwd(), env_map) catch |err| switch (err) { | |
| 45 | 46 | error.OutOfMemory => { |
| 46 | 47 | std.debug.print("ran out of memory initializing C compilation\n", .{}); |
| 47 | 48 | if (fast_exit) process.exit(1); |
| ... | ... | @@ -114,43 +115,41 @@ pub const usage = |
| 114 | 115 | \\ |
| 115 | 116 | ; |
| 116 | 117 | |
| 117 | fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration: bool) !void { | |
| 118 | fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: []const [:0]const u8, zig_integration: bool) !void { | |
| 118 | 119 | const gpa = d.comp.gpa; |
| 119 | 120 | const io = d.comp.io; |
| 120 | 121 | |
| 121 | const aro_args = args: { | |
| 122 | var i: usize = 0; | |
| 123 | for (args) |arg| { | |
| 124 | args[i] = arg; | |
| 125 | if (mem.eql(u8, arg, "--help")) { | |
| 126 | var stdout_buf: [512]u8 = undefined; | |
| 127 | var stdout = Io.File.stdout().writer(io, &stdout_buf); | |
| 128 | try stdout.interface.print(usage, .{args[0]}); | |
| 129 | try stdout.interface.flush(); | |
| 130 | return; | |
| 131 | } else if (mem.eql(u8, arg, "--version")) { | |
| 132 | var stdout_buf: [512]u8 = undefined; | |
| 133 | var stdout = Io.File.stdout().writer(io, &stdout_buf); | |
| 134 | // TODO add version | |
| 135 | try stdout.interface.writeAll("0.0.0-dev\n"); | |
| 136 | try stdout.interface.flush(); | |
| 137 | return; | |
| 138 | } else if (mem.eql(u8, arg, "--zig-integration")) { | |
| 139 | if (i != 1 or !zig_integration) | |
| 140 | return d.fatal("--zig-integration must be the first argument", .{}); | |
| 141 | } else { | |
| 142 | i += 1; | |
| 143 | } | |
| 122 | var aro_args: std.ArrayList([:0]const u8) = .empty; | |
| 123 | defer aro_args.deinit(gpa); | |
| 124 | ||
| 125 | for (args, 0..) |arg, i| { | |
| 126 | if (mem.eql(u8, arg, "--help")) { | |
| 127 | var stdout_buf: [512]u8 = undefined; | |
| 128 | var stdout = Io.File.stdout().writer(io, &stdout_buf); | |
| 129 | try stdout.interface.print(usage, .{args[0]}); | |
| 130 | try stdout.interface.flush(); | |
| 131 | return; | |
| 132 | } else if (mem.eql(u8, arg, "--version")) { | |
| 133 | var stdout_buf: [512]u8 = undefined; | |
| 134 | var stdout = Io.File.stdout().writer(io, &stdout_buf); | |
| 135 | // TODO add version | |
| 136 | try stdout.interface.writeAll("0.0.0-dev\n"); | |
| 137 | try stdout.interface.flush(); | |
| 138 | return; | |
| 139 | } else if (mem.eql(u8, arg, "--zig-integration")) { | |
| 140 | if (i != 1 or !zig_integration) | |
| 141 | return d.fatal("--zig-integration must be the first argument", .{}); | |
| 142 | } else { | |
| 143 | try aro_args.append(gpa, arg); | |
| 144 | 144 | } |
| 145 | break :args args[0..i]; | |
| 146 | }; | |
| 145 | } | |
| 147 | 146 | const user_macros = macros: { |
| 148 | 147 | var macro_buf: std.ArrayList(u8) = .empty; |
| 149 | 148 | defer macro_buf.deinit(gpa); |
| 150 | 149 | |
| 151 | 150 | var discard_buf: [256]u8 = undefined; |
| 152 | 151 | var discarding: std.Io.Writer.Discarding = .init(&discard_buf); |
| 153 | assert(!try d.parseArgs(&discarding.writer, &macro_buf, aro_args)); | |
| 152 | assert(!try d.parseArgs(&discarding.writer, &macro_buf, aro_args.items)); | |
| 154 | 153 | if (macro_buf.items.len > std.math.maxInt(u32)) { |
| 155 | 154 | return d.fatal("user provided macro source exceeded max size", .{}); |
| 156 | 155 | } |
test/standalone/child_process/main.zig+10-8| ... | ... | @@ -9,7 +9,7 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 9 | 9 | }; |
| 10 | 10 | const gpa = gpa_state.allocator(); |
| 11 | 11 | |
| 12 | var it = try init.iterateAllocator(gpa); | |
| 12 | var it = try init.args.iterateAllocator(gpa); | |
| 13 | 13 | defer it.deinit(); |
| 14 | 14 | _ = it.next() orelse unreachable; // skip binary name |
| 15 | 15 | const child_path, const needs_free = child_path: { |
| ... | ... | @@ -28,11 +28,13 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 28 | 28 | defer threaded.deinit(); |
| 29 | 29 | const io = threaded.io(); |
| 30 | 30 | |
| 31 | var child = std.process.Child.init(&.{ child_path, "hello arg" }, gpa); | |
| 32 | child.stdin_behavior = .pipe; | |
| 33 | child.stdout_behavior = .pipe; | |
| 34 | child.stderr_behavior = .inherit; | |
| 35 | try child.spawn(io); | |
| 31 | var child = try std.process.spawn(.{ | |
| 32 | .argv = &.{ child_path, "hello arg" }, | |
| 33 | .stdin = .pipe, | |
| 34 | .stdout = .pipe, | |
| 35 | .stderr = .inherit, | |
| 36 | }); | |
| 37 | ||
| 36 | 38 | const child_stdin = child.stdin.?; |
| 37 | 39 | try child_stdin.writeStreamingAll(io, "hello from stdin"); // verified in child |
| 38 | 40 | child_stdin.close(io); |
| ... | ... | @@ -47,7 +49,7 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 47 | 49 | } |
| 48 | 50 | |
| 49 | 51 | switch (try child.wait(io)) { |
| 50 | .Exited => |code| { | |
| 52 | .exited => |code| { | |
| 51 | 53 | const child_ok_code = 42; // set by child if no test errors |
| 52 | 54 | if (code != child_ok_code) { |
| 53 | 55 | testError(io, "child exit code: {d}; want {d}", .{ code, child_ok_code }); |
| ... | ... | @@ -60,7 +62,7 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 60 | 62 | // Check that FileNotFound is consistent across platforms when trying to spawn an executable that doesn't exist |
| 61 | 63 | const missing_child_path = try std.mem.concat(gpa, u8, &.{ child_path, "_intentionally_missing" }); |
| 62 | 64 | defer gpa.free(missing_child_path); |
| 63 | try std.testing.expectError(error.FileNotFound, std.process.Child.run(gpa, io, .{ .argv = &.{missing_child_path} })); | |
| 65 | try std.testing.expectError(error.FileNotFound, std.process.run(gpa, io, .{ .argv = &.{missing_child_path} })); | |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | var parent_test_error = false; |
test/standalone/cmakedefine/check.zig+4-8| ... | ... | @@ -1,16 +1,12 @@ |
| 1 | pub fn main() !void { | |
| 2 | var arena_state: std.heap.ArenaAllocator = .init(std.heap.page_allocator); | |
| 3 | defer arena_state.deinit(); | |
| 4 | const arena = arena_state.allocator(); | |
| 5 | ||
| 6 | const args = try std.process.argsAlloc(arena); | |
| 1 | pub fn main(init: std.process.Init) !void { | |
| 2 | const arena = init.arena.allocator(); | |
| 3 | const io = init.io; | |
| 4 | const args = try init.minimal.args.toSlice(arena); | |
| 7 | 5 | |
| 8 | 6 | if (args.len != 3) return error.BadUsage; |
| 9 | 7 | const actual_path = args[1]; |
| 10 | 8 | const expected_path = args[2]; |
| 11 | 9 | |
| 12 | const io = std.Io.Threaded.global_single_threaded.ioBasic(); | |
| 13 | ||
| 14 | 10 | const actual = try std.Io.Dir.cwd().readFileAlloc(io, actual_path, arena, .limited(1024 * 1024)); |
| 15 | 11 | const expected = try std.Io.Dir.cwd().readFileAlloc(io, expected_path, arena, .limited(1024 * 1024)); |
| 16 | 12 |
test/standalone/empty_env/main.zig+2-5| ... | ... | @@ -1,8 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | pub fn main() !void { | |
| 4 | var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init; | |
| 5 | defer _ = gpa.deinit(); | |
| 6 | const env_map = std.process.getEnvMap(gpa.allocator()) catch @panic("unable to get env map"); | |
| 7 | try std.testing.expect(env_map.count() == 0); | |
| 3 | pub fn main(init: std.process.Init) !void { | |
| 4 | try std.testing.expect(init.env_map.count() == 0); | |
| 8 | 5 | } |
test/standalone/entry_point/check_differ.zig+6-8| ... | ... | @@ -1,12 +1,11 @@ |
| 1 | pub fn main() !void { | |
| 2 | var arena_state: std.heap.ArenaAllocator = .init(std.heap.page_allocator); | |
| 3 | defer arena_state.deinit(); | |
| 4 | const arena = arena_state.allocator(); | |
| 1 | const std = @import("std"); | |
| 5 | 2 | |
| 6 | const args = try std.process.argsAlloc(arena); | |
| 7 | if (args.len != 3) return error.BadUsage; // usage: 'check_differ <path a> <path b>' | |
| 3 | pub fn main(init: std.process.Init) !void { | |
| 4 | const arena = init.arena.allocator(); | |
| 5 | const io = init.io; | |
| 6 | const args = try init.minimal.args.toSlice(arena); | |
| 8 | 7 | |
| 9 | const io = std.Io.Threaded.global_single_threaded.ioBasic(); | |
| 8 | if (args.len != 3) return error.BadUsage; // usage: 'check_differ <path a> <path b>' | |
| 10 | 9 | |
| 11 | 10 | const contents_1 = try std.Io.Dir.cwd().readFileAlloc(io, args[1], arena, .limited(1024 * 1024 * 64)); // 64 MiB ought to be plenty |
| 12 | 11 | const contents_2 = try std.Io.Dir.cwd().readFileAlloc(io, args[2], arena, .limited(1024 * 1024 * 64)); // 64 MiB ought to be plenty |
| ... | ... | @@ -16,4 +15,3 @@ pub fn main() !void { |
| 16 | 15 | } |
| 17 | 16 | // success, files differ |
| 18 | 17 | } |
| 19 | const std = @import("std"); |
test/standalone/env_vars/main.zig+73-92| ... | ... | @@ -7,145 +7,126 @@ pub fn main(init: std.process.Init) !void { |
| 7 | 7 | |
| 8 | 8 | const allocator = init.gpa; |
| 9 | 9 | const arena = init.arena.allocator(); |
| 10 | const environ = init.minimal.environ; | |
| 10 | 11 | |
| 11 | // hasNonEmptyEnvVar | |
| 12 | // containsUnempty | |
| 12 | 13 | { |
| 13 | try std.testing.expect(try std.process.hasNonEmptyEnvVar(allocator, "FOO")); | |
| 14 | try std.testing.expect(!(try std.process.hasNonEmptyEnvVar(allocator, "FOO="))); | |
| 15 | try std.testing.expect(!(try std.process.hasNonEmptyEnvVar(allocator, "FO"))); | |
| 16 | try std.testing.expect(!(try std.process.hasNonEmptyEnvVar(allocator, "FOOO"))); | |
| 14 | try std.testing.expect(try environ.containsUnempty(allocator, "FOO")); | |
| 15 | try std.testing.expect(!(try environ.containsUnempty(allocator, "FOO="))); | |
| 16 | try std.testing.expect(!(try environ.containsUnempty(allocator, "FO"))); | |
| 17 | try std.testing.expect(!(try environ.containsUnempty(allocator, "FOOO"))); | |
| 17 | 18 | if (builtin.os.tag == .windows) { |
| 18 | try std.testing.expect(try std.process.hasNonEmptyEnvVar(allocator, "foo")); | |
| 19 | try std.testing.expect(try environ.containsUnempty(allocator, "foo")); | |
| 19 | 20 | } |
| 20 | try std.testing.expect(try std.process.hasNonEmptyEnvVar(allocator, "EQUALS")); | |
| 21 | try std.testing.expect(!(try std.process.hasNonEmptyEnvVar(allocator, "EQUALS=ABC"))); | |
| 22 | try std.testing.expect(try std.process.hasNonEmptyEnvVar(allocator, "КИРиллИЦА")); | |
| 21 | try std.testing.expect(try environ.containsUnempty(allocator, "EQUALS")); | |
| 22 | try std.testing.expect(!(try environ.containsUnempty(allocator, "EQUALS=ABC"))); | |
| 23 | try std.testing.expect(try environ.containsUnempty(allocator, "КИРиллИЦА")); | |
| 23 | 24 | if (builtin.os.tag == .windows) { |
| 24 | try std.testing.expect(try std.process.hasNonEmptyEnvVar(allocator, "кирИЛЛица")); | |
| 25 | try std.testing.expect(try environ.containsUnempty(allocator, "кирИЛЛица")); | |
| 25 | 26 | } |
| 26 | try std.testing.expect(!(try std.process.hasNonEmptyEnvVar(allocator, "NO_VALUE"))); | |
| 27 | try std.testing.expect(!(try std.process.hasNonEmptyEnvVar(allocator, "NOT_SET"))); | |
| 27 | try std.testing.expect(!(try environ.containsUnempty(allocator, "NO_VALUE"))); | |
| 28 | try std.testing.expect(!(try environ.containsUnempty(allocator, "NOT_SET"))); | |
| 28 | 29 | if (builtin.os.tag == .windows) { |
| 29 | try std.testing.expect(try std.process.hasNonEmptyEnvVar(allocator, "=HIDDEN")); | |
| 30 | try std.testing.expect(try std.process.hasNonEmptyEnvVar(allocator, "INVALID_UTF16_\xed\xa0\x80")); | |
| 30 | try std.testing.expect(try environ.containsUnempty(allocator, "=HIDDEN")); | |
| 31 | try std.testing.expect(try environ.containsUnempty(allocator, "INVALID_UTF16_\xed\xa0\x80")); | |
| 31 | 32 | } |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | // hasNonEmptyEnvVarContstant | |
| 35 | // containsUnemptyConstant | |
| 35 | 36 | { |
| 36 | try std.testing.expect(std.process.hasNonEmptyEnvVarConstant("FOO")); | |
| 37 | try std.testing.expect(!std.process.hasNonEmptyEnvVarConstant("FOO=")); | |
| 38 | try std.testing.expect(!std.process.hasNonEmptyEnvVarConstant("FO")); | |
| 39 | try std.testing.expect(!std.process.hasNonEmptyEnvVarConstant("FOOO")); | |
| 37 | try std.testing.expect(environ.containsUnemptyConstant("FOO")); | |
| 38 | try std.testing.expect(!environ.containsUnemptyConstant("FOO=")); | |
| 39 | try std.testing.expect(!environ.containsUnemptyConstant("FO")); | |
| 40 | try std.testing.expect(!environ.containsUnemptyConstant("FOOO")); | |
| 40 | 41 | if (builtin.os.tag == .windows) { |
| 41 | try std.testing.expect(std.process.hasNonEmptyEnvVarConstant("foo")); | |
| 42 | try std.testing.expect(environ.containsUnemptyConstant("foo")); | |
| 42 | 43 | } |
| 43 | try std.testing.expect(std.process.hasNonEmptyEnvVarConstant("EQUALS")); | |
| 44 | try std.testing.expect(!std.process.hasNonEmptyEnvVarConstant("EQUALS=ABC")); | |
| 45 | try std.testing.expect(std.process.hasNonEmptyEnvVarConstant("КИРиллИЦА")); | |
| 44 | try std.testing.expect(environ.containsUnemptyConstant("EQUALS")); | |
| 45 | try std.testing.expect(!environ.containsUnemptyConstant("EQUALS=ABC")); | |
| 46 | try std.testing.expect(environ.containsUnemptyConstant("КИРиллИЦА")); | |
| 46 | 47 | if (builtin.os.tag == .windows) { |
| 47 | try std.testing.expect(std.process.hasNonEmptyEnvVarConstant("кирИЛЛица")); | |
| 48 | try std.testing.expect(environ.containsUnemptyConstant("кирИЛЛица")); | |
| 48 | 49 | } |
| 49 | try std.testing.expect(!(std.process.hasNonEmptyEnvVarConstant("NO_VALUE"))); | |
| 50 | try std.testing.expect(!(std.process.hasNonEmptyEnvVarConstant("NOT_SET"))); | |
| 50 | try std.testing.expect(!(environ.containsUnemptyConstant("NO_VALUE"))); | |
| 51 | try std.testing.expect(!(environ.containsUnemptyConstant("NOT_SET"))); | |
| 51 | 52 | if (builtin.os.tag == .windows) { |
| 52 | try std.testing.expect(std.process.hasNonEmptyEnvVarConstant("=HIDDEN")); | |
| 53 | try std.testing.expect(std.process.hasNonEmptyEnvVarConstant("INVALID_UTF16_\xed\xa0\x80")); | |
| 53 | try std.testing.expect(environ.containsUnemptyConstant("=HIDDEN")); | |
| 54 | try std.testing.expect(environ.containsUnemptyConstant("INVALID_UTF16_\xed\xa0\x80")); | |
| 54 | 55 | } |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | // hasEnvVar | |
| 58 | // contains | |
| 58 | 59 | { |
| 59 | try std.testing.expect(try std.process.hasEnvVar(allocator, "FOO")); | |
| 60 | try std.testing.expect(!(try std.process.hasEnvVar(allocator, "FOO="))); | |
| 61 | try std.testing.expect(!(try std.process.hasEnvVar(allocator, "FO"))); | |
| 62 | try std.testing.expect(!(try std.process.hasEnvVar(allocator, "FOOO"))); | |
| 60 | try std.testing.expect(try environ.contains(allocator, "FOO")); | |
| 61 | try std.testing.expect(!(try environ.contains(allocator, "FOO="))); | |
| 62 | try std.testing.expect(!(try environ.contains(allocator, "FO"))); | |
| 63 | try std.testing.expect(!(try environ.contains(allocator, "FOOO"))); | |
| 63 | 64 | if (builtin.os.tag == .windows) { |
| 64 | try std.testing.expect(try std.process.hasEnvVar(allocator, "foo")); | |
| 65 | try std.testing.expect(try environ.contains(allocator, "foo")); | |
| 65 | 66 | } |
| 66 | try std.testing.expect(try std.process.hasEnvVar(allocator, "EQUALS")); | |
| 67 | try std.testing.expect(!(try std.process.hasEnvVar(allocator, "EQUALS=ABC"))); | |
| 68 | try std.testing.expect(try std.process.hasEnvVar(allocator, "КИРиллИЦА")); | |
| 67 | try std.testing.expect(try environ.contains(allocator, "EQUALS")); | |
| 68 | try std.testing.expect(!(try environ.contains(allocator, "EQUALS=ABC"))); | |
| 69 | try std.testing.expect(try environ.contains(allocator, "КИРиллИЦА")); | |
| 69 | 70 | if (builtin.os.tag == .windows) { |
| 70 | try std.testing.expect(try std.process.hasEnvVar(allocator, "кирИЛЛица")); | |
| 71 | try std.testing.expect(try environ.contains(allocator, "кирИЛЛица")); | |
| 71 | 72 | } |
| 72 | try std.testing.expect(try std.process.hasEnvVar(allocator, "NO_VALUE")); | |
| 73 | try std.testing.expect(!(try std.process.hasEnvVar(allocator, "NOT_SET"))); | |
| 73 | try std.testing.expect(try environ.contains(allocator, "NO_VALUE")); | |
| 74 | try std.testing.expect(!(try environ.contains(allocator, "NOT_SET"))); | |
| 74 | 75 | if (builtin.os.tag == .windows) { |
| 75 | try std.testing.expect(try std.process.hasEnvVar(allocator, "=HIDDEN")); | |
| 76 | try std.testing.expect(try std.process.hasEnvVar(allocator, "INVALID_UTF16_\xed\xa0\x80")); | |
| 76 | try std.testing.expect(try environ.contains(allocator, "=HIDDEN")); | |
| 77 | try std.testing.expect(try environ.contains(allocator, "INVALID_UTF16_\xed\xa0\x80")); | |
| 77 | 78 | } |
| 78 | 79 | } |
| 79 | 80 | |
| 80 | // hasEnvVarConstant | |
| 81 | // containsConstant | |
| 81 | 82 | { |
| 82 | try std.testing.expect(std.process.hasEnvVarConstant("FOO")); | |
| 83 | try std.testing.expect(!std.process.hasEnvVarConstant("FOO=")); | |
| 84 | try std.testing.expect(!std.process.hasEnvVarConstant("FO")); | |
| 85 | try std.testing.expect(!std.process.hasEnvVarConstant("FOOO")); | |
| 83 | try std.testing.expect(environ.containsConstant("FOO")); | |
| 84 | try std.testing.expect(!environ.containsConstant("FOO=")); | |
| 85 | try std.testing.expect(!environ.containsConstant("FO")); | |
| 86 | try std.testing.expect(!environ.containsConstant("FOOO")); | |
| 86 | 87 | if (builtin.os.tag == .windows) { |
| 87 | try std.testing.expect(std.process.hasEnvVarConstant("foo")); | |
| 88 | try std.testing.expect(environ.containsConstant("foo")); | |
| 88 | 89 | } |
| 89 | try std.testing.expect(std.process.hasEnvVarConstant("EQUALS")); | |
| 90 | try std.testing.expect(!std.process.hasEnvVarConstant("EQUALS=ABC")); | |
| 91 | try std.testing.expect(std.process.hasEnvVarConstant("КИРиллИЦА")); | |
| 90 | try std.testing.expect(environ.containsConstant("EQUALS")); | |
| 91 | try std.testing.expect(!environ.containsConstant("EQUALS=ABC")); | |
| 92 | try std.testing.expect(environ.containsConstant("КИРиллИЦА")); | |
| 92 | 93 | if (builtin.os.tag == .windows) { |
| 93 | try std.testing.expect(std.process.hasEnvVarConstant("кирИЛЛица")); | |
| 94 | try std.testing.expect(environ.containsConstant("кирИЛЛица")); | |
| 94 | 95 | } |
| 95 | try std.testing.expect(std.process.hasEnvVarConstant("NO_VALUE")); | |
| 96 | try std.testing.expect(!(std.process.hasEnvVarConstant("NOT_SET"))); | |
| 96 | try std.testing.expect(environ.containsConstant("NO_VALUE")); | |
| 97 | try std.testing.expect(!(environ.containsConstant("NOT_SET"))); | |
| 97 | 98 | if (builtin.os.tag == .windows) { |
| 98 | try std.testing.expect(std.process.hasEnvVarConstant("=HIDDEN")); | |
| 99 | try std.testing.expect(std.process.hasEnvVarConstant("INVALID_UTF16_\xed\xa0\x80")); | |
| 99 | try std.testing.expect(environ.containsConstant("=HIDDEN")); | |
| 100 | try std.testing.expect(environ.containsConstant("INVALID_UTF16_\xed\xa0\x80")); | |
| 100 | 101 | } |
| 101 | 102 | } |
| 102 | 103 | |
| 103 | // getEnvVarOwned | |
| 104 | // getAlloc | |
| 104 | 105 | { |
| 105 | try std.testing.expectEqualSlices(u8, "123", try std.process.getEnvVarOwned(arena, "FOO")); | |
| 106 | try std.testing.expectError(error.EnvironmentVariableNotFound, std.process.getEnvVarOwned(arena, "FOO=")); | |
| 107 | try std.testing.expectError(error.EnvironmentVariableNotFound, std.process.getEnvVarOwned(arena, "FO")); | |
| 108 | try std.testing.expectError(error.EnvironmentVariableNotFound, std.process.getEnvVarOwned(arena, "FOOO")); | |
| 106 | try std.testing.expectEqualSlices(u8, "123", try environ.getAlloc(arena, "FOO")); | |
| 107 | try std.testing.expectError(error.EnvironmentVariableNotFound, environ.getAlloc(arena, "FOO=")); | |
| 108 | try std.testing.expectError(error.EnvironmentVariableNotFound, environ.getAlloc(arena, "FO")); | |
| 109 | try std.testing.expectError(error.EnvironmentVariableNotFound, environ.getAlloc(arena, "FOOO")); | |
| 109 | 110 | if (builtin.os.tag == .windows) { |
| 110 | try std.testing.expectEqualSlices(u8, "123", try std.process.getEnvVarOwned(arena, "foo")); | |
| 111 | try std.testing.expectEqualSlices(u8, "123", try environ.getAlloc(arena, "foo")); | |
| 111 | 112 | } |
| 112 | try std.testing.expectEqualSlices(u8, "ABC=123", try std.process.getEnvVarOwned(arena, "EQUALS")); | |
| 113 | try std.testing.expectError(error.EnvironmentVariableNotFound, std.process.getEnvVarOwned(arena, "EQUALS=ABC")); | |
| 114 | try std.testing.expectEqualSlices(u8, "non-ascii አማáˆáŠ› \u{10FFFF}", try std.process.getEnvVarOwned(arena, "КИРиллИЦА")); | |
| 113 | try std.testing.expectEqualSlices(u8, "ABC=123", try environ.getAlloc(arena, "EQUALS")); | |
| 114 | try std.testing.expectError(error.EnvironmentVariableNotFound, environ.getAlloc(arena, "EQUALS=ABC")); | |
| 115 | try std.testing.expectEqualSlices(u8, "non-ascii አማáˆáŠ› \u{10FFFF}", try environ.getAlloc(arena, "КИРиллИЦА")); | |
| 115 | 116 | if (builtin.os.tag == .windows) { |
| 116 | try std.testing.expectEqualSlices(u8, "non-ascii አማáˆáŠ› \u{10FFFF}", try std.process.getEnvVarOwned(arena, "кирИЛЛица")); | |
| 117 | try std.testing.expectEqualSlices(u8, "non-ascii አማáˆáŠ› \u{10FFFF}", try environ.getAlloc(arena, "кирИЛЛица")); | |
| 117 | 118 | } |
| 118 | try std.testing.expectEqualSlices(u8, "", try std.process.getEnvVarOwned(arena, "NO_VALUE")); | |
| 119 | try std.testing.expectError(error.EnvironmentVariableNotFound, std.process.getEnvVarOwned(arena, "NOT_SET")); | |
| 119 | try std.testing.expectEqualSlices(u8, "", try environ.getAlloc(arena, "NO_VALUE")); | |
| 120 | try std.testing.expectError(error.EnvironmentVariableNotFound, environ.getAlloc(arena, "NOT_SET")); | |
| 120 | 121 | if (builtin.os.tag == .windows) { |
| 121 | try std.testing.expectEqualSlices(u8, "hi", try std.process.getEnvVarOwned(arena, "=HIDDEN")); | |
| 122 | try std.testing.expectEqualSlices(u8, "\xed\xa0\x80", try std.process.getEnvVarOwned(arena, "INVALID_UTF16_\xed\xa0\x80")); | |
| 122 | try std.testing.expectEqualSlices(u8, "hi", try environ.getAlloc(arena, "=HIDDEN")); | |
| 123 | try std.testing.expectEqualSlices(u8, "\xed\xa0\x80", try environ.getAlloc(arena, "INVALID_UTF16_\xed\xa0\x80")); | |
| 123 | 124 | } |
| 124 | 125 | } |
| 125 | 126 | |
| 126 | // parseEnvVarInt | |
| 127 | // Environ.Map | |
| 127 | 128 | { |
| 128 | try std.testing.expectEqual(123, try std.process.parseEnvVarInt("FOO", u32, 10)); | |
| 129 | try std.testing.expectError(error.EnvironmentVariableNotFound, std.process.parseEnvVarInt("FO", u32, 10)); | |
| 130 | try std.testing.expectError(error.EnvironmentVariableNotFound, std.process.parseEnvVarInt("FOOO", u32, 10)); | |
| 131 | try std.testing.expectEqual(0x123, try std.process.parseEnvVarInt("FOO", u32, 16)); | |
| 132 | if (builtin.os.tag == .windows) { | |
| 133 | try std.testing.expectEqual(123, try std.process.parseEnvVarInt("foo", u32, 10)); | |
| 134 | } | |
| 135 | try std.testing.expectError(error.InvalidCharacter, std.process.parseEnvVarInt("EQUALS", u32, 10)); | |
| 136 | try std.testing.expectError(error.EnvironmentVariableNotFound, std.process.parseEnvVarInt("EQUALS=ABC", u32, 10)); | |
| 137 | try std.testing.expectError(error.InvalidCharacter, std.process.parseEnvVarInt("КИРиллИЦА", u32, 10)); | |
| 138 | try std.testing.expectError(error.InvalidCharacter, std.process.parseEnvVarInt("NO_VALUE", u32, 10)); | |
| 139 | try std.testing.expectError(error.EnvironmentVariableNotFound, std.process.parseEnvVarInt("NOT_SET", u32, 10)); | |
| 140 | if (builtin.os.tag == .windows) { | |
| 141 | try std.testing.expectError(error.InvalidCharacter, std.process.parseEnvVarInt("=HIDDEN", u32, 10)); | |
| 142 | try std.testing.expectError(error.InvalidCharacter, std.process.parseEnvVarInt("INVALID_UTF16_\xed\xa0\x80", u32, 10)); | |
| 143 | } | |
| 144 | } | |
| 145 | ||
| 146 | // EnvMap | |
| 147 | { | |
| 148 | var env_map = try std.process.getEnvMap(allocator); | |
| 129 | var env_map = try environ.createMap(allocator); | |
| 149 | 130 | defer env_map.deinit(); |
| 150 | 131 | |
| 151 | 132 | try std.testing.expectEqualSlices(u8, "123", env_map.get("FOO").?); |
test/standalone/posix/getenv.zig+11-10| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | // test getting environment variables | |
| 1 | //! test getting environment variables | |
| 2 | 2 | |
| 3 | 3 | const std = @import("std"); |
| 4 | 4 | const builtin = @import("builtin"); |
| 5 | 5 | |
| 6 | pub fn main() !void { | |
| 6 | pub fn main(init: std.process.Init.Minimal) !void { | |
| 7 | 7 | if (builtin.target.os.tag == .windows) { |
| 8 | 8 | return; // Windows env strings are WTF-16, so not supported by Zig's std.posix.getenv() |
| 9 | 9 | } |
| ... | ... | @@ -12,21 +12,22 @@ pub fn main() !void { |
| 12 | 12 | return; // std.posix.getenv is not supported on WASI due to the need of allocation |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | // Test some unset env vars: | |
| 15 | const environ = init.environ; | |
| 16 | 16 | |
| 17 | try std.testing.expectEqual(std.posix.getenv(""), null); | |
| 18 | try std.testing.expectEqual(std.posix.getenv("BOGUSDOESNOTEXISTENVVAR"), null); | |
| 19 | try std.testing.expectEqual(std.posix.getenvZ("BOGUSDOESNOTEXISTENVVAR"), null); | |
| 17 | // Test some unset env vars: | |
| 18 | try std.testing.expectEqual(environ.getPosix(""), null); | |
| 19 | try std.testing.expectEqual(environ.getPosix("BOGUSDOESNOTEXISTENVVAR"), null); | |
| 20 | try std.testing.expectEqual(environ.getPosix("BOGUSDOESNOTEXISTENVVAR"), null); | |
| 20 | 21 | |
| 21 | 22 | if (builtin.link_libc) { |
| 22 | 23 | // Test if USER matches what C library sees |
| 23 | 24 | const expected = std.mem.span(std.c.getenv("USER") orelse ""); |
| 24 | const actual = std.posix.getenv("USER") orelse ""; | |
| 25 | const actual = environ.getPosix("USER") orelse ""; | |
| 25 | 26 | try std.testing.expectEqualStrings(expected, actual); |
| 26 | 27 | } |
| 27 | 28 | |
| 28 | 29 | // env vars set by our build.zig run step: |
| 29 | try std.testing.expectEqualStrings("", std.posix.getenv("ZIG_TEST_POSIX_EMPTY") orelse "invalid"); | |
| 30 | try std.testing.expectEqualStrings("test=variable", std.posix.getenv("ZIG_TEST_POSIX_1EQ") orelse "invalid"); | |
| 31 | try std.testing.expectEqualStrings("=test=variable=", std.posix.getenv("ZIG_TEST_POSIX_3EQ") orelse "invalid"); | |
| 30 | try std.testing.expectEqualStrings("", environ.getPosix("ZIG_TEST_POSIX_EMPTY") orelse "invalid"); | |
| 31 | try std.testing.expectEqualStrings("test=variable", environ.getPosix("ZIG_TEST_POSIX_1EQ") orelse "invalid"); | |
| 32 | try std.testing.expectEqualStrings("=test=variable=", environ.getPosix("ZIG_TEST_POSIX_3EQ") orelse "invalid"); | |
| 32 | 33 | } |
test/standalone/run_output_caching/main.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | pub fn main(init: std.process.Init) !void { |
| 4 | 4 | const io = init.io; |
| 5 | var args = try init.minimal.argsAllocator(init.arena.allocator()); | |
| 5 | var args = try init.minimal.args.iterateAllocator(init.arena.allocator()); | |
| 6 | 6 | _ = args.skip(); |
| 7 | 7 | const filename = args.next().?; |
| 8 | 8 | const file = try std.Io.Dir.cwd().createFile(io, filename, .{}); |
test/standalone/run_output_paths/create_file.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | pub fn main(init: std.process.Init) !void { |
| 4 | 4 | const io = init.io; |
| 5 | var args = try init.args.iterateAllocator(init.arena.allocator()); | |
| 5 | var args = try init.minimal.args.iterateAllocator(init.arena.allocator()); | |
| 6 | 6 | _ = args.skip(); |
| 7 | 7 | const dir_name = args.next().?; |
| 8 | 8 | const dir = try std.Io.Dir.cwd().openDir(io, if (std.mem.startsWith(u8, dir_name, "--dir=")) |
test/standalone/self_exe_symlink/create-symlink.zig+4-2| ... | ... | @@ -3,14 +3,16 @@ const std = @import("std"); |
| 3 | 3 | pub fn main(init: std.process.Init) !void { |
| 4 | 4 | const io = init.io; |
| 5 | 5 | const gpa = init.gpa; |
| 6 | var it = try init.args.iterateAllocator(gpa); | |
| 6 | var it = try init.minimal.args.iterateAllocator(gpa); | |
| 7 | 7 | defer it.deinit(); |
| 8 | 8 | _ = it.next() orelse unreachable; // skip binary name |
| 9 | 9 | const exe_path = it.next() orelse unreachable; |
| 10 | 10 | const symlink_path = it.next() orelse unreachable; |
| 11 | 11 | |
| 12 | const cwd = std.process.getCwdAlloc(init.arena.allocator()); | |
| 13 | ||
| 12 | 14 | // If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`. |
| 13 | const exe_rel_path = try std.fs.path.relative(gpa, std.fs.path.dirname(symlink_path) orelse ".", exe_path); | |
| 15 | const exe_rel_path = try std.fs.path.relative(gpa, cwd, init.env_map, std.fs.path.dirname(symlink_path) orelse ".", exe_path); | |
| 14 | 16 | defer gpa.free(exe_rel_path); |
| 15 | 17 | |
| 16 | 18 | try std.Io.Dir.cwd().symLink(io, exe_rel_path, symlink_path, .{}); |
test/standalone/self_exe_symlink/main.zig+3-8| ... | ... | @@ -1,13 +1,8 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | pub fn main() !void { | |
| 4 | var debug_allocator: std.heap.DebugAllocator(.{}) = .init; | |
| 5 | defer if (debug_allocator.deinit() == .leak) @panic("found memory leaks"); | |
| 6 | const gpa = debug_allocator.allocator(); | |
| 7 | ||
| 8 | var threaded: std.Io.Threaded = .init(gpa, .{}); | |
| 9 | defer threaded.deinit(); | |
| 10 | const io = threaded.io(); | |
| 3 | pub fn main(init: std.process.Init) !void { | |
| 4 | const gpa = init.gpa; | |
| 5 | const io = init.io; | |
| 11 | 6 | |
| 12 | 7 | const self_path = try std.process.executablePathAlloc(io, gpa); |
| 13 | 8 | defer gpa.free(self_path); |
test/standalone/simple/cat/main.zig+1-1| ... | ... | @@ -7,7 +7,7 @@ const fatal = std.process.fatal; |
| 7 | 7 | pub fn main(init: std.process.Init) !void { |
| 8 | 8 | const arena = init.arena.allocator(); |
| 9 | 9 | const io = init.io; |
| 10 | const args = try init.args.toSlice(arena); | |
| 10 | const args = try init.minimal.args.toSlice(arena); | |
| 11 | 11 | |
| 12 | 12 | const exe = args[0]; |
| 13 | 13 | var catted_anything = false; |
test/standalone/simple/guess_number/main.zig+3-14| ... | ... | @@ -1,22 +1,11 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | 1 | const std = @import("std"); |
| 3 | 2 | |
| 4 | // See https://github.com/ziglang/zig/issues/24510 | |
| 5 | // for the plan to simplify this code. | |
| 6 | pub fn main() !void { | |
| 7 | var debug_allocator: std.heap.DebugAllocator(.{}) = .init; | |
| 8 | defer _ = debug_allocator.deinit(); | |
| 9 | const gpa = debug_allocator.allocator(); | |
| 10 | ||
| 11 | var threaded: std.Io.Threaded = .init(gpa, .{}); | |
| 12 | defer threaded.deinit(); | |
| 13 | const io = threaded.io(); | |
| 14 | ||
| 15 | var stdout_writer = std.Io.File.stdout().writerStreaming(io, &.{}); | |
| 3 | pub fn main(init: std.process.Init) !void { | |
| 4 | var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{}); | |
| 16 | 5 | const out = &stdout_writer.interface; |
| 17 | 6 | |
| 18 | 7 | var line_buffer: [20]u8 = undefined; |
| 19 | var stdin_reader: std.Io.File.Reader = .init(.stdin(), io, &line_buffer); | |
| 8 | var stdin_reader: std.Io.File.Reader = .init(.stdin(), init.io, &line_buffer); | |
| 20 | 9 | const in = &stdin_reader.interface; |
| 21 | 10 | |
| 22 | 11 | try out.writeAll("Welcome to the Guess Number Game in Zig.\n"); |
test/standalone/windows_bat_args/fuzz.zig+1-1| ... | ... | @@ -93,7 +93,7 @@ fn testExecBat(gpa: Allocator, io: Io, bat: []const u8, args: []const []const u8 |
| 93 | 93 | |
| 94 | 94 | const can_have_trailing_empty_args = std.mem.eql(u8, bat, "args3.bat"); |
| 95 | 95 | |
| 96 | const result = try std.process.Child.run(gpa, io, .{ | |
| 96 | const result = try std.process.run(gpa, io, .{ | |
| 97 | 97 | .env_map = env, |
| 98 | 98 | .argv = argv, |
| 99 | 99 | }); |
test/standalone/windows_bat_args/test.zig+1-1| ... | ... | @@ -140,7 +140,7 @@ fn testExecBat(gpa: Allocator, io: Io, bat: []const u8, args: []const []const u8 |
| 140 | 140 | |
| 141 | 141 | const can_have_trailing_empty_args = std.mem.eql(u8, bat, "args3.bat"); |
| 142 | 142 | |
| 143 | const result = try std.process.Child.run(gpa, io, .{ | |
| 143 | const result = try std.process.run(gpa, io, .{ | |
| 144 | 144 | .env_map = env, |
| 145 | 145 | .argv = argv, |
| 146 | 146 | }); |
test/standalone/windows_paths/test.zig+1-1| ... | ... | @@ -98,7 +98,7 @@ fn checkRelative( |
| 98 | 98 | cwd: ?[]const u8, |
| 99 | 99 | env_map: ?*const std.process.Environ.Map, |
| 100 | 100 | ) !void { |
| 101 | const result = try std.process.Child.run(allocator, io, .{ | |
| 101 | const result = try std.process.run(allocator, io, .{ | |
| 102 | 102 | .argv = argv, |
| 103 | 103 | .cwd = cwd, |
| 104 | 104 | .env_map = env_map, |
test/standalone/windows_spawn/main.zig+1-1| ... | ... | @@ -207,7 +207,7 @@ fn testExec(gpa: Allocator, io: Io, command: []const u8, expected_stdout: []cons |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | fn testExecWithCwd(gpa: Allocator, io: Io, command: []const u8, cwd: ?[]const u8, expected_stdout: []const u8) !void { |
| 210 | const result = try std.process.Child.run(gpa, io, .{ | |
| 210 | const result = try std.process.run(gpa, io, .{ | |
| 211 | 211 | .argv = &[_][]const u8{command}, |
| 212 | 212 | .cwd = cwd, |
| 213 | 213 | }); |
tools/doctest.zig+14-14| ... | ... | @@ -193,14 +193,14 @@ fn printOutput( |
| 193 | 193 | try shell_out.print("\n", .{}); |
| 194 | 194 | |
| 195 | 195 | if (expected_outcome == .build_fail) { |
| 196 | const result = try process.Child.run(arena, io, .{ | |
| 196 | const result = try process.run(arena, io, .{ | |
| 197 | 197 | .argv = build_args.items, |
| 198 | 198 | .cwd = tmp_dir_path, |
| 199 | 199 | .env_map = &env_map, |
| 200 | 200 | .max_output_bytes = max_doc_file_size, |
| 201 | 201 | }); |
| 202 | 202 | switch (result.term) { |
| 203 | .Exited => |exit_code| { | |
| 203 | .exited => |exit_code| { | |
| 204 | 204 | if (exit_code == 0) { |
| 205 | 205 | print("{s}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 206 | 206 | dumpArgs(build_args.items); |
| ... | ... | @@ -249,21 +249,21 @@ fn printOutput( |
| 249 | 249 | var exited_with_signal = false; |
| 250 | 250 | |
| 251 | 251 | const result = if (expected_outcome == .fail) blk: { |
| 252 | const result = try process.Child.run(arena, io, .{ | |
| 252 | const result = try process.run(arena, io, .{ | |
| 253 | 253 | .argv = run_args, |
| 254 | 254 | .env_map = &env_map, |
| 255 | 255 | .cwd = tmp_dir_path, |
| 256 | 256 | .max_output_bytes = max_doc_file_size, |
| 257 | 257 | }); |
| 258 | 258 | switch (result.term) { |
| 259 | .Exited => |exit_code| { | |
| 259 | .exited => |exit_code| { | |
| 260 | 260 | if (exit_code == 0) { |
| 261 | 261 | print("{s}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 262 | 262 | dumpArgs(run_args); |
| 263 | 263 | fatal("example incorrectly compiled", .{}); |
| 264 | 264 | } |
| 265 | 265 | }, |
| 266 | .Signal => exited_with_signal = true, | |
| 266 | .signal => exited_with_signal = true, | |
| 267 | 267 | else => {}, |
| 268 | 268 | } |
| 269 | 269 | break :blk result; |
| ... | ... | @@ -368,14 +368,14 @@ fn printOutput( |
| 368 | 368 | try test_args.append("-lc"); |
| 369 | 369 | try shell_out.print("-lc ", .{}); |
| 370 | 370 | } |
| 371 | const result = try process.Child.run(arena, io, .{ | |
| 371 | const result = try process.run(arena, io, .{ | |
| 372 | 372 | .argv = test_args.items, |
| 373 | 373 | .env_map = &env_map, |
| 374 | 374 | .cwd = tmp_dir_path, |
| 375 | 375 | .max_output_bytes = max_doc_file_size, |
| 376 | 376 | }); |
| 377 | 377 | switch (result.term) { |
| 378 | .Exited => |exit_code| { | |
| 378 | .exited => |exit_code| { | |
| 379 | 379 | if (exit_code == 0) { |
| 380 | 380 | print("{s}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 381 | 381 | dumpArgs(test_args.items); |
| ... | ... | @@ -424,14 +424,14 @@ fn printOutput( |
| 424 | 424 | }, |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | const result = try process.Child.run(arena, io, .{ | |
| 427 | const result = try process.run(arena, io, .{ | |
| 428 | 428 | .argv = test_args.items, |
| 429 | 429 | .env_map = &env_map, |
| 430 | 430 | .cwd = tmp_dir_path, |
| 431 | 431 | .max_output_bytes = max_doc_file_size, |
| 432 | 432 | }); |
| 433 | 433 | switch (result.term) { |
| 434 | .Exited => |exit_code| { | |
| 434 | .exited => |exit_code| { | |
| 435 | 435 | if (exit_code == 0) { |
| 436 | 436 | print("{s}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 437 | 437 | dumpArgs(test_args.items); |
| ... | ... | @@ -500,14 +500,14 @@ fn printOutput( |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | if (maybe_error_match) |error_match| { |
| 503 | const result = try process.Child.run(arena, io, .{ | |
| 503 | const result = try process.run(arena, io, .{ | |
| 504 | 504 | .argv = build_args.items, |
| 505 | 505 | .env_map = &env_map, |
| 506 | 506 | .cwd = tmp_dir_path, |
| 507 | 507 | .max_output_bytes = max_doc_file_size, |
| 508 | 508 | }); |
| 509 | 509 | switch (result.term) { |
| 510 | .Exited => |exit_code| { | |
| 510 | .exited => |exit_code| { | |
| 511 | 511 | if (exit_code == 0) { |
| 512 | 512 | print("{s}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 513 | 513 | dumpArgs(build_args.items); |
| ... | ... | @@ -1123,15 +1123,15 @@ fn run( |
| 1123 | 1123 | env_map: *process.Environ.Map, |
| 1124 | 1124 | cwd: []const u8, |
| 1125 | 1125 | args: []const []const u8, |
| 1126 | ) !process.Child.RunResult { | |
| 1127 | const result = try process.Child.run(allocator, io, .{ | |
| 1126 | ) !process.RunResult { | |
| 1127 | const result = try process.run(allocator, io, .{ | |
| 1128 | 1128 | .argv = args, |
| 1129 | 1129 | .env_map = env_map, |
| 1130 | 1130 | .cwd = cwd, |
| 1131 | 1131 | .max_output_bytes = max_doc_file_size, |
| 1132 | 1132 | }); |
| 1133 | 1133 | switch (result.term) { |
| 1134 | .Exited => |exit_code| { | |
| 1134 | .exited => |exit_code| { | |
| 1135 | 1135 | if (exit_code != 0) { |
| 1136 | 1136 | std.debug.print("{s}\nThe following command exited with code {}:\n", .{ result.stderr, exit_code }); |
| 1137 | 1137 | dumpArgs(args); |
tools/dump-cov.zig+2-2| ... | ... | @@ -10,9 +10,9 @@ const SeenPcsHeader = std.Build.abi.fuzz.SeenPcsHeader; |
| 10 | 10 | |
| 11 | 11 | pub fn main(init: std.process.Init) !void { |
| 12 | 12 | const gpa = init.gpa; |
| 13 | const arena = init.arena; | |
| 13 | const arena = init.arena.allocator(); | |
| 14 | 14 | const io = init.io; |
| 15 | const args = try init.args.toSlice(arena); | |
| 15 | const args = try init.minimal.args.toSlice(arena); | |
| 16 | 16 | |
| 17 | 17 | const target_query_str = switch (args.len) { |
| 18 | 18 | 3 => "native", |
tools/fetch_them_macos_headers.zig+2-2| ... | ... | @@ -68,7 +68,7 @@ const usage = |
| 68 | 68 | |
| 69 | 69 | pub fn main(init: std.process.Init) !void { |
| 70 | 70 | const allocator = init.arena; |
| 71 | const args = try init.args.toSlice(allocator); | |
| 71 | const args = try init.minimal.args.toSlice(allocator); | |
| 72 | 72 | |
| 73 | 73 | var argv = std.array_list.Managed([]const u8).init(allocator); |
| 74 | 74 | var sysroot: ?[]const u8 = null; |
| ... | ... | @@ -161,7 +161,7 @@ fn fetchTarget( |
| 161 | 161 | }); |
| 162 | 162 | try cc_argv.appendSlice(args); |
| 163 | 163 | |
| 164 | const res = try std.process.Child.run(arena, io, .{ .argv = cc_argv.items }); | |
| 164 | const res = try std.process.run(arena, io, .{ .argv = cc_argv.items }); | |
| 165 | 165 | |
| 166 | 166 | if (res.stderr.len != 0) { |
| 167 | 167 | std.log.err("{s}", .{res.stderr}); |
tools/gen_macos_headers_c.zig+1-1| ... | ... | @@ -16,8 +16,8 @@ const usage = |
| 16 | 16 | pub fn main(init: std.process.Init) !void { |
| 17 | 17 | const arena = init.arena; |
| 18 | 18 | const io = init.io; |
| 19 | const args = try init.minimal.args.toSlice(arena); | |
| 19 | 20 | |
| 20 | const args = try init.args.toSlice(arena); | |
| 21 | 21 | if (args.len == 1) fatal("no command or option specified", .{}); |
| 22 | 22 | |
| 23 | 23 | var positionals = std.array_list.Managed([]const u8).init(arena); |
tools/gen_outline_atomics.zig+1-1| ... | ... | @@ -12,7 +12,7 @@ const AtomicOp = enum { |
| 12 | 12 | }; |
| 13 | 13 | |
| 14 | 14 | pub fn main(init: std.process.Init) !void { |
| 15 | const arena = init.arena; | |
| 15 | const arena = init.arena.allocator(); | |
| 16 | 16 | const io = init.io; |
| 17 | 17 | |
| 18 | 18 | //const args = try std.process.argsAlloc(arena); |
tools/gen_spirv_spec.zig+49-49| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const Io = std.Io; |
| 3 | 3 | const Allocator = std.mem.Allocator; |
| 4 | const assert = std.debug.assert; | |
| 4 | 5 | |
| 5 | 6 | const g = @import("spirv/grammar.zig"); |
| 6 | 7 | const CoreRegistry = g.CoreRegistry; |
| ... | ... | @@ -54,28 +55,22 @@ const set_names = std.StaticStringMap(struct { []const u8, []const u8 }).initCom |
| 54 | 55 | .{ "zig", .{ "zig", "Zig" } }, |
| 55 | 56 | }); |
| 56 | 57 | |
| 57 | var arena = std.heap.ArenaAllocator.init(std.heap.smp_allocator); | |
| 58 | const allocator = arena.allocator(); | |
| 59 | ||
| 60 | pub fn main() !void { | |
| 61 | defer arena.deinit(); | |
| 62 | ||
| 63 | const args = try std.process.argsAlloc(allocator); | |
| 58 | pub fn main(init: std.process.Init) !void { | |
| 59 | const arena = init.arena.allocator(); | |
| 60 | const args = try init.minimal.args.toSlice(arena); | |
| 64 | 61 | if (args.len != 3) { |
| 65 | 62 | usageAndExit(args[0], 1); |
| 66 | 63 | } |
| 67 | 64 | |
| 68 | var threaded: std.Io.Threaded = .init(allocator, .{}); | |
| 69 | defer threaded.deinit(); | |
| 70 | const io = threaded.io(); | |
| 65 | const io = init.io; | |
| 71 | 66 | |
| 72 | const json_path = try Io.Dir.path.join(allocator, &.{ args[1], "include/spirv/unified1/" }); | |
| 67 | const json_path = try Io.Dir.path.join(arena, &.{ args[1], "include/spirv/unified1/" }); | |
| 73 | 68 | const dir = try Io.Dir.cwd().openDir(io, json_path, .{ .iterate = true }); |
| 74 | 69 | |
| 75 | const core_spec = try readRegistry(io, CoreRegistry, dir, "spirv.core.grammar.json"); | |
| 70 | const core_spec = try readRegistry(io, arena, CoreRegistry, dir, "spirv.core.grammar.json"); | |
| 76 | 71 | std.mem.sortUnstable(Instruction, core_spec.instructions, CmpInst{}, CmpInst.lt); |
| 77 | 72 | |
| 78 | var exts = std.array_list.Managed(Extension).init(allocator); | |
| 73 | var exts = std.array_list.Managed(Extension).init(arena); | |
| 79 | 74 | |
| 80 | 75 | var it = dir.iterate(); |
| 81 | 76 | while (try it.next(io)) |entry| { |
| ... | ... | @@ -83,48 +78,48 @@ pub fn main() !void { |
| 83 | 78 | continue; |
| 84 | 79 | } |
| 85 | 80 | |
| 86 | try readExtRegistry(io, &exts, dir, entry.name); | |
| 81 | try readExtRegistry(io, arena, &exts, dir, entry.name); | |
| 87 | 82 | } |
| 88 | 83 | |
| 89 | try readExtRegistry(io, &exts, Io.Dir.cwd(), args[2]); | |
| 84 | try readExtRegistry(io, arena, &exts, Io.Dir.cwd(), args[2]); | |
| 90 | 85 | |
| 91 | var allocating: std.Io.Writer.Allocating = .init(allocator); | |
| 86 | var allocating: std.Io.Writer.Allocating = .init(arena); | |
| 92 | 87 | defer allocating.deinit(); |
| 93 | try render(&allocating.writer, core_spec, exts.items); | |
| 88 | try render(arena, &allocating.writer, core_spec, exts.items); | |
| 94 | 89 | try allocating.writer.writeByte(0); |
| 95 | 90 | const output = allocating.written()[0 .. allocating.written().len - 1 :0]; |
| 96 | 91 | |
| 97 | var tree = try std.zig.Ast.parse(allocator, output, .zig); | |
| 92 | var tree = try std.zig.Ast.parse(arena, output, .zig); | |
| 98 | 93 | |
| 99 | 94 | if (tree.errors.len != 0) { |
| 100 | try std.zig.printAstErrorsToStderr(allocator, io, tree, "", .auto); | |
| 95 | try std.zig.printAstErrorsToStderr(arena, io, tree, "", .auto); | |
| 101 | 96 | return; |
| 102 | 97 | } |
| 103 | 98 | |
| 104 | var zir = try std.zig.AstGen.generate(allocator, tree); | |
| 99 | var zir = try std.zig.AstGen.generate(arena, tree); | |
| 105 | 100 | if (zir.hasCompileErrors()) { |
| 106 | 101 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 107 | try wip_errors.init(allocator); | |
| 102 | try wip_errors.init(arena); | |
| 108 | 103 | defer wip_errors.deinit(); |
| 109 | 104 | try wip_errors.addZirErrorMessages(zir, tree, output, ""); |
| 110 | 105 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 111 | defer error_bundle.deinit(allocator); | |
| 106 | defer error_bundle.deinit(arena); | |
| 112 | 107 | try error_bundle.renderToStderr(io, .{}, .auto); |
| 113 | 108 | } |
| 114 | 109 | |
| 115 | const formatted_output = try tree.renderAlloc(allocator); | |
| 110 | const formatted_output = try tree.renderAlloc(arena); | |
| 116 | 111 | try Io.File.stdout().writeStreamingAll(io, formatted_output); |
| 117 | 112 | } |
| 118 | 113 | |
| 119 | fn readExtRegistry(io: Io, exts: *std.array_list.Managed(Extension), dir: Io.Dir, sub_path: []const u8) !void { | |
| 114 | fn readExtRegistry(io: Io, arena: Allocator, exts: *std.array_list.Managed(Extension), dir: Io.Dir, sub_path: []const u8) !void { | |
| 120 | 115 | const filename = Io.Dir.path.basename(sub_path); |
| 121 | 116 | if (!std.mem.startsWith(u8, filename, "extinst.")) { |
| 122 | 117 | return; |
| 123 | 118 | } |
| 124 | 119 | |
| 125 | std.debug.assert(std.mem.endsWith(u8, filename, ".grammar.json")); | |
| 120 | assert(std.mem.endsWith(u8, filename, ".grammar.json")); | |
| 126 | 121 | const name = filename["extinst.".len .. filename.len - ".grammar.json".len]; |
| 127 | const spec = try readRegistry(io, ExtensionRegistry, dir, sub_path); | |
| 122 | const spec = try readRegistry(io, arena, ExtensionRegistry, dir, sub_path); | |
| 128 | 123 | |
| 129 | 124 | const set_name = set_names.get(name) orelse { |
| 130 | 125 | std.log.info("ignored instruction set '{s}'", .{name}); |
| ... | ... | @@ -140,16 +135,16 @@ fn readExtRegistry(io: Io, exts: *std.array_list.Managed(Extension), dir: Io.Dir |
| 140 | 135 | }); |
| 141 | 136 | } |
| 142 | 137 | |
| 143 | fn readRegistry(io: Io, comptime RegistryType: type, dir: Io.Dir, path: []const u8) !RegistryType { | |
| 144 | const spec = try dir.readFileAlloc(io, path, allocator, .unlimited); | |
| 138 | fn readRegistry(io: Io, arena: Allocator, comptime RegistryType: type, dir: Io.Dir, path: []const u8) !RegistryType { | |
| 139 | const spec = try dir.readFileAlloc(io, path, arena, .unlimited); | |
| 145 | 140 | // Required for json parsing. |
| 146 | 141 | // TODO: ALI |
| 147 | 142 | @setEvalBranchQuota(10000); |
| 148 | 143 | |
| 149 | var scanner = std.json.Scanner.initCompleteInput(allocator, spec); | |
| 144 | var scanner = std.json.Scanner.initCompleteInput(arena, spec); | |
| 150 | 145 | var diagnostics = std.json.Diagnostics{}; |
| 151 | 146 | scanner.enableDiagnostics(&diagnostics); |
| 152 | const parsed = std.json.parseFromTokenSource(RegistryType, allocator, &scanner, .{}) catch |err| { | |
| 147 | const parsed = std.json.parseFromTokenSource(RegistryType, arena, &scanner, .{}) catch |err| { | |
| 153 | 148 | std.debug.print("{s}:{}:{}:\n", .{ path, diagnostics.getLine(), diagnostics.getColumn() }); |
| 154 | 149 | return err; |
| 155 | 150 | }; |
| ... | ... | @@ -158,8 +153,8 @@ fn readRegistry(io: Io, comptime RegistryType: type, dir: Io.Dir, path: []const |
| 158 | 153 | |
| 159 | 154 | /// Returns a set with types that require an extra struct for the `Instruction` interface |
| 160 | 155 | /// to the spir-v spec, or whether the original type can be used. |
| 161 | fn extendedStructs(kinds: []const OperandKind) !ExtendedStructSet { | |
| 162 | var map = ExtendedStructSet.init(allocator); | |
| 156 | fn extendedStructs(arena: Allocator, kinds: []const OperandKind) !ExtendedStructSet { | |
| 157 | var map = ExtendedStructSet.init(arena); | |
| 163 | 158 | try map.ensureTotalCapacity(@as(u32, @intCast(kinds.len))); |
| 164 | 159 | |
| 165 | 160 | for (kinds) |kind| { |
| ... | ... | @@ -194,6 +189,7 @@ fn tagPriorityScore(tag: []const u8) usize { |
| 194 | 189 | } |
| 195 | 190 | |
| 196 | 191 | fn render( |
| 192 | arena: Allocator, | |
| 197 | 193 | writer: *std.Io.Writer, |
| 198 | 194 | registry: CoreRegistry, |
| 199 | 195 | extensions: []const Extension, |
| ... | ... | @@ -299,7 +295,7 @@ fn render( |
| 299 | 295 | ); |
| 300 | 296 | |
| 301 | 297 | // Merge the operand kinds from all extensions together. |
| 302 | var all_operand_kinds = OperandKindMap.init(allocator); | |
| 298 | var all_operand_kinds = OperandKindMap.init(arena); | |
| 303 | 299 | for (registry.operand_kinds) |kind| { |
| 304 | 300 | try all_operand_kinds.putNoClobber(.{ "core", kind.kind }, kind); |
| 305 | 301 | } |
| ... | ... | @@ -312,22 +308,22 @@ fn render( |
| 312 | 308 | try all_operand_kinds.ensureUnusedCapacity(ext.spec.operand_kinds.len); |
| 313 | 309 | for (ext.spec.operand_kinds) |kind| { |
| 314 | 310 | var new_kind = kind; |
| 315 | new_kind.kind = try std.mem.join(allocator, ".", &.{ ext.name, kind.kind }); | |
| 311 | new_kind.kind = try std.mem.join(arena, ".", &.{ ext.name, kind.kind }); | |
| 316 | 312 | try all_operand_kinds.putNoClobber(.{ ext.name, kind.kind }, new_kind); |
| 317 | 313 | } |
| 318 | 314 | } |
| 319 | 315 | |
| 320 | const extended_structs = try extendedStructs(all_operand_kinds.values()); | |
| 316 | const extended_structs = try extendedStructs(arena, all_operand_kinds.values()); | |
| 321 | 317 | // Note: extensions don't seem to have class. |
| 322 | try renderClass(writer, registry.instructions); | |
| 318 | try renderClass(arena, writer, registry.instructions); | |
| 323 | 319 | try renderOperandKind(writer, all_operand_kinds.values()); |
| 324 | 320 | |
| 325 | try renderOpcodes(writer, "Opcode", true, registry.instructions, extended_structs); | |
| 321 | try renderOpcodes(arena, writer, "Opcode", true, registry.instructions, extended_structs); | |
| 326 | 322 | for (extensions) |ext| { |
| 327 | try renderOpcodes(writer, ext.opcode_name, false, ext.spec.instructions, extended_structs); | |
| 323 | try renderOpcodes(arena, writer, ext.opcode_name, false, ext.spec.instructions, extended_structs); | |
| 328 | 324 | } |
| 329 | 325 | |
| 330 | try renderOperandKinds(writer, all_operand_kinds.values(), extended_structs); | |
| 326 | try renderOperandKinds(arena, writer, all_operand_kinds.values(), extended_structs); | |
| 331 | 327 | try renderInstructionSet(writer, registry, extensions, all_operand_kinds); |
| 332 | 328 | } |
| 333 | 329 | |
| ... | ... | @@ -414,8 +410,8 @@ fn renderInstructionsCase( |
| 414 | 410 | ); |
| 415 | 411 | } |
| 416 | 412 | |
| 417 | fn renderClass(writer: *std.Io.Writer, instructions: []const Instruction) !void { | |
| 418 | var class_map = std.StringArrayHashMap(void).init(allocator); | |
| 413 | fn renderClass(arena: Allocator, writer: *std.Io.Writer, instructions: []const Instruction) !void { | |
| 414 | var class_map = std.StringArrayHashMap(void).init(arena); | |
| 419 | 415 | |
| 420 | 416 | for (instructions) |inst| { |
| 421 | 417 | if (std.mem.eql(u8, inst.class.?, "@exclude")) continue; |
| ... | ... | @@ -535,16 +531,17 @@ fn renderEnumerant(writer: *std.Io.Writer, enumerant: Enumerant) !void { |
| 535 | 531 | } |
| 536 | 532 | |
| 537 | 533 | fn renderOpcodes( |
| 534 | arena: Allocator, | |
| 538 | 535 | writer: *std.Io.Writer, |
| 539 | 536 | opcode_type_name: []const u8, |
| 540 | 537 | want_operands: bool, |
| 541 | 538 | instructions: []const Instruction, |
| 542 | 539 | extended_structs: ExtendedStructSet, |
| 543 | 540 | ) !void { |
| 544 | var inst_map = std.AutoArrayHashMap(u32, usize).init(allocator); | |
| 541 | var inst_map = std.AutoArrayHashMap(u32, usize).init(arena); | |
| 545 | 542 | try inst_map.ensureTotalCapacity(instructions.len); |
| 546 | 543 | |
| 547 | var aliases = std.array_list.Managed(struct { inst: usize, alias: usize }).init(allocator); | |
| 544 | var aliases = std.array_list.Managed(struct { inst: usize, alias: usize }).init(arena); | |
| 548 | 545 | try aliases.ensureTotalCapacity(instructions.len); |
| 549 | 546 | |
| 550 | 547 | for (instructions, 0..) |inst, i| { |
| ... | ... | @@ -634,30 +631,32 @@ fn renderOpcodes( |
| 634 | 631 | } |
| 635 | 632 | |
| 636 | 633 | fn renderOperandKinds( |
| 634 | arena: Allocator, | |
| 637 | 635 | writer: *std.Io.Writer, |
| 638 | 636 | kinds: []const OperandKind, |
| 639 | 637 | extended_structs: ExtendedStructSet, |
| 640 | 638 | ) !void { |
| 641 | 639 | for (kinds) |kind| { |
| 642 | 640 | switch (kind.category) { |
| 643 | .ValueEnum => try renderValueEnum(writer, kind, extended_structs), | |
| 644 | .BitEnum => try renderBitEnum(writer, kind, extended_structs), | |
| 641 | .ValueEnum => try renderValueEnum(arena, writer, kind, extended_structs), | |
| 642 | .BitEnum => try renderBitEnum(arena, writer, kind, extended_structs), | |
| 645 | 643 | else => {}, |
| 646 | 644 | } |
| 647 | 645 | } |
| 648 | 646 | } |
| 649 | 647 | |
| 650 | 648 | fn renderValueEnum( |
| 649 | arena: Allocator, | |
| 651 | 650 | writer: *std.Io.Writer, |
| 652 | 651 | enumeration: OperandKind, |
| 653 | 652 | extended_structs: ExtendedStructSet, |
| 654 | 653 | ) !void { |
| 655 | 654 | const enumerants = enumeration.enumerants orelse return error.InvalidRegistry; |
| 656 | 655 | |
| 657 | var enum_map = std.AutoArrayHashMap(u32, usize).init(allocator); | |
| 656 | var enum_map = std.AutoArrayHashMap(u32, usize).init(arena); | |
| 658 | 657 | try enum_map.ensureTotalCapacity(enumerants.len); |
| 659 | 658 | |
| 660 | var aliases = std.array_list.Managed(struct { enumerant: usize, alias: usize }).init(allocator); | |
| 659 | var aliases = std.array_list.Managed(struct { enumerant: usize, alias: usize }).init(arena); | |
| 661 | 660 | try aliases.ensureTotalCapacity(enumerants.len); |
| 662 | 661 | |
| 663 | 662 | for (enumerants, 0..) |enumerant, i| { |
| ... | ... | @@ -726,6 +725,7 @@ fn renderValueEnum( |
| 726 | 725 | } |
| 727 | 726 | |
| 728 | 727 | fn renderBitEnum( |
| 728 | arena: Allocator, | |
| 729 | 729 | writer: *std.Io.Writer, |
| 730 | 730 | enumeration: OperandKind, |
| 731 | 731 | extended_structs: ExtendedStructSet, |
| ... | ... | @@ -735,7 +735,7 @@ fn renderBitEnum( |
| 735 | 735 | var flags_by_bitpos = [_]?usize{null} ** 32; |
| 736 | 736 | const enumerants = enumeration.enumerants orelse return error.InvalidRegistry; |
| 737 | 737 | |
| 738 | var aliases = std.array_list.Managed(struct { flag: usize, alias: u5 }).init(allocator); | |
| 738 | var aliases = std.array_list.Managed(struct { flag: usize, alias: u5 }).init(arena); | |
| 739 | 739 | try aliases.ensureTotalCapacity(enumerants.len); |
| 740 | 740 | |
| 741 | 741 | for (enumerants, 0..) |enumerant, i| { |
| ... | ... | @@ -749,7 +749,7 @@ fn renderBitEnum( |
| 749 | 749 | continue; |
| 750 | 750 | } |
| 751 | 751 | |
| 752 | std.debug.assert(@popCount(value) == 1); | |
| 752 | assert(@popCount(value) == 1); | |
| 753 | 753 | |
| 754 | 754 | const bitpos = std.math.log2_int(u32, value); |
| 755 | 755 | if (flags_by_bitpos[bitpos]) |*existing| { |
tools/gen_stubs.zig+4-10| ... | ... | @@ -281,16 +281,10 @@ const Parse = struct { |
| 281 | 281 | arch: Arch, |
| 282 | 282 | }; |
| 283 | 283 | |
| 284 | pub fn main() !void { | |
| 285 | var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 286 | defer arena_instance.deinit(); | |
| 287 | const arena = arena_instance.allocator(); | |
| 288 | ||
| 289 | var threaded: std.Io.Threaded = .init(arena, .{}); | |
| 290 | defer threaded.deinit(); | |
| 291 | const io = threaded.io(); | |
| 292 | ||
| 293 | const args = try std.process.argsAlloc(arena); | |
| 284 | pub fn main(init: std.process.Init) !void { | |
| 285 | const arena = init.arena.allocator(); | |
| 286 | const io = init.io; | |
| 287 | const args = try init.minimal.args.toSlice(arena); | |
| 294 | 288 | const build_all_path = args[1]; |
| 295 | 289 | |
| 296 | 290 | var build_all_dir = try Io.Dir.cwd().openDir(io, build_all_path, .{}); |
tools/generate_c_size_and_align_checks.zig+1-1| ... | ... | @@ -29,7 +29,7 @@ fn cName(ty: std.Target.CType) []const u8 { |
| 29 | 29 | var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init; |
| 30 | 30 | |
| 31 | 31 | pub fn main(init: std.process.Init) !void { |
| 32 | const args = try init.args.toSlice(init.arena); | |
| 32 | const args = try init.minimal.args.toSlice(init.arena.allocator()); | |
| 33 | 33 | const io = init.io; |
| 34 | 34 | |
| 35 | 35 | if (args.len != 2) { |
tools/generate_linux_syscalls.zig+1-1| ... | ... | @@ -174,7 +174,7 @@ pub fn main(init: std.process.Init) !void { |
| 174 | 174 | const gpa = init.gpa; |
| 175 | 175 | const io = init.io; |
| 176 | 176 | |
| 177 | const args = try std.process.argsAlloc(gpa); | |
| 177 | const args = try init.minimal.args.toSlice(init.arena.allocator()); | |
| 178 | 178 | if (args.len < 2 or mem.eql(u8, args[1], "--help")) { |
| 179 | 179 | const stderr = std.debug.lockStderr(&.{}); |
| 180 | 180 | const w = &stderr.file_writer.interface; |
tools/incr-check.zig+24-22| ... | ... | @@ -171,14 +171,6 @@ pub fn main(init: std.process.Init) !void { |
| 171 | 171 | const zig_prog_node = target_prog_node.start("zig build-exe", 0); |
| 172 | 172 | defer zig_prog_node.end(); |
| 173 | 173 | |
| 174 | var child = std.process.Child.init(child_args.items, arena); | |
| 175 | child.stdin_behavior = .Pipe; | |
| 176 | child.stdout_behavior = .Pipe; | |
| 177 | child.stderr_behavior = .Pipe; | |
| 178 | child.progress_node = zig_prog_node; | |
| 179 | child.cwd_dir = tmp_dir; | |
| 180 | child.cwd = tmp_dir_path; | |
| 181 | ||
| 182 | 174 | var cc_child_args: std.ArrayList([]const u8) = .empty; |
| 183 | 175 | if (target.backend == .cbe) { |
| 184 | 176 | const resolved_cc_zig_exe = if (opt_cc_zig) |cc_zig_exe| |
| ... | ... | @@ -201,6 +193,17 @@ pub fn main(init: std.process.Init) !void { |
| 201 | 193 | try cc_child_args.append(arena, "-o"); |
| 202 | 194 | } |
| 203 | 195 | |
| 196 | var child = std.process.spawn(io, .{ | |
| 197 | .argv = child_args.items, | |
| 198 | .stdin = .pipe, | |
| 199 | .stdout = .pipe, | |
| 200 | .stderr = .pipe, | |
| 201 | .progress_node = zig_prog_node, | |
| 202 | .cwd_dir = tmp_dir, | |
| 203 | .cwd = tmp_dir_path, | |
| 204 | }); | |
| 205 | defer child.kill(io); | |
| 206 | ||
| 204 | 207 | var eval: Eval = .{ |
| 205 | 208 | .arena = arena, |
| 206 | 209 | .io = io, |
| ... | ... | @@ -219,11 +222,6 @@ pub fn main(init: std.process.Init) !void { |
| 219 | 222 | .enable_darling = enable_darling, |
| 220 | 223 | }; |
| 221 | 224 | |
| 222 | try child.spawn(io); | |
| 223 | errdefer { | |
| 224 | _ = child.kill(io) catch {}; | |
| 225 | } | |
| 226 | ||
| 227 | 225 | var poller = Io.poll(arena, Eval.StreamEnum, .{ |
| 228 | 226 | .stdout = child.stdout.?, |
| 229 | 227 | .stderr = child.stderr.?, |
| ... | ... | @@ -528,7 +526,7 @@ const Eval = struct { |
| 528 | 526 | const run_prog_node = prog_node.start("run generated executable", 0); |
| 529 | 527 | defer run_prog_node.end(); |
| 530 | 528 | |
| 531 | const result = std.process.Child.run(eval.arena, io, .{ | |
| 529 | const result = std.process.run(eval.arena, io, .{ | |
| 532 | 530 | .argv = argv, |
| 533 | 531 | .cwd_dir = eval.tmp_dir, |
| 534 | 532 | .cwd = eval.tmp_dir_path, |
| ... | ... | @@ -556,7 +554,7 @@ const Eval = struct { |
| 556 | 554 | } |
| 557 | 555 | |
| 558 | 556 | switch (result.term) { |
| 559 | .Exited => |code| switch (update.outcome) { | |
| 557 | .exited => |code| switch (update.outcome) { | |
| 560 | 558 | .unknown, .compile_errors => unreachable, |
| 561 | 559 | .stdout => |expected_stdout| { |
| 562 | 560 | if (code != 0) { |
| ... | ... | @@ -564,9 +562,12 @@ const Eval = struct { |
| 564 | 562 | } |
| 565 | 563 | try std.testing.expectEqualStrings(expected_stdout, result.stdout); |
| 566 | 564 | }, |
| 567 | .exit_code => |expected_code| try std.testing.expectEqual(expected_code, result.term.Exited), | |
| 565 | .exit_code => |expected_code| try std.testing.expectEqual(expected_code, code), | |
| 566 | }, | |
| 567 | .signal => |sig| { | |
| 568 | eval.fatal("generated executable '{s}' terminated with signal {t}", .{ binary_path, sig }); | |
| 568 | 569 | }, |
| 569 | .Signal, .Stopped, .Unknown => { | |
| 570 | .stopped, .unknown => { | |
| 570 | 571 | eval.fatal("generated executable '{s}' terminated unexpectedly", .{binary_path}); |
| 571 | 572 | }, |
| 572 | 573 | } |
| ... | ... | @@ -614,7 +615,7 @@ const Eval = struct { |
| 614 | 615 | try eval.cc_child_args.appendSlice(eval.arena, &.{ out_path, c_path }); |
| 615 | 616 | defer eval.cc_child_args.items.len -= 2; |
| 616 | 617 | |
| 617 | const result = std.process.Child.run(eval.arena, eval.io, .{ | |
| 618 | const result = std.process.run(eval.arena, eval.io, .{ | |
| 618 | 619 | .argv = eval.cc_child_args.items, |
| 619 | 620 | .cwd_dir = eval.tmp_dir, |
| 620 | 621 | .cwd = eval.tmp_dir_path, |
| ... | ... | @@ -623,13 +624,13 @@ const Eval = struct { |
| 623 | 624 | eval.fatal("failed to spawn zig cc for '{s}': {t}", .{ c_path, err }); |
| 624 | 625 | }; |
| 625 | 626 | switch (result.term) { |
| 626 | .Exited => |code| if (code != 0) { | |
| 627 | .exited => |code| if (code != 0) { | |
| 627 | 628 | if (result.stderr.len != 0) { |
| 628 | 629 | std.log.err("zig cc stderr:\n{s}", .{result.stderr}); |
| 629 | 630 | } |
| 630 | 631 | eval.fatal("zig cc for '{s}' failed with code {d}", .{ c_path, code }); |
| 631 | 632 | }, |
| 632 | .Signal, .Stopped, .Unknown => { | |
| 633 | .signal, .stopped, .unknown => { | |
| 633 | 634 | if (result.stderr.len != 0) { |
| 634 | 635 | std.log.err("zig cc stderr:\n{s}", .{result.stderr}); |
| 635 | 636 | } |
| ... | ... | @@ -909,8 +910,9 @@ fn waitChild(child: *std.process.Child, eval: *Eval) void { |
| 909 | 910 | requestExit(child, eval); |
| 910 | 911 | const term = child.wait(io) catch |err| eval.fatal("child process failed: {t}", .{err}); |
| 911 | 912 | switch (term) { |
| 912 | .Exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}), | |
| 913 | .Signal, .Stopped, .Unknown => eval.fatal("compiler terminated unexpectedly", .{}), | |
| 913 | .exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}), | |
| 914 | .signal => |sig| eval.fatal("compiler terminated with signal {t}", .{sig}), | |
| 915 | .stopped, .unknown => eval.fatal("compiler terminated unexpectedly", .{}), | |
| 914 | 916 | } |
| 915 | 917 | } |
| 916 | 918 |
tools/migrate_langref.zig+4-11| ... | ... | @@ -11,21 +11,14 @@ const fatal = std.process.fatal; |
| 11 | 11 | |
| 12 | 12 | const max_doc_file_size = 10 * 1024 * 1024; |
| 13 | 13 | |
| 14 | pub fn main() !void { | |
| 15 | var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 16 | defer arena_instance.deinit(); | |
| 17 | const arena = arena_instance.allocator(); | |
| 14 | pub fn main(init: std.process.Init) !void { | |
| 15 | const arena = init.arena.allocator(); | |
| 16 | const io = init.io; | |
| 17 | const args = try init.minimal.args.toSlice(arena); | |
| 18 | 18 | |
| 19 | const gpa = arena; | |
| 20 | ||
| 21 | const args = try std.process.argsAlloc(arena); | |
| 22 | 19 | const input_file = args[1]; |
| 23 | 20 | const output_file = args[2]; |
| 24 | 21 | |
| 25 | var threaded: std.Io.Threaded = .init(gpa, .{}); | |
| 26 | defer threaded.deinit(); | |
| 27 | const io = threaded.io(); | |
| 28 | ||
| 29 | 22 | var in_file = try Dir.cwd().openFile(io, input_file, .{ .mode = .read_only }); |
| 30 | 23 | defer in_file.close(io); |
| 31 | 24 |
tools/update-linux-headers.zig+7-9| ... | ... | @@ -141,15 +141,13 @@ const HashToContents = std.StringHashMap(Contents); |
| 141 | 141 | const TargetToHash = std.ArrayHashMap(DestTarget, []const u8, DestTarget.HashContext, true); |
| 142 | 142 | const PathTable = std.StringHashMap(*TargetToHash); |
| 143 | 143 | |
| 144 | pub fn main() !void { | |
| 145 | var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 146 | const arena = arena_state.allocator(); | |
| 144 | pub fn main(init: std.process.Init) !void { | |
| 145 | const arena = init.arena.allocator(); | |
| 146 | const io = init.io; | |
| 147 | const args = try init.minimal.args.toSlice(arena); | |
| 148 | const env_map = init.env_map; | |
| 149 | const cwd = try std.process.getCwdAlloc(arena); | |
| 147 | 150 | |
| 148 | var threaded: Io.Threaded = .init(arena, .{}); | |
| 149 | defer threaded.deinit(); | |
| 150 | const io = threaded.io(); | |
| 151 | ||
| 152 | const args = try std.process.argsAlloc(arena); | |
| 153 | 151 | var search_paths = std.array_list.Managed([]const u8).init(arena); |
| 154 | 152 | var opt_out_dir: ?[]const u8 = null; |
| 155 | 153 | |
| ... | ... | @@ -211,7 +209,7 @@ pub fn main() !void { |
| 211 | 209 | switch (entry.kind) { |
| 212 | 210 | .directory => try dir_stack.append(full_path), |
| 213 | 211 | .file => { |
| 214 | const rel_path = try Dir.path.relative(arena, target_include_dir, full_path); | |
| 212 | const rel_path = try Dir.path.relative(arena, cwd, env_map, target_include_dir, full_path); | |
| 215 | 213 | const max_size = 2 * 1024 * 1024 * 1024; |
| 216 | 214 | const raw_bytes = try Dir.cwd().readFileAlloc(io, full_path, arena, .limited(max_size)); |
| 217 | 215 | const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t"); |
tools/update_clang_options.zig+12-18| ... | ... | @@ -627,16 +627,10 @@ const cpu_targets = struct { |
| 627 | 627 | pub const xtensa = std.Target.xtensa; |
| 628 | 628 | }; |
| 629 | 629 | |
| 630 | pub fn main() anyerror!void { | |
| 631 | var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 632 | defer arena.deinit(); | |
| 633 | ||
| 634 | const allocator = arena.allocator(); | |
| 635 | const args = try std.process.argsAlloc(allocator); | |
| 636 | ||
| 637 | var threaded: std.Io.Threaded = .init(allocator, .{}); | |
| 638 | defer threaded.deinit(); | |
| 639 | const io = threaded.io(); | |
| 630 | pub fn main(init: std.process.Init) !void { | |
| 631 | const arena = init.arena.allocator(); | |
| 632 | const args = try init.minimal.args.toSlice(arena); | |
| 633 | const io = init.io; | |
| 640 | 634 | |
| 641 | 635 | var stdout_buffer: [4000]u8 = undefined; |
| 642 | 636 | var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); |
| ... | ... | @@ -658,7 +652,7 @@ pub fn main() anyerror!void { |
| 658 | 652 | const llvm_src_root = args[2]; |
| 659 | 653 | if (std.mem.startsWith(u8, llvm_src_root, "-")) printUsageAndExit(args[0]); |
| 660 | 654 | |
| 661 | var llvm_to_zig_cpu_features = std.StringHashMap([]const u8).init(allocator); | |
| 655 | var llvm_to_zig_cpu_features = std.StringHashMap([]const u8).init(arena); | |
| 662 | 656 | |
| 663 | 657 | inline for (@typeInfo(cpu_targets).@"struct".decls) |decl| { |
| 664 | 658 | const Feature = @field(cpu_targets, decl.name).Feature; |
| ... | ... | @@ -675,12 +669,12 @@ pub fn main() anyerror!void { |
| 675 | 669 | const child_args = [_][]const u8{ |
| 676 | 670 | llvm_tblgen_exe, |
| 677 | 671 | "--dump-json", |
| 678 | try std.fmt.allocPrint(allocator, "{s}/clang/include/clang/Driver/Options.td", .{llvm_src_root}), | |
| 679 | try std.fmt.allocPrint(allocator, "-I={s}/llvm/include", .{llvm_src_root}), | |
| 680 | try std.fmt.allocPrint(allocator, "-I={s}/clang/include/clang/Driver", .{llvm_src_root}), | |
| 672 | try std.fmt.allocPrint(arena, "{s}/clang/include/clang/Driver/Options.td", .{llvm_src_root}), | |
| 673 | try std.fmt.allocPrint(arena, "-I={s}/llvm/include", .{llvm_src_root}), | |
| 674 | try std.fmt.allocPrint(arena, "-I={s}/clang/include/clang/Driver", .{llvm_src_root}), | |
| 681 | 675 | }; |
| 682 | 676 | |
| 683 | const child_result = try std.process.Child.run(allocator, io, .{ | |
| 677 | const child_result = try std.process.run(arena, io, .{ | |
| 684 | 678 | .argv = &child_args, |
| 685 | 679 | .max_output_bytes = 100 * 1024 * 1024, |
| 686 | 680 | }); |
| ... | ... | @@ -688,7 +682,7 @@ pub fn main() anyerror!void { |
| 688 | 682 | std.debug.print("{s}\n", .{child_result.stderr}); |
| 689 | 683 | |
| 690 | 684 | const json_text = switch (child_result.term) { |
| 691 | .Exited => |code| if (code == 0) child_result.stdout else { | |
| 685 | .exited => |code| if (code == 0) child_result.stdout else { | |
| 692 | 686 | std.debug.print("llvm-tblgen exited with code {d}\n", .{code}); |
| 693 | 687 | std.process.exit(1); |
| 694 | 688 | }, |
| ... | ... | @@ -698,11 +692,11 @@ pub fn main() anyerror!void { |
| 698 | 692 | }, |
| 699 | 693 | }; |
| 700 | 694 | |
| 701 | const parsed = try json.parseFromSlice(json.Value, allocator, json_text, .{}); | |
| 695 | const parsed = try json.parseFromSlice(json.Value, arena, json_text, .{}); | |
| 702 | 696 | defer parsed.deinit(); |
| 703 | 697 | const root_map = &parsed.value.object; |
| 704 | 698 | |
| 705 | var all_objects = std.array_list.Managed(*json.ObjectMap).init(allocator); | |
| 699 | var all_objects = std.array_list.Managed(*json.ObjectMap).init(arena); | |
| 706 | 700 | { |
| 707 | 701 | var it = root_map.iterator(); |
| 708 | 702 | it_map: while (it.next()) |kv| { |
tools/update_cpu_features.zig+3-3| ... | ... | @@ -1884,7 +1884,7 @@ const targets = [_]ArchTarget{ |
| 1884 | 1884 | }; |
| 1885 | 1885 | |
| 1886 | 1886 | pub fn main(init: std.process.Init) !void { |
| 1887 | const arena = init.arena_allocator.allocator(); | |
| 1887 | const arena = init.arena.allocator(); | |
| 1888 | 1888 | const io = init.io; |
| 1889 | 1889 | |
| 1890 | 1890 | var args = try init.minimal.args.iterateAllocator(arena); |
| ... | ... | @@ -1985,7 +1985,7 @@ fn processOneTarget(io: Io, job: Job) void { |
| 1985 | 1985 | }), |
| 1986 | 1986 | }; |
| 1987 | 1987 | |
| 1988 | const child_result = try std.process.Child.run(arena, io, .{ | |
| 1988 | const child_result = try std.process.run(arena, io, .{ | |
| 1989 | 1989 | .argv = &child_args, |
| 1990 | 1990 | .max_output_bytes = 500 * 1024 * 1024, |
| 1991 | 1991 | }); |
| ... | ... | @@ -1995,7 +1995,7 @@ fn processOneTarget(io: Io, job: Job) void { |
| 1995 | 1995 | } |
| 1996 | 1996 | |
| 1997 | 1997 | const json_text = switch (child_result.term) { |
| 1998 | .Exited => |code| if (code == 0) child_result.stdout else { | |
| 1998 | .exited => |code| if (code == 0) child_result.stdout else { | |
| 1999 | 1999 | std.debug.print("llvm-tblgen exited with code {d}\n", .{code}); |
| 2000 | 2000 | std.process.exit(1); |
| 2001 | 2001 | }, |
tools/update_crc_catalog.zig+7-9| ... | ... | @@ -6,16 +6,14 @@ const ascii = std.ascii; |
| 6 | 6 | |
| 7 | 7 | const catalog_txt = @embedFile("crc/catalog.txt"); |
| 8 | 8 | |
| 9 | pub fn main() anyerror!void { | |
| 10 | var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 11 | defer arena_state.deinit(); | |
| 12 | const arena = arena_state.allocator(); | |
| 13 | ||
| 14 | var threaded: Io.Threaded = .init(arena, .{}); | |
| 15 | defer threaded.deinit(); | |
| 16 | const io = threaded.io(); | |
| 9 | pub fn main(init: std.process.Init) !void { | |
| 10 | const arena = init.arena.allocator(); | |
| 11 | const io = init.io; | |
| 12 | const args = try init.minimal.args.toSlice(arena); | |
| 13 | return @"i like cheese"(arena, io, args); | |
| 14 | } | |
| 17 | 15 | |
| 18 | const args = try std.process.argsAlloc(arena); | |
| 16 | fn @"i like cheese"(arena: std.mem.Allocator, io: Io, args: []const []const u8) !void { | |
| 19 | 17 | if (args.len <= 1) printUsageAndExit(args[0]); |
| 20 | 18 | |
| 21 | 19 | const zig_src_root = args[1]; |
tools/update_freebsd_libc.zig+4-9| ... | ... | @@ -12,16 +12,11 @@ const exempt_files = [_][]const u8{ |
| 12 | 12 | "abilists", |
| 13 | 13 | }; |
| 14 | 14 | |
| 15 | pub fn main() !void { | |
| 16 | var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 17 | defer arena_instance.deinit(); | |
| 18 | const arena = arena_instance.allocator(); | |
| 15 | pub fn main(init: std.process.Init) !void { | |
| 16 | const arena = init.arena.allocator(); | |
| 17 | const io = init.io; | |
| 18 | const args = try init.minimal.args.toSlice(arena); | |
| 19 | 19 | |
| 20 | var threaded: Io.Threaded = .init(arena, .{}); | |
| 21 | defer threaded.deinit(); | |
| 22 | const io = threaded.io(); | |
| 23 | ||
| 24 | const args = try std.process.argsAlloc(arena); | |
| 25 | 20 | const freebsd_src_path = args[1]; |
| 26 | 21 | const zig_src_path = args[2]; |
| 27 | 22 |
tools/update_glibc.zig+4-9| ... | ... | @@ -38,16 +38,11 @@ const exempt_extensions = [_][]const u8{ |
| 38 | 38 | "-2.33.c", |
| 39 | 39 | }; |
| 40 | 40 | |
| 41 | pub fn main() !void { | |
| 42 | var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 43 | defer arena_instance.deinit(); | |
| 44 | const arena = arena_instance.allocator(); | |
| 41 | pub fn main(init: std.process.Init) !void { | |
| 42 | const arena = init.arena.allocator(); | |
| 43 | const io = init.io; | |
| 44 | const args = try init.minimal.args.toSlice(arena); | |
| 45 | 45 | |
| 46 | var threaded: Io.Threaded = .init(arena, .{}); | |
| 47 | defer threaded.deinit(); | |
| 48 | const io = threaded.io(); | |
| 49 | ||
| 50 | const args = try std.process.argsAlloc(arena); | |
| 51 | 46 | const glibc_src_path = args[1]; |
| 52 | 47 | const zig_src_path = args[2]; |
| 53 | 48 |
tools/update_mingw.zig+4-9| ... | ... | @@ -2,16 +2,11 @@ const std = @import("std"); |
| 2 | 2 | const Io = std.Io; |
| 3 | 3 | const Dir = std.Io.Dir; |
| 4 | 4 | |
| 5 | pub fn main() !void { | |
| 6 | var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 7 | defer arena_instance.deinit(); | |
| 8 | const arena = arena_instance.allocator(); | |
| 5 | pub fn main(init: std.process.Init) !void { | |
| 6 | const arena = init.arena.allocator(); | |
| 7 | const io = init.io; | |
| 8 | const args = try init.minimal.args.toSlice(arena); | |
| 9 | 9 | |
| 10 | var threaded: Io.Threaded = .init(arena, .{}); | |
| 11 | defer threaded.deinit(); | |
| 12 | const io = threaded.io(); | |
| 13 | ||
| 14 | const args = try std.process.argsAlloc(arena); | |
| 15 | 10 | const zig_src_lib_path = args[1]; |
| 16 | 11 | const mingw_src_path = args[2]; |
| 17 | 12 |
tools/update_netbsd_libc.zig+4-9| ... | ... | @@ -12,16 +12,11 @@ const exempt_files = [_][]const u8{ |
| 12 | 12 | "abilists", |
| 13 | 13 | }; |
| 14 | 14 | |
| 15 | pub fn main() !void { | |
| 16 | var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 17 | defer arena_instance.deinit(); | |
| 18 | const arena = arena_instance.allocator(); | |
| 15 | pub fn main(init: std.process.Init) !void { | |
| 16 | const arena = init.arena.allocator(); | |
| 17 | const io = init.io; | |
| 18 | const args = try init.minimal.args.toSlice(arena); | |
| 19 | 19 | |
| 20 | var threaded: Io.Threaded = .init(arena, .{}); | |
| 21 | defer threaded.deinit(); | |
| 22 | const io = threaded.io(); | |
| 23 | ||
| 24 | const args = try std.process.argsAlloc(arena); | |
| 25 | 20 | const netbsd_src_path = args[1]; |
| 26 | 21 | const zig_src_path = args[2]; |
| 27 | 22 |