| author | |
| committer | |
| log | 4afed3e9ef83724bdfddd1d06b7727acda55e642 |
| tree | 5b208954088cea6efd753ac4c6b4dd110b916487 |
| parent | e149c0e2aa9e35ce90760ebef158bb05f3a74d0d |
8 files changed, 53 insertions(+), 66 deletions(-)
lib/compiler/objcopy.zig+4-14| ... | ... | @@ -17,20 +17,10 @@ var stdout_buffer: [1024]u8 = undefined; |
| 17 | 17 | var input_buffer: [1024]u8 = undefined; |
| 18 | 18 | var output_buffer: [1024]u8 = undefined; |
| 19 | 19 | |
| 20 | pub fn main() !void { | |
| 21 | var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 22 | defer arena_instance.deinit(); | |
| 23 | const arena = arena_instance.allocator(); | |
| 24 | ||
| 25 | var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init; | |
| 26 | const gpa = general_purpose_allocator.allocator(); | |
| 27 | ||
| 28 | var threaded: std.Io.Threaded = .init(gpa, .{}); | |
| 29 | defer threaded.deinit(); | |
| 30 | const io = threaded.io(); | |
| 31 | ||
| 32 | const args = try std.process.argsAlloc(arena); | |
| 33 | return cmdObjCopy(arena, io, args[1..]); | |
| 20 | pub fn main(init: std.process.Init) !void { | |
| 21 | const arena = init.arena.allocator(); | |
| 22 | const args = try init.minimal.args.toSlice(arena); | |
| 23 | return cmdObjCopy(arena, init.io, args[1..]); | |
| 34 | 24 | } |
| 35 | 25 | |
| 36 | 26 | fn cmdObjCopy(arena: Allocator, io: Io, args: []const []const u8) !void { |
test/standalone/child_process/main.zig+8-2| ... | ... | @@ -9,6 +9,12 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 9 | 9 | }; |
| 10 | 10 | const gpa = gpa_state.allocator(); |
| 11 | 11 | |
| 12 | const process_cwd_path = try std.process.getCwdAlloc(gpa); | |
| 13 | defer gpa.free(process_cwd_path); | |
| 14 | ||
| 15 | var env_map = try init.environ.createMap(gpa); | |
| 16 | defer env_map.deinit(); | |
| 17 | ||
| 12 | 18 | var it = try init.args.iterateAllocator(gpa); |
| 13 | 19 | defer it.deinit(); |
| 14 | 20 | _ = it.next() orelse unreachable; // skip binary name |
| ... | ... | @@ -17,7 +23,7 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 17 | 23 | const cwd_path = it.next() orelse break :child_path .{ child_path, false }; |
| 18 | 24 | // If there is a third argument, it is the current CWD somewhere within the cache directory. |
| 19 | 25 | // In that case, modify the child path in order to test spawning a path with a leading `..` component. |
| 20 | break :child_path .{ try std.fs.path.relative(gpa, cwd_path, child_path), true }; | |
| 26 | break :child_path .{ try std.fs.path.relative(gpa, process_cwd_path, &env_map, cwd_path, child_path), true }; | |
| 21 | 27 | }; |
| 22 | 28 | defer if (needs_free) gpa.free(child_path); |
| 23 | 29 | |
| ... | ... | @@ -28,7 +34,7 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 28 | 34 | defer threaded.deinit(); |
| 29 | 35 | const io = threaded.io(); |
| 30 | 36 | |
| 31 | var child = try std.process.spawn(.{ | |
| 37 | var child = try std.process.spawn(io, .{ | |
| 32 | 38 | .argv = &.{ child_path, "hello arg" }, |
| 33 | 39 | .stdin = .pipe, |
| 34 | 40 | .stdout = .pipe, |
test/standalone/empty_env/main.zig+1-1| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | pub fn main(init: std.process.Init) !void { |
| 4 | try std.testing.expect(init.env_map.count() == 0); | |
| 4 | try std.testing.expectEqual(0, init.env_map.count()); | |
| 5 | 5 | } |
test/standalone/env_vars/main.zig+5-5| ... | ... | @@ -104,20 +104,20 @@ pub fn main(init: std.process.Init) !void { |
| 104 | 104 | // getAlloc |
| 105 | 105 | { |
| 106 | 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")); | |
| 107 | try std.testing.expectError(error.EnvironmentVariableMissing, environ.getAlloc(arena, "FOO=")); | |
| 108 | try std.testing.expectError(error.EnvironmentVariableMissing, environ.getAlloc(arena, "FO")); | |
| 109 | try std.testing.expectError(error.EnvironmentVariableMissing, environ.getAlloc(arena, "FOOO")); | |
| 110 | 110 | if (builtin.os.tag == .windows) { |
| 111 | 111 | try std.testing.expectEqualSlices(u8, "123", try environ.getAlloc(arena, "foo")); |
| 112 | 112 | } |
| 113 | 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")); | |
| 114 | try std.testing.expectError(error.EnvironmentVariableMissing, environ.getAlloc(arena, "EQUALS=ABC")); | |
| 115 | 115 | try std.testing.expectEqualSlices(u8, "non-ascii አማርኛ \u{10FFFF}", try environ.getAlloc(arena, "КИРиллИЦА")); |
| 116 | 116 | if (builtin.os.tag == .windows) { |
| 117 | 117 | try std.testing.expectEqualSlices(u8, "non-ascii አማርኛ \u{10FFFF}", try environ.getAlloc(arena, "кирИЛЛица")); |
| 118 | 118 | } |
| 119 | 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 | try std.testing.expectError(error.EnvironmentVariableMissing, environ.getAlloc(arena, "NOT_SET")); | |
| 121 | 121 | if (builtin.os.tag == .windows) { |
| 122 | 122 | try std.testing.expectEqualSlices(u8, "hi", try environ.getAlloc(arena, "=HIDDEN")); |
| 123 | 123 | try std.testing.expectEqualSlices(u8, "\xed\xa0\x80", try environ.getAlloc(arena, "INVALID_UTF16_\xed\xa0\x80")); |
test/standalone/self_exe_symlink/create-symlink.zig+1-1| ... | ... | @@ -9,7 +9,7 @@ pub fn main(init: std.process.Init) !void { |
| 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()); | |
| 12 | const cwd = try std.process.getCwdAlloc(init.arena.allocator()); | |
| 13 | 13 | |
| 14 | 14 | // If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`. |
| 15 | 15 | const exe_rel_path = try std.fs.path.relative(gpa, cwd, init.env_map, std.fs.path.dirname(symlink_path) orelse ".", exe_path); |
tools/fetch_them_macos_headers.zig+9-16| ... | ... | @@ -6,13 +6,9 @@ const process = std.process; |
| 6 | 6 | const assert = std.debug.assert; |
| 7 | 7 | const fatal = std.process.fatal; |
| 8 | 8 | const info = std.log.info; |
| 9 | ||
| 10 | const Allocator = mem.Allocator; | |
| 9 | const Allocator = std.mem.Allocator; | |
| 11 | 10 | const OsTag = std.Target.Os.Tag; |
| 12 | 11 | |
| 13 | var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; | |
| 14 | const gpa = general_purpose_allocator.allocator(); | |
| 15 | ||
| 16 | 12 | const Arch = enum { |
| 17 | 13 | aarch64, |
| 18 | 14 | x86_64, |
| ... | ... | @@ -67,10 +63,11 @@ const usage = |
| 67 | 63 | ; |
| 68 | 64 | |
| 69 | 65 | pub fn main(init: std.process.Init) !void { |
| 70 | const allocator = init.arena; | |
| 71 | const args = try init.minimal.args.toSlice(allocator); | |
| 66 | const io = init.io; | |
| 67 | const arena = init.arena.allocator(); | |
| 68 | const args = try init.minimal.args.toSlice(arena); | |
| 72 | 69 | |
| 73 | var argv = std.array_list.Managed([]const u8).init(allocator); | |
| 70 | var argv = std.array_list.Managed([]const u8).init(arena); | |
| 74 | 71 | var sysroot: ?[]const u8 = null; |
| 75 | 72 | |
| 76 | 73 | var args_iter = ArgsIterator{ .args = args[1..] }; |
| ... | ... | @@ -82,23 +79,19 @@ pub fn main(init: std.process.Init) !void { |
| 82 | 79 | } else try argv.append(arg); |
| 83 | 80 | } |
| 84 | 81 | |
| 85 | var threaded: Io.Threaded = .init(gpa, .{}); | |
| 86 | defer threaded.deinit(); | |
| 87 | const io = threaded.io(); | |
| 88 | ||
| 89 | 82 | const sysroot_path = sysroot orelse blk: { |
| 90 | 83 | const target = try std.zig.system.resolveTargetQuery(io, .{}); |
| 91 | break :blk std.zig.system.darwin.getSdk(allocator, io, &target) orelse | |
| 84 | break :blk std.zig.system.darwin.getSdk(arena, io, &target) orelse | |
| 92 | 85 | fatal("no SDK found; you can provide one explicitly with '--sysroot' flag", .{}); |
| 93 | 86 | }; |
| 94 | 87 | |
| 95 | 88 | var sdk_dir = try Dir.cwd().openDir(io, sysroot_path, .{}); |
| 96 | 89 | defer sdk_dir.close(io); |
| 97 | const sdk_info = try sdk_dir.readFileAlloc(io, "SDKSettings.json", allocator, .limited(std.math.maxInt(u32))); | |
| 90 | const sdk_info = try sdk_dir.readFileAlloc(io, "SDKSettings.json", arena, .limited(std.math.maxInt(u32))); | |
| 98 | 91 | |
| 99 | 92 | const parsed_json = try std.json.parseFromSlice(struct { |
| 100 | 93 | DefaultProperties: struct { MACOSX_DEPLOYMENT_TARGET: []const u8 }, |
| 101 | }, allocator, sdk_info, .{ .ignore_unknown_fields = true }); | |
| 94 | }, arena, sdk_info, .{ .ignore_unknown_fields = true }); | |
| 102 | 95 | |
| 103 | 96 | const version = Version.parse(parsed_json.value.DefaultProperties.MACOSX_DEPLOYMENT_TARGET) orelse |
| 104 | 97 | fatal("don't know how to parse SDK version: {s}", .{ |
| ... | ... | @@ -114,7 +107,7 @@ pub fn main(init: std.process.Init) !void { |
| 114 | 107 | .arch = arch, |
| 115 | 108 | .os_ver = os_ver, |
| 116 | 109 | }; |
| 117 | try fetchTarget(allocator, io, argv.items, sysroot_path, target, version, tmp_dir); | |
| 110 | try fetchTarget(arena, io, argv.items, sysroot_path, target, version, tmp_dir); | |
| 118 | 111 | } |
| 119 | 112 | } |
| 120 | 113 |
tools/gen_macos_headers_c.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ const usage = |
| 14 | 14 | ; |
| 15 | 15 | |
| 16 | 16 | pub fn main(init: std.process.Init) !void { |
| 17 | const arena = init.arena; | |
| 17 | const arena = init.arena.allocator(); | |
| 18 | 18 | const io = init.io; |
| 19 | 19 | const args = try init.minimal.args.toSlice(arena); |
| 20 | 20 |
tools/process_headers.zig+24-26| ... | ... | @@ -127,16 +127,14 @@ const LibCVendor = enum { |
| 127 | 127 | netbsd, |
| 128 | 128 | }; |
| 129 | 129 | |
| 130 | pub fn main() !void { | |
| 131 | var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
| 132 | const allocator = arena.allocator(); | |
| 133 | ||
| 134 | var threaded: Io.Threaded = .init(allocator, .{}); | |
| 135 | defer threaded.deinit(); | |
| 136 | const io = threaded.io(); | |
| 137 | ||
| 138 | const args = try std.process.argsAlloc(allocator); | |
| 139 | var search_paths = std.array_list.Managed([]const u8).init(allocator); | |
| 130 | pub fn main(init: std.process.Init) !void { | |
| 131 | const arena = init.arena.allocator(); | |
| 132 | const io = init.io; | |
| 133 | const args = try init.minimal.args.toSlice(arena); | |
| 134 | const cwd_path = try std.process.getCwdAlloc(arena); | |
| 135 | const env_map = init.env_map; | |
| 136 | ||
| 137 | var search_paths = std.array_list.Managed([]const u8).init(arena); | |
| 140 | 138 | var opt_out_dir: ?[]const u8 = null; |
| 141 | 139 | var opt_abi: ?[]const u8 = null; |
| 142 | 140 | |
| ... | ... | @@ -172,7 +170,7 @@ pub fn main() !void { |
| 172 | 170 | usageAndExit(args[0]); |
| 173 | 171 | }; |
| 174 | 172 | |
| 175 | const generic_name = try std.fmt.allocPrint(allocator, "generic-{s}", .{abi_name}); | |
| 173 | const generic_name = try std.fmt.allocPrint(arena, "generic-{s}", .{abi_name}); | |
| 176 | 174 | const libc_targets = switch (vendor) { |
| 177 | 175 | .glibc => &glibc_targets, |
| 178 | 176 | .musl => &musl_targets, |
| ... | ... | @@ -180,8 +178,8 @@ pub fn main() !void { |
| 180 | 178 | .netbsd => &netbsd_targets, |
| 181 | 179 | }; |
| 182 | 180 | |
| 183 | var path_table = PathTable.init(allocator); | |
| 184 | var hash_to_contents = HashToContents.init(allocator); | |
| 181 | var path_table = PathTable.init(arena); | |
| 182 | var hash_to_contents = HashToContents.init(arena); | |
| 185 | 183 | var max_bytes_saved: usize = 0; |
| 186 | 184 | var total_bytes: usize = 0; |
| 187 | 185 | |
| ... | ... | @@ -189,7 +187,7 @@ pub fn main() !void { |
| 189 | 187 | |
| 190 | 188 | for (libc_targets) |libc_target| { |
| 191 | 189 | const libc_dir = switch (vendor) { |
| 192 | .glibc => try std.zig.target.glibcRuntimeTriple(allocator, libc_target.arch, .linux, libc_target.abi), | |
| 190 | .glibc => try std.zig.target.glibcRuntimeTriple(arena, libc_target.arch, .linux, libc_target.abi), | |
| 193 | 191 | .musl => std.zig.target.muslArchName(libc_target.arch, libc_target.abi), |
| 194 | 192 | .freebsd => switch (libc_target.arch) { |
| 195 | 193 | .arm => "armv7", |
| ... | ... | @@ -221,7 +219,7 @@ pub fn main() !void { |
| 221 | 219 | }, |
| 222 | 220 | }; |
| 223 | 221 | |
| 224 | const dest_target = if (libc_target.dest) |dest| dest else try std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ | |
| 222 | const dest_target = if (libc_target.dest) |dest| dest else try std.fmt.allocPrint(arena, "{s}-{s}-{s}", .{ | |
| 225 | 223 | @tagName(libc_target.arch), |
| 226 | 224 | switch (vendor) { |
| 227 | 225 | .musl, .glibc => "linux", |
| ... | ... | @@ -239,8 +237,8 @@ pub fn main() !void { |
| 239 | 237 | => &[_][]const u8{ search_path, libc_dir, "usr", "include" }, |
| 240 | 238 | .musl => &[_][]const u8{ search_path, libc_dir, "usr", "local", "musl", "include" }, |
| 241 | 239 | }; |
| 242 | const target_include_dir = try Dir.path.join(allocator, sub_path); | |
| 243 | var dir_stack = std.array_list.Managed([]const u8).init(allocator); | |
| 240 | const target_include_dir = try Dir.path.join(arena, sub_path); | |
| 241 | var dir_stack = std.array_list.Managed([]const u8).init(arena); | |
| 244 | 242 | try dir_stack.append(target_include_dir); |
| 245 | 243 | |
| 246 | 244 | while (dir_stack.pop()) |full_dir_name| { |
| ... | ... | @@ -254,16 +252,16 @@ pub fn main() !void { |
| 254 | 252 | var dir_it = dir.iterate(); |
| 255 | 253 | |
| 256 | 254 | while (try dir_it.next(io)) |entry| { |
| 257 | const full_path = try Dir.path.join(allocator, &[_][]const u8{ full_dir_name, entry.name }); | |
| 255 | const full_path = try Dir.path.join(arena, &[_][]const u8{ full_dir_name, entry.name }); | |
| 258 | 256 | switch (entry.kind) { |
| 259 | 257 | .directory => try dir_stack.append(full_path), |
| 260 | 258 | .file, .sym_link => { |
| 261 | const rel_path = try Dir.path.relative(allocator, target_include_dir, full_path); | |
| 259 | const rel_path = try Dir.path.relative(arena, cwd_path, env_map, target_include_dir, full_path); | |
| 262 | 260 | const max_size = 2 * 1024 * 1024 * 1024; |
| 263 | const raw_bytes = try Dir.cwd().readFileAlloc(io, full_path, allocator, .limited(max_size)); | |
| 261 | const raw_bytes = try Dir.cwd().readFileAlloc(io, full_path, arena, .limited(max_size)); | |
| 264 | 262 | const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t"); |
| 265 | 263 | total_bytes += raw_bytes.len; |
| 266 | const hash = try allocator.alloc(u8, 32); | |
| 264 | const hash = try arena.alloc(u8, 32); | |
| 267 | 265 | hasher = Blake3.init(.{}); |
| 268 | 266 | hasher.update(rel_path); |
| 269 | 267 | hasher.update(trimmed); |
| ... | ... | @@ -285,8 +283,8 @@ pub fn main() !void { |
| 285 | 283 | } |
| 286 | 284 | const path_gop = try path_table.getOrPut(rel_path); |
| 287 | 285 | const target_to_hash = if (path_gop.found_existing) path_gop.value_ptr.* else blk: { |
| 288 | const ptr = try allocator.create(TargetToHash); | |
| 289 | ptr.* = TargetToHash.init(allocator); | |
| 286 | const ptr = try arena.create(TargetToHash); | |
| 287 | ptr.* = TargetToHash.init(arena); | |
| 290 | 288 | path_gop.value_ptr.* = ptr; |
| 291 | 289 | break :blk ptr; |
| 292 | 290 | }; |
| ... | ... | @@ -327,7 +325,7 @@ pub fn main() !void { |
| 327 | 325 | // gets their header in a separate arch directory. |
| 328 | 326 | var path_it = path_table.iterator(); |
| 329 | 327 | while (path_it.next()) |path_kv| { |
| 330 | var contents_list = std.array_list.Managed(*Contents).init(allocator); | |
| 328 | var contents_list = std.array_list.Managed(*Contents).init(arena); | |
| 331 | 329 | { |
| 332 | 330 | var hash_it = path_kv.value_ptr.*.iterator(); |
| 333 | 331 | while (hash_it.next()) |hash_kv| { |
| ... | ... | @@ -339,7 +337,7 @@ pub fn main() !void { |
| 339 | 337 | const best_contents = contents_list.pop().?; |
| 340 | 338 | if (best_contents.hit_count > 1) { |
| 341 | 339 | // worth it to make it generic |
| 342 | const full_path = try Dir.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); | |
| 340 | const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); | |
| 343 | 341 | try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?); |
| 344 | 342 | try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = best_contents.bytes }); |
| 345 | 343 | best_contents.is_generic = true; |
| ... | ... | @@ -360,7 +358,7 @@ pub fn main() !void { |
| 360 | 358 | if (contents.is_generic) continue; |
| 361 | 359 | |
| 362 | 360 | const dest_target = hash_kv.key_ptr.*; |
| 363 | const full_path = try Dir.path.join(allocator, &[_][]const u8{ out_dir, dest_target, path_kv.key_ptr.* }); | |
| 361 | const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, dest_target, path_kv.key_ptr.* }); | |
| 364 | 362 | try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?); |
| 365 | 363 | try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = contents.bytes }); |
| 366 | 364 | } |