diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 6cbb820d96229d11f555d506317c54df170fe574..70ef8d0e2088682fa9e5049422ea13860c30e717 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -945,7 +945,7 @@ pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run { /// * `addSystemCommand` /// * `addRunArtifact` pub fn addRunFile(b: *Build, executable: LazyPath) *Step.Run { - const run_step = Step.Run.create(b, b.fmt("run {f}", .{executable.fmt(b.graph)})); + const run_step = Step.Run.create(b, b.fmt("run {f}", .{executable})); run_step.addFileArg(executable); return run_step; } diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index fc08080a976063388f90be8503d1df66f7d7cea1..f6d158be55e4d90551744979852f33375d6c913c 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -982,6 +982,7 @@ pub const Manifest = struct { .stat = undefined, .bin_digest = undefined, .contents = null, + .handle = null, }; self.files.lockPointers(); diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig index 91855a065279fb8ee9d9955878431635c683f4e1..f946227eb632d59cd0025efab4a98507c62de487 100644 --- a/lib/std/Build/Cache/Path.zig +++ b/lib/std/Build/Cache/Path.zig @@ -2,7 +2,6 @@ const Path = @This(); const std = @import("../../std.zig"); const Io = std.Io; -const fs = std.fs; const assert = std.debug.assert; const Allocator = std.mem.Allocator; const Cache = std.Build.Cache; @@ -33,13 +32,13 @@ pub fn join(p: Path, arena: Allocator, sub_path: []const u8) Allocator.Error!Pat if (p.sub_path.len == 0) &.{sub_path} else &.{ p.sub_path, sub_path }; return .{ .root_dir = p.root_dir, - .sub_path = try fs.path.join(arena, parts), + .sub_path = try Io.Dir.path.join(arena, parts), }; } pub fn resolvePosix(p: Path, arena: Allocator, sub_path: []const u8) Allocator.Error!Path { if (sub_path.len == 0) return p; - const new_sub_path = try fs.path.resolvePosix(arena, &.{ p.sub_path, sub_path }); + const new_sub_path = try Io.Dir.path.resolvePosix(arena, &.{ p.sub_path, sub_path }); return .{ .root_dir = p.root_dir, // Use "" instead of "." to represent `root_dir` itself. @@ -60,9 +59,9 @@ pub fn joinStringZ(p: Path, gpa: Allocator, sub_path: []const u8) Allocator.Erro } pub fn openFile(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.OpenFileOptions) !Io.File { - var buf: [fs.max_path_bytes]u8 = undefined; + var buf: [Io.Dir.max_path_bytes]u8 = undefined; const joined_path = if (p.sub_path.len == 0) sub_path else p: { - break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ + break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ p.sub_path, sub_path, }) catch return error.NameTooLong; }; @@ -75,19 +74,19 @@ pub fn openDir( sub_path: []const u8, args: Io.Dir.OpenOptions, ) Io.Dir.OpenError!Io.Dir { - var buf: [fs.max_path_bytes]u8 = undefined; + var buf: [Io.Dir.max_path_bytes]u8 = undefined; const joined_path = if (p.sub_path.len == 0) sub_path else p: { - break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ + break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ p.sub_path, sub_path, }) catch return error.NameTooLong; }; return p.root_dir.handle.openDir(io, joined_path, args); } -pub fn createDirPathOpen(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.OpenOptions) !Io.Dir { - var buf: [fs.max_path_bytes]u8 = undefined; +pub fn createDirPathOpen(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.CreateDirPathOpenOptions) !Io.Dir { + var buf: [Io.Dir.max_path_bytes]u8 = undefined; const joined_path = if (p.sub_path.len == 0) sub_path else p: { - break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ + break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ p.sub_path, sub_path, }) catch return error.NameTooLong; }; @@ -95,9 +94,9 @@ pub fn createDirPathOpen(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.Ope } pub fn statFile(p: Path, io: Io, sub_path: []const u8) !Io.Dir.Stat { - var buf: [fs.max_path_bytes]u8 = undefined; + var buf: [Io.Dir.max_path_bytes]u8 = undefined; const joined_path = if (p.sub_path.len == 0) sub_path else p: { - break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ + break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ p.sub_path, sub_path, }) catch return error.NameTooLong; }; @@ -108,21 +107,21 @@ pub fn atomicFile( p: Path, io: Io, sub_path: []const u8, - options: Io.Dir.AtomicFileOptions, - buf: *[fs.max_path_bytes]u8, -) !fs.AtomicFile { + options: Io.Dir.CreateFileAtomicOptions, + buf: *[Io.Dir.max_path_bytes]u8, +) !Io.File.Atomic { const joined_path = if (p.sub_path.len == 0) sub_path else p: { - break :p std.fmt.bufPrint(buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ + break :p std.fmt.bufPrint(buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ p.sub_path, sub_path, }) catch return error.NameTooLong; }; - return p.root_dir.handle.atomicFile(io, joined_path, options); + return p.root_dir.handle.createFileAtomic(io, joined_path, options); } pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void { - var buf: [fs.max_path_bytes]u8 = undefined; + var buf: [Io.Dir.max_path_bytes]u8 = undefined; const joined_path = if (p.sub_path.len == 0) sub_path else p: { - break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ + break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ p.sub_path, sub_path, }) catch return error.NameTooLong; }; @@ -130,9 +129,9 @@ pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions } pub fn createDirPath(p: Path, io: Io, sub_path: []const u8) !void { - var buf: [fs.max_path_bytes]u8 = undefined; + var buf: [Io.Dir.max_path_bytes]u8 = undefined; const joined_path = if (p.sub_path.len == 0) sub_path else p: { - break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ + break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ p.sub_path, sub_path, }) catch return error.NameTooLong; }; @@ -154,7 +153,7 @@ pub fn fmtEscapeString(path: Path) std.fmt.Alt(Path, formatEscapeString) { pub fn formatEscapeString(path: Path, writer: *Io.Writer) Io.Writer.Error!void { if (path.root_dir.path) |p| { try std.zig.stringEscape(p, writer); - if (path.sub_path.len > 0) try std.zig.stringEscape(fs.path.sep_str, writer); + if (path.sub_path.len > 0) try std.zig.stringEscape(Io.Dir.path.sep_str, writer); } if (path.sub_path.len > 0) { try std.zig.stringEscape(path.sub_path, writer); @@ -170,7 +169,7 @@ pub fn fmtEscapeChar(path: Path) std.fmt.Alt(Path, formatEscapeChar) { pub fn formatEscapeChar(path: Path, writer: *Io.Writer) Io.Writer.Error!void { if (path.root_dir.path) |p| { for (p) |byte| try std.zig.charEscape(byte, writer); - if (path.sub_path.len > 0) try writer.writeByte(fs.path.sep); + if (path.sub_path.len > 0) try writer.writeByte(Io.Dir.path.sep); } if (path.sub_path.len > 0) { for (path.sub_path) |byte| try std.zig.charEscape(byte, writer); @@ -178,14 +177,14 @@ pub fn formatEscapeChar(path: Path, writer: *Io.Writer) Io.Writer.Error!void { } pub fn format(self: Path, writer: *Io.Writer) Io.Writer.Error!void { - if (fs.path.isAbsolute(self.sub_path)) { + if (Io.Dir.path.isAbsolute(self.sub_path)) { try writer.writeAll(self.sub_path); return; } if (self.root_dir.path) |p| { try writer.writeAll(p); if (self.sub_path.len > 0) { - try writer.writeAll(fs.path.sep_str); + try writer.writeAll(Io.Dir.path.sep_str); try writer.writeAll(self.sub_path); } return; @@ -210,18 +209,18 @@ pub fn subPathOrDot(self: Path) []const u8 { } pub fn stem(p: Path) []const u8 { - return fs.path.stem(p.sub_path); + return Io.Dir.path.stem(p.sub_path); } pub fn dirname(p: Path) ?Path { return .{ .root_dir = p.root_dir, - .sub_path = fs.path.dirname(p.subPathOpt() orelse return null) orelse "", + .sub_path = Io.Dir.path.dirname(p.subPathOpt() orelse return null) orelse "", }; } pub fn basename(p: Path) []const u8 { - return fs.path.basename(p.sub_path); + return Io.Dir.path.basename(p.sub_path); } /// Useful to make `Path` a key in `std.ArrayHashMap`. diff --git a/lib/std/Build/Configuration.zig b/lib/std/Build/Configuration.zig index 26fb7b68e43e358b8cb3bc2991148b8cda4441fc..5f4887cbe08547f60ac8271b557567a88900298f 100644 --- a/lib/std/Build/Configuration.zig +++ b/lib/std/Build/Configuration.zig @@ -2219,14 +2219,6 @@ pub const TargetQuery = struct { windows: std.Target.Os.WindowsVersion, default: void, - pub fn init(x: ?std.Target.Query.OsVersion) @This() { - return switch (x orelse return .default) { - .none => .none, - .semver => .semver, - .windows => .windows, - }; - } - pub fn unwrap(this: @This(), c: *const Configuration) ?std.Target.Query.OsVersion { return switch (this) { .none => .none, diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index f61a55d9214ed096c793e29866cf96bfafab9057..5de789c8b2a7b762601c73a2b16a1598338e37c4 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -573,7 +573,7 @@ pub fn setVersionScript(compile: *Compile, source: LazyPath) void { pub fn forceUndefinedSymbol(compile: *Compile, symbol_name: []const u8) void { const graph = compile.step.owner.graph; - const arena = graph.allocator; + const arena = graph.arena; compile.force_undefined_symbols.put(arena, graph.dupeString(symbol_name), {}) catch @panic("OOM"); } @@ -710,12 +710,6 @@ pub fn getEmittedPdb(compile: *Compile) LazyPath { return compile.getEmittedFileGeneric(&compile.generated_pdb); } -/// Returns the generated compiler_rt dynamic library. -/// This is a hack for stage2_x86_64 + coff. -pub fn getEmittedCompilerRtDynLib(compile: *Compile) ?LazyPath { - return compile.getEmittedFileGeneric(&compile.generated_compiler_rt_dyn_lib); -} - /// Returns the path to the generated documentation directory. pub fn getEmittedDocs(compile: *Compile) LazyPath { return compile.getEmittedFileGeneric(&compile.generated_docs); @@ -740,7 +734,7 @@ pub fn setExecCmd(compile: *Compile, args: []const ?[]const u8) void { const graph = compile.step.owner.graph; const arena = graph.arena; assert(compile.kind == .@"test"); - const duped_args = arena.alloc(?[]u8, args.len) catch @panic("OOM"); + const duped_args = arena.alloc(?[]const u8, args.len) catch @panic("OOM"); for (args, 0..) |arg, i| { duped_args[i] = if (arg) |a| graph.dupeString(a) else null; } diff --git a/lib/std/Build/Step/ObjCopy.zig b/lib/std/Build/Step/ObjCopy.zig index e02974b5701cdf49865ad8b178b0f2c5b3e50440..026fa5de3756f80f24dff173d528e36819b000dd 100644 --- a/lib/std/Build/Step/ObjCopy.zig +++ b/lib/std/Build/Step/ObjCopy.zig @@ -89,7 +89,7 @@ pub const UpdateSectionOptions = struct { }; pub fn updateSection(oc: *ObjCopy, section_name: []const u8, options: UpdateSectionOptions) void { - const graph = oc.owner.graph; + const graph = oc.step.owner.graph; const arena = graph.arena; const wc = &graph.wip_configuration; oc.update_sections.append(arena, .{ @@ -106,7 +106,7 @@ pub const AddSectionOptions = struct { }; pub fn addSection(oc: *ObjCopy, section_name: []const u8, options: AddSectionOptions) void { - const graph = oc.owner.graph; + const graph = oc.step.owner.graph; const arena = graph.arena; const wc = &graph.wip_configuration; oc.add_sections.append(arena, .{ diff --git a/lib/std/Build/Step/Options.zig b/lib/std/Build/Step/Options.zig index e78baff95f83862c85b175b7fe1a10328fcd4b2b..c8a490cfaee72ec5a20ac76115d3bf1b6e116ae9 100644 --- a/lib/std/Build/Step/Options.zig +++ b/lib/std/Build/Step/Options.zig @@ -421,8 +421,8 @@ pub fn addOptionPath(options: *Options, name: []const u8, path: LazyPath) void { const wc = &graph.wip_configuration; options.args.append(arena, .{ - .name = try wc.addString(name), - .path = path.dupe(options.step.owner), + .name = wc.addString(name) catch @panic("OOM"), + .path = path.dupe(options.step.owner.graph), }) catch @panic("OOM"); path.addStepDependencies(&options.step); } diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index 00b80ed5900425c40616b2afa783786ff7e753dc..4ace7803225ea6e14caf26bf6769bf4a061567a0 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -556,39 +556,6 @@ pub fn clearEnvironment(run: *Run) void { run.environ_map = new_env_map; } -pub fn addPathDir(run: *Run, search_path: []const u8) void { - const b = run.step.owner; - const environ_map = getEnvMapInternal(run); - - const use_wine = b.enable_wine and b.graph.host.result.os.tag != .windows and use_wine: switch (run.argv.items[0]) { - .artifact => |p| p.artifact.rootModuleTarget().os.tag == .windows, - .lazy_path => |p| { - switch (p.lazy_path) { - .generated => |g| if (g.file.step.cast(Step.Compile)) |cs| break :use_wine cs.rootModuleTarget().os.tag == .windows, - else => {}, - } - break :use_wine std.mem.endsWith(u8, p.lazy_path.basename(b, &run.step), ".exe"); - }, - .decorated_directory => false, - .file_content => unreachable, // not allowed as first arg - .bytes => |bytes| std.mem.endsWith(u8, bytes, ".exe"), - .output_file, .output_file_dep, .output_directory => false, - }; - const key = if (use_wine) "WINEPATH" else "PATH"; - const prev_path = environ_map.get(key); - - if (prev_path) |pp| { - const new_path = b.fmt("{s}{c}{s}", .{ - pp, - if (use_wine) Dir.path.delimiter_windows else Dir.path.delimiter, - search_path, - }); - environ_map.put(key, new_path) catch @panic("OOM"); - } else { - environ_map.put(key, b.dupePath(search_path)) catch @panic("OOM"); - } -} - pub fn getEnvMap(run: *Run) *EnvMap { return getEnvMapInternal(run); }