| author | |
| committer | |
| log | e3424332d3fa1264e1f6861b76bb0d1b2996728d |
| tree | 2d786805328dd51b8d8e804ab6b655fc398d2f3f |
| parent | d582575aba5264aaa02a8af0cdb7da7c4f4c6220 |
* `doc/langref` formatting
* upgrade `.{ .path = "..." }` to `b.path("...")`
* avoid using arguments named `self`
* make `Build.Step.Id` usage more consistent
* add `Build.pathResolve`
* use `pathJoin` and `pathResolve` everywhere
* make sure `Build.LazyPath.getPath2` returns an absolute path59 files changed, 1306 insertions(+), 1311 deletions(-)
doc/langref/Assembly Syntax Explained.zig	+36-36| ... | @@ -15,44 +15,44 @@ pub fn syscall1(number: usize, arg1: usize) usize { | ... | @@ -15,44 +15,44 @@ pub fn syscall1(number: usize, arg1: usize) usize { |
| 15 | // the below code, this is not used. A literal `%` can be | 15 | // the below code, this is not used. A literal `%` can be |
| 16 | // obtained by escaping it with a double percent: `%%`. | 16 | // obtained by escaping it with a double percent: `%%`. |
| 17 | // Often multiline string syntax comes in handy here. | 17 | // Often multiline string syntax comes in handy here. |
| 18 | \\syscall | 18 | \\syscall |
| 19 | // Next is the output. It is possible in the future Zig will | 19 | // Next is the output. It is possible in the future Zig will |
| 20 | // support multiple outputs, depending on how | 20 | // support multiple outputs, depending on how |
| 21 | // https://github.com/ziglang/zig/issues/215 is resolved. | 21 | // https://github.com/ziglang/zig/issues/215 is resolved. |
| 22 | // It is allowed for there to be no outputs, in which case | 22 | // It is allowed for there to be no outputs, in which case |
| 23 | // this colon would be directly followed by the colon for the inputs. | 23 | // this colon would be directly followed by the colon for the inputs. |
| 24 | : | 24 | : |
| 25 | // This specifies the name to be used in `%[ret]` syntax in | 25 | // This specifies the name to be used in `%[ret]` syntax in |
| 26 | // the above assembly string. This example does not use it, | 26 | // the above assembly string. This example does not use it, |
| 27 | // but the syntax is mandatory. | 27 | // but the syntax is mandatory. |
| 28 | [ret] | 28 | [ret] |
| 29 | // Next is the output constraint string. This feature is still | 29 | // Next is the output constraint string. This feature is still |
| 30 | // considered unstable in Zig, and so LLVM/GCC documentation | 30 | // considered unstable in Zig, and so LLVM/GCC documentation |
| 31 | // must be used to understand the semantics. | 31 | // must be used to understand the semantics. |
| 32 | // http://releases.llvm.org/10.0.0/docs/LangRef.html#inline-asm-constraint-string | 32 | // http://releases.llvm.org/10.0.0/docs/LangRef.html#inline-asm-constraint-string |
| 33 | // https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html | 33 | // https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html |
| 34 | // In this example, the constraint string means "the result value of | 34 | // In this example, the constraint string means "the result value of |
| 35 | // this inline assembly instruction is whatever is in $rax". | 35 | // this inline assembly instruction is whatever is in $rax". |
| 36 | "={rax}" | 36 | "={rax}" |
| 37 | // Next is either a value binding, or `->` and then a type. The | 37 | // Next is either a value binding, or `->` and then a type. The |
| 38 | // type is the result type of the inline assembly expression. | 38 | // type is the result type of the inline assembly expression. |
| 39 | // If it is a value binding, then `%[ret]` syntax would be used | 39 | // If it is a value binding, then `%[ret]` syntax would be used |
| 40 | // to refer to the register bound to the value. | 40 | // to refer to the register bound to the value. |
| 41 | (-> usize), | 41 | (-> usize), |
| 42 | // Next is the list of inputs. | 42 | // Next is the list of inputs. |
| 43 | // The constraint for these inputs means, "when the assembly code is | 43 | // The constraint for these inputs means, "when the assembly code is |
| 44 | // executed, $rax shall have the value of `number` and $rdi shall have | 44 | // executed, $rax shall have the value of `number` and $rdi shall have |
| 45 | // the value of `arg1`". Any number of input parameters is allowed, | 45 | // the value of `arg1`". Any number of input parameters is allowed, |
| 46 | // including none. | 46 | // including none. |
| 47 | : [number] "{rax}" (number), | 47 | : [number] "{rax}" (number), |
| 48 | [arg1] "{rdi}" (arg1), | 48 | [arg1] "{rdi}" (arg1), |
| 49 | // Next is the list of clobbers. These declare a set of registers whose | 49 | // Next is the list of clobbers. These declare a set of registers whose |
| 50 | // values will not be preserved by the execution of this assembly code. | 50 | // values will not be preserved by the execution of this assembly code. |
| 51 | // These do not include output or input registers. The special clobber | 51 | // These do not include output or input registers. The special clobber |
| 52 | // value of "memory" means that the assembly writes to arbitrary undeclared | 52 | // value of "memory" means that the assembly writes to arbitrary undeclared |
| 53 | // memory locations - not only the memory pointed to by a declared indirect | 53 | // memory locations - not only the memory pointed to by a declared indirect |
| 54 | // output. In this example we list $rcx and $r11 because it is known the | 54 | // output. In this example we list $rcx and $r11 because it is known the |
| 55 | // kernel syscall does not preserve these registers. | 55 | // kernel syscall does not preserve these registers. |
| 56 | : "rcx", "r11" | 56 | : "rcx", "r11" |
| 57 | ); | 57 | ); |
| 58 | } | 58 | } |
doc/langref/build.zig+1-1| ... | @@ -4,7 +4,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -4,7 +4,7 @@ pub fn build(b: *std.Build) void { |
| 4 | const optimize = b.standardOptimizeOption(.{}); | 4 | const optimize = b.standardOptimizeOption(.{}); |
| 5 | const exe = b.addExecutable(.{ | 5 | const exe = b.addExecutable(.{ |
| 6 | .name = "example", | 6 | .name = "example", |
| 7 | .root_source_file = .{ .path = "example.zig" }, | 7 | .root_source_file = b.path("example.zig"), |
| 8 | .optimize = optimize, | 8 | .optimize = optimize, |
| 9 | }); | 9 | }); |
| 10 | b.default_step.dependOn(&exe.step); | 10 | b.default_step.dependOn(&exe.step); |
doc/langref/build_c.zig+2-2| ... | @@ -3,13 +3,13 @@ const std = @import("std"); | ... | @@ -3,13 +3,13 @@ const std = @import("std"); |
| 3 | pub fn build(b: *std.Build) void { | 3 | pub fn build(b: *std.Build) void { |
| 4 | const lib = b.addSharedLibrary(.{ | 4 | const lib = b.addSharedLibrary(.{ |
| 5 | .name = "mathtest", | 5 | .name = "mathtest", |
| 6 | .root_source_file = .{ .path = "mathtest.zig" }, | 6 | .root_source_file = b.path("mathtest.zig"), |
| 7 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, | 7 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, |
| 8 | }); | 8 | }); |
| 9 | const exe = b.addExecutable(.{ | 9 | const exe = b.addExecutable(.{ |
| 10 | .name = "test", | 10 | .name = "test", |
| 11 | }); | 11 | }); |
| 12 | exe.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &.{"-std=c99"} }); | 12 | exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} }); |
| 13 | exe.linkLibrary(lib); | 13 | exe.linkLibrary(lib); |
| 14 | exe.linkSystemLibrary("c"); | 14 | exe.linkSystemLibrary("c"); |
| 15 | 15 |
doc/langref/build_object.zig+2-2| ... | @@ -3,13 +3,13 @@ const std = @import("std"); | ... | @@ -3,13 +3,13 @@ const std = @import("std"); |
| 3 | pub fn build(b: *std.Build) void { | 3 | pub fn build(b: *std.Build) void { |
| 4 | const obj = b.addObject(.{ | 4 | const obj = b.addObject(.{ |
| 5 | .name = "base64", | 5 | .name = "base64", |
| 6 | .root_source_file = .{ .path = "base64.zig" }, | 6 | .root_source_file = b.path("base64.zig"), |
| 7 | }); | 7 | }); |
| 8 | 8 | ||
| 9 | const exe = b.addExecutable(.{ | 9 | const exe = b.addExecutable(.{ |
| 10 | .name = "test", | 10 | .name = "test", |
| 11 | }); | 11 | }); |
| 12 | exe.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &.{"-std=c99",} }); | 12 | exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} }); |
| 13 | exe.addObject(obj); | 13 | exe.addObject(obj); |
| 14 | exe.linkSystemLibrary("c"); | 14 | exe.linkSystemLibrary("c"); |
| 15 | b.installArtifact(exe); | 15 | b.installArtifact(exe); |
doc/langref/checking_null_in_zig.zig+5-3| ... | @@ -1,11 +1,13 @@ | ... | @@ -1,11 +1,13 @@ |
| 1 | const Foo = struct{}; | 1 | const Foo = struct {}; |
| 2 | fn doSomethingWithFoo(foo: *Foo) void { _ = foo; } | 2 | fn doSomethingWithFoo(foo: *Foo) void { |
| 3 | _ = foo; | ||
| 4 | } | ||
| 3 | 5 | ||
| 4 | fn doAThing(optional_foo: ?*Foo) void { | 6 | fn doAThing(optional_foo: ?*Foo) void { |
| 5 | // do some stuff | 7 | // do some stuff |
| 6 | 8 | ||
| 7 | if (optional_foo) |foo| { | 9 | if (optional_foo) |foo| { |
| 8 | doSomethingWithFoo(foo); | 10 | doSomethingWithFoo(foo); |
| 9 | } | 11 | } |
| 10 | 12 | ||
| 11 | // do some stuff | 13 | // do some stuff |
doc/langref/doc_comments.zig+1-1| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | /// multiline doc comment). | 2 | /// multiline doc comment). |
| 3 | const Timestamp = struct { | 3 | const Timestamp = struct { |
| 4 | /// The number of seconds since the epoch (this is also a doc comment). | 4 | /// The number of seconds since the epoch (this is also a doc comment). |
| 5 | seconds: i64, // signed so we can represent pre-1970 (not a doc comment) | 5 | seconds: i64, // signed so we can represent pre-1970 (not a doc comment) |
| 6 | /// The number of nanoseconds past the second (doc comment again). | 6 | /// The number of nanoseconds past the second (doc comment again). |
| 7 | nanos: u32, | 7 | nanos: u32, |
| 8 | 8 |
doc/langref/enum_export.zig+3-1| ... | @@ -1,4 +1,6 @@ | ... | @@ -1,4 +1,6 @@ |
| 1 | const Foo = enum(c_int) { a, b, c }; | 1 | const Foo = enum(c_int) { a, b, c }; |
| 2 | export fn entry(foo: Foo) void { _ = foo; } | 2 | export fn entry(foo: Foo) void { |
| 3 | _ = foo; | ||
| 4 | } | ||
| 3 | 5 | ||
| 4 | // obj | 6 | // obj |
doc/langref/enum_export_error.zig+3-1| ... | @@ -1,4 +1,6 @@ | ... | @@ -1,4 +1,6 @@ |
| 1 | const Foo = enum { a, b, c }; | 1 | const Foo = enum { a, b, c }; |
| 2 | export fn entry(foo: Foo) void { _ = foo; } | 2 | export fn entry(foo: Foo) void { |
| 3 | _ = foo; | ||
| 4 | } | ||
| 3 | 5 | ||
| 4 | // obj=parameter of type 'enum_export_error.Foo' not allowed in function with calling convention 'C' | 6 | // obj=parameter of type 'enum_export_error.Foo' not allowed in function with calling convention 'C' |
doc/langref/error_union_parsing_u64.zig+3-3| ... | @@ -26,9 +26,9 @@ pub fn parseU64(buf: []const u8, radix: u8) !u64 { | ... | @@ -26,9 +26,9 @@ pub fn parseU64(buf: []const u8, radix: u8) !u64 { |
| 26 | 26 | ||
| 27 | fn charToDigit(c: u8) u8 { | 27 | fn charToDigit(c: u8) u8 { |
| 28 | return switch (c) { | 28 | return switch (c) { |
| 29 | '0' ... '9' => c - '0', | 29 | '0'...'9' => c - '0', |
| 30 | 'A' ... 'Z' => c - 'A' + 10, | 30 | 'A'...'Z' => c - 'A' + 10, |
| 31 | 'a' ... 'z' => c - 'a' + 10, | 31 | 'a'...'z' => c - 'a' + 10, |
| 32 | else => maxInt(u8), | 32 | else => maxInt(u8), |
| 33 | }; | 33 | }; |
| 34 | } | 34 | } |
doc/langref/identifiers.zig+2-2| ... | @@ -6,8 +6,8 @@ pub extern "c" fn @"error"() void; | ... | @@ -6,8 +6,8 @@ pub extern "c" fn @"error"() void; |
| 6 | pub extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int; | 6 | pub extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int; |
| 7 | 7 | ||
| 8 | const Color = enum { | 8 | const Color = enum { |
| 9 | red, | 9 | red, |
| 10 | @"really red", | 10 | @"really red", |
| 11 | }; | 11 | }; |
| 12 | const color: Color = .@"really red"; | 12 | const color: Color = .@"really red"; |
| 13 | 13 |
doc/langref/print.zig+1-1| ... | @@ -4,7 +4,7 @@ const a_number: i32 = 1234; | ... | @@ -4,7 +4,7 @@ const a_number: i32 = 1234; |
| 4 | const a_string = "foobar"; | 4 | const a_string = "foobar"; |
| 5 | 5 | ||
| 6 | pub fn main() void { | 6 | pub fn main() void { |
| 7 | print("here is a string: '{s}' here is a number: {}\n", .{a_string, a_number}); | 7 | print("here is a string: '{s}' here is a number: {}\n", .{ a_string, a_number }); |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | // exe=succeed | 10 | // exe=succeed |
doc/langref/print_comptime-known_format.zig+1-1| ... | @@ -5,7 +5,7 @@ const a_string = "foobar"; | ... | @@ -5,7 +5,7 @@ const a_string = "foobar"; |
| 5 | const fmt = "here is a string: '{s}' here is a number: {}\n"; | 5 | const fmt = "here is a string: '{s}' here is a number: {}\n"; |
| 6 | 6 | ||
| 7 | pub fn main() void { | 7 | pub fn main() void { |
| 8 | print(fmt, .{a_string, a_number}); | 8 | print(fmt, .{ a_string, a_number }); |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | // exe=succeed | 11 | // exe=succeed |
doc/langref/single_value_error_set.zig+1-1| ... | @@ -1,3 +1,3 @@ | ... | @@ -1,3 +1,3 @@ |
| 1 | const err = (error {FileNotFound}).FileNotFound; | 1 | const err = (error{FileNotFound}).FileNotFound; |
| 2 | 2 | ||
| 3 | // syntax | 3 | // syntax |
doc/langref/string_literals.zig+10-10| ... | @@ -3,19 +3,19 @@ const mem = @import("std").mem; // will be used to compare bytes | ... | @@ -3,19 +3,19 @@ const mem = @import("std").mem; // will be used to compare bytes |
| 3 | 3 | ||
| 4 | pub fn main() void { | 4 | pub fn main() void { |
| 5 | const bytes = "hello"; | 5 | const bytes = "hello"; |
| 6 | print("{}\n", .{@TypeOf(bytes)}); // *const [5:0]u8 | 6 | print("{}\n", .{@TypeOf(bytes)}); // *const [5:0]u8 |
| 7 | print("{d}\n", .{bytes.len}); // 5 | 7 | print("{d}\n", .{bytes.len}); // 5 |
| 8 | print("{c}\n", .{bytes[1]}); // 'e' | 8 | print("{c}\n", .{bytes[1]}); // 'e' |
| 9 | print("{d}\n", .{bytes[5]}); // 0 | 9 | print("{d}\n", .{bytes[5]}); // 0 |
| 10 | print("{}\n", .{'e' == '\x65'}); // true | 10 | print("{}\n", .{'e' == '\x65'}); // true |
| 11 | print("{d}\n", .{'\u{1f4a9}'}); // 128169 | 11 | print("{d}\n", .{'\u{1f4a9}'}); // 128169 |
| 12 | print("{d}\n", .{'💯'}); // 128175 | 12 | print("{d}\n", .{'💯'}); // 128175 |
| 13 | print("{u}\n", .{'âš¡'}); | 13 | print("{u}\n", .{'âš¡'}); |
| 14 | print("{}\n", .{mem.eql(u8, "hello", "h\x65llo")}); // true | 14 | print("{}\n", .{mem.eql(u8, "hello", "h\x65llo")}); // true |
| 15 | print("{}\n", .{mem.eql(u8, "💯", "\xf0\x9f\x92\xaf")}); // also true | 15 | print("{}\n", .{mem.eql(u8, "💯", "\xf0\x9f\x92\xaf")}); // also true |
| 16 | const invalid_utf8 = "\xff\xfe"; // non-UTF-8 strings are possible with \xNN notation. | 16 | const invalid_utf8 = "\xff\xfe"; // non-UTF-8 strings are possible with \xNN notation. |
| 17 | print("0x{x}\n", .{invalid_utf8[1]}); // indexing them returns individual bytes... | 17 | print("0x{x}\n", .{invalid_utf8[1]}); // indexing them returns individual bytes... |
| 18 | print("0x{x}\n", .{"💯"[1]}); // ...as does indexing part-way through non-ASCII characters | 18 | print("0x{x}\n", .{"💯"[1]}); // ...as does indexing part-way through non-ASCII characters |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | // exe=succeed | 21 | // exe=succeed |
doc/langref/test_call_builtin.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const expect = @import("std").testing.expect; | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | ||
| 3 | test "noinline function call" { | 3 | test "noinline function call" { |
| 4 | try expect(@call(.auto, add, .{3, 9}) == 12); | 4 | try expect(@call(.auto, add, .{ 3, 9 }) == 12); |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | fn add(a: i32, b: i32) i32 { | 7 | fn add(a: i32, b: i32) i32 { |
doc/langref/test_coerce_error_subset_to_superset.zig+2-2| ... | @@ -1,12 +1,12 @@ | ... | @@ -1,12 +1,12 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | const FileOpenError = error { | 3 | const FileOpenError = error{ |
| 4 | AccessDenied, | 4 | AccessDenied, |
| 5 | OutOfMemory, | 5 | OutOfMemory, |
| 6 | FileNotFound, | 6 | FileNotFound, |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | const AllocationError = error { | 9 | const AllocationError = error{ |
| 10 | OutOfMemory, | 10 | OutOfMemory, |
| 11 | }; | 11 | }; |
| 12 | 12 |
doc/langref/test_coerce_error_superset_to_subset.zig+2-2| ... | @@ -1,10 +1,10 @@ | ... | @@ -1,10 +1,10 @@ |
| 1 | const FileOpenError = error { | 1 | const FileOpenError = error{ |
| 2 | AccessDenied, | 2 | AccessDenied, |
| 3 | OutOfMemory, | 3 | OutOfMemory, |
| 4 | FileNotFound, | 4 | FileNotFound, |
| 5 | }; | 5 | }; |
| 6 | 6 | ||
| 7 | const AllocationError = error { | 7 | const AllocationError = error{ |
| 8 | OutOfMemory, | 8 | OutOfMemory, |
| 9 | }; | 9 | }; |
| 10 | 10 |
doc/langref/test_coerce_tuples_arrays.zig+4-4| ... | @@ -1,11 +1,11 @@ | ... | @@ -1,11 +1,11 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const expect = std.testing.expect; | 2 | const expect = std.testing.expect; |
| 3 | 3 | ||
| 4 | const Tuple = struct{ u8, u8 }; | 4 | const Tuple = struct { u8, u8 }; |
| 5 | test "coercion from homogenous tuple to array" { | 5 | test "coercion from homogenous tuple to array" { |
| 6 | 	const tuple: Tuple = .{5, 6}; | 6 | const tuple: Tuple = .{ 5, 6 }; |
| 7 | 	const array: [2]u8 = tuple; | 7 | const array: [2]u8 = tuple; |
| 8 | 	_ = array; | 8 | _ = array; |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | // test | 11 | // test |
doc/langref/test_comptime_evaluation.zig+13-7| ... | @@ -2,17 +2,23 @@ const expect = @import("std").testing.expect; | ... | @@ -2,17 +2,23 @@ const expect = @import("std").testing.expect; |
| 2 | 2 | ||
| 3 | const CmdFn = struct { | 3 | const CmdFn = struct { |
| 4 | name: []const u8, | 4 | name: []const u8, |
| 5 | func: fn(i32) i32, | 5 | func: fn (i32) i32, |
| 6 | }; | 6 | }; |
| 7 | 7 | ||
| 8 | const cmd_fns = [_]CmdFn{ | 8 | const cmd_fns = [_]CmdFn{ |
| 9 | CmdFn {.name = "one", .func = one}, | 9 | CmdFn{ .name = "one", .func = one }, |
| 10 | CmdFn {.name = "two", .func = two}, | 10 | CmdFn{ .name = "two", .func = two }, |
| 11 | CmdFn {.name = "three", .func = three}, | 11 | CmdFn{ .name = "three", .func = three }, |
| 12 | }; | 12 | }; |
| 13 | fn one(value: i32) i32 { return value + 1; } | 13 | fn one(value: i32) i32 { |
| 14 | fn two(value: i32) i32 { return value + 2; } | 14 | return value + 1; |
| 15 | fn three(value: i32) i32 { return value + 3; } | 15 | } |
| 16 | fn two(value: i32) i32 { | ||
| 17 | return value + 2; | ||
| 18 | } | ||
| 19 | fn three(value: i32) i32 { | ||
| 20 | return value + 3; | ||
| 21 | } | ||
| 16 | 22 | ||
| 17 | fn performFn(comptime prefix_char: u8, start_value: i32) i32 { | 23 | fn performFn(comptime prefix_char: u8, start_value: i32) i32 { |
| 18 | var result: i32 = start_value; | 24 | var result: i32 = start_value; |
doc/langref/test_errdefer_loop.zig+1-3| ... | @@ -1,9 +1,7 @@ | ... | @@ -1,9 +1,7 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const Allocator = std.mem.Allocator; | 2 | const Allocator = std.mem.Allocator; |
| 3 | 3 | ||
| 4 | const Foo = struct { | 4 | const Foo = struct { data: *u32 }; |
| 5 | data: *u32 | ||
| 6 | }; | ||
| 7 | 5 | ||
| 8 | fn getData() !u32 { | 6 | fn getData() !u32 { |
| 9 | return 666; | 7 | return 666; |
doc/langref/test_errdefer_loop_leak.zig+2-4| ... | @@ -1,9 +1,7 @@ | ... | @@ -1,9 +1,7 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const Allocator = std.mem.Allocator; | 2 | const Allocator = std.mem.Allocator; |
| 3 | 3 | ||
| 4 | const Foo = struct { | 4 | const Foo = struct { data: *u32 }; |
| 5 | data: *u32 | ||
| 6 | }; | ||
| 7 | 5 | ||
| 8 | fn getData() !u32 { | 6 | fn getData() !u32 { |
| 9 | return 666; | 7 | return 666; |
| ... | @@ -19,7 +17,7 @@ fn genFoos(allocator: Allocator, num: usize) ![]Foo { | ... | @@ -19,7 +17,7 @@ fn genFoos(allocator: Allocator, num: usize) ![]Foo { |
| 19 | errdefer allocator.destroy(foo.data); | 17 | errdefer allocator.destroy(foo.data); |
| 20 | 18 | ||
| 21 | // The data for the first 3 foos will be leaked | 19 | // The data for the first 3 foos will be leaked |
| 22 | if(i >= 3) return error.TooManyFoos; | 20 | if (i >= 3) return error.TooManyFoos; |
| 23 | 21 | ||
| 24 | foo.data.* = try getData(); | 22 | foo.data.* = try getData(); |
| 25 | } | 23 | } |
doc/langref/test_for.zig+2-2| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const expect = @import("std").testing.expect; | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | ||
| 3 | test "for basics" { | 3 | test "for basics" { |
| 4 | const items = [_]i32 { 4, 5, 3, 4, 0 }; | 4 | const items = [_]i32{ 4, 5, 3, 4, 0 }; |
| 5 | var sum: i32 = 0; | 5 | var sum: i32 = 0; |
| 6 | 6 | ||
| 7 | // For loops iterate over slices and arrays. | 7 | // For loops iterate over slices and arrays. |
| ... | @@ -31,7 +31,7 @@ test "for basics" { | ... | @@ -31,7 +31,7 @@ test "for basics" { |
| 31 | 31 | ||
| 32 | // To iterate over consecutive integers, use the range syntax. | 32 | // To iterate over consecutive integers, use the range syntax. |
| 33 | // Unbounded range is always a compile error. | 33 | // Unbounded range is always a compile error. |
| 34 | var sum3 : usize = 0; | 34 | var sum3: usize = 0; |
| 35 | for (0..5) |i| { | 35 | for (0..5) |i| { |
| 36 | sum3 += i; | 36 | sum3 += i; |
| 37 | } | 37 | } |
doc/langref/test_functions.zig+7-3| ... | @@ -14,7 +14,9 @@ fn add(a: i8, b: i8) i8 { | ... | @@ -14,7 +14,9 @@ fn add(a: i8, b: i8) i8 { |
| 14 | 14 | ||
| 15 | // The export specifier makes a function externally visible in the generated | 15 | // The export specifier makes a function externally visible in the generated |
| 16 | // object file, and makes it use the C ABI. | 16 | // object file, and makes it use the C ABI. |
| 17 | export fn sub(a: i8, b: i8) i8 { return a - b; } | 17 | export fn sub(a: i8, b: i8) i8 { |
| 18 | return a - b; | ||
| 19 | } | ||
| 18 | 20 | ||
| 19 | // The extern specifier is used to declare a function that will be resolved | 21 | // The extern specifier is used to declare a function that will be resolved |
| 20 | // at link time, when linking statically, or at runtime, when linking | 22 | // at link time, when linking statically, or at runtime, when linking |
| ... | @@ -39,13 +41,15 @@ fn _start() callconv(.Naked) noreturn { | ... | @@ -39,13 +41,15 @@ fn _start() callconv(.Naked) noreturn { |
| 39 | 41 | ||
| 40 | // The inline calling convention forces a function to be inlined at all call sites. | 42 | // The inline calling convention forces a function to be inlined at all call sites. |
| 41 | // If the function cannot be inlined, it is a compile-time error. | 43 | // If the function cannot be inlined, it is a compile-time error. |
| 42 | fn shiftLeftOne(a: u32) callconv(.Inline) u32 { | 44 | inline fn shiftLeftOne(a: u32) u32 { |
| 43 | return a << 1; | 45 | return a << 1; |
| 44 | } | 46 | } |
| 45 | 47 | ||
| 46 | // The pub specifier allows the function to be visible when importing. | 48 | // The pub specifier allows the function to be visible when importing. |
| 47 | // Another file can use @import and call sub2 | 49 | // Another file can use @import and call sub2 |
| 48 | pub fn sub2(a: i8, b: i8) i8 { return a - b; } | 50 | pub fn sub2(a: i8, b: i8) i8 { |
| 51 | return a - b; | ||
| 52 | } | ||
| 49 | 53 | ||
| 50 | // Function pointers are prefixed with `*const `. | 54 | // Function pointers are prefixed with `*const `. |
| 51 | const Call2Op = *const fn (a: i8, b: i8) i8; | 55 | const Call2Op = *const fn (a: i8, b: i8) i8; |
doc/langref/test_inferred_error_sets.zig+1-1| ... | @@ -12,7 +12,7 @@ pub fn add_explicit(comptime T: type, a: T, b: T) Error!T { | ... | @@ -12,7 +12,7 @@ pub fn add_explicit(comptime T: type, a: T, b: T) Error!T { |
| 12 | return ov[0]; | 12 | return ov[0]; |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | const Error = error { | 15 | const Error = error{ |
| 16 | Overflow, | 16 | Overflow, |
| 17 | }; | 17 | }; |
| 18 | 18 |
doc/langref/test_inline_for.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const expect = @import("std").testing.expect; | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | ||
| 3 | test "inline for loop" { | 3 | test "inline for loop" { |
| 4 | const nums = [_]i32{2, 4, 6}; | 4 | const nums = [_]i32{ 2, 4, 6 }; |
| 5 | var sum: usize = 0; | 5 | var sum: usize = 0; |
| 6 | inline for (nums) |i| { | 6 | inline for (nums) |i| { |
| 7 | const T = switch (i) { | 7 | const T = switch (i) { |
doc/langref/test_inline_switch_union_tag.zig+1-1| ... | @@ -15,7 +15,7 @@ fn getNum(u: U) u32 { | ... | @@ -15,7 +15,7 @@ fn getNum(u: U) u32 { |
| 15 | return @intFromFloat(num); | 15 | return @intFromFloat(num); |
| 16 | } | 16 | } |
| 17 | return num; | 17 | return num; |
| 18 | } | 18 | }, |
| 19 | } | 19 | } |
| 20 | } | 20 | } |
| 21 | 21 |
doc/langref/test_null_terminated_array.zig+2-2| ... | @@ -2,7 +2,7 @@ const std = @import("std"); | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | const expect = std.testing.expect; | 2 | const expect = std.testing.expect; |
| 3 | 3 | ||
| 4 | test "0-terminated sentinel array" { | 4 | test "0-terminated sentinel array" { |
| 5 | const array = [_:0]u8 {1, 2, 3, 4}; | 5 | const array = [_:0]u8{ 1, 2, 3, 4 }; |
| 6 | 6 | ||
| 7 | try expect(@TypeOf(array) == [4:0]u8); | 7 | try expect(@TypeOf(array) == [4:0]u8); |
| 8 | try expect(array.len == 4); | 8 | try expect(array.len == 4); |
| ... | @@ -11,7 +11,7 @@ test "0-terminated sentinel array" { | ... | @@ -11,7 +11,7 @@ test "0-terminated sentinel array" { |
| 11 | 11 | ||
| 12 | test "extra 0s in 0-terminated sentinel array" { | 12 | test "extra 0s in 0-terminated sentinel array" { |
| 13 | // The sentinel value may appear earlier, but does not influence the compile-time 'len'. | 13 | // The sentinel value may appear earlier, but does not influence the compile-time 'len'. |
| 14 | const array = [_:0]u8 {1, 0, 0, 4}; | 14 | const array = [_:0]u8{ 1, 0, 0, 4 }; |
| 15 | 15 | ||
| 16 | try expect(@TypeOf(array) == [4:0]u8); | 16 | try expect(@TypeOf(array) == [4:0]u8); |
| 17 | try expect(array.len == 4); | 17 | try expect(array.len == 4); |
doc/langref/test_struct_result.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const expect = std.testing.expect; | 2 | const expect = std.testing.expect; |
| 3 | 3 | ||
| 4 | const Point = struct {x: i32, y: i32}; | 4 | const Point = struct { x: i32, y: i32 }; |
| 5 | 5 | ||
| 6 | test "anonymous struct literal" { | 6 | test "anonymous struct literal" { |
| 7 | const pt: Point = .{ | 7 | const pt: Point = .{ |
doc/langref/test_structs.zig+7-8| ... | @@ -13,15 +13,14 @@ const Point2 = packed struct { | ... | @@ -13,15 +13,14 @@ const Point2 = packed struct { |
| 13 | y: f32, | 13 | y: f32, |
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| 16 | |||
| 17 | // Declare an instance of a struct. | 16 | // Declare an instance of a struct. |
| 18 | const p = Point { | 17 | const p = Point{ |
| 19 | .x = 0.12, | 18 | .x = 0.12, |
| 20 | .y = 0.34, | 19 | .y = 0.34, |
| 21 | }; | 20 | }; |
| 22 | 21 | ||
| 23 | // Maybe we're not ready to fill out some of the fields. | 22 | // Maybe we're not ready to fill out some of the fields. |
| 24 | var p2 = Point { | 23 | var p2 = Point{ |
| 25 | .x = 0.12, | 24 | .x = 0.12, |
| 26 | .y = undefined, | 25 | .y = undefined, |
| 27 | }; | 26 | }; |
| ... | @@ -35,7 +34,7 @@ const Vec3 = struct { | ... | @@ -35,7 +34,7 @@ const Vec3 = struct { |
| 35 | z: f32, | 34 | z: f32, |
| 36 | 35 | ||
| 37 | pub fn init(x: f32, y: f32, z: f32) Vec3 { | 36 | pub fn init(x: f32, y: f32, z: f32) Vec3 { |
| 38 | return Vec3 { | 37 | return Vec3{ |
| 39 | .x = x, | 38 | .x = x, |
| 40 | .y = y, | 39 | .y = y, |
| 41 | .z = z, | 40 | .z = z, |
| ... | @@ -69,7 +68,7 @@ test "struct namespaced variable" { | ... | @@ -69,7 +68,7 @@ test "struct namespaced variable" { |
| 69 | try expect(@sizeOf(Empty) == 0); | 68 | try expect(@sizeOf(Empty) == 0); |
| 70 | 69 | ||
| 71 | // you can still instantiate an empty struct | 70 | // you can still instantiate an empty struct |
| 72 | const does_nothing = Empty {}; | 71 | const does_nothing = Empty{}; |
| 73 | 72 | ||
| 74 | _ = does_nothing; | 73 | _ = does_nothing; |
| 75 | } | 74 | } |
| ... | @@ -81,7 +80,7 @@ fn setYBasedOnX(x: *f32, y: f32) void { | ... | @@ -81,7 +80,7 @@ fn setYBasedOnX(x: *f32, y: f32) void { |
| 81 | point.y = y; | 80 | point.y = y; |
| 82 | } | 81 | } |
| 83 | test "field parent pointer" { | 82 | test "field parent pointer" { |
| 84 | var point = Point { | 83 | var point = Point{ |
| 85 | .x = 0.1234, | 84 | .x = 0.1234, |
| 86 | .y = 0.5678, | 85 | .y = 0.5678, |
| 87 | }; | 86 | }; |
| ... | @@ -100,8 +99,8 @@ fn LinkedList(comptime T: type) type { | ... | @@ -100,8 +99,8 @@ fn LinkedList(comptime T: type) type { |
| 100 | }; | 99 | }; |
| 101 | 100 | ||
| 102 | first: ?*Node, | 101 | first: ?*Node, |
| 103 | last: ?*Node, | 102 | last: ?*Node, |
| 104 | len: usize, | 103 | len: usize, |
| 105 | }; | 104 | }; |
| 106 | } | 105 | } |
| 107 | 106 |
doc/langref/test_switch_non-exhaustive.zig+1-2| ... | @@ -12,8 +12,7 @@ test "switch on non-exhaustive enum" { | ... | @@ -12,8 +12,7 @@ test "switch on non-exhaustive enum" { |
| 12 | const number = Number.one; | 12 | const number = Number.one; |
| 13 | const result = switch (number) { | 13 | const result = switch (number) { |
| 14 | .one => true, | 14 | .one => true, |
| 15 | .two, | 15 | .two, .three => false, |
| 16 | .three => false, | ||
| 17 | _ => false, | 16 | _ => false, |
| 18 | }; | 17 | }; |
| 19 | try expect(result); | 18 | try expect(result); |
doc/langref/test_unresolved_comptime_value.zig+1-4| ... | @@ -5,10 +5,7 @@ test "try to pass a runtime type" { | ... | @@ -5,10 +5,7 @@ test "try to pass a runtime type" { |
| 5 | foo(false); | 5 | foo(false); |
| 6 | } | 6 | } |
| 7 | fn foo(condition: bool) void { | 7 | fn foo(condition: bool) void { |
| 8 | const result = max( | 8 | const result = max(if (condition) f32 else u64, 1234, 5678); |
| 9 | if (condition) f32 else u64, | ||
| 10 | 1234, | ||
| 11 | 5678); | ||
| 12 | _ = result; | 9 | _ = result; |
| 13 | } | 10 | } |
| 14 | 11 |
doc/langref/test_while_continue_expression.zig+4-1| ... | @@ -9,7 +9,10 @@ test "while loop continue expression" { | ... | @@ -9,7 +9,10 @@ test "while loop continue expression" { |
| 9 | test "while loop continue expression, more complicated" { | 9 | test "while loop continue expression, more complicated" { |
| 10 | var i: usize = 1; | 10 | var i: usize = 1; |
| 11 | var j: usize = 1; | 11 | var j: usize = 1; |
| 12 | while (i * j < 2000) : ({ i *= 2; j *= 3; }) { | 12 | while (i * j < 2000) : ({ |
| 13 | i *= 2; | ||
| 14 | j *= 3; | ||
| 15 | }) { | ||
| 13 | const my_ij = i * j; | 16 | const my_ij = i * j; |
| 14 | try expect(my_ij < 2000); | 17 | try expect(my_ij < 2000); |
| 15 | } | 18 | } |
doc/langref/values.zig+3-1| ... | @@ -39,7 +39,9 @@ pub fn main() void { | ... | @@ -39,7 +39,9 @@ pub fn main() void { |
| 39 | var number_or_error: anyerror!i32 = error.ArgNotFound; | 39 | var number_or_error: anyerror!i32 = error.ArgNotFound; |
| 40 | 40 | ||
| 41 | print("\nerror union 1\ntype: {}\nvalue: {!}\n", .{ | 41 | print("\nerror union 1\ntype: {}\nvalue: {!}\n", .{ |
| 42 | @TypeOf(number_or_error), number_or_error, }); | 42 | @TypeOf(number_or_error), |
| 43 | number_or_error, | ||
| 44 | }); | ||
| 43 | 45 | ||
| 44 | number_or_error = 1234; | 46 | number_or_error = 1234; |
| 45 | 47 |
lib/std/Build.zig+188-194| ... | @@ -13,8 +13,7 @@ const Allocator = mem.Allocator; | ... | @@ -13,8 +13,7 @@ const Allocator = mem.Allocator; |
| 13 | const Target = std.Target; | 13 | const Target = std.Target; |
| 14 | const process = std.process; | 14 | const process = std.process; |
| 15 | const EnvMap = std.process.EnvMap; | 15 | const EnvMap = std.process.EnvMap; |
| 16 | const fmt_lib = std.fmt; | 16 | const File = fs.File; |
| 17 | const File = std.fs.File; | ||
| 18 | const Sha256 = std.crypto.hash.sha2.Sha256; | 17 | const Sha256 = std.crypto.hash.sha2.Sha256; |
| 19 | const Build = @This(); | 18 | const Build = @This(); |
| 20 | 19 | ||
| ... | @@ -149,15 +148,14 @@ const InitializedDepKey = struct { | ... | @@ -149,15 +148,14 @@ const InitializedDepKey = struct { |
| 149 | const InitializedDepContext = struct { | 148 | const InitializedDepContext = struct { |
| 150 | allocator: Allocator, | 149 | allocator: Allocator, |
| 151 | 150 | ||
| 152 | pub fn hash(self: @This(), k: InitializedDepKey) u64 { | 151 | pub fn hash(ctx: @This(), k: InitializedDepKey) u64 { |
| 153 | var hasher = std.hash.Wyhash.init(0); | 152 | var hasher = std.hash.Wyhash.init(0); |
| 154 | hasher.update(k.build_root_string); | 153 | hasher.update(k.build_root_string); |
| 155 | hashUserInputOptionsMap(self.allocator, k.user_input_options, &hasher); | 154 | hashUserInputOptionsMap(ctx.allocator, k.user_input_options, &hasher); |
| 156 | return hasher.final(); | 155 | return hasher.final(); |
| 157 | } | 156 | } |
| 158 | 157 | ||
| 159 | pub fn eql(self: @This(), lhs: InitializedDepKey, rhs: InitializedDepKey) bool { | 158 | pub fn eql(_: @This(), lhs: InitializedDepKey, rhs: InitializedDepKey) bool { |
| 160 | _ = self; | ||
| 161 | if (!std.mem.eql(u8, lhs.build_root_string, rhs.build_root_string)) | 159 | if (!std.mem.eql(u8, lhs.build_root_string, rhs.build_root_string)) |
| 162 | return false; | 160 | return false; |
| 163 | 161 | ||
| ... | @@ -229,7 +227,7 @@ const TypeId = enum { | ... | @@ -229,7 +227,7 @@ const TypeId = enum { |
| 229 | }; | 227 | }; |
| 230 | 228 | ||
| 231 | const TopLevelStep = struct { | 229 | const TopLevelStep = struct { |
| 232 | pub const base_id = .top_level; | 230 | pub const base_id: Step.Id = .top_level; |
| 233 | 231 | ||
| 234 | step: Step, | 232 | step: Step, |
| 235 | description: []const u8, | 233 | description: []const u8, |
| ... | @@ -251,8 +249,8 @@ pub fn create( | ... | @@ -251,8 +249,8 @@ pub fn create( |
| 251 | const initialized_deps = try arena.create(InitializedDepMap); | 249 | const initialized_deps = try arena.create(InitializedDepMap); |
| 252 | initialized_deps.* = InitializedDepMap.initContext(arena, .{ .allocator = arena }); | 250 | initialized_deps.* = InitializedDepMap.initContext(arena, .{ .allocator = arena }); |
| 253 | 251 | ||
| 254 | const self = try arena.create(Build); | 252 | const b = try arena.create(Build); |
| 255 | self.* = .{ | 253 | b.* = .{ |
| 256 | .graph = graph, | 254 | .graph = graph, |
| 257 | .build_root = build_root, | 255 | .build_root = build_root, |
| 258 | .cache_root = cache_root, | 256 | .cache_root = cache_root, |
| ... | @@ -280,17 +278,17 @@ pub fn create( | ... | @@ -280,17 +278,17 @@ pub fn create( |
| 280 | .installed_files = ArrayList(InstalledFile).init(arena), | 278 | .installed_files = ArrayList(InstalledFile).init(arena), |
| 281 | .install_tls = .{ | 279 | .install_tls = .{ |
| 282 | .step = Step.init(.{ | 280 | .step = Step.init(.{ |
| 283 | .id = .top_level, | 281 | .id = TopLevelStep.base_id, |
| 284 | .name = "install", | 282 | .name = "install", |
| 285 | .owner = self, | 283 | .owner = b, |
| 286 | }), | 284 | }), |
| 287 | .description = "Copy build artifacts to prefix path", | 285 | .description = "Copy build artifacts to prefix path", |
| 288 | }, | 286 | }, |
| 289 | .uninstall_tls = .{ | 287 | .uninstall_tls = .{ |
| 290 | .step = Step.init(.{ | 288 | .step = Step.init(.{ |
| 291 | .id = .top_level, | 289 | .id = TopLevelStep.base_id, |
| 292 | .name = "uninstall", | 290 | .name = "uninstall", |
| 293 | .owner = self, | 291 | .owner = b, |
| 294 | .makeFn = makeUninstall, | 292 | .makeFn = makeUninstall, |
| 295 | }), | 293 | }), |
| 296 | .description = "Remove build artifacts from prefix path", | 294 | .description = "Remove build artifacts from prefix path", |
| ... | @@ -306,10 +304,10 @@ pub fn create( | ... | @@ -306,10 +304,10 @@ pub fn create( |
| 306 | .available_deps = available_deps, | 304 | .available_deps = available_deps, |
| 307 | .release_mode = .off, | 305 | .release_mode = .off, |
| 308 | }; | 306 | }; |
| 309 | try self.top_level_steps.put(arena, self.install_tls.step.name, &self.install_tls); | 307 | try b.top_level_steps.put(arena, b.install_tls.step.name, &b.install_tls); |
| 310 | try self.top_level_steps.put(arena, self.uninstall_tls.step.name, &self.uninstall_tls); | 308 | try b.top_level_steps.put(arena, b.uninstall_tls.step.name, &b.uninstall_tls); |
| 311 | self.default_step = &self.install_tls.step; | 309 | b.default_step = &b.install_tls.step; |
| 312 | return self; | 310 | return b; |
| 313 | } | 311 | } |
| 314 | 312 | ||
| 315 | fn createChild( | 313 | fn createChild( |
| ... | @@ -340,7 +338,7 @@ fn createChildOnly( | ... | @@ -340,7 +338,7 @@ fn createChildOnly( |
| 340 | .allocator = allocator, | 338 | .allocator = allocator, |
| 341 | .install_tls = .{ | 339 | .install_tls = .{ |
| 342 | .step = Step.init(.{ | 340 | .step = Step.init(.{ |
| 343 | .id = .top_level, | 341 | .id = TopLevelStep.base_id, |
| 344 | .name = "install", | 342 | .name = "install", |
| 345 | .owner = child, | 343 | .owner = child, |
| 346 | }), | 344 | }), |
| ... | @@ -348,7 +346,7 @@ fn createChildOnly( | ... | @@ -348,7 +346,7 @@ fn createChildOnly( |
| 348 | }, | 346 | }, |
| 349 | .uninstall_tls = .{ | 347 | .uninstall_tls = .{ |
| 350 | .step = Step.init(.{ | 348 | .step = Step.init(.{ |
| 351 | .id = .top_level, | 349 | .id = TopLevelStep.base_id, |
| 352 | .name = "uninstall", | 350 | .name = "uninstall", |
| 353 | .owner = child, | 351 | .owner = child, |
| 354 | .makeFn = makeUninstall, | 352 | .makeFn = makeUninstall, |
| ... | @@ -498,8 +496,8 @@ const OrderedUserValue = union(enum) { | ... | @@ -498,8 +496,8 @@ const OrderedUserValue = union(enum) { |
| 498 | } | 496 | } |
| 499 | }; | 497 | }; |
| 500 | 498 | ||
| 501 | fn hash(self: OrderedUserValue, hasher: *std.hash.Wyhash) void { | 499 | fn hash(val: OrderedUserValue, hasher: *std.hash.Wyhash) void { |
| 502 | switch (self) { | 500 | switch (val) { |
| 503 | .flag => {}, | 501 | .flag => {}, |
| 504 | .scalar => |scalar| hasher.update(scalar), | 502 | .scalar => |scalar| hasher.update(scalar), |
| 505 | // lists are already ordered | 503 | // lists are already ordered |
| ... | @@ -541,9 +539,9 @@ const OrderedUserInputOption = struct { | ... | @@ -541,9 +539,9 @@ const OrderedUserInputOption = struct { |
| 541 | value: OrderedUserValue, | 539 | value: OrderedUserValue, |
| 542 | used: bool, | 540 | used: bool, |
| 543 | 541 | ||
| 544 | fn hash(self: OrderedUserInputOption, hasher: *std.hash.Wyhash) void { | 542 | fn hash(opt: OrderedUserInputOption, hasher: *std.hash.Wyhash) void { |
| 545 | hasher.update(self.name); | 543 | hasher.update(opt.name); |
| 546 | self.value.hash(hasher); | 544 | opt.value.hash(hasher); |
| 547 | } | 545 | } |
| 548 | 546 | ||
| 549 | fn fromUnordered(allocator: Allocator, user_input_option: UserInputOption) OrderedUserInputOption { | 547 | fn fromUnordered(allocator: Allocator, user_input_option: UserInputOption) OrderedUserInputOption { |
| ... | @@ -593,38 +591,38 @@ fn determineAndApplyInstallPrefix(b: *Build) !void { | ... | @@ -593,38 +591,38 @@ fn determineAndApplyInstallPrefix(b: *Build) !void { |
| 593 | } | 591 | } |
| 594 | 592 | ||
| 595 | /// This function is intended to be called by lib/build_runner.zig, not a build.zig file. | 593 | /// This function is intended to be called by lib/build_runner.zig, not a build.zig file. |
| 596 | pub fn resolveInstallPrefix(self: *Build, install_prefix: ?[]const u8, dir_list: DirList) void { | 594 | pub fn resolveInstallPrefix(b: *Build, install_prefix: ?[]const u8, dir_list: DirList) void { |
| 597 | if (self.dest_dir) |dest_dir| { | 595 | if (b.dest_dir) |dest_dir| { |
| 598 | self.install_prefix = install_prefix orelse "/usr"; | 596 | b.install_prefix = install_prefix orelse "/usr"; |
| 599 | self.install_path = self.pathJoin(&.{ dest_dir, self.install_prefix }); | 597 | b.install_path = b.pathJoin(&.{ dest_dir, b.install_prefix }); |
| 600 | } else { | 598 | } else { |
| 601 | self.install_prefix = install_prefix orelse | 599 | b.install_prefix = install_prefix orelse |
| 602 | (self.build_root.join(self.allocator, &.{"zig-out"}) catch @panic("unhandled error")); | 600 | (b.build_root.join(b.allocator, &.{"zig-out"}) catch @panic("unhandled error")); |
| 603 | self.install_path = self.install_prefix; | 601 | b.install_path = b.install_prefix; |
| 604 | } | 602 | } |
| 605 | 603 | ||
| 606 | var lib_list = [_][]const u8{ self.install_path, "lib" }; | 604 | var lib_list = [_][]const u8{ b.install_path, "lib" }; |
| 607 | var exe_list = [_][]const u8{ self.install_path, "bin" }; | 605 | var exe_list = [_][]const u8{ b.install_path, "bin" }; |
| 608 | var h_list = [_][]const u8{ self.install_path, "include" }; | 606 | var h_list = [_][]const u8{ b.install_path, "include" }; |
| 609 | 607 | ||
| 610 | if (dir_list.lib_dir) |dir| { | 608 | if (dir_list.lib_dir) |dir| { |
| 611 | if (fs.path.isAbsolute(dir)) lib_list[0] = self.dest_dir orelse ""; | 609 | if (fs.path.isAbsolute(dir)) lib_list[0] = b.dest_dir orelse ""; |
| 612 | lib_list[1] = dir; | 610 | lib_list[1] = dir; |
| 613 | } | 611 | } |
| 614 | 612 | ||
| 615 | if (dir_list.exe_dir) |dir| { | 613 | if (dir_list.exe_dir) |dir| { |
| 616 | if (fs.path.isAbsolute(dir)) exe_list[0] = self.dest_dir orelse ""; | 614 | if (fs.path.isAbsolute(dir)) exe_list[0] = b.dest_dir orelse ""; |
| 617 | exe_list[1] = dir; | 615 | exe_list[1] = dir; |
| 618 | } | 616 | } |
| 619 | 617 | ||
| 620 | if (dir_list.include_dir) |dir| { | 618 | if (dir_list.include_dir) |dir| { |
| 621 | if (fs.path.isAbsolute(dir)) h_list[0] = self.dest_dir orelse ""; | 619 | if (fs.path.isAbsolute(dir)) h_list[0] = b.dest_dir orelse ""; |
| 622 | h_list[1] = dir; | 620 | h_list[1] = dir; |
| 623 | } | 621 | } |
| 624 | 622 | ||
| 625 | self.lib_dir = self.pathJoin(&lib_list); | 623 | b.lib_dir = b.pathJoin(&lib_list); |
| 626 | self.exe_dir = self.pathJoin(&exe_list); | 624 | b.exe_dir = b.pathJoin(&exe_list); |
| 627 | self.h_dir = self.pathJoin(&h_list); | 625 | b.h_dir = b.pathJoin(&h_list); |
| 628 | } | 626 | } |
| 629 | 627 | ||
| 630 | /// Create a set of key-value pairs that can be converted into a Zig source | 628 | /// Create a set of key-value pairs that can be converted into a Zig source |
| ... | @@ -632,8 +630,8 @@ pub fn resolveInstallPrefix(self: *Build, install_prefix: ?[]const u8, dir_list: | ... | @@ -632,8 +630,8 @@ pub fn resolveInstallPrefix(self: *Build, install_prefix: ?[]const u8, dir_list: |
| 632 | /// In other words, this provides a way to expose build.zig values to Zig | 630 | /// In other words, this provides a way to expose build.zig values to Zig |
| 633 | /// source code with `@import`. | 631 | /// source code with `@import`. |
| 634 | /// Related: `Module.addOptions`. | 632 | /// Related: `Module.addOptions`. |
| 635 | pub fn addOptions(self: *Build) *Step.Options { | 633 | pub fn addOptions(b: *Build) *Step.Options { |
| 636 | return Step.Options.create(self); | 634 | return Step.Options.create(b); |
| 637 | } | 635 | } |
| 638 | 636 | ||
| 639 | pub const ExecutableOptions = struct { | 637 | pub const ExecutableOptions = struct { |
| ... | @@ -959,9 +957,9 @@ pub fn createModule(b: *Build, options: Module.CreateOptions) *Module { | ... | @@ -959,9 +957,9 @@ pub fn createModule(b: *Build, options: Module.CreateOptions) *Module { |
| 959 | /// `addArgs`, and `addArtifactArg`. | 957 | /// `addArgs`, and `addArtifactArg`. |
| 960 | /// Be careful using this function, as it introduces a system dependency. | 958 | /// Be careful using this function, as it introduces a system dependency. |
| 961 | /// To run an executable built with zig build, see `Step.Compile.run`. | 959 | /// To run an executable built with zig build, see `Step.Compile.run`. |
| 962 | pub fn addSystemCommand(self: *Build, argv: []const []const u8) *Step.Run { | 960 | pub fn addSystemCommand(b: *Build, argv: []const []const u8) *Step.Run { |
| 963 | assert(argv.len >= 1); | 961 | assert(argv.len >= 1); |
| 964 | const run_step = Step.Run.create(self, self.fmt("run {s}", .{argv[0]})); | 962 | const run_step = Step.Run.create(b, b.fmt("run {s}", .{argv[0]})); |
| 965 | run_step.addArgs(argv); | 963 | run_step.addArgs(argv); |
| 966 | return run_step; | 964 | return run_step; |
| 967 | } | 965 | } |
| ... | @@ -1002,20 +1000,20 @@ pub fn addConfigHeader( | ... | @@ -1002,20 +1000,20 @@ pub fn addConfigHeader( |
| 1002 | } | 1000 | } |
| 1003 | 1001 | ||
| 1004 | /// Allocator.dupe without the need to handle out of memory. | 1002 | /// Allocator.dupe without the need to handle out of memory. |
| 1005 | pub fn dupe(self: *Build, bytes: []const u8) []u8 { | 1003 | pub fn dupe(b: *Build, bytes: []const u8) []u8 { |
| 1006 | return self.allocator.dupe(u8, bytes) catch @panic("OOM"); | 1004 | return b.allocator.dupe(u8, bytes) catch @panic("OOM"); |
| 1007 | } | 1005 | } |
| 1008 | 1006 | ||
| 1009 | /// Duplicates an array of strings without the need to handle out of memory. | 1007 | /// Duplicates an array of strings without the need to handle out of memory. |
| 1010 | pub fn dupeStrings(self: *Build, strings: []const []const u8) [][]u8 { | 1008 | pub fn dupeStrings(b: *Build, strings: []const []const u8) [][]u8 { |
| 1011 | const array = self.allocator.alloc([]u8, strings.len) catch @panic("OOM"); | 1009 | const array = b.allocator.alloc([]u8, strings.len) catch @panic("OOM"); |
| 1012 | for (array, strings) |*dest, source| dest.* = self.dupe(source); | 1010 | for (array, strings) |*dest, source| dest.* = b.dupe(source); |
| 1013 | return array; | 1011 | return array; |
| 1014 | } | 1012 | } |
| 1015 | 1013 | ||
| 1016 | /// Duplicates a path and converts all slashes to the OS's canonical path separator. | 1014 | /// Duplicates a path and converts all slashes to the OS's canonical path separator. |
| 1017 | pub fn dupePath(self: *Build, bytes: []const u8) []u8 { | 1015 | pub fn dupePath(b: *Build, bytes: []const u8) []u8 { |
| 1018 | const the_copy = self.dupe(bytes); | 1016 | const the_copy = b.dupe(bytes); |
| 1019 | for (the_copy) |*byte| { | 1017 | for (the_copy) |*byte| { |
| 1020 | switch (byte.*) { | 1018 | switch (byte.*) { |
| 1021 | '/', '\\' => byte.* = fs.path.sep, | 1019 | '/', '\\' => byte.* = fs.path.sep, |
| ... | @@ -1025,8 +1023,8 @@ pub fn dupePath(self: *Build, bytes: []const u8) []u8 { | ... | @@ -1025,8 +1023,8 @@ pub fn dupePath(self: *Build, bytes: []const u8) []u8 { |
| 1025 | return the_copy; | 1023 | return the_copy; |
| 1026 | } | 1024 | } |
| 1027 | 1025 | ||
| 1028 | pub fn addWriteFile(self: *Build, file_path: []const u8, data: []const u8) *Step.WriteFile { | 1026 | pub fn addWriteFile(b: *Build, file_path: []const u8, data: []const u8) *Step.WriteFile { |
| 1029 | const write_file_step = self.addWriteFiles(); | 1027 | const write_file_step = b.addWriteFiles(); |
| 1030 | _ = write_file_step.add(file_path, data); | 1028 | _ = write_file_step.add(file_path, data); |
| 1031 | return write_file_step; | 1029 | return write_file_step; |
| 1032 | } | 1030 | } |
| ... | @@ -1041,34 +1039,34 @@ pub fn addWriteFiles(b: *Build) *Step.WriteFile { | ... | @@ -1041,34 +1039,34 @@ pub fn addWriteFiles(b: *Build) *Step.WriteFile { |
| 1041 | return Step.WriteFile.create(b); | 1039 | return Step.WriteFile.create(b); |
| 1042 | } | 1040 | } |
| 1043 | 1041 | ||
| 1044 | pub fn addRemoveDirTree(self: *Build, dir_path: []const u8) *Step.RemoveDir { | 1042 | pub fn addRemoveDirTree(b: *Build, dir_path: []const u8) *Step.RemoveDir { |
| 1045 | return Step.RemoveDir.create(self, dir_path); | 1043 | return Step.RemoveDir.create(b, dir_path); |
| 1046 | } | 1044 | } |
| 1047 | 1045 | ||
| 1048 | pub fn addFmt(b: *Build, options: Step.Fmt.Options) *Step.Fmt { | 1046 | pub fn addFmt(b: *Build, options: Step.Fmt.Options) *Step.Fmt { |
| 1049 | return Step.Fmt.create(b, options); | 1047 | return Step.Fmt.create(b, options); |
| 1050 | } | 1048 | } |
| 1051 | 1049 | ||
| 1052 | pub fn addTranslateC(self: *Build, options: Step.TranslateC.Options) *Step.TranslateC { | 1050 | pub fn addTranslateC(b: *Build, options: Step.TranslateC.Options) *Step.TranslateC { |
| 1053 | return Step.TranslateC.create(self, options); | 1051 | return Step.TranslateC.create(b, options); |
| 1054 | } | 1052 | } |
| 1055 | 1053 | ||
| 1056 | pub fn getInstallStep(self: *Build) *Step { | 1054 | pub fn getInstallStep(b: *Build) *Step { |
| 1057 | return &self.install_tls.step; | 1055 | return &b.install_tls.step; |
| 1058 | } | 1056 | } |
| 1059 | 1057 | ||
| 1060 | pub fn getUninstallStep(self: *Build) *Step { | 1058 | pub fn getUninstallStep(b: *Build) *Step { |
| 1061 | return &self.uninstall_tls.step; | 1059 | return &b.uninstall_tls.step; |
| 1062 | } | 1060 | } |
| 1063 | 1061 | ||
| 1064 | fn makeUninstall(uninstall_step: *Step, prog_node: *std.Progress.Node) anyerror!void { | 1062 | fn makeUninstall(uninstall_step: *Step, prog_node: *std.Progress.Node) anyerror!void { |
| 1065 | _ = prog_node; | 1063 | _ = prog_node; |
| 1066 | const uninstall_tls: *TopLevelStep = @fieldParentPtr("step", uninstall_step); | 1064 | const uninstall_tls: *TopLevelStep = @fieldParentPtr("step", uninstall_step); |
| 1067 | const self: *Build = @fieldParentPtr("uninstall_tls", uninstall_tls); | 1065 | const b: *Build = @fieldParentPtr("uninstall_tls", uninstall_tls); |
| 1068 | 1066 | ||
| 1069 | for (self.installed_files.items) |installed_file| { | 1067 | for (b.installed_files.items) |installed_file| { |
| 1070 | const full_path = self.getInstallPath(installed_file.dir, installed_file.path); | 1068 | const full_path = b.getInstallPath(installed_file.dir, installed_file.path); |
| 1071 | if (self.verbose) { | 1069 | if (b.verbose) { |
| 1072 | log.info("rm {s}", .{full_path}); | 1070 | log.info("rm {s}", .{full_path}); |
| 1073 | } | 1071 | } |
| 1074 | fs.cwd().deleteTree(full_path) catch {}; | 1072 | fs.cwd().deleteTree(full_path) catch {}; |
| ... | @@ -1082,13 +1080,13 @@ fn makeUninstall(uninstall_step: *Step, prog_node: *std.Progress.Node) anyerror! | ... | @@ -1082,13 +1080,13 @@ fn makeUninstall(uninstall_step: *Step, prog_node: *std.Progress.Node) anyerror! |
| 1082 | /// When a project depends on a Zig package as a dependency, it programmatically sets | 1080 | /// When a project depends on a Zig package as a dependency, it programmatically sets |
| 1083 | /// these options when calling the dependency's build.zig script as a function. | 1081 | /// these options when calling the dependency's build.zig script as a function. |
| 1084 | /// `null` is returned when an option is left to default. | 1082 | /// `null` is returned when an option is left to default. |
| 1085 | pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_raw: []const u8) ?T { | 1083 | pub fn option(b: *Build, comptime T: type, name_raw: []const u8, description_raw: []const u8) ?T { |
| 1086 | const name = self.dupe(name_raw); | 1084 | const name = b.dupe(name_raw); |
| 1087 | const description = self.dupe(description_raw); | 1085 | const description = b.dupe(description_raw); |
| 1088 | const type_id = comptime typeToEnum(T); | 1086 | const type_id = comptime typeToEnum(T); |
| 1089 | const enum_options = if (type_id == .@"enum") blk: { | 1087 | const enum_options = if (type_id == .@"enum") blk: { |
| 1090 | const fields = comptime std.meta.fields(T); | 1088 | const fields = comptime std.meta.fields(T); |
| 1091 | var options = ArrayList([]const u8).initCapacity(self.allocator, fields.len) catch @panic("OOM"); | 1089 | var options = ArrayList([]const u8).initCapacity(b.allocator, fields.len) catch @panic("OOM"); |
| 1092 | 1090 | ||
| 1093 | inline for (fields) |field| { | 1091 | inline for (fields) |field| { |
| 1094 | options.appendAssumeCapacity(field.name); | 1092 | options.appendAssumeCapacity(field.name); |
| ... | @@ -1102,12 +1100,12 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1102,12 +1100,12 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1102 | .description = description, | 1100 | .description = description, |
| 1103 | .enum_options = enum_options, | 1101 | .enum_options = enum_options, |
| 1104 | }; | 1102 | }; |
| 1105 | if ((self.available_options_map.fetchPut(name, available_option) catch @panic("OOM")) != null) { | 1103 | if ((b.available_options_map.fetchPut(name, available_option) catch @panic("OOM")) != null) { |
| 1106 | panic("Option '{s}' declared twice", .{name}); | 1104 | panic("Option '{s}' declared twice", .{name}); |
| 1107 | } | 1105 | } |
| 1108 | self.available_options_list.append(available_option) catch @panic("OOM"); | 1106 | b.available_options_list.append(available_option) catch @panic("OOM"); |
| 1109 | 1107 | ||
| 1110 | const option_ptr = self.user_input_options.getPtr(name) orelse return null; | 1108 | const option_ptr = b.user_input_options.getPtr(name) orelse return null; |
| 1111 | option_ptr.used = true; | 1109 | option_ptr.used = true; |
| 1112 | switch (type_id) { | 1110 | switch (type_id) { |
| 1113 | .bool => switch (option_ptr.value) { | 1111 | .bool => switch (option_ptr.value) { |
| ... | @@ -1119,7 +1117,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1119,7 +1117,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1119 | return false; | 1117 | return false; |
| 1120 | } else { | 1118 | } else { |
| 1121 | log.err("Expected -D{s} to be a boolean, but received '{s}'", .{ name, s }); | 1119 | log.err("Expected -D{s} to be a boolean, but received '{s}'", .{ name, s }); |
| 1122 | self.markInvalidUserInput(); | 1120 | b.markInvalidUserInput(); |
| 1123 | return null; | 1121 | return null; |
| 1124 | } | 1122 | } |
| 1125 | }, | 1123 | }, |
| ... | @@ -1127,7 +1125,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1127,7 +1125,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1127 | log.err("Expected -D{s} to be a boolean, but received a {s}.", .{ | 1125 | log.err("Expected -D{s} to be a boolean, but received a {s}.", .{ |
| 1128 | name, @tagName(option_ptr.value), | 1126 | name, @tagName(option_ptr.value), |
| 1129 | }); | 1127 | }); |
| 1130 | self.markInvalidUserInput(); | 1128 | b.markInvalidUserInput(); |
| 1131 | return null; | 1129 | return null; |
| 1132 | }, | 1130 | }, |
| 1133 | }, | 1131 | }, |
| ... | @@ -1136,19 +1134,19 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1136,19 +1134,19 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1136 | log.err("Expected -D{s} to be an integer, but received a {s}.", .{ | 1134 | log.err("Expected -D{s} to be an integer, but received a {s}.", .{ |
| 1137 | name, @tagName(option_ptr.value), | 1135 | name, @tagName(option_ptr.value), |
| 1138 | }); | 1136 | }); |
| 1139 | self.markInvalidUserInput(); | 1137 | b.markInvalidUserInput(); |
| 1140 | return null; | 1138 | return null; |
| 1141 | }, | 1139 | }, |
| 1142 | .scalar => |s| { | 1140 | .scalar => |s| { |
| 1143 | const n = std.fmt.parseInt(T, s, 10) catch |err| switch (err) { | 1141 | const n = std.fmt.parseInt(T, s, 10) catch |err| switch (err) { |
| 1144 | error.Overflow => { | 1142 | error.Overflow => { |
| 1145 | log.err("-D{s} value {s} cannot fit into type {s}.", .{ name, s, @typeName(T) }); | 1143 | log.err("-D{s} value {s} cannot fit into type {s}.", .{ name, s, @typeName(T) }); |
| 1146 | self.markInvalidUserInput(); | 1144 | b.markInvalidUserInput(); |
| 1147 | return null; | 1145 | return null; |
| 1148 | }, | 1146 | }, |
| 1149 | else => { | 1147 | else => { |
| 1150 | log.err("Expected -D{s} to be an integer of type {s}.", .{ name, @typeName(T) }); | 1148 | log.err("Expected -D{s} to be an integer of type {s}.", .{ name, @typeName(T) }); |
| 1151 | self.markInvalidUserInput(); | 1149 | b.markInvalidUserInput(); |
| 1152 | return null; | 1150 | return null; |
| 1153 | }, | 1151 | }, |
| 1154 | }; | 1152 | }; |
| ... | @@ -1160,13 +1158,13 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1160,13 +1158,13 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1160 | log.err("Expected -D{s} to be a float, but received a {s}.", .{ | 1158 | log.err("Expected -D{s} to be a float, but received a {s}.", .{ |
| 1161 | name, @tagName(option_ptr.value), | 1159 | name, @tagName(option_ptr.value), |
| 1162 | }); | 1160 | }); |
| 1163 | self.markInvalidUserInput(); | 1161 | b.markInvalidUserInput(); |
| 1164 | return null; | 1162 | return null; |
| 1165 | }, | 1163 | }, |
| 1166 | .scalar => |s| { | 1164 | .scalar => |s| { |
| 1167 | const n = std.fmt.parseFloat(T, s) catch { | 1165 | const n = std.fmt.parseFloat(T, s) catch { |
| 1168 | log.err("Expected -D{s} to be a float of type {s}.", .{ name, @typeName(T) }); | 1166 | log.err("Expected -D{s} to be a float of type {s}.", .{ name, @typeName(T) }); |
| 1169 | self.markInvalidUserInput(); | 1167 | b.markInvalidUserInput(); |
| 1170 | return null; | 1168 | return null; |
| 1171 | }; | 1169 | }; |
| 1172 | return n; | 1170 | return n; |
| ... | @@ -1177,7 +1175,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1177,7 +1175,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1177 | log.err("Expected -D{s} to be an enum, but received a {s}.", .{ | 1175 | log.err("Expected -D{s} to be an enum, but received a {s}.", .{ |
| 1178 | name, @tagName(option_ptr.value), | 1176 | name, @tagName(option_ptr.value), |
| 1179 | }); | 1177 | }); |
| 1180 | self.markInvalidUserInput(); | 1178 | b.markInvalidUserInput(); |
| 1181 | return null; | 1179 | return null; |
| 1182 | }, | 1180 | }, |
| 1183 | .scalar => |s| { | 1181 | .scalar => |s| { |
| ... | @@ -1185,7 +1183,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1185,7 +1183,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1185 | return enum_lit; | 1183 | return enum_lit; |
| 1186 | } else { | 1184 | } else { |
| 1187 | log.err("Expected -D{s} to be of type {s}.", .{ name, @typeName(T) }); | 1185 | log.err("Expected -D{s} to be of type {s}.", .{ name, @typeName(T) }); |
| 1188 | self.markInvalidUserInput(); | 1186 | b.markInvalidUserInput(); |
| 1189 | return null; | 1187 | return null; |
| 1190 | } | 1188 | } |
| 1191 | }, | 1189 | }, |
| ... | @@ -1195,7 +1193,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1195,7 +1193,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1195 | log.err("Expected -D{s} to be a string, but received a {s}.", .{ | 1193 | log.err("Expected -D{s} to be a string, but received a {s}.", .{ |
| 1196 | name, @tagName(option_ptr.value), | 1194 | name, @tagName(option_ptr.value), |
| 1197 | }); | 1195 | }); |
| 1198 | self.markInvalidUserInput(); | 1196 | b.markInvalidUserInput(); |
| 1199 | return null; | 1197 | return null; |
| 1200 | }, | 1198 | }, |
| 1201 | .scalar => |s| return s, | 1199 | .scalar => |s| return s, |
| ... | @@ -1205,7 +1203,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1205,7 +1203,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1205 | log.err("Expected -D{s} to be an enum, but received a {s}.", .{ | 1203 | log.err("Expected -D{s} to be an enum, but received a {s}.", .{ |
| 1206 | name, @tagName(option_ptr.value), | 1204 | name, @tagName(option_ptr.value), |
| 1207 | }); | 1205 | }); |
| 1208 | self.markInvalidUserInput(); | 1206 | b.markInvalidUserInput(); |
| 1209 | return null; | 1207 | return null; |
| 1210 | }, | 1208 | }, |
| 1211 | .scalar => |s| { | 1209 | .scalar => |s| { |
| ... | @@ -1213,7 +1211,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1213,7 +1211,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1213 | return build_id; | 1211 | return build_id; |
| 1214 | } else |err| { | 1212 | } else |err| { |
| 1215 | log.err("unable to parse option '-D{s}': {s}", .{ name, @errorName(err) }); | 1213 | log.err("unable to parse option '-D{s}': {s}", .{ name, @errorName(err) }); |
| 1216 | self.markInvalidUserInput(); | 1214 | b.markInvalidUserInput(); |
| 1217 | return null; | 1215 | return null; |
| 1218 | } | 1216 | } |
| 1219 | }, | 1217 | }, |
| ... | @@ -1223,28 +1221,28 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1223,28 +1221,28 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1223 | log.err("Expected -D{s} to be a list, but received a {s}.", .{ | 1221 | log.err("Expected -D{s} to be a list, but received a {s}.", .{ |
| 1224 | name, @tagName(option_ptr.value), | 1222 | name, @tagName(option_ptr.value), |
| 1225 | }); | 1223 | }); |
| 1226 | self.markInvalidUserInput(); | 1224 | b.markInvalidUserInput(); |
| 1227 | return null; | 1225 | return null; |
| 1228 | }, | 1226 | }, |
| 1229 | .scalar => |s| { | 1227 | .scalar => |s| { |
| 1230 | return self.allocator.dupe([]const u8, &[_][]const u8{s}) catch @panic("OOM"); | 1228 | return b.allocator.dupe([]const u8, &[_][]const u8{s}) catch @panic("OOM"); |
| 1231 | }, | 1229 | }, |
| 1232 | .list => |lst| return lst.items, | 1230 | .list => |lst| return lst.items, |
| 1233 | }, | 1231 | }, |
| 1234 | } | 1232 | } |
| 1235 | } | 1233 | } |
| 1236 | 1234 | ||
| 1237 | pub fn step(self: *Build, name: []const u8, description: []const u8) *Step { | 1235 | pub fn step(b: *Build, name: []const u8, description: []const u8) *Step { |
| 1238 | const step_info = self.allocator.create(TopLevelStep) catch @panic("OOM"); | 1236 | const step_info = b.allocator.create(TopLevelStep) catch @panic("OOM"); |
| 1239 | step_info.* = .{ | 1237 | step_info.* = .{ |
| 1240 | .step = Step.init(.{ | 1238 | .step = Step.init(.{ |
| 1241 | .id = .top_level, | 1239 | .id = TopLevelStep.base_id, |
| 1242 | .name = name, | 1240 | .name = name, |
| 1243 | .owner = self, | 1241 | .owner = b, |
| 1244 | }), | 1242 | }), |
| 1245 | .description = self.dupe(description), | 1243 | .description = b.dupe(description), |
| 1246 | }; | 1244 | }; |
| 1247 | const gop = self.top_level_steps.getOrPut(self.allocator, name) catch @panic("OOM"); | 1245 | const gop = b.top_level_steps.getOrPut(b.allocator, name) catch @panic("OOM"); |
| 1248 | if (gop.found_existing) std.debug.panic("A top-level step with name \"{s}\" already exists", .{name}); | 1246 | if (gop.found_existing) std.debug.panic("A top-level step with name \"{s}\" already exists", .{name}); |
| 1249 | 1247 | ||
| 1250 | gop.key_ptr.* = step_info.step.name; | 1248 | gop.key_ptr.* = step_info.step.name; |
| ... | @@ -1406,10 +1404,10 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs | ... | @@ -1406,10 +1404,10 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs |
| 1406 | return args.default_target; | 1404 | return args.default_target; |
| 1407 | } | 1405 | } |
| 1408 | 1406 | ||
| 1409 | pub fn addUserInputOption(self: *Build, name_raw: []const u8, value_raw: []const u8) !bool { | 1407 | pub fn addUserInputOption(b: *Build, name_raw: []const u8, value_raw: []const u8) !bool { |
| 1410 | const name = self.dupe(name_raw); | 1408 | const name = b.dupe(name_raw); |
| 1411 | const value = self.dupe(value_raw); | 1409 | const value = b.dupe(value_raw); |
| 1412 | const gop = try self.user_input_options.getOrPut(name); | 1410 | const gop = try b.user_input_options.getOrPut(name); |
| 1413 | if (!gop.found_existing) { | 1411 | if (!gop.found_existing) { |
| 1414 | gop.value_ptr.* = UserInputOption{ | 1412 | gop.value_ptr.* = UserInputOption{ |
| 1415 | .name = name, | 1413 | .name = name, |
| ... | @@ -1423,10 +1421,10 @@ pub fn addUserInputOption(self: *Build, name_raw: []const u8, value_raw: []const | ... | @@ -1423,10 +1421,10 @@ pub fn addUserInputOption(self: *Build, name_raw: []const u8, value_raw: []const |
| 1423 | switch (gop.value_ptr.value) { | 1421 | switch (gop.value_ptr.value) { |
| 1424 | .scalar => |s| { | 1422 | .scalar => |s| { |
| 1425 | // turn it into a list | 1423 | // turn it into a list |
| 1426 | var list = ArrayList([]const u8).init(self.allocator); | 1424 | var list = ArrayList([]const u8).init(b.allocator); |
| 1427 | try list.append(s); | 1425 | try list.append(s); |
| 1428 | try list.append(value); | 1426 | try list.append(value); |
| 1429 | try self.user_input_options.put(name, .{ | 1427 | try b.user_input_options.put(name, .{ |
| 1430 | .name = name, | 1428 | .name = name, |
| 1431 | .value = .{ .list = list }, | 1429 | .value = .{ .list = list }, |
| 1432 | .used = false, | 1430 | .used = false, |
| ... | @@ -1435,7 +1433,7 @@ pub fn addUserInputOption(self: *Build, name_raw: []const u8, value_raw: []const | ... | @@ -1435,7 +1433,7 @@ pub fn addUserInputOption(self: *Build, name_raw: []const u8, value_raw: []const |
| 1435 | .list => |*list| { | 1433 | .list => |*list| { |
| 1436 | // append to the list | 1434 | // append to the list |
| 1437 | try list.append(value); | 1435 | try list.append(value); |
| 1438 | try self.user_input_options.put(name, .{ | 1436 | try b.user_input_options.put(name, .{ |
| 1439 | .name = name, | 1437 | .name = name, |
| 1440 | .value = .{ .list = list.* }, | 1438 | .value = .{ .list = list.* }, |
| 1441 | .used = false, | 1439 | .used = false, |
| ... | @@ -1454,9 +1452,9 @@ pub fn addUserInputOption(self: *Build, name_raw: []const u8, value_raw: []const | ... | @@ -1454,9 +1452,9 @@ pub fn addUserInputOption(self: *Build, name_raw: []const u8, value_raw: []const |
| 1454 | return false; | 1452 | return false; |
| 1455 | } | 1453 | } |
| 1456 | 1454 | ||
| 1457 | pub fn addUserInputFlag(self: *Build, name_raw: []const u8) !bool { | 1455 | pub fn addUserInputFlag(b: *Build, name_raw: []const u8) !bool { |
| 1458 | const name = self.dupe(name_raw); | 1456 | const name = b.dupe(name_raw); |
| 1459 | const gop = try self.user_input_options.getOrPut(name); | 1457 | const gop = try b.user_input_options.getOrPut(name); |
| 1460 | if (!gop.found_existing) { | 1458 | if (!gop.found_existing) { |
| 1461 | gop.value_ptr.* = .{ | 1459 | gop.value_ptr.* = .{ |
| 1462 | .name = name, | 1460 | .name = name, |
| ... | @@ -1498,8 +1496,8 @@ fn typeToEnum(comptime T: type) TypeId { | ... | @@ -1498,8 +1496,8 @@ fn typeToEnum(comptime T: type) TypeId { |
| 1498 | }; | 1496 | }; |
| 1499 | } | 1497 | } |
| 1500 | 1498 | ||
| 1501 | fn markInvalidUserInput(self: *Build) void { | 1499 | fn markInvalidUserInput(b: *Build) void { |
| 1502 | self.invalid_user_input = true; | 1500 | b.invalid_user_input = true; |
| 1503 | } | 1501 | } |
| 1504 | 1502 | ||
| 1505 | pub fn validateUserInputDidItFail(b: *Build) bool { | 1503 | pub fn validateUserInputDidItFail(b: *Build) bool { |
| ... | @@ -1532,18 +1530,18 @@ fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void { | ... | @@ -1532,18 +1530,18 @@ fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void { |
| 1532 | /// This creates the install step and adds it to the dependencies of the | 1530 | /// This creates the install step and adds it to the dependencies of the |
| 1533 | /// top-level install step, using all the default options. | 1531 | /// top-level install step, using all the default options. |
| 1534 | /// See `addInstallArtifact` for a more flexible function. | 1532 | /// See `addInstallArtifact` for a more flexible function. |
| 1535 | pub fn installArtifact(self: *Build, artifact: *Step.Compile) void { | 1533 | pub fn installArtifact(b: *Build, artifact: *Step.Compile) void { |
| 1536 | self.getInstallStep().dependOn(&self.addInstallArtifact(artifact, .{}).step); | 1534 | b.getInstallStep().dependOn(&b.addInstallArtifact(artifact, .{}).step); |
| 1537 | } | 1535 | } |
| 1538 | 1536 | ||
| 1539 | /// This merely creates the step; it does not add it to the dependencies of the | 1537 | /// This merely creates the step; it does not add it to the dependencies of the |
| 1540 | /// top-level install step. | 1538 | /// top-level install step. |
| 1541 | pub fn addInstallArtifact( | 1539 | pub fn addInstallArtifact( |
| 1542 | self: *Build, | 1540 | b: *Build, |
| 1543 | artifact: *Step.Compile, | 1541 | artifact: *Step.Compile, |
| 1544 | options: Step.InstallArtifact.Options, | 1542 | options: Step.InstallArtifact.Options, |
| 1545 | ) *Step.InstallArtifact { | 1543 | ) *Step.InstallArtifact { |
| 1546 | return Step.InstallArtifact.create(self, artifact, options); | 1544 | return Step.InstallArtifact.create(b, artifact, options); |
| 1547 | } | 1545 | } |
| 1548 | 1546 | ||
| 1549 | ///`dest_rel_path` is relative to prefix path | 1547 | ///`dest_rel_path` is relative to prefix path |
| ... | @@ -1590,16 +1588,16 @@ pub fn addInstallHeaderFile(b: *Build, source: LazyPath, dest_rel_path: []const | ... | @@ -1590,16 +1588,16 @@ pub fn addInstallHeaderFile(b: *Build, source: LazyPath, dest_rel_path: []const |
| 1590 | } | 1588 | } |
| 1591 | 1589 | ||
| 1592 | pub fn addInstallFileWithDir( | 1590 | pub fn addInstallFileWithDir( |
| 1593 | self: *Build, | 1591 | b: *Build, |
| 1594 | source: LazyPath, | 1592 | source: LazyPath, |
| 1595 | install_dir: InstallDir, | 1593 | install_dir: InstallDir, |
| 1596 | dest_rel_path: []const u8, | 1594 | dest_rel_path: []const u8, |
| 1597 | ) *Step.InstallFile { | 1595 | ) *Step.InstallFile { |
| 1598 | return Step.InstallFile.create(self, source, install_dir, dest_rel_path); | 1596 | return Step.InstallFile.create(b, source, install_dir, dest_rel_path); |
| 1599 | } | 1597 | } |
| 1600 | 1598 | ||
| 1601 | pub fn addInstallDirectory(self: *Build, options: Step.InstallDir.Options) *Step.InstallDir { | 1599 | pub fn addInstallDirectory(b: *Build, options: Step.InstallDir.Options) *Step.InstallDir { |
| 1602 | return Step.InstallDir.create(self, options); | 1600 | return Step.InstallDir.create(b, options); |
| 1603 | } | 1601 | } |
| 1604 | 1602 | ||
| 1605 | pub fn addCheckFile( | 1603 | pub fn addCheckFile( |
| ... | @@ -1611,16 +1609,16 @@ pub fn addCheckFile( | ... | @@ -1611,16 +1609,16 @@ pub fn addCheckFile( |
| 1611 | } | 1609 | } |
| 1612 | 1610 | ||
| 1613 | /// deprecated: https://github.com/ziglang/zig/issues/14943 | 1611 | /// deprecated: https://github.com/ziglang/zig/issues/14943 |
| 1614 | pub fn pushInstalledFile(self: *Build, dir: InstallDir, dest_rel_path: []const u8) void { | 1612 | pub fn pushInstalledFile(b: *Build, dir: InstallDir, dest_rel_path: []const u8) void { |
| 1615 | const file = InstalledFile{ | 1613 | const file = InstalledFile{ |
| 1616 | .dir = dir, | 1614 | .dir = dir, |
| 1617 | .path = dest_rel_path, | 1615 | .path = dest_rel_path, |
| 1618 | }; | 1616 | }; |
| 1619 | self.installed_files.append(file.dupe(self)) catch @panic("OOM"); | 1617 | b.installed_files.append(file.dupe(b)) catch @panic("OOM"); |
| 1620 | } | 1618 | } |
| 1621 | 1619 | ||
| 1622 | pub fn truncateFile(self: *Build, dest_path: []const u8) !void { | 1620 | pub fn truncateFile(b: *Build, dest_path: []const u8) !void { |
| 1623 | if (self.verbose) { | 1621 | if (b.verbose) { |
| 1624 | log.info("truncate {s}", .{dest_path}); | 1622 | log.info("truncate {s}", .{dest_path}); |
| 1625 | } | 1623 | } |
| 1626 | const cwd = fs.cwd(); | 1624 | const cwd = fs.cwd(); |
| ... | @@ -1652,50 +1650,54 @@ pub fn path(b: *Build, sub_path: []const u8) LazyPath { | ... | @@ -1652,50 +1650,54 @@ pub fn path(b: *Build, sub_path: []const u8) LazyPath { |
| 1652 | /// This is low-level implementation details of the build system, not meant to | 1650 | /// This is low-level implementation details of the build system, not meant to |
| 1653 | /// be called by users' build scripts. Even in the build system itself it is a | 1651 | /// be called by users' build scripts. Even in the build system itself it is a |
| 1654 | /// code smell to call this function. | 1652 | /// code smell to call this function. |
| 1655 | pub fn pathFromRoot(b: *Build, p: []const u8) []u8 { | 1653 | pub fn pathFromRoot(b: *Build, sub_path: []const u8) []u8 { |
| 1656 | return fs.path.resolve(b.allocator, &.{ b.build_root.path orelse ".", p }) catch @panic("OOM"); | 1654 | return b.pathResolve(&.{ b.build_root.path orelse ".", sub_path }); |
| 1657 | } | 1655 | } |
| 1658 | 1656 | ||
| 1659 | fn pathFromCwd(b: *Build, p: []const u8) []u8 { | 1657 | fn pathFromCwd(b: *Build, sub_path: []const u8) []u8 { |
| 1660 | const cwd = process.getCwdAlloc(b.allocator) catch @panic("OOM"); | 1658 | const cwd = process.getCwdAlloc(b.allocator) catch @panic("OOM"); |
| 1661 | return fs.path.resolve(b.allocator, &.{ cwd, p }) catch @panic("OOM"); | 1659 | return b.pathResolve(&.{ cwd, sub_path }); |
| 1662 | } | 1660 | } |
| 1663 | 1661 | ||
| 1664 | pub fn pathJoin(self: *Build, paths: []const []const u8) []u8 { | 1662 | pub fn pathJoin(b: *Build, paths: []const []const u8) []u8 { |
| 1665 | return fs.path.join(self.allocator, paths) catch @panic("OOM"); | 1663 | return fs.path.join(b.allocator, paths) catch @panic("OOM"); |
| 1666 | } | 1664 | } |
| 1667 | 1665 | ||
| 1668 | pub fn fmt(self: *Build, comptime format: []const u8, args: anytype) []u8 { | 1666 | pub fn pathResolve(b: *Build, paths: []const []const u8) []u8 { |
| 1669 | return fmt_lib.allocPrint(self.allocator, format, args) catch @panic("OOM"); | 1667 | return fs.path.resolve(b.allocator, paths) catch @panic("OOM"); |
| 1670 | } | 1668 | } |
| 1671 | 1669 | ||
| 1672 | pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []const u8) ![]const u8 { | 1670 | pub fn fmt(b: *Build, comptime format: []const u8, args: anytype) []u8 { |
| 1671 | return std.fmt.allocPrint(b.allocator, format, args) catch @panic("OOM"); | ||
| 1672 | } | ||
| 1673 | |||
| 1674 | pub fn findProgram(b: *Build, names: []const []const u8, paths: []const []const u8) ![]const u8 { | ||
| 1673 | // TODO report error for ambiguous situations | 1675 | // TODO report error for ambiguous situations |
| 1674 | const exe_extension = self.host.result.exeFileExt(); | 1676 | const exe_extension = b.host.result.exeFileExt(); |
| 1675 | for (self.search_prefixes.items) |search_prefix| { | 1677 | for (b.search_prefixes.items) |search_prefix| { |
| 1676 | for (names) |name| { | 1678 | for (names) |name| { |
| 1677 | if (fs.path.isAbsolute(name)) { | 1679 | if (fs.path.isAbsolute(name)) { |
| 1678 | return name; | 1680 | return name; |
| 1679 | } | 1681 | } |
| 1680 | const full_path = self.pathJoin(&.{ | 1682 | const full_path = b.pathJoin(&.{ |
| 1681 | search_prefix, | 1683 | search_prefix, |
| 1682 | "bin", | 1684 | "bin", |
| 1683 | self.fmt("{s}{s}", .{ name, exe_extension }), | 1685 | b.fmt("{s}{s}", .{ name, exe_extension }), |
| 1684 | }); | 1686 | }); |
| 1685 | return fs.realpathAlloc(self.allocator, full_path) catch continue; | 1687 | return fs.realpathAlloc(b.allocator, full_path) catch continue; |
| 1686 | } | 1688 | } |
| 1687 | } | 1689 | } |
| 1688 | if (self.graph.env_map.get("PATH")) |PATH| { | 1690 | if (b.graph.env_map.get("PATH")) |PATH| { |
| 1689 | for (names) |name| { | 1691 | for (names) |name| { |
| 1690 | if (fs.path.isAbsolute(name)) { | 1692 | if (fs.path.isAbsolute(name)) { |
| 1691 | return name; | 1693 | return name; |
| 1692 | } | 1694 | } |
| 1693 | var it = mem.tokenizeScalar(u8, PATH, fs.path.delimiter); | 1695 | var it = mem.tokenizeScalar(u8, PATH, fs.path.delimiter); |
| 1694 | while (it.next()) |p| { | 1696 | while (it.next()) |p| { |
| 1695 | const full_path = self.pathJoin(&.{ | 1697 | const full_path = b.pathJoin(&.{ |
| 1696 | p, self.fmt("{s}{s}", .{ name, exe_extension }), | 1698 | p, b.fmt("{s}{s}", .{ name, exe_extension }), |
| 1697 | }); | 1699 | }); |
| 1698 | return fs.realpathAlloc(self.allocator, full_path) catch continue; | 1700 | return fs.realpathAlloc(b.allocator, full_path) catch continue; |
| 1699 | } | 1701 | } |
| 1700 | } | 1702 | } |
| 1701 | } | 1703 | } |
| ... | @@ -1704,17 +1706,17 @@ pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []con | ... | @@ -1704,17 +1706,17 @@ pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []con |
| 1704 | return name; | 1706 | return name; |
| 1705 | } | 1707 | } |
| 1706 | for (paths) |p| { | 1708 | for (paths) |p| { |
| 1707 | const full_path = self.pathJoin(&.{ | 1709 | const full_path = b.pathJoin(&.{ |
| 1708 | p, self.fmt("{s}{s}", .{ name, exe_extension }), | 1710 | p, b.fmt("{s}{s}", .{ name, exe_extension }), |
| 1709 | }); | 1711 | }); |
| 1710 | return fs.realpathAlloc(self.allocator, full_path) catch continue; | 1712 | return fs.realpathAlloc(b.allocator, full_path) catch continue; |
| 1711 | } | 1713 | } |
| 1712 | } | 1714 | } |
| 1713 | return error.FileNotFound; | 1715 | return error.FileNotFound; |
| 1714 | } | 1716 | } |
| 1715 | 1717 | ||
| 1716 | pub fn runAllowFail( | 1718 | pub fn runAllowFail( |
| 1717 | self: *Build, | 1719 | b: *Build, |
| 1718 | argv: []const []const u8, | 1720 | argv: []const []const u8, |
| 1719 | out_code: *u8, | 1721 | out_code: *u8, |
| 1720 | stderr_behavior: std.ChildProcess.StdIo, | 1722 | stderr_behavior: std.ChildProcess.StdIo, |
| ... | @@ -1725,18 +1727,18 @@ pub fn runAllowFail( | ... | @@ -1725,18 +1727,18 @@ pub fn runAllowFail( |
| 1725 | return error.ExecNotSupported; | 1727 | return error.ExecNotSupported; |
| 1726 | 1728 | ||
| 1727 | const max_output_size = 400 * 1024; | 1729 | const max_output_size = 400 * 1024; |
| 1728 | var child = std.ChildProcess.init(argv, self.allocator); | 1730 | var child = std.ChildProcess.init(argv, b.allocator); |
| 1729 | child.stdin_behavior = .Ignore; | 1731 | child.stdin_behavior = .Ignore; |
| 1730 | child.stdout_behavior = .Pipe; | 1732 | child.stdout_behavior = .Pipe; |
| 1731 | child.stderr_behavior = stderr_behavior; | 1733 | child.stderr_behavior = stderr_behavior; |
| 1732 | child.env_map = &self.graph.env_map; | 1734 | child.env_map = &b.graph.env_map; |
| 1733 | 1735 | ||
| 1734 | try child.spawn(); | 1736 | try child.spawn(); |
| 1735 | 1737 | ||
| 1736 | const stdout = child.stdout.?.reader().readAllAlloc(self.allocator, max_output_size) catch { | 1738 | const stdout = child.stdout.?.reader().readAllAlloc(b.allocator, max_output_size) catch { |
| 1737 | return error.ReadFailure; | 1739 | return error.ReadFailure; |
| 1738 | }; | 1740 | }; |
| 1739 | errdefer self.allocator.free(stdout); | 1741 | errdefer b.allocator.free(stdout); |
| 1740 | 1742 | ||
| 1741 | const term = try child.wait(); | 1743 | const term = try child.wait(); |
| 1742 | switch (term) { | 1744 | switch (term) { |
| ... | @@ -1779,19 +1781,16 @@ pub fn addSearchPrefix(b: *Build, search_prefix: []const u8) void { | ... | @@ -1779,19 +1781,16 @@ pub fn addSearchPrefix(b: *Build, search_prefix: []const u8) void { |
| 1779 | b.search_prefixes.append(b.allocator, b.dupePath(search_prefix)) catch @panic("OOM"); | 1781 | b.search_prefixes.append(b.allocator, b.dupePath(search_prefix)) catch @panic("OOM"); |
| 1780 | } | 1782 | } |
| 1781 | 1783 | ||
| 1782 | pub fn getInstallPath(self: *Build, dir: InstallDir, dest_rel_path: []const u8) []const u8 { | 1784 | pub fn getInstallPath(b: *Build, dir: InstallDir, dest_rel_path: []const u8) []const u8 { |
| 1783 | assert(!fs.path.isAbsolute(dest_rel_path)); // Install paths must be relative to the prefix | 1785 | assert(!fs.path.isAbsolute(dest_rel_path)); // Install paths must be relative to the prefix |
| 1784 | const base_dir = switch (dir) { | 1786 | const base_dir = switch (dir) { |
| 1785 | .prefix => self.install_path, | 1787 | .prefix => b.install_path, |
| 1786 | .bin => self.exe_dir, | 1788 | .bin => b.exe_dir, |
| 1787 | .lib => self.lib_dir, | 1789 | .lib => b.lib_dir, |
| 1788 | .header => self.h_dir, | 1790 | .header => b.h_dir, |
| 1789 | .custom => |p| self.pathJoin(&.{ self.install_path, p }), | 1791 | .custom => |p| b.pathJoin(&.{ b.install_path, p }), |
| 1790 | }; | 1792 | }; |
| 1791 | return fs.path.resolve( | 1793 | return b.pathResolve(&.{ base_dir, dest_rel_path }); |
| 1792 | self.allocator, | ||
| 1793 | &[_][]const u8{ base_dir, dest_rel_path }, | ||
| 1794 | ) catch @panic("OOM"); | ||
| 1795 | } | 1794 | } |
| 1796 | 1795 | ||
| 1797 | pub const Dependency = struct { | 1796 | pub const Dependency = struct { |
| ... | @@ -2092,11 +2091,11 @@ pub const GeneratedFile = struct { | ... | @@ -2092,11 +2091,11 @@ pub const GeneratedFile = struct { |
| 2092 | /// This value must be set in the `fn make()` of the `step` and must not be `null` afterwards. | 2091 | /// This value must be set in the `fn make()` of the `step` and must not be `null` afterwards. |
| 2093 | path: ?[]const u8 = null, | 2092 | path: ?[]const u8 = null, |
| 2094 | 2093 | ||
| 2095 | pub fn getPath(self: GeneratedFile) []const u8 { | 2094 | pub fn getPath(gen: GeneratedFile) []const u8 { |
| 2096 | return self.path orelse std.debug.panic( | 2095 | return gen.step.owner.pathFromRoot(gen.path orelse std.debug.panic( |
| 2097 | "getPath() was called on a GeneratedFile that wasn't built yet. Is there a missing Step dependency on step '{s}'?", | 2096 | "getPath() was called on a GeneratedFile that wasn't built yet. Is there a missing Step dependency on step '{s}'?", |
| 2098 | .{self.step.name}, | 2097 | .{gen.step.name}, |
| 2099 | ); | 2098 | )); |
| 2100 | } | 2099 | } |
| 2101 | }; | 2100 | }; |
| 2102 | 2101 | ||
| ... | @@ -2170,9 +2169,9 @@ pub const LazyPath = union(enum) { | ... | @@ -2170,9 +2169,9 @@ pub const LazyPath = union(enum) { |
| 2170 | }, | 2169 | }, |
| 2171 | 2170 | ||
| 2172 | /// Deprecated. Call `path` instead. | 2171 | /// Deprecated. Call `path` instead. |
| 2173 | pub fn relative(p: []const u8) LazyPath { | 2172 | pub fn relative(sub_path: []const u8) LazyPath { |
| 2174 | std.log.warn("deprecated. call std.Build.path instead", .{}); | 2173 | std.log.warn("deprecated. call std.Build.path instead", .{}); |
| 2175 | return .{ .path = p }; | 2174 | return .{ .path = sub_path }; |
| 2176 | } | 2175 | } |
| 2177 | 2176 | ||
| 2178 | /// Returns a lazy path referring to the directory containing this path. | 2177 | /// Returns a lazy path referring to the directory containing this path. |
| ... | @@ -2182,8 +2181,8 @@ pub const LazyPath = union(enum) { | ... | @@ -2182,8 +2181,8 @@ pub const LazyPath = union(enum) { |
| 2182 | /// the dirname is not allowed to traverse outside of the build root. | 2181 | /// the dirname is not allowed to traverse outside of the build root. |
| 2183 | /// Similarly, if the path is a generated file inside zig-cache, | 2182 | /// Similarly, if the path is a generated file inside zig-cache, |
| 2184 | /// the dirname is not allowed to traverse outside of zig-cache. | 2183 | /// the dirname is not allowed to traverse outside of zig-cache. |
| 2185 | pub fn dirname(self: LazyPath) LazyPath { | 2184 | pub fn dirname(lazy_path: LazyPath) LazyPath { |
| 2186 | return switch (self) { | 2185 | return switch (lazy_path) { |
| 2187 | .generated => |gen| .{ .generated_dirname = .{ .generated = gen, .up = 0 } }, | 2186 | .generated => |gen| .{ .generated_dirname = .{ .generated = gen, .up = 0 } }, |
| 2188 | .generated_dirname => |gen| .{ .generated_dirname = .{ .generated = gen.generated, .up = gen.up + 1 } }, | 2187 | .generated_dirname => |gen| .{ .generated_dirname = .{ .generated = gen.generated, .up = gen.up + 1 } }, |
| 2189 | .src_path => |sp| .{ .src_path = .{ | 2188 | .src_path => |sp| .{ .src_path = .{ |
| ... | @@ -2193,20 +2192,20 @@ pub const LazyPath = union(enum) { | ... | @@ -2193,20 +2192,20 @@ pub const LazyPath = union(enum) { |
| 2193 | @panic("misconfigured build script"); | 2192 | @panic("misconfigured build script"); |
| 2194 | }, | 2193 | }, |
| 2195 | } }, | 2194 | } }, |
| 2196 | .path => |p| .{ | 2195 | .path => |sub_path| .{ |
| 2197 | .path = dirnameAllowEmpty(p) orelse { | 2196 | .path = dirnameAllowEmpty(sub_path) orelse { |
| 2198 | dumpBadDirnameHelp(null, null, "dirname() attempted to traverse outside the build root\n", .{}) catch {}; | 2197 | dumpBadDirnameHelp(null, null, "dirname() attempted to traverse outside the build root\n", .{}) catch {}; |
| 2199 | @panic("misconfigured build script"); | 2198 | @panic("misconfigured build script"); |
| 2200 | }, | 2199 | }, |
| 2201 | }, | 2200 | }, |
| 2202 | .cwd_relative => |p| .{ | 2201 | .cwd_relative => |rel_path| .{ |
| 2203 | .cwd_relative = dirnameAllowEmpty(p) orelse { | 2202 | .cwd_relative = dirnameAllowEmpty(rel_path) orelse { |
| 2204 | // If we get null, it means one of two things: | 2203 | // If we get null, it means one of two things: |
| 2205 | // - p was absolute, and is now root | 2204 | // - rel_path was absolute, and is now root |
| 2206 | // - p was relative, and is now "" | 2205 | // - rel_path was relative, and is now "" |
| 2207 | // In either case, the build script tried to go too far | 2206 | // In either case, the build script tried to go too far |
| 2208 | // and we should panic. | 2207 | // and we should panic. |
| 2209 | if (fs.path.isAbsolute(p)) { | 2208 | if (fs.path.isAbsolute(rel_path)) { |
| 2210 | dumpBadDirnameHelp(null, null, | 2209 | dumpBadDirnameHelp(null, null, |
| 2211 | \\dirname() attempted to traverse outside the root. | 2210 | \\dirname() attempted to traverse outside the root. |
| 2212 | \\No more directories left to go up. | 2211 | \\No more directories left to go up. |
| ... | @@ -2237,10 +2236,10 @@ pub const LazyPath = union(enum) { | ... | @@ -2237,10 +2236,10 @@ pub const LazyPath = union(enum) { |
| 2237 | 2236 | ||
| 2238 | /// Returns a string that can be shown to represent the file source. | 2237 | /// Returns a string that can be shown to represent the file source. |
| 2239 | /// Either returns the path or `"generated"`. | 2238 | /// Either returns the path or `"generated"`. |
| 2240 | pub fn getDisplayName(self: LazyPath) []const u8 { | 2239 | pub fn getDisplayName(lazy_path: LazyPath) []const u8 { |
| 2241 | return switch (self) { | 2240 | return switch (lazy_path) { |
| 2242 | .src_path => |sp| sp.sub_path, | 2241 | .src_path => |src_path| src_path.sub_path, |
| 2243 | .path, .cwd_relative => |p| p, | 2242 | .path, .cwd_relative => |sub_path| sub_path, |
| 2244 | .generated => "generated", | 2243 | .generated => "generated", |
| 2245 | .generated_dirname => "generated", | 2244 | .generated_dirname => "generated", |
| 2246 | .dependency => "dependency", | 2245 | .dependency => "dependency", |
| ... | @@ -2248,8 +2247,8 @@ pub const LazyPath = union(enum) { | ... | @@ -2248,8 +2247,8 @@ pub const LazyPath = union(enum) { |
| 2248 | } | 2247 | } |
| 2249 | 2248 | ||
| 2250 | /// Adds dependencies this file source implies to the given step. | 2249 | /// Adds dependencies this file source implies to the given step. |
| 2251 | pub fn addStepDependencies(self: LazyPath, other_step: *Step) void { | 2250 | pub fn addStepDependencies(lazy_path: LazyPath, other_step: *Step) void { |
| 2252 | switch (self) { | 2251 | switch (lazy_path) { |
| 2253 | .src_path, .path, .cwd_relative, .dependency => {}, | 2252 | .src_path, .path, .cwd_relative, .dependency => {}, |
| 2254 | .generated => |gen| other_step.dependOn(gen.step), | 2253 | .generated => |gen| other_step.dependOn(gen.step), |
| 2255 | .generated_dirname => |gen| other_step.dependOn(gen.generated.step), | 2254 | .generated_dirname => |gen| other_step.dependOn(gen.generated.step), |
| ... | @@ -2258,8 +2257,8 @@ pub const LazyPath = union(enum) { | ... | @@ -2258,8 +2257,8 @@ pub const LazyPath = union(enum) { |
| 2258 | 2257 | ||
| 2259 | /// Returns an absolute path. | 2258 | /// Returns an absolute path. |
| 2260 | /// Intended to be used during the make phase only. | 2259 | /// Intended to be used during the make phase only. |
| 2261 | pub fn getPath(self: LazyPath, src_builder: *Build) []const u8 { | 2260 | pub fn getPath(lazy_path: LazyPath, src_builder: *Build) []const u8 { |
| 2262 | return getPath2(self, src_builder, null); | 2261 | return getPath2(lazy_path, src_builder, null); |
| 2263 | } | 2262 | } |
| 2264 | 2263 | ||
| 2265 | /// Returns an absolute path. | 2264 | /// Returns an absolute path. |
| ... | @@ -2267,17 +2266,17 @@ pub const LazyPath = union(enum) { | ... | @@ -2267,17 +2266,17 @@ pub const LazyPath = union(enum) { |
| 2267 | /// | 2266 | /// |
| 2268 | /// `asking_step` is only used for debugging purposes; it's the step being | 2267 | /// `asking_step` is only used for debugging purposes; it's the step being |
| 2269 | /// run that is asking for the path. | 2268 | /// run that is asking for the path. |
| 2270 | pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { | 2269 | pub fn getPath2(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { |
| 2271 | switch (self) { | 2270 | switch (lazy_path) { |
| 2272 | .path => |p| return src_builder.pathFromRoot(p), | 2271 | .path => |p| return src_builder.pathFromRoot(p), |
| 2273 | .src_path => |sp| return sp.owner.pathFromRoot(sp.sub_path), | 2272 | .src_path => |sp| return sp.owner.pathFromRoot(sp.sub_path), |
| 2274 | .cwd_relative => |p| return src_builder.pathFromCwd(p), | 2273 | .cwd_relative => |p| return src_builder.pathFromCwd(p), |
| 2275 | .generated => |gen| return gen.path orelse { | 2274 | .generated => |gen| return gen.step.owner.pathFromRoot(gen.path orelse { |
| 2276 | std.debug.getStderrMutex().lock(); | 2275 | std.debug.getStderrMutex().lock(); |
| 2277 | const stderr = std.io.getStdErr(); | 2276 | const stderr = std.io.getStdErr(); |
| 2278 | dumpBadGetPathHelp(gen.step, stderr, src_builder, asking_step) catch {}; | 2277 | dumpBadGetPathHelp(gen.step, stderr, src_builder, asking_step) catch {}; |
| 2279 | @panic("misconfigured build script"); | 2278 | @panic("misconfigured build script"); |
| 2280 | }, | 2279 | }), |
| 2281 | .generated_dirname => |gen| { | 2280 | .generated_dirname => |gen| { |
| 2282 | const cache_root_path = src_builder.cache_root.path orelse | 2281 | const cache_root_path = src_builder.cache_root.path orelse |
| 2283 | (src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM")); | 2282 | (src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM")); |
| ... | @@ -2311,12 +2310,7 @@ pub const LazyPath = union(enum) { | ... | @@ -2311,12 +2310,7 @@ pub const LazyPath = union(enum) { |
| 2311 | } | 2310 | } |
| 2312 | return p; | 2311 | return p; |
| 2313 | }, | 2312 | }, |
| 2314 | .dependency => |dep| { | 2313 | .dependency => |dep| return dep.dependency.builder.pathFromRoot(dep.sub_path), |
| 2315 | return dep.dependency.builder.pathJoin(&[_][]const u8{ | ||
| 2316 | dep.dependency.builder.build_root.path.?, | ||
| 2317 | dep.sub_path, | ||
| 2318 | }); | ||
| 2319 | }, | ||
| 2320 | } | 2314 | } |
| 2321 | } | 2315 | } |
| 2322 | 2316 | ||
| ... | @@ -2324,8 +2318,8 @@ pub const LazyPath = union(enum) { | ... | @@ -2324,8 +2318,8 @@ pub const LazyPath = union(enum) { |
| 2324 | /// | 2318 | /// |
| 2325 | /// The `b` parameter is only used for its allocator. All *Build instances | 2319 | /// The `b` parameter is only used for its allocator. All *Build instances |
| 2326 | /// share the same allocator. | 2320 | /// share the same allocator. |
| 2327 | pub fn dupe(self: LazyPath, b: *Build) LazyPath { | 2321 | pub fn dupe(lazy_path: LazyPath, b: *Build) LazyPath { |
| 2328 | return switch (self) { | 2322 | return switch (lazy_path) { |
| 2329 | .src_path => |sp| .{ .src_path = .{ | 2323 | .src_path => |sp| .{ .src_path = .{ |
| 2330 | .owner = sp.owner, | 2324 | .owner = sp.owner, |
| 2331 | .sub_path = sp.owner.dupePath(sp.sub_path), | 2325 | .sub_path = sp.owner.dupePath(sp.sub_path), |
| ... | @@ -2425,11 +2419,11 @@ pub const InstallDir = union(enum) { | ... | @@ -2425,11 +2419,11 @@ pub const InstallDir = union(enum) { |
| 2425 | custom: []const u8, | 2419 | custom: []const u8, |
| 2426 | 2420 | ||
| 2427 | /// Duplicates the install directory including the path if set to custom. | 2421 | /// Duplicates the install directory including the path if set to custom. |
| 2428 | pub fn dupe(self: InstallDir, builder: *Build) InstallDir { | 2422 | pub fn dupe(dir: InstallDir, builder: *Build) InstallDir { |
| 2429 | if (self == .custom) { | 2423 | if (dir == .custom) { |
| 2430 | return .{ .custom = builder.dupe(self.custom) }; | 2424 | return .{ .custom = builder.dupe(dir.custom) }; |
| 2431 | } else { | 2425 | } else { |
| 2432 | return self; | 2426 | return dir; |
| 2433 | } | 2427 | } |
| 2434 | } | 2428 | } |
| 2435 | }; | 2429 | }; |
| ... | @@ -2439,10 +2433,10 @@ pub const InstalledFile = struct { | ... | @@ -2439,10 +2433,10 @@ pub const InstalledFile = struct { |
| 2439 | path: []const u8, | 2433 | path: []const u8, |
| 2440 | 2434 | ||
| 2441 | /// Duplicates the installed file path and directory. | 2435 | /// Duplicates the installed file path and directory. |
| 2442 | pub fn dupe(self: InstalledFile, builder: *Build) InstalledFile { | 2436 | pub fn dupe(file: InstalledFile, builder: *Build) InstalledFile { |
| 2443 | return .{ | 2437 | return .{ |
| 2444 | .dir = self.dir.dupe(builder), | 2438 | .dir = file.dir.dupe(builder), |
| 2445 | .path = builder.dupe(self.path), | 2439 | .path = builder.dupe(file.path), |
| 2446 | }; | 2440 | }; |
| 2447 | } | 2441 | } |
| 2448 | }; | 2442 | }; |
lib/std/Build/Module.zig+13-18| ... | @@ -89,10 +89,10 @@ pub const CSourceFile = struct { | ... | @@ -89,10 +89,10 @@ pub const CSourceFile = struct { |
| 89 | file: LazyPath, | 89 | file: LazyPath, |
| 90 | flags: []const []const u8 = &.{}, | 90 | flags: []const []const u8 = &.{}, |
| 91 | 91 | ||
| 92 | pub fn dupe(self: CSourceFile, b: *std.Build) CSourceFile { | 92 | pub fn dupe(file: CSourceFile, b: *std.Build) CSourceFile { |
| 93 | return .{ | 93 | return .{ |
| 94 | .file = self.file.dupe(b), | 94 | .file = file.file.dupe(b), |
| 95 | .flags = b.dupeStrings(self.flags), | 95 | .flags = b.dupeStrings(file.flags), |
| 96 | }; | 96 | }; |
| 97 | } | 97 | } |
| 98 | }; | 98 | }; |
| ... | @@ -115,12 +115,12 @@ pub const RcSourceFile = struct { | ... | @@ -115,12 +115,12 @@ pub const RcSourceFile = struct { |
| 115 | /// as `/I <resolved path>`. | 115 | /// as `/I <resolved path>`. |
| 116 | include_paths: []const LazyPath = &.{}, | 116 | include_paths: []const LazyPath = &.{}, |
| 117 | 117 | ||
| 118 | pub fn dupe(self: RcSourceFile, b: *std.Build) RcSourceFile { | 118 | pub fn dupe(file: RcSourceFile, b: *std.Build) RcSourceFile { |
| 119 | const include_paths = b.allocator.alloc(LazyPath, self.include_paths.len) catch @panic("OOM"); | 119 | const include_paths = b.allocator.alloc(LazyPath, file.include_paths.len) catch @panic("OOM"); |
| 120 | for (include_paths, self.include_paths) |*dest, lazy_path| dest.* = lazy_path.dupe(b); | 120 | for (include_paths, file.include_paths) |*dest, lazy_path| dest.* = lazy_path.dupe(b); |
| 121 | return .{ | 121 | return .{ |
| 122 | .file = self.file.dupe(b), | 122 | .file = file.file.dupe(b), |
| 123 | .flags = b.dupeStrings(self.flags), | 123 | .flags = b.dupeStrings(file.flags), |
| 124 | .include_paths = include_paths, | 124 | .include_paths = include_paths, |
| 125 | }; | 125 | }; |
| 126 | } | 126 | } |
| ... | @@ -665,24 +665,19 @@ pub fn appendZigProcessFlags( | ... | @@ -665,24 +665,19 @@ pub fn appendZigProcessFlags( |
| 665 | for (m.include_dirs.items) |include_dir| { | 665 | for (m.include_dirs.items) |include_dir| { |
| 666 | switch (include_dir) { | 666 | switch (include_dir) { |
| 667 | .path => |include_path| { | 667 | .path => |include_path| { |
| 668 | try zig_args.append("-I"); | 668 | try zig_args.appendSlice(&.{ "-I", include_path.getPath2(b, asking_step) }); |
| 669 | try zig_args.append(include_path.getPath(b)); | ||
| 670 | }, | 669 | }, |
| 671 | .path_system => |include_path| { | 670 | .path_system => |include_path| { |
| 672 | try zig_args.append("-isystem"); | 671 | try zig_args.appendSlice(&.{ "-isystem", include_path.getPath2(b, asking_step) }); |
| 673 | try zig_args.append(include_path.getPath(b)); | ||
| 674 | }, | 672 | }, |
| 675 | .path_after => |include_path| { | 673 | .path_after => |include_path| { |
| 676 | try zig_args.append("-idirafter"); | 674 | try zig_args.appendSlice(&.{ "-idirafter", include_path.getPath2(b, asking_step) }); |
| 677 | try zig_args.append(include_path.getPath(b)); | ||
| 678 | }, | 675 | }, |
| 679 | .framework_path => |include_path| { | 676 | .framework_path => |include_path| { |
| 680 | try zig_args.append("-F"); | 677 | try zig_args.appendSlice(&.{ "-F", include_path.getPath2(b, asking_step) }); |
| 681 | try zig_args.append(include_path.getPath2(b, asking_step)); | ||
| 682 | }, | 678 | }, |
| 683 | .framework_path_system => |include_path| { | 679 | .framework_path_system => |include_path| { |
| 684 | try zig_args.append("-iframework"); | 680 | try zig_args.appendSlice(&.{ "-iframework", include_path.getPath2(b, asking_step) }); |
| 685 | try zig_args.append(include_path.getPath2(b, asking_step)); | ||
| 686 | }, | 681 | }, |
| 687 | .other_step => |other| { | 682 | .other_step => |other| { |
| 688 | if (other.generated_h) |header| { | 683 | if (other.generated_h) |header| { |
lib/std/Build/Step.zig+3-3| ... | @@ -58,7 +58,7 @@ pub const TestResults = struct { | ... | @@ -58,7 +58,7 @@ pub const TestResults = struct { |
| 58 | } | 58 | } |
| 59 | }; | 59 | }; |
| 60 | 60 | ||
| 61 | pub const MakeFn = *const fn (self: *Step, prog_node: *std.Progress.Node) anyerror!void; | 61 | pub const MakeFn = *const fn (step: *Step, prog_node: *std.Progress.Node) anyerror!void; |
| 62 | 62 | ||
| 63 | pub const State = enum { | 63 | pub const State = enum { |
| 64 | precheck_unstarted, | 64 | precheck_unstarted, |
| ... | @@ -201,8 +201,8 @@ pub fn make(s: *Step, prog_node: *std.Progress.Node) error{ MakeFailed, MakeSkip | ... | @@ -201,8 +201,8 @@ pub fn make(s: *Step, prog_node: *std.Progress.Node) error{ MakeFailed, MakeSkip |
| 201 | } | 201 | } |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | pub fn dependOn(self: *Step, other: *Step) void { | 204 | pub fn dependOn(step: *Step, other: *Step) void { |
| 205 | self.dependencies.append(other) catch @panic("OOM"); | 205 | step.dependencies.append(other) catch @panic("OOM"); |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | pub fn getStackTrace(s: *Step) ?std.builtin.StackTrace { | 208 | pub fn getStackTrace(s: *Step) ?std.builtin.StackTrace { |
lib/std/Build/Step/CheckFile.zig+13-13| ... | @@ -14,7 +14,7 @@ expected_exact: ?[]const u8, | ... | @@ -14,7 +14,7 @@ expected_exact: ?[]const u8, |
| 14 | source: std.Build.LazyPath, | 14 | source: std.Build.LazyPath, |
| 15 | max_bytes: usize = 20 * 1024 * 1024, | 15 | max_bytes: usize = 20 * 1024 * 1024, |
| 16 | 16 | ||
| 17 | pub const base_id = .check_file; | 17 | pub const base_id: Step.Id = .check_file; |
| 18 | 18 | ||
| 19 | pub const Options = struct { | 19 | pub const Options = struct { |
| 20 | expected_matches: []const []const u8 = &.{}, | 20 | expected_matches: []const []const u8 = &.{}, |
| ... | @@ -26,10 +26,10 @@ pub fn create( | ... | @@ -26,10 +26,10 @@ pub fn create( |
| 26 | source: std.Build.LazyPath, | 26 | source: std.Build.LazyPath, |
| 27 | options: Options, | 27 | options: Options, |
| 28 | ) *CheckFile { | 28 | ) *CheckFile { |
| 29 | const self = owner.allocator.create(CheckFile) catch @panic("OOM"); | 29 | const check_file = owner.allocator.create(CheckFile) catch @panic("OOM"); |
| 30 | self.* = .{ | 30 | check_file.* = .{ |
| 31 | .step = Step.init(.{ | 31 | .step = Step.init(.{ |
| 32 | .id = .check_file, | 32 | .id = base_id, |
| 33 | .name = "CheckFile", | 33 | .name = "CheckFile", |
| 34 | .owner = owner, | 34 | .owner = owner, |
| 35 | .makeFn = make, | 35 | .makeFn = make, |
| ... | @@ -38,27 +38,27 @@ pub fn create( | ... | @@ -38,27 +38,27 @@ pub fn create( |
| 38 | .expected_matches = owner.dupeStrings(options.expected_matches), | 38 | .expected_matches = owner.dupeStrings(options.expected_matches), |
| 39 | .expected_exact = options.expected_exact, | 39 | .expected_exact = options.expected_exact, |
| 40 | }; | 40 | }; |
| 41 | self.source.addStepDependencies(&self.step); | 41 | check_file.source.addStepDependencies(&check_file.step); |
| 42 | return self; | 42 | return check_file; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | pub fn setName(self: *CheckFile, name: []const u8) void { | 45 | pub fn setName(check_file: *CheckFile, name: []const u8) void { |
| 46 | self.step.name = name; | 46 | check_file.step.name = name; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 49 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 50 | _ = prog_node; | 50 | _ = prog_node; |
| 51 | const b = step.owner; | 51 | const b = step.owner; |
| 52 | const self: *CheckFile = @fieldParentPtr("step", step); | 52 | const check_file: *CheckFile = @fieldParentPtr("step", step); |
| 53 | 53 | ||
| 54 | const src_path = self.source.getPath(b); | 54 | const src_path = check_file.source.getPath2(b, step); |
| 55 | const contents = fs.cwd().readFileAlloc(b.allocator, src_path, self.max_bytes) catch |err| { | 55 | const contents = fs.cwd().readFileAlloc(b.allocator, src_path, check_file.max_bytes) catch |err| { |
| 56 | return step.fail("unable to read '{s}': {s}", .{ | 56 | return step.fail("unable to read '{s}': {s}", .{ |
| 57 | src_path, @errorName(err), | 57 | src_path, @errorName(err), |
| 58 | }); | 58 | }); |
| 59 | }; | 59 | }; |
| 60 | 60 | ||
| 61 | for (self.expected_matches) |expected_match| { | 61 | for (check_file.expected_matches) |expected_match| { |
| 62 | if (mem.indexOf(u8, contents, expected_match) == null) { | 62 | if (mem.indexOf(u8, contents, expected_match) == null) { |
| 63 | return step.fail( | 63 | return step.fail( |
| 64 | \\ | 64 | \\ |
| ... | @@ -71,7 +71,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -71,7 +71,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | if (self.expected_exact) |expected_exact| { | 74 | if (check_file.expected_exact) |expected_exact| { |
| 75 | if (!mem.eql(u8, expected_exact, contents)) { | 75 | if (!mem.eql(u8, expected_exact, contents)) { |
| 76 | return step.fail( | 76 | return step.fail( |
| 77 | \\ | 77 | \\ |
lib/std/Build/Step/CheckObject.zig+107-107| ... | @@ -12,7 +12,7 @@ const CheckObject = @This(); | ... | @@ -12,7 +12,7 @@ const CheckObject = @This(); |
| 12 | const Allocator = mem.Allocator; | 12 | const Allocator = mem.Allocator; |
| 13 | const Step = std.Build.Step; | 13 | const Step = std.Build.Step; |
| 14 | 14 | ||
| 15 | pub const base_id = .check_object; | 15 | pub const base_id: Step.Id = .check_object; |
| 16 | 16 | ||
| 17 | step: Step, | 17 | step: Step, |
| 18 | source: std.Build.LazyPath, | 18 | source: std.Build.LazyPath, |
| ... | @@ -26,10 +26,10 @@ pub fn create( | ... | @@ -26,10 +26,10 @@ pub fn create( |
| 26 | obj_format: std.Target.ObjectFormat, | 26 | obj_format: std.Target.ObjectFormat, |
| 27 | ) *CheckObject { | 27 | ) *CheckObject { |
| 28 | const gpa = owner.allocator; | 28 | const gpa = owner.allocator; |
| 29 | const self = gpa.create(CheckObject) catch @panic("OOM"); | 29 | const check_object = gpa.create(CheckObject) catch @panic("OOM"); |
| 30 | self.* = .{ | 30 | check_object.* = .{ |
| 31 | .step = Step.init(.{ | 31 | .step = Step.init(.{ |
| 32 | .id = .check_file, | 32 | .id = base_id, |
| 33 | .name = "CheckObject", | 33 | .name = "CheckObject", |
| 34 | .owner = owner, | 34 | .owner = owner, |
| 35 | .makeFn = make, | 35 | .makeFn = make, |
| ... | @@ -38,8 +38,8 @@ pub fn create( | ... | @@ -38,8 +38,8 @@ pub fn create( |
| 38 | .checks = std.ArrayList(Check).init(gpa), | 38 | .checks = std.ArrayList(Check).init(gpa), |
| 39 | .obj_format = obj_format, | 39 | .obj_format = obj_format, |
| 40 | }; | 40 | }; |
| 41 | self.source.addStepDependencies(&self.step); | 41 | check_object.source.addStepDependencies(&check_object.step); |
| 42 | return self; | 42 | return check_object; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | const SearchPhrase = struct { | 45 | const SearchPhrase = struct { |
| ... | @@ -268,36 +268,36 @@ const Check = struct { | ... | @@ -268,36 +268,36 @@ const Check = struct { |
| 268 | return check; | 268 | return check; |
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | fn extract(self: *Check, phrase: SearchPhrase) void { | 271 | fn extract(check: *Check, phrase: SearchPhrase) void { |
| 272 | self.actions.append(.{ | 272 | check.actions.append(.{ |
| 273 | .tag = .extract, | 273 | .tag = .extract, |
| 274 | .phrase = phrase, | 274 | .phrase = phrase, |
| 275 | }) catch @panic("OOM"); | 275 | }) catch @panic("OOM"); |
| 276 | } | 276 | } |
| 277 | 277 | ||
| 278 | fn exact(self: *Check, phrase: SearchPhrase) void { | 278 | fn exact(check: *Check, phrase: SearchPhrase) void { |
| 279 | self.actions.append(.{ | 279 | check.actions.append(.{ |
| 280 | .tag = .exact, | 280 | .tag = .exact, |
| 281 | .phrase = phrase, | 281 | .phrase = phrase, |
| 282 | }) catch @panic("OOM"); | 282 | }) catch @panic("OOM"); |
| 283 | } | 283 | } |
| 284 | 284 | ||
| 285 | fn contains(self: *Check, phrase: SearchPhrase) void { | 285 | fn contains(check: *Check, phrase: SearchPhrase) void { |
| 286 | self.actions.append(.{ | 286 | check.actions.append(.{ |
| 287 | .tag = .contains, | 287 | .tag = .contains, |
| 288 | .phrase = phrase, | 288 | .phrase = phrase, |
| 289 | }) catch @panic("OOM"); | 289 | }) catch @panic("OOM"); |
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | fn notPresent(self: *Check, phrase: SearchPhrase) void { | 292 | fn notPresent(check: *Check, phrase: SearchPhrase) void { |
| 293 | self.actions.append(.{ | 293 | check.actions.append(.{ |
| 294 | .tag = .not_present, | 294 | .tag = .not_present, |
| 295 | .phrase = phrase, | 295 | .phrase = phrase, |
| 296 | }) catch @panic("OOM"); | 296 | }) catch @panic("OOM"); |
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | fn computeCmp(self: *Check, phrase: SearchPhrase, expected: ComputeCompareExpected) void { | 299 | fn computeCmp(check: *Check, phrase: SearchPhrase, expected: ComputeCompareExpected) void { |
| 300 | self.actions.append(.{ | 300 | check.actions.append(.{ |
| 301 | .tag = .compute_cmp, | 301 | .tag = .compute_cmp, |
| 302 | .phrase = phrase, | 302 | .phrase = phrase, |
| 303 | .expected = expected, | 303 | .expected = expected, |
| ... | @@ -328,246 +328,246 @@ const Check = struct { | ... | @@ -328,246 +328,246 @@ const Check = struct { |
| 328 | }; | 328 | }; |
| 329 | 329 | ||
| 330 | /// Creates a new empty sequence of actions. | 330 | /// Creates a new empty sequence of actions. |
| 331 | fn checkStart(self: *CheckObject, kind: Check.Kind) void { | 331 | fn checkStart(check_object: *CheckObject, kind: Check.Kind) void { |
| 332 | const new_check = Check.create(self.step.owner.allocator, kind); | 332 | const check = Check.create(check_object.step.owner.allocator, kind); |
| 333 | self.checks.append(new_check) catch @panic("OOM"); | 333 | check_object.checks.append(check) catch @panic("OOM"); |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | /// Adds an exact match phrase to the latest created Check. | 336 | /// Adds an exact match phrase to the latest created Check. |
| 337 | pub fn checkExact(self: *CheckObject, phrase: []const u8) void { | 337 | pub fn checkExact(check_object: *CheckObject, phrase: []const u8) void { |
| 338 | self.checkExactInner(phrase, null); | 338 | check_object.checkExactInner(phrase, null); |
| 339 | } | 339 | } |
| 340 | 340 | ||
| 341 | /// Like `checkExact()` but takes an additional argument `LazyPath` which will be | 341 | /// Like `checkExact()` but takes an additional argument `LazyPath` which will be |
| 342 | /// resolved to a full search query in `make()`. | 342 | /// resolved to a full search query in `make()`. |
| 343 | pub fn checkExactPath(self: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { | 343 | pub fn checkExactPath(check_object: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { |
| 344 | self.checkExactInner(phrase, lazy_path); | 344 | check_object.checkExactInner(phrase, lazy_path); |
| 345 | } | 345 | } |
| 346 | 346 | ||
| 347 | fn checkExactInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { | 347 | fn checkExactInner(check_object: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { |
| 348 | assert(self.checks.items.len > 0); | 348 | assert(check_object.checks.items.len > 0); |
| 349 | const last = &self.checks.items[self.checks.items.len - 1]; | 349 | const last = &check_object.checks.items[check_object.checks.items.len - 1]; |
| 350 | last.exact(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); | 350 | last.exact(.{ .string = check_object.step.owner.dupe(phrase), .lazy_path = lazy_path }); |
| 351 | } | 351 | } |
| 352 | 352 | ||
| 353 | /// Adds a fuzzy match phrase to the latest created Check. | 353 | /// Adds a fuzzy match phrase to the latest created Check. |
| 354 | pub fn checkContains(self: *CheckObject, phrase: []const u8) void { | 354 | pub fn checkContains(check_object: *CheckObject, phrase: []const u8) void { |
| 355 | self.checkContainsInner(phrase, null); | 355 | check_object.checkContainsInner(phrase, null); |
| 356 | } | 356 | } |
| 357 | 357 | ||
| 358 | /// Like `checkContains()` but takes an additional argument `lazy_path` which will be | 358 | /// Like `checkContains()` but takes an additional argument `lazy_path` which will be |
| 359 | /// resolved to a full search query in `make()`. | 359 | /// resolved to a full search query in `make()`. |
| 360 | pub fn checkContainsPath( | 360 | pub fn checkContainsPath( |
| 361 | self: *CheckObject, | 361 | check_object: *CheckObject, |
| 362 | phrase: []const u8, | 362 | phrase: []const u8, |
| 363 | lazy_path: std.Build.LazyPath, | 363 | lazy_path: std.Build.LazyPath, |
| 364 | ) void { | 364 | ) void { |
| 365 | self.checkContainsInner(phrase, lazy_path); | 365 | check_object.checkContainsInner(phrase, lazy_path); |
| 366 | } | 366 | } |
| 367 | 367 | ||
| 368 | fn checkContainsInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { | 368 | fn checkContainsInner(check_object: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { |
| 369 | assert(self.checks.items.len > 0); | 369 | assert(check_object.checks.items.len > 0); |
| 370 | const last = &self.checks.items[self.checks.items.len - 1]; | 370 | const last = &check_object.checks.items[check_object.checks.items.len - 1]; |
| 371 | last.contains(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); | 371 | last.contains(.{ .string = check_object.step.owner.dupe(phrase), .lazy_path = lazy_path }); |
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | /// Adds an exact match phrase with variable extractor to the latest created Check. | 374 | /// Adds an exact match phrase with variable extractor to the latest created Check. |
| 375 | pub fn checkExtract(self: *CheckObject, phrase: []const u8) void { | 375 | pub fn checkExtract(check_object: *CheckObject, phrase: []const u8) void { |
| 376 | self.checkExtractInner(phrase, null); | 376 | check_object.checkExtractInner(phrase, null); |
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | /// Like `checkExtract()` but takes an additional argument `LazyPath` which will be | 379 | /// Like `checkExtract()` but takes an additional argument `LazyPath` which will be |
| 380 | /// resolved to a full search query in `make()`. | 380 | /// resolved to a full search query in `make()`. |
| 381 | pub fn checkExtractLazyPath(self: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { | 381 | pub fn checkExtractLazyPath(check_object: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { |
| 382 | self.checkExtractInner(phrase, lazy_path); | 382 | check_object.checkExtractInner(phrase, lazy_path); |
| 383 | } | 383 | } |
| 384 | 384 | ||
| 385 | fn checkExtractInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { | 385 | fn checkExtractInner(check_object: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { |
| 386 | assert(self.checks.items.len > 0); | 386 | assert(check_object.checks.items.len > 0); |
| 387 | const last = &self.checks.items[self.checks.items.len - 1]; | 387 | const last = &check_object.checks.items[check_object.checks.items.len - 1]; |
| 388 | last.extract(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); | 388 | last.extract(.{ .string = check_object.step.owner.dupe(phrase), .lazy_path = lazy_path }); |
| 389 | } | 389 | } |
| 390 | 390 | ||
| 391 | /// Adds another searched phrase to the latest created Check | 391 | /// Adds another searched phrase to the latest created Check |
| 392 | /// however ensures there is no matching phrase in the output. | 392 | /// however ensures there is no matching phrase in the output. |
| 393 | pub fn checkNotPresent(self: *CheckObject, phrase: []const u8) void { | 393 | pub fn checkNotPresent(check_object: *CheckObject, phrase: []const u8) void { |
| 394 | self.checkNotPresentInner(phrase, null); | 394 | check_object.checkNotPresentInner(phrase, null); |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | /// Like `checkExtract()` but takes an additional argument `LazyPath` which will be | 397 | /// Like `checkExtract()` but takes an additional argument `LazyPath` which will be |
| 398 | /// resolved to a full search query in `make()`. | 398 | /// resolved to a full search query in `make()`. |
| 399 | pub fn checkNotPresentLazyPath(self: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { | 399 | pub fn checkNotPresentLazyPath(check_object: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { |
| 400 | self.checkNotPresentInner(phrase, lazy_path); | 400 | check_object.checkNotPresentInner(phrase, lazy_path); |
| 401 | } | 401 | } |
| 402 | 402 | ||
| 403 | fn checkNotPresentInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { | 403 | fn checkNotPresentInner(check_object: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { |
| 404 | assert(self.checks.items.len > 0); | 404 | assert(check_object.checks.items.len > 0); |
| 405 | const last = &self.checks.items[self.checks.items.len - 1]; | 405 | const last = &check_object.checks.items[check_object.checks.items.len - 1]; |
| 406 | last.notPresent(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); | 406 | last.notPresent(.{ .string = check_object.step.owner.dupe(phrase), .lazy_path = lazy_path }); |
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | /// Creates a new check checking in the file headers (section, program headers, etc.). | 409 | /// Creates a new check checking in the file headers (section, program headers, etc.). |
| 410 | pub fn checkInHeaders(self: *CheckObject) void { | 410 | pub fn checkInHeaders(check_object: *CheckObject) void { |
| 411 | self.checkStart(.headers); | 411 | check_object.checkStart(.headers); |
| 412 | } | 412 | } |
| 413 | 413 | ||
| 414 | /// Creates a new check checking specifically symbol table parsed and dumped from the object | 414 | /// Creates a new check checking specifically symbol table parsed and dumped from the object |
| 415 | /// file. | 415 | /// file. |
| 416 | pub fn checkInSymtab(self: *CheckObject) void { | 416 | pub fn checkInSymtab(check_object: *CheckObject) void { |
| 417 | const label = switch (self.obj_format) { | 417 | const label = switch (check_object.obj_format) { |
| 418 | .macho => MachODumper.symtab_label, | 418 | .macho => MachODumper.symtab_label, |
| 419 | .elf => ElfDumper.symtab_label, | 419 | .elf => ElfDumper.symtab_label, |
| 420 | .wasm => WasmDumper.symtab_label, | 420 | .wasm => WasmDumper.symtab_label, |
| 421 | .coff => @panic("TODO symtab for coff"), | 421 | .coff => @panic("TODO symtab for coff"), |
| 422 | else => @panic("TODO other file formats"), | 422 | else => @panic("TODO other file formats"), |
| 423 | }; | 423 | }; |
| 424 | self.checkStart(.symtab); | 424 | check_object.checkStart(.symtab); |
| 425 | self.checkExact(label); | 425 | check_object.checkExact(label); |
| 426 | } | 426 | } |
| 427 | 427 | ||
| 428 | /// Creates a new check checking specifically dyld rebase opcodes contents parsed and dumped | 428 | /// Creates a new check checking specifically dyld rebase opcodes contents parsed and dumped |
| 429 | /// from the object file. | 429 | /// from the object file. |
| 430 | /// This check is target-dependent and applicable to MachO only. | 430 | /// This check is target-dependent and applicable to MachO only. |
| 431 | pub fn checkInDyldRebase(self: *CheckObject) void { | 431 | pub fn checkInDyldRebase(check_object: *CheckObject) void { |
| 432 | const label = switch (self.obj_format) { | 432 | const label = switch (check_object.obj_format) { |
| 433 | .macho => MachODumper.dyld_rebase_label, | 433 | .macho => MachODumper.dyld_rebase_label, |
| 434 | else => @panic("Unsupported target platform"), | 434 | else => @panic("Unsupported target platform"), |
| 435 | }; | 435 | }; |
| 436 | self.checkStart(.dyld_rebase); | 436 | check_object.checkStart(.dyld_rebase); |
| 437 | self.checkExact(label); | 437 | check_object.checkExact(label); |
| 438 | } | 438 | } |
| 439 | 439 | ||
| 440 | /// Creates a new check checking specifically dyld bind opcodes contents parsed and dumped | 440 | /// Creates a new check checking specifically dyld bind opcodes contents parsed and dumped |
| 441 | /// from the object file. | 441 | /// from the object file. |
| 442 | /// This check is target-dependent and applicable to MachO only. | 442 | /// This check is target-dependent and applicable to MachO only. |
| 443 | pub fn checkInDyldBind(self: *CheckObject) void { | 443 | pub fn checkInDyldBind(check_object: *CheckObject) void { |
| 444 | const label = switch (self.obj_format) { | 444 | const label = switch (check_object.obj_format) { |
| 445 | .macho => MachODumper.dyld_bind_label, | 445 | .macho => MachODumper.dyld_bind_label, |
| 446 | else => @panic("Unsupported target platform"), | 446 | else => @panic("Unsupported target platform"), |
| 447 | }; | 447 | }; |
| 448 | self.checkStart(.dyld_bind); | 448 | check_object.checkStart(.dyld_bind); |
| 449 | self.checkExact(label); | 449 | check_object.checkExact(label); |
| 450 | } | 450 | } |
| 451 | 451 | ||
| 452 | /// Creates a new check checking specifically dyld weak bind opcodes contents parsed and dumped | 452 | /// Creates a new check checking specifically dyld weak bind opcodes contents parsed and dumped |
| 453 | /// from the object file. | 453 | /// from the object file. |
| 454 | /// This check is target-dependent and applicable to MachO only. | 454 | /// This check is target-dependent and applicable to MachO only. |
| 455 | pub fn checkInDyldWeakBind(self: *CheckObject) void { | 455 | pub fn checkInDyldWeakBind(check_object: *CheckObject) void { |
| 456 | const label = switch (self.obj_format) { | 456 | const label = switch (check_object.obj_format) { |
| 457 | .macho => MachODumper.dyld_weak_bind_label, | 457 | .macho => MachODumper.dyld_weak_bind_label, |
| 458 | else => @panic("Unsupported target platform"), | 458 | else => @panic("Unsupported target platform"), |
| 459 | }; | 459 | }; |
| 460 | self.checkStart(.dyld_weak_bind); | 460 | check_object.checkStart(.dyld_weak_bind); |
| 461 | self.checkExact(label); | 461 | check_object.checkExact(label); |
| 462 | } | 462 | } |
| 463 | 463 | ||
| 464 | /// Creates a new check checking specifically dyld lazy bind opcodes contents parsed and dumped | 464 | /// Creates a new check checking specifically dyld lazy bind opcodes contents parsed and dumped |
| 465 | /// from the object file. | 465 | /// from the object file. |
| 466 | /// This check is target-dependent and applicable to MachO only. | 466 | /// This check is target-dependent and applicable to MachO only. |
| 467 | pub fn checkInDyldLazyBind(self: *CheckObject) void { | 467 | pub fn checkInDyldLazyBind(check_object: *CheckObject) void { |
| 468 | const label = switch (self.obj_format) { | 468 | const label = switch (check_object.obj_format) { |
| 469 | .macho => MachODumper.dyld_lazy_bind_label, | 469 | .macho => MachODumper.dyld_lazy_bind_label, |
| 470 | else => @panic("Unsupported target platform"), | 470 | else => @panic("Unsupported target platform"), |
| 471 | }; | 471 | }; |
| 472 | self.checkStart(.dyld_lazy_bind); | 472 | check_object.checkStart(.dyld_lazy_bind); |
| 473 | self.checkExact(label); | 473 | check_object.checkExact(label); |
| 474 | } | 474 | } |
| 475 | 475 | ||
| 476 | /// Creates a new check checking specifically exports info contents parsed and dumped | 476 | /// Creates a new check checking specifically exports info contents parsed and dumped |
| 477 | /// from the object file. | 477 | /// from the object file. |
| 478 | /// This check is target-dependent and applicable to MachO only. | 478 | /// This check is target-dependent and applicable to MachO only. |
| 479 | pub fn checkInExports(self: *CheckObject) void { | 479 | pub fn checkInExports(check_object: *CheckObject) void { |
| 480 | const label = switch (self.obj_format) { | 480 | const label = switch (check_object.obj_format) { |
| 481 | .macho => MachODumper.exports_label, | 481 | .macho => MachODumper.exports_label, |
| 482 | else => @panic("Unsupported target platform"), | 482 | else => @panic("Unsupported target platform"), |
| 483 | }; | 483 | }; |
| 484 | self.checkStart(.exports); | 484 | check_object.checkStart(.exports); |
| 485 | self.checkExact(label); | 485 | check_object.checkExact(label); |
| 486 | } | 486 | } |
| 487 | 487 | ||
| 488 | /// Creates a new check checking specifically indirect symbol table parsed and dumped | 488 | /// Creates a new check checking specifically indirect symbol table parsed and dumped |
| 489 | /// from the object file. | 489 | /// from the object file. |
| 490 | /// This check is target-dependent and applicable to MachO only. | 490 | /// This check is target-dependent and applicable to MachO only. |
| 491 | pub fn checkInIndirectSymtab(self: *CheckObject) void { | 491 | pub fn checkInIndirectSymtab(check_object: *CheckObject) void { |
| 492 | const label = switch (self.obj_format) { | 492 | const label = switch (check_object.obj_format) { |
| 493 | .macho => MachODumper.indirect_symtab_label, | 493 | .macho => MachODumper.indirect_symtab_label, |
| 494 | else => @panic("Unsupported target platform"), | 494 | else => @panic("Unsupported target platform"), |
| 495 | }; | 495 | }; |
| 496 | self.checkStart(.indirect_symtab); | 496 | check_object.checkStart(.indirect_symtab); |
| 497 | self.checkExact(label); | 497 | check_object.checkExact(label); |
| 498 | } | 498 | } |
| 499 | 499 | ||
| 500 | /// Creates a new check checking specifically dynamic symbol table parsed and dumped from the object | 500 | /// Creates a new check checking specifically dynamic symbol table parsed and dumped from the object |
| 501 | /// file. | 501 | /// file. |
| 502 | /// This check is target-dependent and applicable to ELF only. | 502 | /// This check is target-dependent and applicable to ELF only. |
| 503 | pub fn checkInDynamicSymtab(self: *CheckObject) void { | 503 | pub fn checkInDynamicSymtab(check_object: *CheckObject) void { |
| 504 | const label = switch (self.obj_format) { | 504 | const label = switch (check_object.obj_format) { |
| 505 | .elf => ElfDumper.dynamic_symtab_label, | 505 | .elf => ElfDumper.dynamic_symtab_label, |
| 506 | else => @panic("Unsupported target platform"), | 506 | else => @panic("Unsupported target platform"), |
| 507 | }; | 507 | }; |
| 508 | self.checkStart(.dynamic_symtab); | 508 | check_object.checkStart(.dynamic_symtab); |
| 509 | self.checkExact(label); | 509 | check_object.checkExact(label); |
| 510 | } | 510 | } |
| 511 | 511 | ||
| 512 | /// Creates a new check checking specifically dynamic section parsed and dumped from the object | 512 | /// Creates a new check checking specifically dynamic section parsed and dumped from the object |
| 513 | /// file. | 513 | /// file. |
| 514 | /// This check is target-dependent and applicable to ELF only. | 514 | /// This check is target-dependent and applicable to ELF only. |
| 515 | pub fn checkInDynamicSection(self: *CheckObject) void { | 515 | pub fn checkInDynamicSection(check_object: *CheckObject) void { |
| 516 | const label = switch (self.obj_format) { | 516 | const label = switch (check_object.obj_format) { |
| 517 | .elf => ElfDumper.dynamic_section_label, | 517 | .elf => ElfDumper.dynamic_section_label, |
| 518 | else => @panic("Unsupported target platform"), | 518 | else => @panic("Unsupported target platform"), |
| 519 | }; | 519 | }; |
| 520 | self.checkStart(.dynamic_section); | 520 | check_object.checkStart(.dynamic_section); |
| 521 | self.checkExact(label); | 521 | check_object.checkExact(label); |
| 522 | } | 522 | } |
| 523 | 523 | ||
| 524 | /// Creates a new check checking specifically symbol table parsed and dumped from the archive | 524 | /// Creates a new check checking specifically symbol table parsed and dumped from the archive |
| 525 | /// file. | 525 | /// file. |
| 526 | pub fn checkInArchiveSymtab(self: *CheckObject) void { | 526 | pub fn checkInArchiveSymtab(check_object: *CheckObject) void { |
| 527 | const label = switch (self.obj_format) { | 527 | const label = switch (check_object.obj_format) { |
| 528 | .elf => ElfDumper.archive_symtab_label, | 528 | .elf => ElfDumper.archive_symtab_label, |
| 529 | else => @panic("TODO other file formats"), | 529 | else => @panic("TODO other file formats"), |
| 530 | }; | 530 | }; |
| 531 | self.checkStart(.archive_symtab); | 531 | check_object.checkStart(.archive_symtab); |
| 532 | self.checkExact(label); | 532 | check_object.checkExact(label); |
| 533 | } | 533 | } |
| 534 | 534 | ||
| 535 | pub fn dumpSection(self: *CheckObject, name: [:0]const u8) void { | 535 | pub fn dumpSection(check_object: *CheckObject, name: [:0]const u8) void { |
| 536 | const new_check = Check.dumpSection(self.step.owner.allocator, name); | 536 | const check = Check.dumpSection(check_object.step.owner.allocator, name); |
| 537 | self.checks.append(new_check) catch @panic("OOM"); | 537 | check_object.checks.append(check) catch @panic("OOM"); |
| 538 | } | 538 | } |
| 539 | 539 | ||
| 540 | /// Creates a new standalone, singular check which allows running simple binary operations | 540 | /// Creates a new standalone, singular check which allows running simple binary operations |
| 541 | /// on the extracted variables. It will then compare the reduced program with the value of | 541 | /// on the extracted variables. It will then compare the reduced program with the value of |
| 542 | /// the expected variable. | 542 | /// the expected variable. |
| 543 | pub fn checkComputeCompare( | 543 | pub fn checkComputeCompare( |
| 544 | self: *CheckObject, | 544 | check_object: *CheckObject, |
| 545 | program: []const u8, | 545 | program: []const u8, |
| 546 | expected: ComputeCompareExpected, | 546 | expected: ComputeCompareExpected, |
| 547 | ) void { | 547 | ) void { |
| 548 | var new_check = Check.create(self.step.owner.allocator, .compute_compare); | 548 | var check = Check.create(check_object.step.owner.allocator, .compute_compare); |
| 549 | new_check.computeCmp(.{ .string = self.step.owner.dupe(program) }, expected); | 549 | check.computeCmp(.{ .string = check_object.step.owner.dupe(program) }, expected); |
| 550 | self.checks.append(new_check) catch @panic("OOM"); | 550 | check_object.checks.append(check) catch @panic("OOM"); |
| 551 | } | 551 | } |
| 552 | 552 | ||
| 553 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 553 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 554 | _ = prog_node; | 554 | _ = prog_node; |
| 555 | const b = step.owner; | 555 | const b = step.owner; |
| 556 | const gpa = b.allocator; | 556 | const gpa = b.allocator; |
| 557 | const self: *CheckObject = @fieldParentPtr("step", step); | 557 | const check_object: *CheckObject = @fieldParentPtr("step", step); |
| 558 | 558 | ||
| 559 | const src_path = self.source.getPath(b); | 559 | const src_path = check_object.source.getPath2(b, step); |
| 560 | const contents = fs.cwd().readFileAllocOptions( | 560 | const contents = fs.cwd().readFileAllocOptions( |
| 561 | gpa, | 561 | gpa, |
| 562 | src_path, | 562 | src_path, |
| 563 | self.max_bytes, | 563 | check_object.max_bytes, |
| 564 | null, | 564 | null, |
| 565 | @alignOf(u64), | 565 | @alignOf(u64), |
| 566 | null, | 566 | null, |
| 567 | ) catch |err| return step.fail("unable to read '{s}': {s}", .{ src_path, @errorName(err) }); | 567 | ) catch |err| return step.fail("unable to read '{s}': {s}", .{ src_path, @errorName(err) }); |
| 568 | 568 | ||
| 569 | var vars = std.StringHashMap(u64).init(gpa); | 569 | var vars = std.StringHashMap(u64).init(gpa); |
| 570 | for (self.checks.items) |chk| { | 570 | for (check_object.checks.items) |chk| { |
| 571 | if (chk.kind == .compute_compare) { | 571 | if (chk.kind == .compute_compare) { |
| 572 | assert(chk.actions.items.len == 1); | 572 | assert(chk.actions.items.len == 1); |
| 573 | const act = chk.actions.items[0]; | 573 | const act = chk.actions.items[0]; |
| ... | @@ -587,7 +587,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -587,7 +587,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 587 | continue; | 587 | continue; |
| 588 | } | 588 | } |
| 589 | 589 | ||
| 590 | const output = switch (self.obj_format) { | 590 | const output = switch (check_object.obj_format) { |
| 591 | .macho => try MachODumper.parseAndDump(step, chk, contents), | 591 | .macho => try MachODumper.parseAndDump(step, chk, contents), |
| 592 | .elf => try ElfDumper.parseAndDump(step, chk, contents), | 592 | .elf => try ElfDumper.parseAndDump(step, chk, contents), |
| 593 | .coff => return step.fail("TODO coff parser", .{}), | 593 | .coff => return step.fail("TODO coff parser", .{}), |
| ... | @@ -1597,8 +1597,8 @@ const MachODumper = struct { | ... | @@ -1597,8 +1597,8 @@ const MachODumper = struct { |
| 1597 | }, | 1597 | }, |
| 1598 | }, | 1598 | }, |
| 1599 | 1599 | ||
| 1600 | inline fn rankByTag(self: Export) u3 { | 1600 | inline fn rankByTag(@"export": Export) u3 { |
| 1601 | return switch (self.tag) { | 1601 | return switch (@"export".tag) { |
| 1602 | .@"export" => 1, | 1602 | .@"export" => 1, |
| 1603 | .reexport => 2, | 1603 | .reexport => 2, |
| 1604 | .stub_resolver => 3, | 1604 | .stub_resolver => 3, |
lib/std/Build/Step/Compile.zig+350-351| ... | @@ -263,10 +263,10 @@ pub const HeaderInstallation = union(enum) { | ... | @@ -263,10 +263,10 @@ pub const HeaderInstallation = union(enum) { |
| 263 | source: LazyPath, | 263 | source: LazyPath, |
| 264 | dest_rel_path: []const u8, | 264 | dest_rel_path: []const u8, |
| 265 | 265 | ||
| 266 | pub fn dupe(self: File, b: *std.Build) File { | 266 | pub fn dupe(file: File, b: *std.Build) File { |
| 267 | return .{ | 267 | return .{ |
| 268 | .source = self.source.dupe(b), | 268 | .source = file.source.dupe(b), |
| 269 | .dest_rel_path = b.dupePath(self.dest_rel_path), | 269 | .dest_rel_path = b.dupePath(file.dest_rel_path), |
| 270 | }; | 270 | }; |
| 271 | } | 271 | } |
| 272 | }; | 272 | }; |
| ... | @@ -284,31 +284,31 @@ pub const HeaderInstallation = union(enum) { | ... | @@ -284,31 +284,31 @@ pub const HeaderInstallation = union(enum) { |
| 284 | /// `exclude_extensions` takes precedence over `include_extensions`. | 284 | /// `exclude_extensions` takes precedence over `include_extensions`. |
| 285 | include_extensions: ?[]const []const u8 = &.{".h"}, | 285 | include_extensions: ?[]const []const u8 = &.{".h"}, |
| 286 | 286 | ||
| 287 | pub fn dupe(self: Directory.Options, b: *std.Build) Directory.Options { | 287 | pub fn dupe(opts: Directory.Options, b: *std.Build) Directory.Options { |
| 288 | return .{ | 288 | return .{ |
| 289 | .exclude_extensions = b.dupeStrings(self.exclude_extensions), | 289 | .exclude_extensions = b.dupeStrings(opts.exclude_extensions), |
| 290 | .include_extensions = if (self.include_extensions) |incs| b.dupeStrings(incs) else null, | 290 | .include_extensions = if (opts.include_extensions) |incs| b.dupeStrings(incs) else null, |
| 291 | }; | 291 | }; |
| 292 | } | 292 | } |
| 293 | }; | 293 | }; |
| 294 | 294 | ||
| 295 | pub fn dupe(self: Directory, b: *std.Build) Directory { | 295 | pub fn dupe(dir: Directory, b: *std.Build) Directory { |
| 296 | return .{ | 296 | return .{ |
| 297 | .source = self.source.dupe(b), | 297 | .source = dir.source.dupe(b), |
| 298 | .dest_rel_path = b.dupePath(self.dest_rel_path), | 298 | .dest_rel_path = b.dupePath(dir.dest_rel_path), |
| 299 | .options = self.options.dupe(b), | 299 | .options = dir.options.dupe(b), |
| 300 | }; | 300 | }; |
| 301 | } | 301 | } |
| 302 | }; | 302 | }; |
| 303 | 303 | ||
| 304 | pub fn getSource(self: HeaderInstallation) LazyPath { | 304 | pub fn getSource(installation: HeaderInstallation) LazyPath { |
| 305 | return switch (self) { | 305 | return switch (installation) { |
| 306 | inline .file, .directory => |x| x.source, | 306 | inline .file, .directory => |x| x.source, |
| 307 | }; | 307 | }; |
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | pub fn dupe(self: HeaderInstallation, b: *std.Build) HeaderInstallation { | 310 | pub fn dupe(installation: HeaderInstallation, b: *std.Build) HeaderInstallation { |
| 311 | return switch (self) { | 311 | return switch (installation) { |
| 312 | .file => |f| .{ .file = f.dupe(b) }, | 312 | .file => |f| .{ .file = f.dupe(b) }, |
| 313 | .directory => |d| .{ .directory = d.dupe(b) }, | 313 | .directory => |d| .{ .directory = d.dupe(b) }, |
| 314 | }; | 314 | }; |
| ... | @@ -354,8 +354,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -354,8 +354,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 354 | .version = options.version, | 354 | .version = options.version, |
| 355 | }) catch @panic("OOM"); | 355 | }) catch @panic("OOM"); |
| 356 | 356 | ||
| 357 | const self = owner.allocator.create(Compile) catch @panic("OOM"); | 357 | const compile = owner.allocator.create(Compile) catch @panic("OOM"); |
| 358 | self.* = .{ | 358 | compile.* = .{ |
| 359 | .root_module = undefined, | 359 | .root_module = undefined, |
| 360 | .verbose_link = false, | 360 | .verbose_link = false, |
| 361 | .verbose_cc = false, | 361 | .verbose_cc = false, |
| ... | @@ -398,57 +398,57 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -398,57 +398,57 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 398 | .use_lld = options.use_lld, | 398 | .use_lld = options.use_lld, |
| 399 | }; | 399 | }; |
| 400 | 400 | ||
| 401 | self.root_module.init(owner, options.root_module, self); | 401 | compile.root_module.init(owner, options.root_module, compile); |
| 402 | 402 | ||
| 403 | if (options.zig_lib_dir) |lp| { | 403 | if (options.zig_lib_dir) |lp| { |
| 404 | self.zig_lib_dir = lp.dupe(self.step.owner); | 404 | compile.zig_lib_dir = lp.dupe(compile.step.owner); |
| 405 | lp.addStepDependencies(&self.step); | 405 | lp.addStepDependencies(&compile.step); |
| 406 | } | 406 | } |
| 407 | 407 | ||
| 408 | if (options.test_runner) |lp| { | 408 | if (options.test_runner) |lp| { |
| 409 | self.test_runner = lp.dupe(self.step.owner); | 409 | compile.test_runner = lp.dupe(compile.step.owner); |
| 410 | lp.addStepDependencies(&self.step); | 410 | lp.addStepDependencies(&compile.step); |
| 411 | } | 411 | } |
| 412 | 412 | ||
| 413 | // Only the PE/COFF format has a Resource Table which is where the manifest | 413 | // Only the PE/COFF format has a Resource Table which is where the manifest |
| 414 | // gets embedded, so for any other target the manifest file is just ignored. | 414 | // gets embedded, so for any other target the manifest file is just ignored. |
| 415 | if (target.ofmt == .coff) { | 415 | if (target.ofmt == .coff) { |
| 416 | if (options.win32_manifest) |lp| { | 416 | if (options.win32_manifest) |lp| { |
| 417 | self.win32_manifest = lp.dupe(self.step.owner); | 417 | compile.win32_manifest = lp.dupe(compile.step.owner); |
| 418 | lp.addStepDependencies(&self.step); | 418 | lp.addStepDependencies(&compile.step); |
| 419 | } | 419 | } |
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | if (self.kind == .lib) { | 422 | if (compile.kind == .lib) { |
| 423 | if (self.linkage != null and self.linkage.? == .static) { | 423 | if (compile.linkage != null and compile.linkage.? == .static) { |
| 424 | self.out_lib_filename = self.out_filename; | 424 | compile.out_lib_filename = compile.out_filename; |
| 425 | } else if (self.version) |version| { | 425 | } else if (compile.version) |version| { |
| 426 | if (target.isDarwin()) { | 426 | if (target.isDarwin()) { |
| 427 | self.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{ | 427 | compile.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{ |
| 428 | self.name, | 428 | compile.name, |
| 429 | version.major, | 429 | version.major, |
| 430 | }); | 430 | }); |
| 431 | self.name_only_filename = owner.fmt("lib{s}.dylib", .{self.name}); | 431 | compile.name_only_filename = owner.fmt("lib{s}.dylib", .{compile.name}); |
| 432 | self.out_lib_filename = self.out_filename; | 432 | compile.out_lib_filename = compile.out_filename; |
| 433 | } else if (target.os.tag == .windows) { | 433 | } else if (target.os.tag == .windows) { |
| 434 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); | 434 | compile.out_lib_filename = owner.fmt("{s}.lib", .{compile.name}); |
| 435 | } else { | 435 | } else { |
| 436 | self.major_only_filename = owner.fmt("lib{s}.so.{d}", .{ self.name, version.major }); | 436 | compile.major_only_filename = owner.fmt("lib{s}.so.{d}", .{ compile.name, version.major }); |
| 437 | self.name_only_filename = owner.fmt("lib{s}.so", .{self.name}); | 437 | compile.name_only_filename = owner.fmt("lib{s}.so", .{compile.name}); |
| 438 | self.out_lib_filename = self.out_filename; | 438 | compile.out_lib_filename = compile.out_filename; |
| 439 | } | 439 | } |
| 440 | } else { | 440 | } else { |
| 441 | if (target.isDarwin()) { | 441 | if (target.isDarwin()) { |
| 442 | self.out_lib_filename = self.out_filename; | 442 | compile.out_lib_filename = compile.out_filename; |
| 443 | } else if (target.os.tag == .windows) { | 443 | } else if (target.os.tag == .windows) { |
| 444 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); | 444 | compile.out_lib_filename = owner.fmt("{s}.lib", .{compile.name}); |
| 445 | } else { | 445 | } else { |
| 446 | self.out_lib_filename = self.out_filename; | 446 | compile.out_lib_filename = compile.out_filename; |
| 447 | } | 447 | } |
| 448 | } | 448 | } |
| 449 | } | 449 | } |
| 450 | 450 | ||
| 451 | return self; | 451 | return compile; |
| 452 | } | 452 | } |
| 453 | 453 | ||
| 454 | /// Marks the specified header for installation alongside this artifact. | 454 | /// Marks the specified header for installation alongside this artifact. |
| ... | @@ -545,38 +545,38 @@ pub fn addObjCopy(cs: *Compile, options: Step.ObjCopy.Options) *Step.ObjCopy { | ... | @@ -545,38 +545,38 @@ pub fn addObjCopy(cs: *Compile, options: Step.ObjCopy.Options) *Step.ObjCopy { |
| 545 | return b.addObjCopy(cs.getEmittedBin(), copy); | 545 | return b.addObjCopy(cs.getEmittedBin(), copy); |
| 546 | } | 546 | } |
| 547 | 547 | ||
| 548 | pub fn checkObject(self: *Compile) *Step.CheckObject { | 548 | pub fn checkObject(compile: *Compile) *Step.CheckObject { |
| 549 | return Step.CheckObject.create(self.step.owner, self.getEmittedBin(), self.rootModuleTarget().ofmt); | 549 | return Step.CheckObject.create(compile.step.owner, compile.getEmittedBin(), compile.rootModuleTarget().ofmt); |
| 550 | } | 550 | } |
| 551 | 551 | ||
| 552 | /// deprecated: use `setLinkerScript` | 552 | /// deprecated: use `setLinkerScript` |
| 553 | pub const setLinkerScriptPath = setLinkerScript; | 553 | pub const setLinkerScriptPath = setLinkerScript; |
| 554 | 554 | ||
| 555 | pub fn setLinkerScript(self: *Compile, source: LazyPath) void { | 555 | pub fn setLinkerScript(compile: *Compile, source: LazyPath) void { |
| 556 | const b = self.step.owner; | 556 | const b = compile.step.owner; |
| 557 | self.linker_script = source.dupe(b); | 557 | compile.linker_script = source.dupe(b); |
| 558 | source.addStepDependencies(&self.step); | 558 | source.addStepDependencies(&compile.step); |
| 559 | } | 559 | } |
| 560 | 560 | ||
| 561 | pub fn setVersionScript(self: *Compile, source: LazyPath) void { | 561 | pub fn setVersionScript(compile: *Compile, source: LazyPath) void { |
| 562 | const b = self.step.owner; | 562 | const b = compile.step.owner; |
| 563 | self.version_script = source.dupe(b); | 563 | compile.version_script = source.dupe(b); |
| 564 | source.addStepDependencies(&self.step); | 564 | source.addStepDependencies(&compile.step); |
| 565 | } | 565 | } |
| 566 | 566 | ||
| 567 | pub fn forceUndefinedSymbol(self: *Compile, symbol_name: []const u8) void { | 567 | pub fn forceUndefinedSymbol(compile: *Compile, symbol_name: []const u8) void { |
| 568 | const b = self.step.owner; | 568 | const b = compile.step.owner; |
| 569 | self.force_undefined_symbols.put(b.dupe(symbol_name), {}) catch @panic("OOM"); | 569 | compile.force_undefined_symbols.put(b.dupe(symbol_name), {}) catch @panic("OOM"); |
| 570 | } | 570 | } |
| 571 | 571 | ||
| 572 | /// Returns whether the library, executable, or object depends on a particular system library. | 572 | /// Returns whether the library, executable, or object depends on a particular system library. |
| 573 | /// Includes transitive dependencies. | 573 | /// Includes transitive dependencies. |
| 574 | pub fn dependsOnSystemLibrary(self: *const Compile, name: []const u8) bool { | 574 | pub fn dependsOnSystemLibrary(compile: *const Compile, name: []const u8) bool { |
| 575 | var is_linking_libc = false; | 575 | var is_linking_libc = false; |
| 576 | var is_linking_libcpp = false; | 576 | var is_linking_libcpp = false; |
| 577 | 577 | ||
| 578 | var it = self.root_module.iterateDependencies(self, true); | 578 | var dep_it = compile.root_module.iterateDependencies(compile, true); |
| 579 | while (it.next()) |module| { | 579 | while (dep_it.next()) |module| { |
| 580 | for (module.link_objects.items) |link_object| { | 580 | for (module.link_objects.items) |link_object| { |
| 581 | switch (link_object) { | 581 | switch (link_object) { |
| 582 | .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, | 582 | .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, |
| ... | @@ -587,31 +587,31 @@ pub fn dependsOnSystemLibrary(self: *const Compile, name: []const u8) bool { | ... | @@ -587,31 +587,31 @@ pub fn dependsOnSystemLibrary(self: *const Compile, name: []const u8) bool { |
| 587 | is_linking_libcpp = is_linking_libcpp or module.link_libcpp == true; | 587 | is_linking_libcpp = is_linking_libcpp or module.link_libcpp == true; |
| 588 | } | 588 | } |
| 589 | 589 | ||
| 590 | if (self.rootModuleTarget().is_libc_lib_name(name)) { | 590 | if (compile.rootModuleTarget().is_libc_lib_name(name)) { |
| 591 | return is_linking_libc; | 591 | return is_linking_libc; |
| 592 | } | 592 | } |
| 593 | 593 | ||
| 594 | if (self.rootModuleTarget().is_libcpp_lib_name(name)) { | 594 | if (compile.rootModuleTarget().is_libcpp_lib_name(name)) { |
| 595 | return is_linking_libcpp; | 595 | return is_linking_libcpp; |
| 596 | } | 596 | } |
| 597 | 597 | ||
| 598 | return false; | 598 | return false; |
| 599 | } | 599 | } |
| 600 | 600 | ||
| 601 | pub fn isDynamicLibrary(self: *const Compile) bool { | 601 | pub fn isDynamicLibrary(compile: *const Compile) bool { |
| 602 | return self.kind == .lib and self.linkage == .dynamic; | 602 | return compile.kind == .lib and compile.linkage == .dynamic; |
| 603 | } | 603 | } |
| 604 | 604 | ||
| 605 | pub fn isStaticLibrary(self: *const Compile) bool { | 605 | pub fn isStaticLibrary(compile: *const Compile) bool { |
| 606 | return self.kind == .lib and self.linkage != .dynamic; | 606 | return compile.kind == .lib and compile.linkage != .dynamic; |
| 607 | } | 607 | } |
| 608 | 608 | ||
| 609 | pub fn isDll(self: *Compile) bool { | 609 | pub fn isDll(compile: *Compile) bool { |
| 610 | return self.isDynamicLibrary() and self.rootModuleTarget().os.tag == .windows; | 610 | return compile.isDynamicLibrary() and compile.rootModuleTarget().os.tag == .windows; |
| 611 | } | 611 | } |
| 612 | 612 | ||
| 613 | pub fn producesPdbFile(self: *Compile) bool { | 613 | pub fn producesPdbFile(compile: *Compile) bool { |
| 614 | const target = self.rootModuleTarget(); | 614 | const target = compile.rootModuleTarget(); |
| 615 | // TODO: Is this right? Isn't PDB for *any* PE/COFF file? | 615 | // TODO: Is this right? Isn't PDB for *any* PE/COFF file? |
| 616 | // TODO: just share this logic with the compiler, silly! | 616 | // TODO: just share this logic with the compiler, silly! |
| 617 | switch (target.os.tag) { | 617 | switch (target.os.tag) { |
| ... | @@ -619,24 +619,24 @@ pub fn producesPdbFile(self: *Compile) bool { | ... | @@ -619,24 +619,24 @@ pub fn producesPdbFile(self: *Compile) bool { |
| 619 | else => return false, | 619 | else => return false, |
| 620 | } | 620 | } |
| 621 | if (target.ofmt == .c) return false; | 621 | if (target.ofmt == .c) return false; |
| 622 | if (self.root_module.strip == true or | 622 | if (compile.root_module.strip == true or |
| 623 | (self.root_module.strip == null and self.root_module.optimize == .ReleaseSmall)) | 623 | (compile.root_module.strip == null and compile.root_module.optimize == .ReleaseSmall)) |
| 624 | { | 624 | { |
| 625 | return false; | 625 | return false; |
| 626 | } | 626 | } |
| 627 | return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test"; | 627 | return compile.isDynamicLibrary() or compile.kind == .exe or compile.kind == .@"test"; |
| 628 | } | 628 | } |
| 629 | 629 | ||
| 630 | pub fn producesImplib(self: *Compile) bool { | 630 | pub fn producesImplib(compile: *Compile) bool { |
| 631 | return self.isDll(); | 631 | return compile.isDll(); |
| 632 | } | 632 | } |
| 633 | 633 | ||
| 634 | pub fn linkLibC(self: *Compile) void { | 634 | pub fn linkLibC(compile: *Compile) void { |
| 635 | self.root_module.link_libc = true; | 635 | compile.root_module.link_libc = true; |
| 636 | } | 636 | } |
| 637 | 637 | ||
| 638 | pub fn linkLibCpp(self: *Compile) void { | 638 | pub fn linkLibCpp(compile: *Compile) void { |
| 639 | self.root_module.link_libcpp = true; | 639 | compile.root_module.link_libcpp = true; |
| 640 | } | 640 | } |
| 641 | 641 | ||
| 642 | /// Deprecated. Use `c.root_module.addCMacro`. | 642 | /// Deprecated. Use `c.root_module.addCMacro`. |
| ... | @@ -651,8 +651,8 @@ const PkgConfigResult = struct { | ... | @@ -651,8 +651,8 @@ const PkgConfigResult = struct { |
| 651 | 651 | ||
| 652 | /// Run pkg-config for the given library name and parse the output, returning the arguments | 652 | /// Run pkg-config for the given library name and parse the output, returning the arguments |
| 653 | /// that should be passed to zig to link the given library. | 653 | /// that should be passed to zig to link the given library. |
| 654 | fn runPkgConfig(self: *Compile, lib_name: []const u8) !PkgConfigResult { | 654 | fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult { |
| 655 | const b = self.step.owner; | 655 | const b = compile.step.owner; |
| 656 | const pkg_name = match: { | 656 | const pkg_name = match: { |
| 657 | // First we have to map the library name to pkg config name. Unfortunately, | 657 | // First we have to map the library name to pkg config name. Unfortunately, |
| 658 | // there are several examples where this is not straightforward: | 658 | // there are several examples where this is not straightforward: |
| ... | @@ -717,30 +717,30 @@ fn runPkgConfig(self: *Compile, lib_name: []const u8) !PkgConfigResult { | ... | @@ -717,30 +717,30 @@ fn runPkgConfig(self: *Compile, lib_name: []const u8) !PkgConfigResult { |
| 717 | var zig_libs = ArrayList([]const u8).init(b.allocator); | 717 | var zig_libs = ArrayList([]const u8).init(b.allocator); |
| 718 | defer zig_libs.deinit(); | 718 | defer zig_libs.deinit(); |
| 719 | 719 | ||
| 720 | var it = mem.tokenizeAny(u8, stdout, " \r\n\t"); | 720 | var arg_it = mem.tokenizeAny(u8, stdout, " \r\n\t"); |
| 721 | while (it.next()) |tok| { | 721 | while (arg_it.next()) |arg| { |
| 722 | if (mem.eql(u8, tok, "-I")) { | 722 | if (mem.eql(u8, arg, "-I")) { |
| 723 | const dir = it.next() orelse return error.PkgConfigInvalidOutput; | 723 | const dir = arg_it.next() orelse return error.PkgConfigInvalidOutput; |
| 724 | try zig_cflags.appendSlice(&[_][]const u8{ "-I", dir }); | 724 | try zig_cflags.appendSlice(&[_][]const u8{ "-I", dir }); |
| 725 | } else if (mem.startsWith(u8, tok, "-I")) { | 725 | } else if (mem.startsWith(u8, arg, "-I")) { |
| 726 | try zig_cflags.append(tok); | 726 | try zig_cflags.append(arg); |
| 727 | } else if (mem.eql(u8, tok, "-L")) { | 727 | } else if (mem.eql(u8, arg, "-L")) { |
| 728 | const dir = it.next() orelse return error.PkgConfigInvalidOutput; | 728 | const dir = arg_it.next() orelse return error.PkgConfigInvalidOutput; |
| 729 | try zig_libs.appendSlice(&[_][]const u8{ "-L", dir }); | 729 | try zig_libs.appendSlice(&[_][]const u8{ "-L", dir }); |
| 730 | } else if (mem.startsWith(u8, tok, "-L")) { | 730 | } else if (mem.startsWith(u8, arg, "-L")) { |
| 731 | try zig_libs.append(tok); | 731 | try zig_libs.append(arg); |
| 732 | } else if (mem.eql(u8, tok, "-l")) { | 732 | } else if (mem.eql(u8, arg, "-l")) { |
| 733 | const lib = it.next() orelse return error.PkgConfigInvalidOutput; | 733 | const lib = arg_it.next() orelse return error.PkgConfigInvalidOutput; |
| 734 | try zig_libs.appendSlice(&[_][]const u8{ "-l", lib }); | 734 | try zig_libs.appendSlice(&[_][]const u8{ "-l", lib }); |
| 735 | } else if (mem.startsWith(u8, tok, "-l")) { | 735 | } else if (mem.startsWith(u8, arg, "-l")) { |
| 736 | try zig_libs.append(tok); | 736 | try zig_libs.append(arg); |
| 737 | } else if (mem.eql(u8, tok, "-D")) { | 737 | } else if (mem.eql(u8, arg, "-D")) { |
| 738 | const macro = it.next() orelse return error.PkgConfigInvalidOutput; | 738 | const macro = arg_it.next() orelse return error.PkgConfigInvalidOutput; |
| 739 | try zig_cflags.appendSlice(&[_][]const u8{ "-D", macro }); | 739 | try zig_cflags.appendSlice(&[_][]const u8{ "-D", macro }); |
| 740 | } else if (mem.startsWith(u8, tok, "-D")) { | 740 | } else if (mem.startsWith(u8, arg, "-D")) { |
| 741 | try zig_cflags.append(tok); | 741 | try zig_cflags.append(arg); |
| 742 | } else if (b.debug_pkg_config) { | 742 | } else if (b.debug_pkg_config) { |
| 743 | return self.step.fail("unknown pkg-config flag '{s}'", .{tok}); | 743 | return compile.step.fail("unknown pkg-config flag '{s}'", .{arg}); |
| 744 | } | 744 | } |
| 745 | } | 745 | } |
| 746 | 746 | ||
| ... | @@ -750,16 +750,16 @@ fn runPkgConfig(self: *Compile, lib_name: []const u8) !PkgConfigResult { | ... | @@ -750,16 +750,16 @@ fn runPkgConfig(self: *Compile, lib_name: []const u8) !PkgConfigResult { |
| 750 | }; | 750 | }; |
| 751 | } | 751 | } |
| 752 | 752 | ||
| 753 | pub fn linkSystemLibrary(self: *Compile, name: []const u8) void { | 753 | pub fn linkSystemLibrary(compile: *Compile, name: []const u8) void { |
| 754 | return self.root_module.linkSystemLibrary(name, .{}); | 754 | return compile.root_module.linkSystemLibrary(name, .{}); |
| 755 | } | 755 | } |
| 756 | 756 | ||
| 757 | pub fn linkSystemLibrary2( | 757 | pub fn linkSystemLibrary2( |
| 758 | self: *Compile, | 758 | compile: *Compile, |
| 759 | name: []const u8, | 759 | name: []const u8, |
| 760 | options: Module.LinkSystemLibraryOptions, | 760 | options: Module.LinkSystemLibraryOptions, |
| 761 | ) void { | 761 | ) void { |
| 762 | return self.root_module.linkSystemLibrary(name, options); | 762 | return compile.root_module.linkSystemLibrary(name, options); |
| 763 | } | 763 | } |
| 764 | 764 | ||
| 765 | pub fn linkFramework(c: *Compile, name: []const u8) void { | 765 | pub fn linkFramework(c: *Compile, name: []const u8) void { |
| ... | @@ -777,155 +777,155 @@ pub fn linkFrameworkWeak(c: *Compile, name: []const u8) void { | ... | @@ -777,155 +777,155 @@ pub fn linkFrameworkWeak(c: *Compile, name: []const u8) void { |
| 777 | } | 777 | } |
| 778 | 778 | ||
| 779 | /// Handy when you have many C/C++ source files and want them all to have the same flags. | 779 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 780 | pub fn addCSourceFiles(self: *Compile, options: Module.AddCSourceFilesOptions) void { | 780 | pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void { |
| 781 | self.root_module.addCSourceFiles(options); | 781 | compile.root_module.addCSourceFiles(options); |
| 782 | } | 782 | } |
| 783 | 783 | ||
| 784 | pub fn addCSourceFile(self: *Compile, source: Module.CSourceFile) void { | 784 | pub fn addCSourceFile(compile: *Compile, source: Module.CSourceFile) void { |
| 785 | self.root_module.addCSourceFile(source); | 785 | compile.root_module.addCSourceFile(source); |
| 786 | } | 786 | } |
| 787 | 787 | ||
| 788 | /// Resource files must have the extension `.rc`. | 788 | /// Resource files must have the extension `.rc`. |
| 789 | /// Can be called regardless of target. The .rc file will be ignored | 789 | /// Can be called regardless of target. The .rc file will be ignored |
| 790 | /// if the target object format does not support embedded resources. | 790 | /// if the target object format does not support embedded resources. |
| 791 | pub fn addWin32ResourceFile(self: *Compile, source: Module.RcSourceFile) void { | 791 | pub fn addWin32ResourceFile(compile: *Compile, source: Module.RcSourceFile) void { |
| 792 | self.root_module.addWin32ResourceFile(source); | 792 | compile.root_module.addWin32ResourceFile(source); |
| 793 | } | 793 | } |
| 794 | 794 | ||
| 795 | pub fn setVerboseLink(self: *Compile, value: bool) void { | 795 | pub fn setVerboseLink(compile: *Compile, value: bool) void { |
| 796 | self.verbose_link = value; | 796 | compile.verbose_link = value; |
| 797 | } | 797 | } |
| 798 | 798 | ||
| 799 | pub fn setVerboseCC(self: *Compile, value: bool) void { | 799 | pub fn setVerboseCC(compile: *Compile, value: bool) void { |
| 800 | self.verbose_cc = value; | 800 | compile.verbose_cc = value; |
| 801 | } | 801 | } |
| 802 | 802 | ||
| 803 | pub fn setLibCFile(self: *Compile, libc_file: ?LazyPath) void { | 803 | pub fn setLibCFile(compile: *Compile, libc_file: ?LazyPath) void { |
| 804 | const b = self.step.owner; | 804 | const b = compile.step.owner; |
| 805 | self.libc_file = if (libc_file) |f| f.dupe(b) else null; | 805 | compile.libc_file = if (libc_file) |f| f.dupe(b) else null; |
| 806 | } | 806 | } |
| 807 | 807 | ||
| 808 | fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath { | 808 | fn getEmittedFileGeneric(compile: *Compile, output_file: *?*GeneratedFile) LazyPath { |
| 809 | if (output_file.*) |g| { | 809 | if (output_file.*) |g| { |
| 810 | return .{ .generated = g }; | 810 | return .{ .generated = g }; |
| 811 | } | 811 | } |
| 812 | const arena = self.step.owner.allocator; | 812 | const arena = compile.step.owner.allocator; |
| 813 | const generated_file = arena.create(GeneratedFile) catch @panic("OOM"); | 813 | const generated_file = arena.create(GeneratedFile) catch @panic("OOM"); |
| 814 | generated_file.* = .{ .step = &self.step }; | 814 | generated_file.* = .{ .step = &compile.step }; |
| 815 | output_file.* = generated_file; | 815 | output_file.* = generated_file; |
| 816 | return .{ .generated = generated_file }; | 816 | return .{ .generated = generated_file }; |
| 817 | } | 817 | } |
| 818 | 818 | ||
| 819 | /// Returns the path to the directory that contains the emitted binary file. | 819 | /// Returns the path to the directory that contains the emitted binary file. |
| 820 | pub fn getEmittedBinDirectory(self: *Compile) LazyPath { | 820 | pub fn getEmittedBinDirectory(compile: *Compile) LazyPath { |
| 821 | _ = self.getEmittedBin(); | 821 | _ = compile.getEmittedBin(); |
| 822 | return self.getEmittedFileGeneric(&self.emit_directory); | 822 | return compile.getEmittedFileGeneric(&compile.emit_directory); |
| 823 | } | 823 | } |
| 824 | 824 | ||
| 825 | /// Returns the path to the generated executable, library or object file. | 825 | /// Returns the path to the generated executable, library or object file. |
| 826 | /// To run an executable built with zig build, use `run`, or create an install step and invoke it. | 826 | /// To run an executable built with zig build, use `run`, or create an install step and invoke it. |
| 827 | pub fn getEmittedBin(self: *Compile) LazyPath { | 827 | pub fn getEmittedBin(compile: *Compile) LazyPath { |
| 828 | return self.getEmittedFileGeneric(&self.generated_bin); | 828 | return compile.getEmittedFileGeneric(&compile.generated_bin); |
| 829 | } | 829 | } |
| 830 | 830 | ||
| 831 | /// Returns the path to the generated import library. | 831 | /// Returns the path to the generated import library. |
| 832 | /// This function can only be called for libraries. | 832 | /// This function can only be called for libraries. |
| 833 | pub fn getEmittedImplib(self: *Compile) LazyPath { | 833 | pub fn getEmittedImplib(compile: *Compile) LazyPath { |
| 834 | assert(self.kind == .lib); | 834 | assert(compile.kind == .lib); |
| 835 | return self.getEmittedFileGeneric(&self.generated_implib); | 835 | return compile.getEmittedFileGeneric(&compile.generated_implib); |
| 836 | } | 836 | } |
| 837 | 837 | ||
| 838 | /// Returns the path to the generated header file. | 838 | /// Returns the path to the generated header file. |
| 839 | /// This function can only be called for libraries or objects. | 839 | /// This function can only be called for libraries or objects. |
| 840 | pub fn getEmittedH(self: *Compile) LazyPath { | 840 | pub fn getEmittedH(compile: *Compile) LazyPath { |
| 841 | assert(self.kind != .exe and self.kind != .@"test"); | 841 | assert(compile.kind != .exe and compile.kind != .@"test"); |
| 842 | return self.getEmittedFileGeneric(&self.generated_h); | 842 | return compile.getEmittedFileGeneric(&compile.generated_h); |
| 843 | } | 843 | } |
| 844 | 844 | ||
| 845 | /// Returns the generated PDB file. | 845 | /// Returns the generated PDB file. |
| 846 | /// If the compilation does not produce a PDB file, this causes a FileNotFound error | 846 | /// If the compilation does not produce a PDB file, this causes a FileNotFound error |
| 847 | /// at build time. | 847 | /// at build time. |
| 848 | pub fn getEmittedPdb(self: *Compile) LazyPath { | 848 | pub fn getEmittedPdb(compile: *Compile) LazyPath { |
| 849 | _ = self.getEmittedBin(); | 849 | _ = compile.getEmittedBin(); |
| 850 | return self.getEmittedFileGeneric(&self.generated_pdb); | 850 | return compile.getEmittedFileGeneric(&compile.generated_pdb); |
| 851 | } | 851 | } |
| 852 | 852 | ||
| 853 | /// Returns the path to the generated documentation directory. | 853 | /// Returns the path to the generated documentation directory. |
| 854 | pub fn getEmittedDocs(self: *Compile) LazyPath { | 854 | pub fn getEmittedDocs(compile: *Compile) LazyPath { |
| 855 | return self.getEmittedFileGeneric(&self.generated_docs); | 855 | return compile.getEmittedFileGeneric(&compile.generated_docs); |
| 856 | } | 856 | } |
| 857 | 857 | ||
| 858 | /// Returns the path to the generated assembly code. | 858 | /// Returns the path to the generated assembly code. |
| 859 | pub fn getEmittedAsm(self: *Compile) LazyPath { | 859 | pub fn getEmittedAsm(compile: *Compile) LazyPath { |
| 860 | return self.getEmittedFileGeneric(&self.generated_asm); | 860 | return compile.getEmittedFileGeneric(&compile.generated_asm); |
| 861 | } | 861 | } |
| 862 | 862 | ||
| 863 | /// Returns the path to the generated LLVM IR. | 863 | /// Returns the path to the generated LLVM IR. |
| 864 | pub fn getEmittedLlvmIr(self: *Compile) LazyPath { | 864 | pub fn getEmittedLlvmIr(compile: *Compile) LazyPath { |
| 865 | return self.getEmittedFileGeneric(&self.generated_llvm_ir); | 865 | return compile.getEmittedFileGeneric(&compile.generated_llvm_ir); |
| 866 | } | 866 | } |
| 867 | 867 | ||
| 868 | /// Returns the path to the generated LLVM BC. | 868 | /// Returns the path to the generated LLVM BC. |
| 869 | pub fn getEmittedLlvmBc(self: *Compile) LazyPath { | 869 | pub fn getEmittedLlvmBc(compile: *Compile) LazyPath { |
| 870 | return self.getEmittedFileGeneric(&self.generated_llvm_bc); | 870 | return compile.getEmittedFileGeneric(&compile.generated_llvm_bc); |
| 871 | } | 871 | } |
| 872 | 872 | ||
| 873 | pub fn addAssemblyFile(self: *Compile, source: LazyPath) void { | 873 | pub fn addAssemblyFile(compile: *Compile, source: LazyPath) void { |
| 874 | self.root_module.addAssemblyFile(source); | 874 | compile.root_module.addAssemblyFile(source); |
| 875 | } | 875 | } |
| 876 | 876 | ||
| 877 | pub fn addObjectFile(self: *Compile, source: LazyPath) void { | 877 | pub fn addObjectFile(compile: *Compile, source: LazyPath) void { |
| 878 | self.root_module.addObjectFile(source); | 878 | compile.root_module.addObjectFile(source); |
| 879 | } | 879 | } |
| 880 | 880 | ||
| 881 | pub fn addObject(self: *Compile, object: *Compile) void { | 881 | pub fn addObject(compile: *Compile, object: *Compile) void { |
| 882 | self.root_module.addObject(object); | 882 | compile.root_module.addObject(object); |
| 883 | } | 883 | } |
| 884 | 884 | ||
| 885 | pub fn linkLibrary(self: *Compile, library: *Compile) void { | 885 | pub fn linkLibrary(compile: *Compile, library: *Compile) void { |
| 886 | self.root_module.linkLibrary(library); | 886 | compile.root_module.linkLibrary(library); |
| 887 | } | 887 | } |
| 888 | 888 | ||
| 889 | pub fn addAfterIncludePath(self: *Compile, lazy_path: LazyPath) void { | 889 | pub fn addAfterIncludePath(compile: *Compile, lazy_path: LazyPath) void { |
| 890 | self.root_module.addAfterIncludePath(lazy_path); | 890 | compile.root_module.addAfterIncludePath(lazy_path); |
| 891 | } | 891 | } |
| 892 | 892 | ||
| 893 | pub fn addSystemIncludePath(self: *Compile, lazy_path: LazyPath) void { | 893 | pub fn addSystemIncludePath(compile: *Compile, lazy_path: LazyPath) void { |
| 894 | self.root_module.addSystemIncludePath(lazy_path); | 894 | compile.root_module.addSystemIncludePath(lazy_path); |
| 895 | } | 895 | } |
| 896 | 896 | ||
| 897 | pub fn addIncludePath(self: *Compile, lazy_path: LazyPath) void { | 897 | pub fn addIncludePath(compile: *Compile, lazy_path: LazyPath) void { |
| 898 | self.root_module.addIncludePath(lazy_path); | 898 | compile.root_module.addIncludePath(lazy_path); |
| 899 | } | 899 | } |
| 900 | 900 | ||
| 901 | pub fn addConfigHeader(self: *Compile, config_header: *Step.ConfigHeader) void { | 901 | pub fn addConfigHeader(compile: *Compile, config_header: *Step.ConfigHeader) void { |
| 902 | self.root_module.addConfigHeader(config_header); | 902 | compile.root_module.addConfigHeader(config_header); |
| 903 | } | 903 | } |
| 904 | 904 | ||
| 905 | pub fn addLibraryPath(self: *Compile, directory_path: LazyPath) void { | 905 | pub fn addLibraryPath(compile: *Compile, directory_path: LazyPath) void { |
| 906 | self.root_module.addLibraryPath(directory_path); | 906 | compile.root_module.addLibraryPath(directory_path); |
| 907 | } | 907 | } |
| 908 | 908 | ||
| 909 | pub fn addRPath(self: *Compile, directory_path: LazyPath) void { | 909 | pub fn addRPath(compile: *Compile, directory_path: LazyPath) void { |
| 910 | self.root_module.addRPath(directory_path); | 910 | compile.root_module.addRPath(directory_path); |
| 911 | } | 911 | } |
| 912 | 912 | ||
| 913 | pub fn addSystemFrameworkPath(self: *Compile, directory_path: LazyPath) void { | 913 | pub fn addSystemFrameworkPath(compile: *Compile, directory_path: LazyPath) void { |
| 914 | self.root_module.addSystemFrameworkPath(directory_path); | 914 | compile.root_module.addSystemFrameworkPath(directory_path); |
| 915 | } | 915 | } |
| 916 | 916 | ||
| 917 | pub fn addFrameworkPath(self: *Compile, directory_path: LazyPath) void { | 917 | pub fn addFrameworkPath(compile: *Compile, directory_path: LazyPath) void { |
| 918 | self.root_module.addFrameworkPath(directory_path); | 918 | compile.root_module.addFrameworkPath(directory_path); |
| 919 | } | 919 | } |
| 920 | 920 | ||
| 921 | pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { | 921 | pub fn setExecCmd(compile: *Compile, args: []const ?[]const u8) void { |
| 922 | const b = self.step.owner; | 922 | const b = compile.step.owner; |
| 923 | assert(self.kind == .@"test"); | 923 | assert(compile.kind == .@"test"); |
| 924 | const duped_args = b.allocator.alloc(?[]u8, args.len) catch @panic("OOM"); | 924 | const duped_args = b.allocator.alloc(?[]u8, args.len) catch @panic("OOM"); |
| 925 | for (args, 0..) |arg, i| { | 925 | for (args, 0..) |arg, i| { |
| 926 | duped_args[i] = if (arg) |a| b.dupe(a) else null; | 926 | duped_args[i] = if (arg) |a| b.dupe(a) else null; |
| 927 | } | 927 | } |
| 928 | self.exec_cmd_args = duped_args; | 928 | compile.exec_cmd_args = duped_args; |
| 929 | } | 929 | } |
| 930 | 930 | ||
| 931 | const CliNamedModules = struct { | 931 | const CliNamedModules = struct { |
| ... | @@ -937,42 +937,42 @@ const CliNamedModules = struct { | ... | @@ -937,42 +937,42 @@ const CliNamedModules = struct { |
| 937 | /// It will help here to have both a mapping from module to name and a set | 937 | /// It will help here to have both a mapping from module to name and a set |
| 938 | /// of all the currently-used names. | 938 | /// of all the currently-used names. |
| 939 | fn init(arena: Allocator, root_module: *Module) Allocator.Error!CliNamedModules { | 939 | fn init(arena: Allocator, root_module: *Module) Allocator.Error!CliNamedModules { |
| 940 | var self: CliNamedModules = .{ | 940 | var compile: CliNamedModules = .{ |
| 941 | .modules = .{}, | 941 | .modules = .{}, |
| 942 | .names = .{}, | 942 | .names = .{}, |
| 943 | }; | 943 | }; |
| 944 | var it = root_module.iterateDependencies(null, false); | 944 | var dep_it = root_module.iterateDependencies(null, false); |
| 945 | { | 945 | { |
| 946 | const item = it.next().?; | 946 | const item = dep_it.next().?; |
| 947 | assert(root_module == item.module); | 947 | assert(root_module == item.module); |
| 948 | try self.modules.put(arena, root_module, {}); | 948 | try compile.modules.put(arena, root_module, {}); |
| 949 | try self.names.put(arena, "root", {}); | 949 | try compile.names.put(arena, "root", {}); |
| 950 | } | 950 | } |
| 951 | while (it.next()) |item| { | 951 | while (dep_it.next()) |item| { |
| 952 | var name = item.name; | 952 | var name = item.name; |
| 953 | var n: usize = 0; | 953 | var n: usize = 0; |
| 954 | while (true) { | 954 | while (true) { |
| 955 | const gop = try self.names.getOrPut(arena, name); | 955 | const gop = try compile.names.getOrPut(arena, name); |
| 956 | if (!gop.found_existing) { | 956 | if (!gop.found_existing) { |
| 957 | try self.modules.putNoClobber(arena, item.module, {}); | 957 | try compile.modules.putNoClobber(arena, item.module, {}); |
| 958 | break; | 958 | break; |
| 959 | } | 959 | } |
| 960 | name = try std.fmt.allocPrint(arena, "{s}{d}", .{ item.name, n }); | 960 | name = try std.fmt.allocPrint(arena, "{s}{d}", .{ item.name, n }); |
| 961 | n += 1; | 961 | n += 1; |
| 962 | } | 962 | } |
| 963 | } | 963 | } |
| 964 | return self; | 964 | return compile; |
| 965 | } | 965 | } |
| 966 | }; | 966 | }; |
| 967 | 967 | ||
| 968 | fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_step: ?*Step) []const u8 { | 968 | fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking_step: ?*Step) []const u8 { |
| 969 | const maybe_path: ?*GeneratedFile = @field(self, tag_name); | 969 | const maybe_path: ?*GeneratedFile = @field(compile, tag_name); |
| 970 | 970 | ||
| 971 | const generated_file = maybe_path orelse { | 971 | const generated_file = maybe_path orelse { |
| 972 | std.debug.getStderrMutex().lock(); | 972 | std.debug.getStderrMutex().lock(); |
| 973 | const stderr = std.io.getStdErr(); | 973 | const stderr = std.io.getStdErr(); |
| 974 | 974 | ||
| 975 | std.Build.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, asking_step) catch {}; | 975 | std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {}; |
| 976 | 976 | ||
| 977 | @panic("missing emit option for " ++ tag_name); | 977 | @panic("missing emit option for " ++ tag_name); |
| 978 | }; | 978 | }; |
| ... | @@ -981,7 +981,7 @@ fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_st | ... | @@ -981,7 +981,7 @@ fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_st |
| 981 | std.debug.getStderrMutex().lock(); | 981 | std.debug.getStderrMutex().lock(); |
| 982 | const stderr = std.io.getStdErr(); | 982 | const stderr = std.io.getStdErr(); |
| 983 | 983 | ||
| 984 | std.Build.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, asking_step) catch {}; | 984 | std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {}; |
| 985 | 985 | ||
| 986 | @panic(tag_name ++ " is null. Is there a missing step dependency?"); | 986 | @panic(tag_name ++ " is null. Is there a missing step dependency?"); |
| 987 | }; | 987 | }; |
| ... | @@ -992,14 +992,14 @@ fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_st | ... | @@ -992,14 +992,14 @@ fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_st |
| 992 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 992 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 993 | const b = step.owner; | 993 | const b = step.owner; |
| 994 | const arena = b.allocator; | 994 | const arena = b.allocator; |
| 995 | const self: *Compile = @fieldParentPtr("step", step); | 995 | const compile: *Compile = @fieldParentPtr("step", step); |
| 996 | 996 | ||
| 997 | var zig_args = ArrayList([]const u8).init(arena); | 997 | var zig_args = ArrayList([]const u8).init(arena); |
| 998 | defer zig_args.deinit(); | 998 | defer zig_args.deinit(); |
| 999 | 999 | ||
| 1000 | try zig_args.append(b.graph.zig_exe); | 1000 | try zig_args.append(b.graph.zig_exe); |
| 1001 | 1001 | ||
| 1002 | const cmd = switch (self.kind) { | 1002 | const cmd = switch (compile.kind) { |
| 1003 | .lib => "build-lib", | 1003 | .lib => "build-lib", |
| 1004 | .exe => "build-exe", | 1004 | .exe => "build-exe", |
| 1005 | .obj => "build-obj", | 1005 | .obj => "build-obj", |
| ... | @@ -1011,14 +1011,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1011,14 +1011,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1011 | try zig_args.append(try std.fmt.allocPrint(arena, "-freference-trace={d}", .{some})); | 1011 | try zig_args.append(try std.fmt.allocPrint(arena, "-freference-trace={d}", .{some})); |
| 1012 | } | 1012 | } |
| 1013 | 1013 | ||
| 1014 | try addFlag(&zig_args, "llvm", self.use_llvm); | 1014 | try addFlag(&zig_args, "llvm", compile.use_llvm); |
| 1015 | try addFlag(&zig_args, "lld", self.use_lld); | 1015 | try addFlag(&zig_args, "lld", compile.use_lld); |
| 1016 | 1016 | ||
| 1017 | if (self.root_module.resolved_target.?.query.ofmt) |ofmt| { | 1017 | if (compile.root_module.resolved_target.?.query.ofmt) |ofmt| { |
| 1018 | try zig_args.append(try std.fmt.allocPrint(arena, "-ofmt={s}", .{@tagName(ofmt)})); | 1018 | try zig_args.append(try std.fmt.allocPrint(arena, "-ofmt={s}", .{@tagName(ofmt)})); |
| 1019 | } | 1019 | } |
| 1020 | 1020 | ||
| 1021 | switch (self.entry) { | 1021 | switch (compile.entry) { |
| 1022 | .default => {}, | 1022 | .default => {}, |
| 1023 | .disabled => try zig_args.append("-fno-entry"), | 1023 | .disabled => try zig_args.append("-fno-entry"), |
| 1024 | .enabled => try zig_args.append("-fentry"), | 1024 | .enabled => try zig_args.append("-fentry"), |
| ... | @@ -1028,14 +1028,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1028,14 +1028,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1028 | } | 1028 | } |
| 1029 | 1029 | ||
| 1030 | { | 1030 | { |
| 1031 | var it = self.force_undefined_symbols.keyIterator(); | 1031 | var symbol_it = compile.force_undefined_symbols.keyIterator(); |
| 1032 | while (it.next()) |symbol_name| { | 1032 | while (symbol_it.next()) |symbol_name| { |
| 1033 | try zig_args.append("--force_undefined"); | 1033 | try zig_args.append("--force_undefined"); |
| 1034 | try zig_args.append(symbol_name.*); | 1034 | try zig_args.append(symbol_name.*); |
| 1035 | } | 1035 | } |
| 1036 | } | 1036 | } |
| 1037 | 1037 | ||
| 1038 | if (self.stack_size) |stack_size| { | 1038 | if (compile.stack_size) |stack_size| { |
| 1039 | try zig_args.append("--stack"); | 1039 | try zig_args.append("--stack"); |
| 1040 | try zig_args.append(try std.fmt.allocPrint(arena, "{}", .{stack_size})); | 1040 | try zig_args.append(try std.fmt.allocPrint(arena, "{}", .{stack_size})); |
| 1041 | } | 1041 | } |
| ... | @@ -1053,47 +1053,44 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1053,47 +1053,44 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1053 | var prev_preferred_link_mode: std.builtin.LinkMode = .dynamic; | 1053 | var prev_preferred_link_mode: std.builtin.LinkMode = .dynamic; |
| 1054 | // Track the number of positional arguments so that a nice error can be | 1054 | // Track the number of positional arguments so that a nice error can be |
| 1055 | // emitted if there is nothing to link. | 1055 | // emitted if there is nothing to link. |
| 1056 | var total_linker_objects: usize = @intFromBool(self.root_module.root_source_file != null); | 1056 | var total_linker_objects: usize = @intFromBool(compile.root_module.root_source_file != null); |
| 1057 | 1057 | ||
| 1058 | { | 1058 | { |
| 1059 | // Fully recursive iteration including dynamic libraries to detect | 1059 | // Fully recursive iteration including dynamic libraries to detect |
| 1060 | // libc and libc++ linkage. | 1060 | // libc and libc++ linkage. |
| 1061 | var it = self.root_module.iterateDependencies(self, true); | 1061 | var dep_it = compile.root_module.iterateDependencies(compile, true); |
| 1062 | while (it.next()) |key| { | 1062 | while (dep_it.next()) |key| { |
| 1063 | if (key.module.link_libc == true) self.is_linking_libc = true; | 1063 | if (key.module.link_libc == true) compile.is_linking_libc = true; |
| 1064 | if (key.module.link_libcpp == true) self.is_linking_libcpp = true; | 1064 | if (key.module.link_libcpp == true) compile.is_linking_libcpp = true; |
| 1065 | } | 1065 | } |
| 1066 | } | 1066 | } |
| 1067 | 1067 | ||
| 1068 | var cli_named_modules = try CliNamedModules.init(arena, &self.root_module); | 1068 | var cli_named_modules = try CliNamedModules.init(arena, &compile.root_module); |
| 1069 | 1069 | ||
| 1070 | // For this loop, don't chase dynamic libraries because their link | 1070 | // For this loop, don't chase dynamic libraries because their link |
| 1071 | // objects are already linked. | 1071 | // objects are already linked. |
| 1072 | var it = self.root_module.iterateDependencies(self, false); | 1072 | var dep_it = compile.root_module.iterateDependencies(compile, false); |
| 1073 | |||
| 1074 | while (it.next()) |key| { | ||
| 1075 | const module = key.module; | ||
| 1076 | const compile = key.compile.?; | ||
| 1077 | 1073 | ||
| 1074 | while (dep_it.next()) |dep| { | ||
| 1078 | // While walking transitive dependencies, if a given link object is | 1075 | // While walking transitive dependencies, if a given link object is |
| 1079 | // already included in a library, it should not redundantly be | 1076 | // already included in a library, it should not redundantly be |
| 1080 | // placed on the linker line of the dependee. | 1077 | // placed on the linker line of the dependee. |
| 1081 | const my_responsibility = compile == self; | 1078 | const my_responsibility = dep.compile.? == compile; |
| 1082 | const already_linked = !my_responsibility and compile.isDynamicLibrary(); | 1079 | const already_linked = !my_responsibility and dep.compile.?.isDynamicLibrary(); |
| 1083 | 1080 | ||
| 1084 | // Inherit dependencies on darwin frameworks. | 1081 | // Inherit dependencies on darwin frameworks. |
| 1085 | if (!already_linked) { | 1082 | if (!already_linked) { |
| 1086 | for (module.frameworks.keys(), module.frameworks.values()) |name, info| { | 1083 | for (dep.module.frameworks.keys(), dep.module.frameworks.values()) |name, info| { |
| 1087 | try frameworks.put(arena, name, info); | 1084 | try frameworks.put(arena, name, info); |
| 1088 | } | 1085 | } |
| 1089 | } | 1086 | } |
| 1090 | 1087 | ||
| 1091 | // Inherit dependencies on system libraries and static libraries. | 1088 | // Inherit dependencies on system libraries and static libraries. |
| 1092 | for (module.link_objects.items) |link_object| { | 1089 | for (dep.module.link_objects.items) |link_object| { |
| 1093 | switch (link_object) { | 1090 | switch (link_object) { |
| 1094 | .static_path => |static_path| { | 1091 | .static_path => |static_path| { |
| 1095 | if (my_responsibility) { | 1092 | if (my_responsibility) { |
| 1096 | try zig_args.append(static_path.getPath2(module.owner, step)); | 1093 | try zig_args.append(static_path.getPath2(dep.module.owner, step)); |
| 1097 | total_linker_objects += 1; | 1094 | total_linker_objects += 1; |
| 1098 | } | 1095 | } |
| 1099 | }, | 1096 | }, |
| ... | @@ -1111,7 +1108,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1111,7 +1108,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1111 | 1108 | ||
| 1112 | if ((system_lib.search_strategy != prev_search_strategy or | 1109 | if ((system_lib.search_strategy != prev_search_strategy or |
| 1113 | system_lib.preferred_link_mode != prev_preferred_link_mode) and | 1110 | system_lib.preferred_link_mode != prev_preferred_link_mode) and |
| 1114 | self.linkage != .static) | 1111 | compile.linkage != .static) |
| 1115 | { | 1112 | { |
| 1116 | switch (system_lib.search_strategy) { | 1113 | switch (system_lib.search_strategy) { |
| 1117 | .no_fallback => switch (system_lib.preferred_link_mode) { | 1114 | .no_fallback => switch (system_lib.preferred_link_mode) { |
| ... | @@ -1139,7 +1136,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1139,7 +1136,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1139 | switch (system_lib.use_pkg_config) { | 1136 | switch (system_lib.use_pkg_config) { |
| 1140 | .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), | 1137 | .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), |
| 1141 | .yes, .force => { | 1138 | .yes, .force => { |
| 1142 | if (self.runPkgConfig(system_lib.name)) |result| { | 1139 | if (compile.runPkgConfig(system_lib.name)) |result| { |
| 1143 | try zig_args.appendSlice(result.cflags); | 1140 | try zig_args.appendSlice(result.cflags); |
| 1144 | try zig_args.appendSlice(result.libs); | 1141 | try zig_args.appendSlice(result.libs); |
| 1145 | try seen_system_libs.put(arena, system_lib.name, result.cflags); | 1142 | try seen_system_libs.put(arena, system_lib.name, result.cflags); |
| ... | @@ -1174,9 +1171,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1174,9 +1171,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1174 | .exe => return step.fail("cannot link with an executable build artifact", .{}), | 1171 | .exe => return step.fail("cannot link with an executable build artifact", .{}), |
| 1175 | .@"test" => return step.fail("cannot link with a test", .{}), | 1172 | .@"test" => return step.fail("cannot link with a test", .{}), |
| 1176 | .obj => { | 1173 | .obj => { |
| 1177 | const included_in_lib_or_obj = !my_responsibility and (compile.kind == .lib or compile.kind == .obj); | 1174 | const included_in_lib_or_obj = !my_responsibility and |
| 1175 | (dep.compile.?.kind == .lib or dep.compile.?.kind == .obj); | ||
| 1178 | if (!already_linked and !included_in_lib_or_obj) { | 1176 | if (!already_linked and !included_in_lib_or_obj) { |
| 1179 | try zig_args.append(other.getEmittedBin().getPath(b)); | 1177 | try zig_args.append(other.getEmittedBin().getPath2(b, step)); |
| 1180 | total_linker_objects += 1; | 1178 | total_linker_objects += 1; |
| 1181 | } | 1179 | } |
| 1182 | }, | 1180 | }, |
| ... | @@ -1184,7 +1182,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1184,7 +1182,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1184 | const other_produces_implib = other.producesImplib(); | 1182 | const other_produces_implib = other.producesImplib(); |
| 1185 | const other_is_static = other_produces_implib or other.isStaticLibrary(); | 1183 | const other_is_static = other_produces_implib or other.isStaticLibrary(); |
| 1186 | 1184 | ||
| 1187 | if (self.isStaticLibrary() and other_is_static) { | 1185 | if (compile.isStaticLibrary() and other_is_static) { |
| 1188 | // Avoid putting a static library inside a static library. | 1186 | // Avoid putting a static library inside a static library. |
| 1189 | break :l; | 1187 | break :l; |
| 1190 | } | 1188 | } |
| ... | @@ -1193,15 +1191,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1193,15 +1191,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1193 | // For everything else, we directly link | 1191 | // For everything else, we directly link |
| 1194 | // against the library file. | 1192 | // against the library file. |
| 1195 | const full_path_lib = if (other_produces_implib) | 1193 | const full_path_lib = if (other_produces_implib) |
| 1196 | other.getGeneratedFilePath("generated_implib", &self.step) | 1194 | other.getGeneratedFilePath("generated_implib", &compile.step) |
| 1197 | else | 1195 | else |
| 1198 | other.getGeneratedFilePath("generated_bin", &self.step); | 1196 | other.getGeneratedFilePath("generated_bin", &compile.step); |
| 1199 | 1197 | ||
| 1200 | try zig_args.append(full_path_lib); | 1198 | try zig_args.append(full_path_lib); |
| 1201 | total_linker_objects += 1; | 1199 | total_linker_objects += 1; |
| 1202 | 1200 | ||
| 1203 | if (other.linkage == .dynamic and | 1201 | if (other.linkage == .dynamic and |
| 1204 | self.rootModuleTarget().os.tag != .windows) | 1202 | compile.rootModuleTarget().os.tag != .windows) |
| 1205 | { | 1203 | { |
| 1206 | if (fs.path.dirname(full_path_lib)) |dirname| { | 1204 | if (fs.path.dirname(full_path_lib)) |dirname| { |
| 1207 | try zig_args.append("-rpath"); | 1205 | try zig_args.append("-rpath"); |
| ... | @@ -1219,7 +1217,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1219,7 +1217,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1219 | try zig_args.append("--"); | 1217 | try zig_args.append("--"); |
| 1220 | prev_has_cflags = false; | 1218 | prev_has_cflags = false; |
| 1221 | } | 1219 | } |
| 1222 | try zig_args.append(asm_file.getPath2(module.owner, step)); | 1220 | try zig_args.append(asm_file.getPath2(dep.module.owner, step)); |
| 1223 | total_linker_objects += 1; | 1221 | total_linker_objects += 1; |
| 1224 | }, | 1222 | }, |
| 1225 | 1223 | ||
| ... | @@ -1240,7 +1238,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1240,7 +1238,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1240 | try zig_args.append("--"); | 1238 | try zig_args.append("--"); |
| 1241 | prev_has_cflags = true; | 1239 | prev_has_cflags = true; |
| 1242 | } | 1240 | } |
| 1243 | try zig_args.append(c_source_file.file.getPath2(module.owner, step)); | 1241 | try zig_args.append(c_source_file.file.getPath2(dep.module.owner, step)); |
| 1244 | total_linker_objects += 1; | 1242 | total_linker_objects += 1; |
| 1245 | }, | 1243 | }, |
| 1246 | 1244 | ||
| ... | @@ -1262,7 +1260,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1262,7 +1260,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1262 | prev_has_cflags = true; | 1260 | prev_has_cflags = true; |
| 1263 | } | 1261 | } |
| 1264 | 1262 | ||
| 1265 | const root_path = c_source_files.root.getPath2(module.owner, step); | 1263 | const root_path = c_source_files.root.getPath2(dep.module.owner, step); |
| 1266 | for (c_source_files.files) |file| { | 1264 | for (c_source_files.files) |file| { |
| 1267 | try zig_args.append(b.pathJoin(&.{ root_path, file })); | 1265 | try zig_args.append(b.pathJoin(&.{ root_path, file })); |
| 1268 | } | 1266 | } |
| ... | @@ -1286,12 +1284,12 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1286,12 +1284,12 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1286 | } | 1284 | } |
| 1287 | for (rc_source_file.include_paths) |include_path| { | 1285 | for (rc_source_file.include_paths) |include_path| { |
| 1288 | try zig_args.append("/I"); | 1286 | try zig_args.append("/I"); |
| 1289 | try zig_args.append(include_path.getPath2(module.owner, step)); | 1287 | try zig_args.append(include_path.getPath2(dep.module.owner, step)); |
| 1290 | } | 1288 | } |
| 1291 | try zig_args.append("--"); | 1289 | try zig_args.append("--"); |
| 1292 | prev_has_rcflags = true; | 1290 | prev_has_rcflags = true; |
| 1293 | } | 1291 | } |
| 1294 | try zig_args.append(rc_source_file.file.getPath2(module.owner, step)); | 1292 | try zig_args.append(rc_source_file.file.getPath2(dep.module.owner, step)); |
| 1295 | total_linker_objects += 1; | 1293 | total_linker_objects += 1; |
| 1296 | }, | 1294 | }, |
| 1297 | } | 1295 | } |
| ... | @@ -1300,20 +1298,20 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1300,20 +1298,20 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1300 | // We need to emit the --mod argument here so that the above link objects | 1298 | // We need to emit the --mod argument here so that the above link objects |
| 1301 | // have the correct parent module, but only if the module is part of | 1299 | // have the correct parent module, but only if the module is part of |
| 1302 | // this compilation. | 1300 | // this compilation. |
| 1303 | if (cli_named_modules.modules.getIndex(module)) |module_cli_index| { | 1301 | if (cli_named_modules.modules.getIndex(dep.module)) |module_cli_index| { |
| 1304 | const module_cli_name = cli_named_modules.names.keys()[module_cli_index]; | 1302 | const module_cli_name = cli_named_modules.names.keys()[module_cli_index]; |
| 1305 | try module.appendZigProcessFlags(&zig_args, step); | 1303 | try dep.module.appendZigProcessFlags(&zig_args, step); |
| 1306 | 1304 | ||
| 1307 | // --dep arguments | 1305 | // --dep arguments |
| 1308 | try zig_args.ensureUnusedCapacity(module.import_table.count() * 2); | 1306 | try zig_args.ensureUnusedCapacity(dep.module.import_table.count() * 2); |
| 1309 | for (module.import_table.keys(), module.import_table.values()) |name, dep| { | 1307 | for (dep.module.import_table.keys(), dep.module.import_table.values()) |name, import| { |
| 1310 | const dep_index = cli_named_modules.modules.getIndex(dep).?; | 1308 | const import_index = cli_named_modules.modules.getIndex(import).?; |
| 1311 | const dep_cli_name = cli_named_modules.names.keys()[dep_index]; | 1309 | const import_cli_name = cli_named_modules.names.keys()[import_index]; |
| 1312 | zig_args.appendAssumeCapacity("--dep"); | 1310 | zig_args.appendAssumeCapacity("--dep"); |
| 1313 | if (std.mem.eql(u8, dep_cli_name, name)) { | 1311 | if (std.mem.eql(u8, import_cli_name, name)) { |
| 1314 | zig_args.appendAssumeCapacity(dep_cli_name); | 1312 | zig_args.appendAssumeCapacity(import_cli_name); |
| 1315 | } else { | 1313 | } else { |
| 1316 | zig_args.appendAssumeCapacity(b.fmt("{s}={s}", .{ name, dep_cli_name })); | 1314 | zig_args.appendAssumeCapacity(b.fmt("{s}={s}", .{ name, import_cli_name })); |
| 1317 | } | 1315 | } |
| 1318 | } | 1316 | } |
| 1319 | 1317 | ||
| ... | @@ -1324,10 +1322,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1324,10 +1322,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1324 | // perhaps a set of linker objects, or C source files instead. | 1322 | // perhaps a set of linker objects, or C source files instead. |
| 1325 | // Linker objects are added to the CLI globally, while C source | 1323 | // Linker objects are added to the CLI globally, while C source |
| 1326 | // files must have a module parent. | 1324 | // files must have a module parent. |
| 1327 | if (module.root_source_file) |lp| { | 1325 | if (dep.module.root_source_file) |lp| { |
| 1328 | const src = lp.getPath2(module.owner, step); | 1326 | const src = lp.getPath2(dep.module.owner, step); |
| 1329 | try zig_args.append(b.fmt("-M{s}={s}", .{ module_cli_name, src })); | 1327 | try zig_args.append(b.fmt("-M{s}={s}", .{ module_cli_name, src })); |
| 1330 | } else if (moduleNeedsCliArg(module)) { | 1328 | } else if (moduleNeedsCliArg(dep.module)) { |
| 1331 | try zig_args.append(b.fmt("-M{s}", .{module_cli_name})); | 1329 | try zig_args.append(b.fmt("-M{s}", .{module_cli_name})); |
| 1332 | } | 1330 | } |
| 1333 | } | 1331 | } |
| ... | @@ -1348,32 +1346,32 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1348,32 +1346,32 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1348 | try zig_args.append(name); | 1346 | try zig_args.append(name); |
| 1349 | } | 1347 | } |
| 1350 | 1348 | ||
| 1351 | if (self.is_linking_libcpp) { | 1349 | if (compile.is_linking_libcpp) { |
| 1352 | try zig_args.append("-lc++"); | 1350 | try zig_args.append("-lc++"); |
| 1353 | } | 1351 | } |
| 1354 | 1352 | ||
| 1355 | if (self.is_linking_libc) { | 1353 | if (compile.is_linking_libc) { |
| 1356 | try zig_args.append("-lc"); | 1354 | try zig_args.append("-lc"); |
| 1357 | } | 1355 | } |
| 1358 | } | 1356 | } |
| 1359 | 1357 | ||
| 1360 | if (self.win32_manifest) |manifest_file| { | 1358 | if (compile.win32_manifest) |manifest_file| { |
| 1361 | try zig_args.append(manifest_file.getPath(b)); | 1359 | try zig_args.append(manifest_file.getPath2(b, step)); |
| 1362 | } | 1360 | } |
| 1363 | 1361 | ||
| 1364 | if (self.image_base) |image_base| { | 1362 | if (compile.image_base) |image_base| { |
| 1365 | try zig_args.append("--image-base"); | 1363 | try zig_args.append("--image-base"); |
| 1366 | try zig_args.append(b.fmt("0x{x}", .{image_base})); | 1364 | try zig_args.append(b.fmt("0x{x}", .{image_base})); |
| 1367 | } | 1365 | } |
| 1368 | 1366 | ||
| 1369 | for (self.filters) |filter| { | 1367 | for (compile.filters) |filter| { |
| 1370 | try zig_args.append("--test-filter"); | 1368 | try zig_args.append("--test-filter"); |
| 1371 | try zig_args.append(filter); | 1369 | try zig_args.append(filter); |
| 1372 | } | 1370 | } |
| 1373 | 1371 | ||
| 1374 | if (self.test_runner) |test_runner| { | 1372 | if (compile.test_runner) |test_runner| { |
| 1375 | try zig_args.append("--test-runner"); | 1373 | try zig_args.append("--test-runner"); |
| 1376 | try zig_args.append(test_runner.getPath(b)); | 1374 | try zig_args.append(test_runner.getPath2(b, step)); |
| 1377 | } | 1375 | } |
| 1378 | 1376 | ||
| 1379 | for (b.debug_log_scopes) |log_scope| { | 1377 | for (b.debug_log_scopes) |log_scope| { |
| ... | @@ -1389,71 +1387,71 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1389,71 +1387,71 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1389 | if (b.verbose_air) try zig_args.append("--verbose-air"); | 1387 | if (b.verbose_air) try zig_args.append("--verbose-air"); |
| 1390 | if (b.verbose_llvm_ir) |path| try zig_args.append(b.fmt("--verbose-llvm-ir={s}", .{path})); | 1388 | if (b.verbose_llvm_ir) |path| try zig_args.append(b.fmt("--verbose-llvm-ir={s}", .{path})); |
| 1391 | if (b.verbose_llvm_bc) |path| try zig_args.append(b.fmt("--verbose-llvm-bc={s}", .{path})); | 1389 | if (b.verbose_llvm_bc) |path| try zig_args.append(b.fmt("--verbose-llvm-bc={s}", .{path})); |
| 1392 | if (b.verbose_link or self.verbose_link) try zig_args.append("--verbose-link"); | 1390 | if (b.verbose_link or compile.verbose_link) try zig_args.append("--verbose-link"); |
| 1393 | if (b.verbose_cc or self.verbose_cc) try zig_args.append("--verbose-cc"); | 1391 | if (b.verbose_cc or compile.verbose_cc) try zig_args.append("--verbose-cc"); |
| 1394 | if (b.verbose_llvm_cpu_features) try zig_args.append("--verbose-llvm-cpu-features"); | 1392 | if (b.verbose_llvm_cpu_features) try zig_args.append("--verbose-llvm-cpu-features"); |
| 1395 | 1393 | ||
| 1396 | if (self.generated_asm != null) try zig_args.append("-femit-asm"); | 1394 | if (compile.generated_asm != null) try zig_args.append("-femit-asm"); |
| 1397 | if (self.generated_bin == null) try zig_args.append("-fno-emit-bin"); | 1395 | if (compile.generated_bin == null) try zig_args.append("-fno-emit-bin"); |
| 1398 | if (self.generated_docs != null) try zig_args.append("-femit-docs"); | 1396 | if (compile.generated_docs != null) try zig_args.append("-femit-docs"); |
| 1399 | if (self.generated_implib != null) try zig_args.append("-femit-implib"); | 1397 | if (compile.generated_implib != null) try zig_args.append("-femit-implib"); |
| 1400 | if (self.generated_llvm_bc != null) try zig_args.append("-femit-llvm-bc"); | 1398 | if (compile.generated_llvm_bc != null) try zig_args.append("-femit-llvm-bc"); |
| 1401 | if (self.generated_llvm_ir != null) try zig_args.append("-femit-llvm-ir"); | 1399 | if (compile.generated_llvm_ir != null) try zig_args.append("-femit-llvm-ir"); |
| 1402 | if (self.generated_h != null) try zig_args.append("-femit-h"); | 1400 | if (compile.generated_h != null) try zig_args.append("-femit-h"); |
| 1403 | 1401 | ||
| 1404 | try addFlag(&zig_args, "formatted-panics", self.formatted_panics); | 1402 | try addFlag(&zig_args, "formatted-panics", compile.formatted_panics); |
| 1405 | 1403 | ||
| 1406 | switch (self.compress_debug_sections) { | 1404 | switch (compile.compress_debug_sections) { |
| 1407 | .none => {}, | 1405 | .none => {}, |
| 1408 | .zlib => try zig_args.append("--compress-debug-sections=zlib"), | 1406 | .zlib => try zig_args.append("--compress-debug-sections=zlib"), |
| 1409 | .zstd => try zig_args.append("--compress-debug-sections=zstd"), | 1407 | .zstd => try zig_args.append("--compress-debug-sections=zstd"), |
| 1410 | } | 1408 | } |
| 1411 | 1409 | ||
| 1412 | if (self.link_eh_frame_hdr) { | 1410 | if (compile.link_eh_frame_hdr) { |
| 1413 | try zig_args.append("--eh-frame-hdr"); | 1411 | try zig_args.append("--eh-frame-hdr"); |
| 1414 | } | 1412 | } |
| 1415 | if (self.link_emit_relocs) { | 1413 | if (compile.link_emit_relocs) { |
| 1416 | try zig_args.append("--emit-relocs"); | 1414 | try zig_args.append("--emit-relocs"); |
| 1417 | } | 1415 | } |
| 1418 | if (self.link_function_sections) { | 1416 | if (compile.link_function_sections) { |
| 1419 | try zig_args.append("-ffunction-sections"); | 1417 | try zig_args.append("-ffunction-sections"); |
| 1420 | } | 1418 | } |
| 1421 | if (self.link_data_sections) { | 1419 | if (compile.link_data_sections) { |
| 1422 | try zig_args.append("-fdata-sections"); | 1420 | try zig_args.append("-fdata-sections"); |
| 1423 | } | 1421 | } |
| 1424 | if (self.link_gc_sections) |x| { | 1422 | if (compile.link_gc_sections) |x| { |
| 1425 | try zig_args.append(if (x) "--gc-sections" else "--no-gc-sections"); | 1423 | try zig_args.append(if (x) "--gc-sections" else "--no-gc-sections"); |
| 1426 | } | 1424 | } |
| 1427 | if (!self.linker_dynamicbase) { | 1425 | if (!compile.linker_dynamicbase) { |
| 1428 | try zig_args.append("--no-dynamicbase"); | 1426 | try zig_args.append("--no-dynamicbase"); |
| 1429 | } | 1427 | } |
| 1430 | if (self.linker_allow_shlib_undefined) |x| { | 1428 | if (compile.linker_allow_shlib_undefined) |x| { |
| 1431 | try zig_args.append(if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined"); | 1429 | try zig_args.append(if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined"); |
| 1432 | } | 1430 | } |
| 1433 | if (self.link_z_notext) { | 1431 | if (compile.link_z_notext) { |
| 1434 | try zig_args.append("-z"); | 1432 | try zig_args.append("-z"); |
| 1435 | try zig_args.append("notext"); | 1433 | try zig_args.append("notext"); |
| 1436 | } | 1434 | } |
| 1437 | if (!self.link_z_relro) { | 1435 | if (!compile.link_z_relro) { |
| 1438 | try zig_args.append("-z"); | 1436 | try zig_args.append("-z"); |
| 1439 | try zig_args.append("norelro"); | 1437 | try zig_args.append("norelro"); |
| 1440 | } | 1438 | } |
| 1441 | if (self.link_z_lazy) { | 1439 | if (compile.link_z_lazy) { |
| 1442 | try zig_args.append("-z"); | 1440 | try zig_args.append("-z"); |
| 1443 | try zig_args.append("lazy"); | 1441 | try zig_args.append("lazy"); |
| 1444 | } | 1442 | } |
| 1445 | if (self.link_z_common_page_size) |size| { | 1443 | if (compile.link_z_common_page_size) |size| { |
| 1446 | try zig_args.append("-z"); | 1444 | try zig_args.append("-z"); |
| 1447 | try zig_args.append(b.fmt("common-page-size={d}", .{size})); | 1445 | try zig_args.append(b.fmt("common-page-size={d}", .{size})); |
| 1448 | } | 1446 | } |
| 1449 | if (self.link_z_max_page_size) |size| { | 1447 | if (compile.link_z_max_page_size) |size| { |
| 1450 | try zig_args.append("-z"); | 1448 | try zig_args.append("-z"); |
| 1451 | try zig_args.append(b.fmt("max-page-size={d}", .{size})); | 1449 | try zig_args.append(b.fmt("max-page-size={d}", .{size})); |
| 1452 | } | 1450 | } |
| 1453 | 1451 | ||
| 1454 | if (self.libc_file) |libc_file| { | 1452 | if (compile.libc_file) |libc_file| { |
| 1455 | try zig_args.append("--libc"); | 1453 | try zig_args.append("--libc"); |
| 1456 | try zig_args.append(libc_file.getPath(b)); | 1454 | try zig_args.append(libc_file.getPath2(b, step)); |
| 1457 | } else if (b.libc_file) |libc_file| { | 1455 | } else if (b.libc_file) |libc_file| { |
| 1458 | try zig_args.append("--libc"); | 1456 | try zig_args.append("--libc"); |
| 1459 | try zig_args.append(libc_file); | 1457 | try zig_args.append(libc_file); |
| ... | @@ -1466,105 +1464,105 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1466,105 +1464,105 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1466 | try zig_args.append(b.graph.global_cache_root.path orelse "."); | 1464 | try zig_args.append(b.graph.global_cache_root.path orelse "."); |
| 1467 | 1465 | ||
| 1468 | try zig_args.append("--name"); | 1466 | try zig_args.append("--name"); |
| 1469 | try zig_args.append(self.name); | 1467 | try zig_args.append(compile.name); |
| 1470 | 1468 | ||
| 1471 | if (self.linkage) |some| switch (some) { | 1469 | if (compile.linkage) |some| switch (some) { |
| 1472 | .dynamic => try zig_args.append("-dynamic"), | 1470 | .dynamic => try zig_args.append("-dynamic"), |
| 1473 | .static => try zig_args.append("-static"), | 1471 | .static => try zig_args.append("-static"), |
| 1474 | }; | 1472 | }; |
| 1475 | if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic) { | 1473 | if (compile.kind == .lib and compile.linkage != null and compile.linkage.? == .dynamic) { |
| 1476 | if (self.version) |version| { | 1474 | if (compile.version) |version| { |
| 1477 | try zig_args.append("--version"); | 1475 | try zig_args.append("--version"); |
| 1478 | try zig_args.append(b.fmt("{}", .{version})); | 1476 | try zig_args.append(b.fmt("{}", .{version})); |
| 1479 | } | 1477 | } |
| 1480 | 1478 | ||
| 1481 | if (self.rootModuleTarget().isDarwin()) { | 1479 | if (compile.rootModuleTarget().isDarwin()) { |
| 1482 | const install_name = self.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{ | 1480 | const install_name = compile.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{ |
| 1483 | self.rootModuleTarget().libPrefix(), | 1481 | compile.rootModuleTarget().libPrefix(), |
| 1484 | self.name, | 1482 | compile.name, |
| 1485 | self.rootModuleTarget().dynamicLibSuffix(), | 1483 | compile.rootModuleTarget().dynamicLibSuffix(), |
| 1486 | }); | 1484 | }); |
| 1487 | try zig_args.append("-install_name"); | 1485 | try zig_args.append("-install_name"); |
| 1488 | try zig_args.append(install_name); | 1486 | try zig_args.append(install_name); |
| 1489 | } | 1487 | } |
| 1490 | } | 1488 | } |
| 1491 | 1489 | ||
| 1492 | if (self.entitlements) |entitlements| { | 1490 | if (compile.entitlements) |entitlements| { |
| 1493 | try zig_args.appendSlice(&[_][]const u8{ "--entitlements", entitlements }); | 1491 | try zig_args.appendSlice(&[_][]const u8{ "--entitlements", entitlements }); |
| 1494 | } | 1492 | } |
| 1495 | if (self.pagezero_size) |pagezero_size| { | 1493 | if (compile.pagezero_size) |pagezero_size| { |
| 1496 | const size = try std.fmt.allocPrint(arena, "{x}", .{pagezero_size}); | 1494 | const size = try std.fmt.allocPrint(arena, "{x}", .{pagezero_size}); |
| 1497 | try zig_args.appendSlice(&[_][]const u8{ "-pagezero_size", size }); | 1495 | try zig_args.appendSlice(&[_][]const u8{ "-pagezero_size", size }); |
| 1498 | } | 1496 | } |
| 1499 | if (self.headerpad_size) |headerpad_size| { | 1497 | if (compile.headerpad_size) |headerpad_size| { |
| 1500 | const size = try std.fmt.allocPrint(arena, "{x}", .{headerpad_size}); | 1498 | const size = try std.fmt.allocPrint(arena, "{x}", .{headerpad_size}); |
| 1501 | try zig_args.appendSlice(&[_][]const u8{ "-headerpad", size }); | 1499 | try zig_args.appendSlice(&[_][]const u8{ "-headerpad", size }); |
| 1502 | } | 1500 | } |
| 1503 | if (self.headerpad_max_install_names) { | 1501 | if (compile.headerpad_max_install_names) { |
| 1504 | try zig_args.append("-headerpad_max_install_names"); | 1502 | try zig_args.append("-headerpad_max_install_names"); |
| 1505 | } | 1503 | } |
| 1506 | if (self.dead_strip_dylibs) { | 1504 | if (compile.dead_strip_dylibs) { |
| 1507 | try zig_args.append("-dead_strip_dylibs"); | 1505 | try zig_args.append("-dead_strip_dylibs"); |
| 1508 | } | 1506 | } |
| 1509 | if (self.force_load_objc) { | 1507 | if (compile.force_load_objc) { |
| 1510 | try zig_args.append("-ObjC"); | 1508 | try zig_args.append("-ObjC"); |
| 1511 | } | 1509 | } |
| 1512 | 1510 | ||
| 1513 | try addFlag(&zig_args, "compiler-rt", self.bundle_compiler_rt); | 1511 | try addFlag(&zig_args, "compiler-rt", compile.bundle_compiler_rt); |
| 1514 | try addFlag(&zig_args, "dll-export-fns", self.dll_export_fns); | 1512 | try addFlag(&zig_args, "dll-export-fns", compile.dll_export_fns); |
| 1515 | if (self.rdynamic) { | 1513 | if (compile.rdynamic) { |
| 1516 | try zig_args.append("-rdynamic"); | 1514 | try zig_args.append("-rdynamic"); |
| 1517 | } | 1515 | } |
| 1518 | if (self.import_memory) { | 1516 | if (compile.import_memory) { |
| 1519 | try zig_args.append("--import-memory"); | 1517 | try zig_args.append("--import-memory"); |
| 1520 | } | 1518 | } |
| 1521 | if (self.export_memory) { | 1519 | if (compile.export_memory) { |
| 1522 | try zig_args.append("--export-memory"); | 1520 | try zig_args.append("--export-memory"); |
| 1523 | } | 1521 | } |
| 1524 | if (self.import_symbols) { | 1522 | if (compile.import_symbols) { |
| 1525 | try zig_args.append("--import-symbols"); | 1523 | try zig_args.append("--import-symbols"); |
| 1526 | } | 1524 | } |
| 1527 | if (self.import_table) { | 1525 | if (compile.import_table) { |
| 1528 | try zig_args.append("--import-table"); | 1526 | try zig_args.append("--import-table"); |
| 1529 | } | 1527 | } |
| 1530 | if (self.export_table) { | 1528 | if (compile.export_table) { |
| 1531 | try zig_args.append("--export-table"); | 1529 | try zig_args.append("--export-table"); |
| 1532 | } | 1530 | } |
| 1533 | if (self.initial_memory) |initial_memory| { | 1531 | if (compile.initial_memory) |initial_memory| { |
| 1534 | try zig_args.append(b.fmt("--initial-memory={d}", .{initial_memory})); | 1532 | try zig_args.append(b.fmt("--initial-memory={d}", .{initial_memory})); |
| 1535 | } | 1533 | } |
| 1536 | if (self.max_memory) |max_memory| { | 1534 | if (compile.max_memory) |max_memory| { |
| 1537 | try zig_args.append(b.fmt("--max-memory={d}", .{max_memory})); | 1535 | try zig_args.append(b.fmt("--max-memory={d}", .{max_memory})); |
| 1538 | } | 1536 | } |
| 1539 | if (self.shared_memory) { | 1537 | if (compile.shared_memory) { |
| 1540 | try zig_args.append("--shared-memory"); | 1538 | try zig_args.append("--shared-memory"); |
| 1541 | } | 1539 | } |
| 1542 | if (self.global_base) |global_base| { | 1540 | if (compile.global_base) |global_base| { |
| 1543 | try zig_args.append(b.fmt("--global-base={d}", .{global_base})); | 1541 | try zig_args.append(b.fmt("--global-base={d}", .{global_base})); |
| 1544 | } | 1542 | } |
| 1545 | 1543 | ||
| 1546 | if (self.wasi_exec_model) |model| { | 1544 | if (compile.wasi_exec_model) |model| { |
| 1547 | try zig_args.append(b.fmt("-mexec-model={s}", .{@tagName(model)})); | 1545 | try zig_args.append(b.fmt("-mexec-model={s}", .{@tagName(model)})); |
| 1548 | } | 1546 | } |
| 1549 | if (self.linker_script) |linker_script| { | 1547 | if (compile.linker_script) |linker_script| { |
| 1550 | try zig_args.append("--script"); | 1548 | try zig_args.append("--script"); |
| 1551 | try zig_args.append(linker_script.getPath(b)); | 1549 | try zig_args.append(linker_script.getPath2(b, step)); |
| 1552 | } | 1550 | } |
| 1553 | 1551 | ||
| 1554 | if (self.version_script) |version_script| { | 1552 | if (compile.version_script) |version_script| { |
| 1555 | try zig_args.append("--version-script"); | 1553 | try zig_args.append("--version-script"); |
| 1556 | try zig_args.append(version_script.getPath(b)); | 1554 | try zig_args.append(version_script.getPath2(b, step)); |
| 1557 | } | 1555 | } |
| 1558 | if (self.linker_allow_undefined_version) |x| { | 1556 | if (compile.linker_allow_undefined_version) |x| { |
| 1559 | try zig_args.append(if (x) "--undefined-version" else "--no-undefined-version"); | 1557 | try zig_args.append(if (x) "--undefined-version" else "--no-undefined-version"); |
| 1560 | } | 1558 | } |
| 1561 | 1559 | ||
| 1562 | if (self.linker_enable_new_dtags) |enabled| { | 1560 | if (compile.linker_enable_new_dtags) |enabled| { |
| 1563 | try zig_args.append(if (enabled) "--enable-new-dtags" else "--disable-new-dtags"); | 1561 | try zig_args.append(if (enabled) "--enable-new-dtags" else "--disable-new-dtags"); |
| 1564 | } | 1562 | } |
| 1565 | 1563 | ||
| 1566 | if (self.kind == .@"test") { | 1564 | if (compile.kind == .@"test") { |
| 1567 | if (self.exec_cmd_args) |exec_cmd_args| { | 1565 | if (compile.exec_cmd_args) |exec_cmd_args| { |
| 1568 | for (exec_cmd_args) |cmd_arg| { | 1566 | for (exec_cmd_args) |cmd_arg| { |
| 1569 | if (cmd_arg) |arg| { | 1567 | if (cmd_arg) |arg| { |
| 1570 | try zig_args.append("--test-cmd"); | 1568 | try zig_args.append("--test-cmd"); |
| ... | @@ -1595,7 +1593,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1595,7 +1593,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1595 | 1593 | ||
| 1596 | if (prefix_dir.accessZ("lib", .{})) |_| { | 1594 | if (prefix_dir.accessZ("lib", .{})) |_| { |
| 1597 | try zig_args.appendSlice(&.{ | 1595 | try zig_args.appendSlice(&.{ |
| 1598 | "-L", try fs.path.join(arena, &.{ search_prefix, "lib" }), | 1596 | "-L", b.pathJoin(&.{ search_prefix, "lib" }), |
| 1599 | }); | 1597 | }); |
| 1600 | } else |err| switch (err) { | 1598 | } else |err| switch (err) { |
| 1601 | error.FileNotFound => {}, | 1599 | error.FileNotFound => {}, |
| ... | @@ -1606,7 +1604,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1606,7 +1604,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1606 | 1604 | ||
| 1607 | if (prefix_dir.accessZ("include", .{})) |_| { | 1605 | if (prefix_dir.accessZ("include", .{})) |_| { |
| 1608 | try zig_args.appendSlice(&.{ | 1606 | try zig_args.appendSlice(&.{ |
| 1609 | "-I", try fs.path.join(arena, &.{ search_prefix, "include" }), | 1607 | "-I", b.pathJoin(&.{ search_prefix, "include" }), |
| 1610 | }); | 1608 | }); |
| 1611 | } else |err| switch (err) { | 1609 | } else |err| switch (err) { |
| 1612 | error.FileNotFound => {}, | 1610 | error.FileNotFound => {}, |
| ... | @@ -1616,14 +1614,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1616,14 +1614,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1616 | } | 1614 | } |
| 1617 | } | 1615 | } |
| 1618 | 1616 | ||
| 1619 | if (self.rc_includes != .any) { | 1617 | if (compile.rc_includes != .any) { |
| 1620 | try zig_args.append("-rcincludes"); | 1618 | try zig_args.append("-rcincludes"); |
| 1621 | try zig_args.append(@tagName(self.rc_includes)); | 1619 | try zig_args.append(@tagName(compile.rc_includes)); |
| 1622 | } | 1620 | } |
| 1623 | 1621 | ||
| 1624 | try addFlag(&zig_args, "each-lib-rpath", self.each_lib_rpath); | 1622 | try addFlag(&zig_args, "each-lib-rpath", compile.each_lib_rpath); |
| 1625 | 1623 | ||
| 1626 | if (self.build_id) |build_id| { | 1624 | if (compile.build_id) |build_id| { |
| 1627 | try zig_args.append(switch (build_id) { | 1625 | try zig_args.append(switch (build_id) { |
| 1628 | .hexstring => |hs| b.fmt("--build-id=0x{s}", .{ | 1626 | .hexstring => |hs| b.fmt("--build-id=0x{s}", .{ |
| 1629 | std.fmt.fmtSliceHexLower(hs.toSlice()), | 1627 | std.fmt.fmtSliceHexLower(hs.toSlice()), |
| ... | @@ -1632,15 +1630,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1632,15 +1630,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1632 | }); | 1630 | }); |
| 1633 | } | 1631 | } |
| 1634 | 1632 | ||
| 1635 | if (self.zig_lib_dir) |dir| { | 1633 | if (compile.zig_lib_dir) |dir| { |
| 1636 | try zig_args.append("--zig-lib-dir"); | 1634 | try zig_args.append("--zig-lib-dir"); |
| 1637 | try zig_args.append(dir.getPath(b)); | 1635 | try zig_args.append(dir.getPath2(b, step)); |
| 1638 | } | 1636 | } |
| 1639 | 1637 | ||
| 1640 | try addFlag(&zig_args, "PIE", self.pie); | 1638 | try addFlag(&zig_args, "PIE", compile.pie); |
| 1641 | try addFlag(&zig_args, "lto", self.want_lto); | 1639 | try addFlag(&zig_args, "lto", compile.want_lto); |
| 1642 | 1640 | ||
| 1643 | if (self.subsystem) |subsystem| { | 1641 | if (compile.subsystem) |subsystem| { |
| 1644 | try zig_args.append("--subsystem"); | 1642 | try zig_args.append("--subsystem"); |
| 1645 | try zig_args.append(switch (subsystem) { | 1643 | try zig_args.append(switch (subsystem) { |
| 1646 | .Console => "console", | 1644 | .Console => "console", |
| ... | @@ -1654,11 +1652,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1654,11 +1652,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1654 | }); | 1652 | }); |
| 1655 | } | 1653 | } |
| 1656 | 1654 | ||
| 1657 | if (self.mingw_unicode_entry_point) { | 1655 | if (compile.mingw_unicode_entry_point) { |
| 1658 | try zig_args.append("-municode"); | 1656 | try zig_args.append("-municode"); |
| 1659 | } | 1657 | } |
| 1660 | 1658 | ||
| 1661 | if (self.error_limit) |err_limit| try zig_args.appendSlice(&.{ | 1659 | if (compile.error_limit) |err_limit| try zig_args.appendSlice(&.{ |
| 1662 | "--error-limit", | 1660 | "--error-limit", |
| 1663 | b.fmt("{}", .{err_limit}), | 1661 | b.fmt("{}", .{err_limit}), |
| 1664 | }); | 1662 | }); |
| ... | @@ -1724,8 +1722,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1724,8 +1722,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1724 | 1722 | ||
| 1725 | const maybe_output_bin_path = step.evalZigProcess(zig_args.items, prog_node) catch |err| switch (err) { | 1723 | const maybe_output_bin_path = step.evalZigProcess(zig_args.items, prog_node) catch |err| switch (err) { |
| 1726 | error.NeedCompileErrorCheck => { | 1724 | error.NeedCompileErrorCheck => { |
| 1727 | assert(self.expect_errors != null); | 1725 | assert(compile.expect_errors != null); |
| 1728 | try checkCompileErrors(self); | 1726 | try checkCompileErrors(compile); |
| 1729 | return; | 1727 | return; |
| 1730 | }, | 1728 | }, |
| 1731 | else => |e| return e, | 1729 | else => |e| return e, |
| ... | @@ -1735,61 +1733,61 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1735,61 +1733,61 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1735 | if (maybe_output_bin_path) |output_bin_path| { | 1733 | if (maybe_output_bin_path) |output_bin_path| { |
| 1736 | const output_dir = fs.path.dirname(output_bin_path).?; | 1734 | const output_dir = fs.path.dirname(output_bin_path).?; |
| 1737 | 1735 | ||
| 1738 | if (self.emit_directory) |lp| { | 1736 | if (compile.emit_directory) |lp| { |
| 1739 | lp.path = output_dir; | 1737 | lp.path = output_dir; |
| 1740 | } | 1738 | } |
| 1741 | 1739 | ||
| 1742 | // -femit-bin[=path] (default) Output machine code | 1740 | // -femit-bin[=path] (default) Output machine code |
| 1743 | if (self.generated_bin) |bin| { | 1741 | if (compile.generated_bin) |bin| { |
| 1744 | bin.path = b.pathJoin(&.{ output_dir, self.out_filename }); | 1742 | bin.path = b.pathJoin(&.{ output_dir, compile.out_filename }); |
| 1745 | } | 1743 | } |
| 1746 | 1744 | ||
| 1747 | const sep = std.fs.path.sep; | 1745 | const sep = std.fs.path.sep; |
| 1748 | 1746 | ||
| 1749 | // output PDB if someone requested it | 1747 | // output PDB if someone requested it |
| 1750 | if (self.generated_pdb) |pdb| { | 1748 | if (compile.generated_pdb) |pdb| { |
| 1751 | pdb.path = b.fmt("{s}{c}{s}.pdb", .{ output_dir, sep, self.name }); | 1749 | pdb.path = b.fmt("{s}{c}{s}.pdb", .{ output_dir, sep, compile.name }); |
| 1752 | } | 1750 | } |
| 1753 | 1751 | ||
| 1754 | // -femit-implib[=path] (default) Produce an import .lib when building a Windows DLL | 1752 | // -femit-implib[=path] (default) Produce an import .lib when building a Windows DLL |
| 1755 | if (self.generated_implib) |implib| { | 1753 | if (compile.generated_implib) |implib| { |
| 1756 | implib.path = b.fmt("{s}{c}{s}.lib", .{ output_dir, sep, self.name }); | 1754 | implib.path = b.fmt("{s}{c}{s}.lib", .{ output_dir, sep, compile.name }); |
| 1757 | } | 1755 | } |
| 1758 | 1756 | ||
| 1759 | // -femit-h[=path] Generate a C header file (.h) | 1757 | // -femit-h[=path] Generate a C header file (.h) |
| 1760 | if (self.generated_h) |lp| { | 1758 | if (compile.generated_h) |lp| { |
| 1761 | lp.path = b.fmt("{s}{c}{s}.h", .{ output_dir, sep, self.name }); | 1759 | lp.path = b.fmt("{s}{c}{s}.h", .{ output_dir, sep, compile.name }); |
| 1762 | } | 1760 | } |
| 1763 | 1761 | ||
| 1764 | // -femit-docs[=path] Create a docs/ dir with html documentation | 1762 | // -femit-docs[=path] Create a docs/ dir with html documentation |
| 1765 | if (self.generated_docs) |generated_docs| { | 1763 | if (compile.generated_docs) |generated_docs| { |
| 1766 | generated_docs.path = b.pathJoin(&.{ output_dir, "docs" }); | 1764 | generated_docs.path = b.pathJoin(&.{ output_dir, "docs" }); |
| 1767 | } | 1765 | } |
| 1768 | 1766 | ||
| 1769 | // -femit-asm[=path] Output .s (assembly code) | 1767 | // -femit-asm[=path] Output .s (assembly code) |
| 1770 | if (self.generated_asm) |lp| { | 1768 | if (compile.generated_asm) |lp| { |
| 1771 | lp.path = b.fmt("{s}{c}{s}.s", .{ output_dir, sep, self.name }); | 1769 | lp.path = b.fmt("{s}{c}{s}.s", .{ output_dir, sep, compile.name }); |
| 1772 | } | 1770 | } |
| 1773 | 1771 | ||
| 1774 | // -femit-llvm-ir[=path] Produce a .ll file with optimized LLVM IR (requires LLVM extensions) | 1772 | // -femit-llvm-ir[=path] Produce a .ll file with optimized LLVM IR (requires LLVM extensions) |
| 1775 | if (self.generated_llvm_ir) |lp| { | 1773 | if (compile.generated_llvm_ir) |lp| { |
| 1776 | lp.path = b.fmt("{s}{c}{s}.ll", .{ output_dir, sep, self.name }); | 1774 | lp.path = b.fmt("{s}{c}{s}.ll", .{ output_dir, sep, compile.name }); |
| 1777 | } | 1775 | } |
| 1778 | 1776 | ||
| 1779 | // -femit-llvm-bc[=path] Produce an optimized LLVM module as a .bc file (requires LLVM extensions) | 1777 | // -femit-llvm-bc[=path] Produce an optimized LLVM module as a .bc file (requires LLVM extensions) |
| 1780 | if (self.generated_llvm_bc) |lp| { | 1778 | if (compile.generated_llvm_bc) |lp| { |
| 1781 | lp.path = b.fmt("{s}{c}{s}.bc", .{ output_dir, sep, self.name }); | 1779 | lp.path = b.fmt("{s}{c}{s}.bc", .{ output_dir, sep, compile.name }); |
| 1782 | } | 1780 | } |
| 1783 | } | 1781 | } |
| 1784 | 1782 | ||
| 1785 | if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and | 1783 | if (compile.kind == .lib and compile.linkage != null and compile.linkage.? == .dynamic and |
| 1786 | self.version != null and std.Build.wantSharedLibSymLinks(self.rootModuleTarget())) | 1784 | compile.version != null and std.Build.wantSharedLibSymLinks(compile.rootModuleTarget())) |
| 1787 | { | 1785 | { |
| 1788 | try doAtomicSymLinks( | 1786 | try doAtomicSymLinks( |
| 1789 | step, | 1787 | step, |
| 1790 | self.getEmittedBin().getPath(b), | 1788 | compile.getEmittedBin().getPath2(b, step), |
| 1791 | self.major_only_filename.?, | 1789 | compile.major_only_filename.?, |
| 1792 | self.name_only_filename.?, | 1790 | compile.name_only_filename.?, |
| 1793 | ); | 1791 | ); |
| 1794 | } | 1792 | } |
| 1795 | } | 1793 | } |
| ... | @@ -1800,18 +1798,19 @@ pub fn doAtomicSymLinks( | ... | @@ -1800,18 +1798,19 @@ pub fn doAtomicSymLinks( |
| 1800 | filename_major_only: []const u8, | 1798 | filename_major_only: []const u8, |
| 1801 | filename_name_only: []const u8, | 1799 | filename_name_only: []const u8, |
| 1802 | ) !void { | 1800 | ) !void { |
| 1803 | const arena = step.owner.allocator; | 1801 | const b = step.owner; |
| 1802 | const arena = b.allocator; | ||
| 1804 | const out_dir = fs.path.dirname(output_path) orelse "."; | 1803 | const out_dir = fs.path.dirname(output_path) orelse "."; |
| 1805 | const out_basename = fs.path.basename(output_path); | 1804 | const out_basename = fs.path.basename(output_path); |
| 1806 | // sym link for libfoo.so.1 to libfoo.so.1.2.3 | 1805 | // sym link for libfoo.so.1 to libfoo.so.1.2.3 |
| 1807 | const major_only_path = try fs.path.join(arena, &.{ out_dir, filename_major_only }); | 1806 | const major_only_path = b.pathJoin(&.{ out_dir, filename_major_only }); |
| 1808 | fs.atomicSymLink(arena, out_basename, major_only_path) catch |err| { | 1807 | fs.atomicSymLink(arena, out_basename, major_only_path) catch |err| { |
| 1809 | return step.fail("unable to symlink {s} -> {s}: {s}", .{ | 1808 | return step.fail("unable to symlink {s} -> {s}: {s}", .{ |
| 1810 | major_only_path, out_basename, @errorName(err), | 1809 | major_only_path, out_basename, @errorName(err), |
| 1811 | }); | 1810 | }); |
| 1812 | }; | 1811 | }; |
| 1813 | // sym link for libfoo.so to libfoo.so.1 | 1812 | // sym link for libfoo.so to libfoo.so.1 |
| 1814 | const name_only_path = try fs.path.join(arena, &.{ out_dir, filename_name_only }); | 1813 | const name_only_path = b.pathJoin(&.{ out_dir, filename_name_only }); |
| 1815 | fs.atomicSymLink(arena, filename_major_only, name_only_path) catch |err| { | 1814 | fs.atomicSymLink(arena, filename_major_only, name_only_path) catch |err| { |
| 1816 | return step.fail("Unable to symlink {s} -> {s}: {s}", .{ | 1815 | return step.fail("Unable to symlink {s} -> {s}: {s}", .{ |
| 1817 | name_only_path, filename_major_only, @errorName(err), | 1816 | name_only_path, filename_major_only, @errorName(err), |
| ... | @@ -1819,9 +1818,9 @@ pub fn doAtomicSymLinks( | ... | @@ -1819,9 +1818,9 @@ pub fn doAtomicSymLinks( |
| 1819 | }; | 1818 | }; |
| 1820 | } | 1819 | } |
| 1821 | 1820 | ||
| 1822 | fn execPkgConfigList(self: *std.Build, out_code: *u8) (PkgConfigError || RunError)![]const PkgConfigPkg { | 1821 | fn execPkgConfigList(compile: *std.Build, out_code: *u8) (PkgConfigError || RunError)![]const PkgConfigPkg { |
| 1823 | const stdout = try self.runAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore); | 1822 | const stdout = try compile.runAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore); |
| 1824 | var list = ArrayList(PkgConfigPkg).init(self.allocator); | 1823 | var list = ArrayList(PkgConfigPkg).init(compile.allocator); |
| 1825 | errdefer list.deinit(); | 1824 | errdefer list.deinit(); |
| 1826 | var line_it = mem.tokenizeAny(u8, stdout, "\r\n"); | 1825 | var line_it = mem.tokenizeAny(u8, stdout, "\r\n"); |
| 1827 | while (line_it.next()) |line| { | 1826 | while (line_it.next()) |line| { |
| ... | @@ -1835,13 +1834,13 @@ fn execPkgConfigList(self: *std.Build, out_code: *u8) (PkgConfigError || RunErro | ... | @@ -1835,13 +1834,13 @@ fn execPkgConfigList(self: *std.Build, out_code: *u8) (PkgConfigError || RunErro |
| 1835 | return list.toOwnedSlice(); | 1834 | return list.toOwnedSlice(); |
| 1836 | } | 1835 | } |
| 1837 | 1836 | ||
| 1838 | fn getPkgConfigList(self: *std.Build) ![]const PkgConfigPkg { | 1837 | fn getPkgConfigList(compile: *std.Build) ![]const PkgConfigPkg { |
| 1839 | if (self.pkg_config_pkg_list) |res| { | 1838 | if (compile.pkg_config_pkg_list) |res| { |
| 1840 | return res; | 1839 | return res; |
| 1841 | } | 1840 | } |
| 1842 | var code: u8 = undefined; | 1841 | var code: u8 = undefined; |
| 1843 | if (execPkgConfigList(self, &code)) |list| { | 1842 | if (execPkgConfigList(compile, &code)) |list| { |
| 1844 | self.pkg_config_pkg_list = list; | 1843 | compile.pkg_config_pkg_list = list; |
| 1845 | return list; | 1844 | return list; |
| 1846 | } else |err| { | 1845 | } else |err| { |
| 1847 | const result = switch (err) { | 1846 | const result = switch (err) { |
| ... | @@ -1853,7 +1852,7 @@ fn getPkgConfigList(self: *std.Build) ![]const PkgConfigPkg { | ... | @@ -1853,7 +1852,7 @@ fn getPkgConfigList(self: *std.Build) ![]const PkgConfigPkg { |
| 1853 | error.PkgConfigInvalidOutput => error.PkgConfigInvalidOutput, | 1852 | error.PkgConfigInvalidOutput => error.PkgConfigInvalidOutput, |
| 1854 | else => return err, | 1853 | else => return err, |
| 1855 | }; | 1854 | }; |
| 1856 | self.pkg_config_pkg_list = result; | 1855 | compile.pkg_config_pkg_list = result; |
| 1857 | return result; | 1856 | return result; |
| 1858 | } | 1857 | } |
| 1859 | } | 1858 | } |
| ... | @@ -1868,12 +1867,12 @@ fn addFlag(args: *ArrayList([]const u8), comptime name: []const u8, opt: ?bool) | ... | @@ -1868,12 +1867,12 @@ fn addFlag(args: *ArrayList([]const u8), comptime name: []const u8, opt: ?bool) |
| 1868 | } | 1867 | } |
| 1869 | } | 1868 | } |
| 1870 | 1869 | ||
| 1871 | fn checkCompileErrors(self: *Compile) !void { | 1870 | fn checkCompileErrors(compile: *Compile) !void { |
| 1872 | // Clear this field so that it does not get printed by the build runner. | 1871 | // Clear this field so that it does not get printed by the build runner. |
| 1873 | const actual_eb = self.step.result_error_bundle; | 1872 | const actual_eb = compile.step.result_error_bundle; |
| 1874 | self.step.result_error_bundle = std.zig.ErrorBundle.empty; | 1873 | compile.step.result_error_bundle = std.zig.ErrorBundle.empty; |
| 1875 | 1874 | ||
| 1876 | const arena = self.step.owner.allocator; | 1875 | const arena = compile.step.owner.allocator; |
| 1877 | 1876 | ||
| 1878 | var actual_stderr_list = std.ArrayList(u8).init(arena); | 1877 | var actual_stderr_list = std.ArrayList(u8).init(arena); |
| 1879 | try actual_eb.renderToWriter(.{ | 1878 | try actual_eb.renderToWriter(.{ |
| ... | @@ -1885,7 +1884,7 @@ fn checkCompileErrors(self: *Compile) !void { | ... | @@ -1885,7 +1884,7 @@ fn checkCompileErrors(self: *Compile) !void { |
| 1885 | 1884 | ||
| 1886 | // Render the expected lines into a string that we can compare verbatim. | 1885 | // Render the expected lines into a string that we can compare verbatim. |
| 1887 | var expected_generated = std.ArrayList(u8).init(arena); | 1886 | var expected_generated = std.ArrayList(u8).init(arena); |
| 1888 | const expect_errors = self.expect_errors.?; | 1887 | const expect_errors = compile.expect_errors.?; |
| 1889 | 1888 | ||
| 1890 | var actual_line_it = mem.splitScalar(u8, actual_stderr, '\n'); | 1889 | var actual_line_it = mem.splitScalar(u8, actual_stderr, '\n'); |
| 1891 | 1890 | ||
| ... | @@ -1897,7 +1896,7 @@ fn checkCompileErrors(self: *Compile) !void { | ... | @@ -1897,7 +1896,7 @@ fn checkCompileErrors(self: *Compile) !void { |
| 1897 | return; | 1896 | return; |
| 1898 | } | 1897 | } |
| 1899 | 1898 | ||
| 1900 | return self.step.fail( | 1899 | return compile.step.fail( |
| 1901 | \\ | 1900 | \\ |
| 1902 | \\========= should contain: =============== | 1901 | \\========= should contain: =============== |
| 1903 | \\{s} | 1902 | \\{s} |
| ... | @@ -1924,7 +1923,7 @@ fn checkCompileErrors(self: *Compile) !void { | ... | @@ -1924,7 +1923,7 @@ fn checkCompileErrors(self: *Compile) !void { |
| 1924 | 1923 | ||
| 1925 | if (mem.eql(u8, expected_generated.items, actual_stderr)) return; | 1924 | if (mem.eql(u8, expected_generated.items, actual_stderr)) return; |
| 1926 | 1925 | ||
| 1927 | return self.step.fail( | 1926 | return compile.step.fail( |
| 1928 | \\ | 1927 | \\ |
| 1929 | \\========= expected: ===================== | 1928 | \\========= expected: ===================== |
| 1930 | \\{s} | 1929 | \\{s} |
lib/std/Build/Step/ConfigHeader.zig+37-37| ... | @@ -52,7 +52,7 @@ pub const Options = struct { | ... | @@ -52,7 +52,7 @@ pub const Options = struct { |
| 52 | }; | 52 | }; |
| 53 | 53 | ||
| 54 | pub fn create(owner: *std.Build, options: Options) *ConfigHeader { | 54 | pub fn create(owner: *std.Build, options: Options) *ConfigHeader { |
| 55 | const self = owner.allocator.create(ConfigHeader) catch @panic("OOM"); | 55 | const config_header = owner.allocator.create(ConfigHeader) catch @panic("OOM"); |
| 56 | 56 | ||
| 57 | var include_path: []const u8 = "config.h"; | 57 | var include_path: []const u8 = "config.h"; |
| 58 | 58 | ||
| ... | @@ -81,7 +81,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader { | ... | @@ -81,7 +81,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader { |
| 81 | else | 81 | else |
| 82 | owner.fmt("configure {s} header to {s}", .{ @tagName(options.style), include_path }); | 82 | owner.fmt("configure {s} header to {s}", .{ @tagName(options.style), include_path }); |
| 83 | 83 | ||
| 84 | self.* = .{ | 84 | config_header.* = .{ |
| 85 | .step = Step.init(.{ | 85 | .step = Step.init(.{ |
| 86 | .id = base_id, | 86 | .id = base_id, |
| 87 | .name = name, | 87 | .name = name, |
| ... | @@ -95,64 +95,64 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader { | ... | @@ -95,64 +95,64 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader { |
| 95 | .max_bytes = options.max_bytes, | 95 | .max_bytes = options.max_bytes, |
| 96 | .include_path = include_path, | 96 | .include_path = include_path, |
| 97 | .include_guard_override = options.include_guard_override, | 97 | .include_guard_override = options.include_guard_override, |
| 98 | .output_file = .{ .step = &self.step }, | 98 | .output_file = .{ .step = &config_header.step }, |
| 99 | }; | 99 | }; |
| 100 | 100 | ||
| 101 | return self; | 101 | return config_header; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | pub fn addValues(self: *ConfigHeader, values: anytype) void { | 104 | pub fn addValues(config_header: *ConfigHeader, values: anytype) void { |
| 105 | return addValuesInner(self, values) catch @panic("OOM"); | 105 | return addValuesInner(config_header, values) catch @panic("OOM"); |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath { | 108 | pub fn getOutput(config_header: *ConfigHeader) std.Build.LazyPath { |
| 109 | return .{ .generated = &self.output_file }; | 109 | return .{ .generated = &config_header.output_file }; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | fn addValuesInner(self: *ConfigHeader, values: anytype) !void { | 112 | fn addValuesInner(config_header: *ConfigHeader, values: anytype) !void { |
| 113 | inline for (@typeInfo(@TypeOf(values)).Struct.fields) |field| { | 113 | inline for (@typeInfo(@TypeOf(values)).Struct.fields) |field| { |
| 114 | try putValue(self, field.name, field.type, @field(values, field.name)); | 114 | try putValue(config_header, field.name, field.type, @field(values, field.name)); |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | fn putValue(self: *ConfigHeader, field_name: []const u8, comptime T: type, v: T) !void { | 118 | fn putValue(config_header: *ConfigHeader, field_name: []const u8, comptime T: type, v: T) !void { |
| 119 | switch (@typeInfo(T)) { | 119 | switch (@typeInfo(T)) { |
| 120 | .Null => { | 120 | .Null => { |
| 121 | try self.values.put(field_name, .undef); | 121 | try config_header.values.put(field_name, .undef); |
| 122 | }, | 122 | }, |
| 123 | .Void => { | 123 | .Void => { |
| 124 | try self.values.put(field_name, .defined); | 124 | try config_header.values.put(field_name, .defined); |
| 125 | }, | 125 | }, |
| 126 | .Bool => { | 126 | .Bool => { |
| 127 | try self.values.put(field_name, .{ .boolean = v }); | 127 | try config_header.values.put(field_name, .{ .boolean = v }); |
| 128 | }, | 128 | }, |
| 129 | .Int => { | 129 | .Int => { |
| 130 | try self.values.put(field_name, .{ .int = v }); | 130 | try config_header.values.put(field_name, .{ .int = v }); |
| 131 | }, | 131 | }, |
| 132 | .ComptimeInt => { | 132 | .ComptimeInt => { |
| 133 | try self.values.put(field_name, .{ .int = v }); | 133 | try config_header.values.put(field_name, .{ .int = v }); |
| 134 | }, | 134 | }, |
| 135 | .EnumLiteral => { | 135 | .EnumLiteral => { |
| 136 | try self.values.put(field_name, .{ .ident = @tagName(v) }); | 136 | try config_header.values.put(field_name, .{ .ident = @tagName(v) }); |
| 137 | }, | 137 | }, |
| 138 | .Optional => { | 138 | .Optional => { |
| 139 | if (v) |x| { | 139 | if (v) |x| { |
| 140 | return putValue(self, field_name, @TypeOf(x), x); | 140 | return putValue(config_header, field_name, @TypeOf(x), x); |
| 141 | } else { | 141 | } else { |
| 142 | try self.values.put(field_name, .undef); | 142 | try config_header.values.put(field_name, .undef); |
| 143 | } | 143 | } |
| 144 | }, | 144 | }, |
| 145 | .Pointer => |ptr| { | 145 | .Pointer => |ptr| { |
| 146 | switch (@typeInfo(ptr.child)) { | 146 | switch (@typeInfo(ptr.child)) { |
| 147 | .Array => |array| { | 147 | .Array => |array| { |
| 148 | if (ptr.size == .One and array.child == u8) { | 148 | if (ptr.size == .One and array.child == u8) { |
| 149 | try self.values.put(field_name, .{ .string = v }); | 149 | try config_header.values.put(field_name, .{ .string = v }); |
| 150 | return; | 150 | return; |
| 151 | } | 151 | } |
| 152 | }, | 152 | }, |
| 153 | .Int => { | 153 | .Int => { |
| 154 | if (ptr.size == .Slice and ptr.child == u8) { | 154 | if (ptr.size == .Slice and ptr.child == u8) { |
| 155 | try self.values.put(field_name, .{ .string = v }); | 155 | try config_header.values.put(field_name, .{ .string = v }); |
| 156 | return; | 156 | return; |
| 157 | } | 157 | } |
| 158 | }, | 158 | }, |
| ... | @@ -168,7 +168,7 @@ fn putValue(self: *ConfigHeader, field_name: []const u8, comptime T: type, v: T) | ... | @@ -168,7 +168,7 @@ fn putValue(self: *ConfigHeader, field_name: []const u8, comptime T: type, v: T) |
| 168 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 168 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 169 | _ = prog_node; | 169 | _ = prog_node; |
| 170 | const b = step.owner; | 170 | const b = step.owner; |
| 171 | const self: *ConfigHeader = @fieldParentPtr("step", step); | 171 | const config_header: *ConfigHeader = @fieldParentPtr("step", step); |
| 172 | const gpa = b.allocator; | 172 | const gpa = b.allocator; |
| 173 | const arena = b.allocator; | 173 | const arena = b.allocator; |
| 174 | 174 | ||
| ... | @@ -179,8 +179,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -179,8 +179,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 179 | // random bytes when ConfigHeader implementation is modified in a | 179 | // random bytes when ConfigHeader implementation is modified in a |
| 180 | // non-backwards-compatible way. | 180 | // non-backwards-compatible way. |
| 181 | man.hash.add(@as(u32, 0xdef08d23)); | 181 | man.hash.add(@as(u32, 0xdef08d23)); |
| 182 | man.hash.addBytes(self.include_path); | 182 | man.hash.addBytes(config_header.include_path); |
| 183 | man.hash.addOptionalBytes(self.include_guard_override); | 183 | man.hash.addOptionalBytes(config_header.include_guard_override); |
| 184 | 184 | ||
| 185 | var output = std.ArrayList(u8).init(gpa); | 185 | var output = std.ArrayList(u8).init(gpa); |
| 186 | defer output.deinit(); | 186 | defer output.deinit(); |
| ... | @@ -189,34 +189,34 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -189,34 +189,34 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 189 | const c_generated_line = "/* " ++ header_text ++ " */\n"; | 189 | const c_generated_line = "/* " ++ header_text ++ " */\n"; |
| 190 | const asm_generated_line = "; " ++ header_text ++ "\n"; | 190 | const asm_generated_line = "; " ++ header_text ++ "\n"; |
| 191 | 191 | ||
| 192 | switch (self.style) { | 192 | switch (config_header.style) { |
| 193 | .autoconf => |file_source| { | 193 | .autoconf => |file_source| { |
| 194 | try output.appendSlice(c_generated_line); | 194 | try output.appendSlice(c_generated_line); |
| 195 | const src_path = file_source.getPath(b); | 195 | const src_path = file_source.getPath2(b, step); |
| 196 | const contents = std.fs.cwd().readFileAlloc(arena, src_path, self.max_bytes) catch |err| { | 196 | const contents = std.fs.cwd().readFileAlloc(arena, src_path, config_header.max_bytes) catch |err| { |
| 197 | return step.fail("unable to read autoconf input file '{s}': {s}", .{ | 197 | return step.fail("unable to read autoconf input file '{s}': {s}", .{ |
| 198 | src_path, @errorName(err), | 198 | src_path, @errorName(err), |
| 199 | }); | 199 | }); |
| 200 | }; | 200 | }; |
| 201 | try render_autoconf(step, contents, &output, self.values, src_path); | 201 | try render_autoconf(step, contents, &output, config_header.values, src_path); |
| 202 | }, | 202 | }, |
| 203 | .cmake => |file_source| { | 203 | .cmake => |file_source| { |
| 204 | try output.appendSlice(c_generated_line); | 204 | try output.appendSlice(c_generated_line); |
| 205 | const src_path = file_source.getPath(b); | 205 | const src_path = file_source.getPath2(b, step); |
| 206 | const contents = std.fs.cwd().readFileAlloc(arena, src_path, self.max_bytes) catch |err| { | 206 | const contents = std.fs.cwd().readFileAlloc(arena, src_path, config_header.max_bytes) catch |err| { |
| 207 | return step.fail("unable to read cmake input file '{s}': {s}", .{ | 207 | return step.fail("unable to read cmake input file '{s}': {s}", .{ |
| 208 | src_path, @errorName(err), | 208 | src_path, @errorName(err), |
| 209 | }); | 209 | }); |
| 210 | }; | 210 | }; |
| 211 | try render_cmake(step, contents, &output, self.values, src_path); | 211 | try render_cmake(step, contents, &output, config_header.values, src_path); |
| 212 | }, | 212 | }, |
| 213 | .blank => { | 213 | .blank => { |
| 214 | try output.appendSlice(c_generated_line); | 214 | try output.appendSlice(c_generated_line); |
| 215 | try render_blank(&output, self.values, self.include_path, self.include_guard_override); | 215 | try render_blank(&output, config_header.values, config_header.include_path, config_header.include_guard_override); |
| 216 | }, | 216 | }, |
| 217 | .nasm => { | 217 | .nasm => { |
| 218 | try output.appendSlice(asm_generated_line); | 218 | try output.appendSlice(asm_generated_line); |
| 219 | try render_nasm(&output, self.values); | 219 | try render_nasm(&output, config_header.values); |
| 220 | }, | 220 | }, |
| 221 | } | 221 | } |
| 222 | 222 | ||
| ... | @@ -224,8 +224,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -224,8 +224,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 224 | 224 | ||
| 225 | if (try step.cacheHit(&man)) { | 225 | if (try step.cacheHit(&man)) { |
| 226 | const digest = man.final(); | 226 | const digest = man.final(); |
| 227 | self.output_file.path = try b.cache_root.join(arena, &.{ | 227 | config_header.output_file.path = try b.cache_root.join(arena, &.{ |
| 228 | "o", &digest, self.include_path, | 228 | "o", &digest, config_header.include_path, |
| 229 | }); | 229 | }); |
| 230 | return; | 230 | return; |
| 231 | } | 231 | } |
| ... | @@ -237,7 +237,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -237,7 +237,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 237 | // output_path is libavutil/avconfig.h | 237 | // output_path is libavutil/avconfig.h |
| 238 | // We want to open directory zig-cache/o/HASH/libavutil/ | 238 | // We want to open directory zig-cache/o/HASH/libavutil/ |
| 239 | // but keep output_dir as zig-cache/o/HASH for -I include | 239 | // but keep output_dir as zig-cache/o/HASH for -I include |
| 240 | const sub_path = try std.fs.path.join(arena, &.{ "o", &digest, self.include_path }); | 240 | const sub_path = b.pathJoin(&.{ "o", &digest, config_header.include_path }); |
| 241 | const sub_path_dirname = std.fs.path.dirname(sub_path).?; | 241 | const sub_path_dirname = std.fs.path.dirname(sub_path).?; |
| 242 | 242 | ||
| 243 | b.cache_root.handle.makePath(sub_path_dirname) catch |err| { | 243 | b.cache_root.handle.makePath(sub_path_dirname) catch |err| { |
| ... | @@ -252,7 +252,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -252,7 +252,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 252 | }); | 252 | }); |
| 253 | }; | 253 | }; |
| 254 | 254 | ||
| 255 | self.output_file.path = try b.cache_root.join(arena, &.{sub_path}); | 255 | config_header.output_file.path = try b.cache_root.join(arena, &.{sub_path}); |
| 256 | try man.writeManifest(); | 256 | try man.writeManifest(); |
| 257 | } | 257 | } |
| 258 | 258 |
lib/std/Build/Step/Fmt.zig+9-9| ... | @@ -10,7 +10,7 @@ paths: []const []const u8, | ... | @@ -10,7 +10,7 @@ paths: []const []const u8, |
| 10 | exclude_paths: []const []const u8, | 10 | exclude_paths: []const []const u8, |
| 11 | check: bool, | 11 | check: bool, |
| 12 | 12 | ||
| 13 | pub const base_id = .fmt; | 13 | pub const base_id: Step.Id = .fmt; |
| 14 | 14 | ||
| 15 | pub const Options = struct { | 15 | pub const Options = struct { |
| 16 | paths: []const []const u8 = &.{}, | 16 | paths: []const []const u8 = &.{}, |
| ... | @@ -20,9 +20,9 @@ pub const Options = struct { | ... | @@ -20,9 +20,9 @@ pub const Options = struct { |
| 20 | }; | 20 | }; |
| 21 | 21 | ||
| 22 | pub fn create(owner: *std.Build, options: Options) *Fmt { | 22 | pub fn create(owner: *std.Build, options: Options) *Fmt { |
| 23 | const self = owner.allocator.create(Fmt) catch @panic("OOM"); | 23 | const fmt = owner.allocator.create(Fmt) catch @panic("OOM"); |
| 24 | const name = if (options.check) "zig fmt --check" else "zig fmt"; | 24 | const name = if (options.check) "zig fmt --check" else "zig fmt"; |
| 25 | self.* = .{ | 25 | fmt.* = .{ |
| 26 | .step = Step.init(.{ | 26 | .step = Step.init(.{ |
| 27 | .id = base_id, | 27 | .id = base_id, |
| 28 | .name = name, | 28 | .name = name, |
| ... | @@ -33,7 +33,7 @@ pub fn create(owner: *std.Build, options: Options) *Fmt { | ... | @@ -33,7 +33,7 @@ pub fn create(owner: *std.Build, options: Options) *Fmt { |
| 33 | .exclude_paths = owner.dupeStrings(options.exclude_paths), | 33 | .exclude_paths = owner.dupeStrings(options.exclude_paths), |
| 34 | .check = options.check, | 34 | .check = options.check, |
| 35 | }; | 35 | }; |
| 36 | return self; | 36 | return fmt; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 39 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| ... | @@ -47,23 +47,23 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -47,23 +47,23 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 47 | 47 | ||
| 48 | const b = step.owner; | 48 | const b = step.owner; |
| 49 | const arena = b.allocator; | 49 | const arena = b.allocator; |
| 50 | const self: *Fmt = @fieldParentPtr("step", step); | 50 | const fmt: *Fmt = @fieldParentPtr("step", step); |
| 51 | 51 | ||
| 52 | var argv: std.ArrayListUnmanaged([]const u8) = .{}; | 52 | var argv: std.ArrayListUnmanaged([]const u8) = .{}; |
| 53 | try argv.ensureUnusedCapacity(arena, 2 + 1 + self.paths.len + 2 * self.exclude_paths.len); | 53 | try argv.ensureUnusedCapacity(arena, 2 + 1 + fmt.paths.len + 2 * fmt.exclude_paths.len); |
| 54 | 54 | ||
| 55 | argv.appendAssumeCapacity(b.graph.zig_exe); | 55 | argv.appendAssumeCapacity(b.graph.zig_exe); |
| 56 | argv.appendAssumeCapacity("fmt"); | 56 | argv.appendAssumeCapacity("fmt"); |
| 57 | 57 | ||
| 58 | if (self.check) { | 58 | if (fmt.check) { |
| 59 | argv.appendAssumeCapacity("--check"); | 59 | argv.appendAssumeCapacity("--check"); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | for (self.paths) |p| { | 62 | for (fmt.paths) |p| { |
| 63 | argv.appendAssumeCapacity(b.pathFromRoot(p)); | 63 | argv.appendAssumeCapacity(b.pathFromRoot(p)); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | for (self.exclude_paths) |p| { | 66 | for (fmt.exclude_paths) |p| { |
| 67 | argv.appendAssumeCapacity("--exclude"); | 67 | argv.appendAssumeCapacity("--exclude"); |
| 68 | argv.appendAssumeCapacity(b.pathFromRoot(p)); | 68 | argv.appendAssumeCapacity(b.pathFromRoot(p)); |
| 69 | } | 69 | } |
lib/std/Build/Step/InstallArtifact.zig+22-22| ... | @@ -29,7 +29,7 @@ const DylibSymlinkInfo = struct { | ... | @@ -29,7 +29,7 @@ const DylibSymlinkInfo = struct { |
| 29 | name_only_filename: []const u8, | 29 | name_only_filename: []const u8, |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | pub const base_id = .install_artifact; | 32 | pub const base_id: Step.Id = .install_artifact; |
| 33 | 33 | ||
| 34 | pub const Options = struct { | 34 | pub const Options = struct { |
| 35 | /// Which installation directory to put the main output file into. | 35 | /// Which installation directory to put the main output file into. |
| ... | @@ -52,7 +52,7 @@ pub const Options = struct { | ... | @@ -52,7 +52,7 @@ pub const Options = struct { |
| 52 | }; | 52 | }; |
| 53 | 53 | ||
| 54 | pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *InstallArtifact { | 54 | pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *InstallArtifact { |
| 55 | const self = owner.allocator.create(InstallArtifact) catch @panic("OOM"); | 55 | const install_artifact = owner.allocator.create(InstallArtifact) catch @panic("OOM"); |
| 56 | const dest_dir: ?InstallDir = switch (options.dest_dir) { | 56 | const dest_dir: ?InstallDir = switch (options.dest_dir) { |
| 57 | .disabled => null, | 57 | .disabled => null, |
| 58 | .default => switch (artifact.kind) { | 58 | .default => switch (artifact.kind) { |
| ... | @@ -62,7 +62,7 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins | ... | @@ -62,7 +62,7 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins |
| 62 | }, | 62 | }, |
| 63 | .override => |o| o, | 63 | .override => |o| o, |
| 64 | }; | 64 | }; |
| 65 | self.* = .{ | 65 | install_artifact.* = .{ |
| 66 | .step = Step.init(.{ | 66 | .step = Step.init(.{ |
| 67 | .id = base_id, | 67 | .id = base_id, |
| 68 | .name = owner.fmt("install {s}", .{artifact.name}), | 68 | .name = owner.fmt("install {s}", .{artifact.name}), |
| ... | @@ -104,28 +104,28 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins | ... | @@ -104,28 +104,28 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins |
| 104 | .artifact = artifact, | 104 | .artifact = artifact, |
| 105 | }; | 105 | }; |
| 106 | 106 | ||
| 107 | self.step.dependOn(&artifact.step); | 107 | install_artifact.step.dependOn(&artifact.step); |
| 108 | 108 | ||
| 109 | if (self.dest_dir != null) self.emitted_bin = artifact.getEmittedBin(); | 109 | if (install_artifact.dest_dir != null) install_artifact.emitted_bin = artifact.getEmittedBin(); |
| 110 | if (self.pdb_dir != null) self.emitted_pdb = artifact.getEmittedPdb(); | 110 | if (install_artifact.pdb_dir != null) install_artifact.emitted_pdb = artifact.getEmittedPdb(); |
| 111 | // https://github.com/ziglang/zig/issues/9698 | 111 | // https://github.com/ziglang/zig/issues/9698 |
| 112 | //if (self.h_dir != null) self.emitted_h = artifact.getEmittedH(); | 112 | //if (install_artifact.h_dir != null) install_artifact.emitted_h = artifact.getEmittedH(); |
| 113 | if (self.implib_dir != null) self.emitted_implib = artifact.getEmittedImplib(); | 113 | if (install_artifact.implib_dir != null) install_artifact.emitted_implib = artifact.getEmittedImplib(); |
| 114 | 114 | ||
| 115 | return self; | 115 | return install_artifact; |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 118 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 119 | _ = prog_node; | 119 | _ = prog_node; |
| 120 | const self: *InstallArtifact = @fieldParentPtr("step", step); | 120 | const install_artifact: *InstallArtifact = @fieldParentPtr("step", step); |
| 121 | const b = step.owner; | 121 | const b = step.owner; |
| 122 | const cwd = fs.cwd(); | 122 | const cwd = fs.cwd(); |
| 123 | 123 | ||
| 124 | var all_cached = true; | 124 | var all_cached = true; |
| 125 | 125 | ||
| 126 | if (self.dest_dir) |dest_dir| { | 126 | if (install_artifact.dest_dir) |dest_dir| { |
| 127 | const full_dest_path = b.getInstallPath(dest_dir, self.dest_sub_path); | 127 | const full_dest_path = b.getInstallPath(dest_dir, install_artifact.dest_sub_path); |
| 128 | const full_src_path = self.emitted_bin.?.getPath2(b, step); | 128 | const full_src_path = install_artifact.emitted_bin.?.getPath2(b, step); |
| 129 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| { | 129 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| { |
| 130 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | 130 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ |
| 131 | full_src_path, full_dest_path, @errorName(err), | 131 | full_src_path, full_dest_path, @errorName(err), |
| ... | @@ -133,15 +133,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -133,15 +133,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 133 | }; | 133 | }; |
| 134 | all_cached = all_cached and p == .fresh; | 134 | all_cached = all_cached and p == .fresh; |
| 135 | 135 | ||
| 136 | if (self.dylib_symlinks) |dls| { | 136 | if (install_artifact.dylib_symlinks) |dls| { |
| 137 | try Step.Compile.doAtomicSymLinks(step, full_dest_path, dls.major_only_filename, dls.name_only_filename); | 137 | try Step.Compile.doAtomicSymLinks(step, full_dest_path, dls.major_only_filename, dls.name_only_filename); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | self.artifact.installed_path = full_dest_path; | 140 | install_artifact.artifact.installed_path = full_dest_path; |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | if (self.implib_dir) |implib_dir| { | 143 | if (install_artifact.implib_dir) |implib_dir| { |
| 144 | const full_src_path = self.emitted_implib.?.getPath2(b, step); | 144 | const full_src_path = install_artifact.emitted_implib.?.getPath2(b, step); |
| 145 | const full_implib_path = b.getInstallPath(implib_dir, fs.path.basename(full_src_path)); | 145 | const full_implib_path = b.getInstallPath(implib_dir, fs.path.basename(full_src_path)); |
| 146 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_implib_path, .{}) catch |err| { | 146 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_implib_path, .{}) catch |err| { |
| 147 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | 147 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ |
| ... | @@ -151,8 +151,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -151,8 +151,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 151 | all_cached = all_cached and p == .fresh; | 151 | all_cached = all_cached and p == .fresh; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | if (self.pdb_dir) |pdb_dir| { | 154 | if (install_artifact.pdb_dir) |pdb_dir| { |
| 155 | const full_src_path = self.emitted_pdb.?.getPath2(b, step); | 155 | const full_src_path = install_artifact.emitted_pdb.?.getPath2(b, step); |
| 156 | const full_pdb_path = b.getInstallPath(pdb_dir, fs.path.basename(full_src_path)); | 156 | const full_pdb_path = b.getInstallPath(pdb_dir, fs.path.basename(full_src_path)); |
| 157 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_pdb_path, .{}) catch |err| { | 157 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_pdb_path, .{}) catch |err| { |
| 158 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | 158 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ |
| ... | @@ -162,8 +162,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -162,8 +162,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 162 | all_cached = all_cached and p == .fresh; | 162 | all_cached = all_cached and p == .fresh; |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | if (self.h_dir) |h_dir| { | 165 | if (install_artifact.h_dir) |h_dir| { |
| 166 | if (self.emitted_h) |emitted_h| { | 166 | if (install_artifact.emitted_h) |emitted_h| { |
| 167 | const full_src_path = emitted_h.getPath2(b, step); | 167 | const full_src_path = emitted_h.getPath2(b, step); |
| 168 | const full_h_path = b.getInstallPath(h_dir, fs.path.basename(full_src_path)); | 168 | const full_h_path = b.getInstallPath(h_dir, fs.path.basename(full_src_path)); |
| 169 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_h_path, .{}) catch |err| { | 169 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_h_path, .{}) catch |err| { |
| ... | @@ -174,7 +174,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -174,7 +174,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 174 | all_cached = all_cached and p == .fresh; | 174 | all_cached = all_cached and p == .fresh; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | for (self.artifact.installed_headers.items) |installation| switch (installation) { | 177 | for (install_artifact.artifact.installed_headers.items) |installation| switch (installation) { |
| 178 | .file => |file| { | 178 | .file => |file| { |
| 179 | const full_src_path = file.source.getPath2(b, step); | 179 | const full_src_path = file.source.getPath2(b, step); |
| 180 | const full_h_path = b.getInstallPath(h_dir, file.dest_rel_path); | 180 | const full_h_path = b.getInstallPath(h_dir, file.dest_rel_path); |
lib/std/Build/Step/InstallDir.zig+24-25| ... | @@ -3,17 +3,16 @@ const mem = std.mem; | ... | @@ -3,17 +3,16 @@ const mem = std.mem; |
| 3 | const fs = std.fs; | 3 | const fs = std.fs; |
| 4 | const Step = std.Build.Step; | 4 | const Step = std.Build.Step; |
| 5 | const LazyPath = std.Build.LazyPath; | 5 | const LazyPath = std.Build.LazyPath; |
| 6 | const InstallDir = std.Build.InstallDir; | 6 | const InstallDir = @This(); |
| 7 | const InstallDirStep = @This(); | ||
| 8 | 7 | ||
| 9 | step: Step, | 8 | step: Step, |
| 10 | options: Options, | 9 | options: Options, |
| 11 | 10 | ||
| 12 | pub const base_id = .install_dir; | 11 | pub const base_id: Step.Id = .install_dir; |
| 13 | 12 | ||
| 14 | pub const Options = struct { | 13 | pub const Options = struct { |
| 15 | source_dir: LazyPath, | 14 | source_dir: LazyPath, |
| 16 | install_dir: InstallDir, | 15 | install_dir: std.Build.InstallDir, |
| 17 | install_subdir: []const u8, | 16 | install_subdir: []const u8, |
| 18 | /// File paths which end in any of these suffixes will be excluded | 17 | /// File paths which end in any of these suffixes will be excluded |
| 19 | /// from being installed. | 18 | /// from being installed. |
| ... | @@ -29,41 +28,41 @@ pub const Options = struct { | ... | @@ -29,41 +28,41 @@ pub const Options = struct { |
| 29 | /// `@import("test.zig")` would be a compile error. | 28 | /// `@import("test.zig")` would be a compile error. |
| 30 | blank_extensions: []const []const u8 = &.{}, | 29 | blank_extensions: []const []const u8 = &.{}, |
| 31 | 30 | ||
| 32 | fn dupe(self: Options, b: *std.Build) Options { | 31 | fn dupe(opts: Options, b: *std.Build) Options { |
| 33 | return .{ | 32 | return .{ |
| 34 | .source_dir = self.source_dir.dupe(b), | 33 | .source_dir = opts.source_dir.dupe(b), |
| 35 | .install_dir = self.install_dir.dupe(b), | 34 | .install_dir = opts.install_dir.dupe(b), |
| 36 | .install_subdir = b.dupe(self.install_subdir), | 35 | .install_subdir = b.dupe(opts.install_subdir), |
| 37 | .exclude_extensions = b.dupeStrings(self.exclude_extensions), | 36 | .exclude_extensions = b.dupeStrings(opts.exclude_extensions), |
| 38 | .include_extensions = if (self.include_extensions) |incs| b.dupeStrings(incs) else null, | 37 | .include_extensions = if (opts.include_extensions) |incs| b.dupeStrings(incs) else null, |
| 39 | .blank_extensions = b.dupeStrings(self.blank_extensions), | 38 | .blank_extensions = b.dupeStrings(opts.blank_extensions), |
| 40 | }; | 39 | }; |
| 41 | } | 40 | } |
| 42 | }; | 41 | }; |
| 43 | 42 | ||
| 44 | pub fn create(owner: *std.Build, options: Options) *InstallDirStep { | 43 | pub fn create(owner: *std.Build, options: Options) *InstallDir { |
| 45 | owner.pushInstalledFile(options.install_dir, options.install_subdir); | 44 | owner.pushInstalledFile(options.install_dir, options.install_subdir); |
| 46 | const self = owner.allocator.create(InstallDirStep) catch @panic("OOM"); | 45 | const install_dir = owner.allocator.create(InstallDir) catch @panic("OOM"); |
| 47 | self.* = .{ | 46 | install_dir.* = .{ |
| 48 | .step = Step.init(.{ | 47 | .step = Step.init(.{ |
| 49 | .id = .install_dir, | 48 | .id = base_id, |
| 50 | .name = owner.fmt("install {s}/", .{options.source_dir.getDisplayName()}), | 49 | .name = owner.fmt("install {s}/", .{options.source_dir.getDisplayName()}), |
| 51 | .owner = owner, | 50 | .owner = owner, |
| 52 | .makeFn = make, | 51 | .makeFn = make, |
| 53 | }), | 52 | }), |
| 54 | .options = options.dupe(owner), | 53 | .options = options.dupe(owner), |
| 55 | }; | 54 | }; |
| 56 | options.source_dir.addStepDependencies(&self.step); | 55 | options.source_dir.addStepDependencies(&install_dir.step); |
| 57 | return self; | 56 | return install_dir; |
| 58 | } | 57 | } |
| 59 | 58 | ||
| 60 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 59 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 61 | _ = prog_node; | 60 | _ = prog_node; |
| 62 | const b = step.owner; | 61 | const b = step.owner; |
| 63 | const self: *InstallDirStep = @fieldParentPtr("step", step); | 62 | const install_dir: *InstallDir = @fieldParentPtr("step", step); |
| 64 | const arena = b.allocator; | 63 | const arena = b.allocator; |
| 65 | const dest_prefix = b.getInstallPath(self.options.install_dir, self.options.install_subdir); | 64 | const dest_prefix = b.getInstallPath(install_dir.options.install_dir, install_dir.options.install_subdir); |
| 66 | const src_dir_path = self.options.source_dir.getPath2(b, step); | 65 | const src_dir_path = install_dir.options.source_dir.getPath2(b, step); |
| 67 | var src_dir = b.build_root.handle.openDir(src_dir_path, .{ .iterate = true }) catch |err| { | 66 | var src_dir = b.build_root.handle.openDir(src_dir_path, .{ .iterate = true }) catch |err| { |
| 68 | return step.fail("unable to open source directory '{}{s}': {s}", .{ | 67 | return step.fail("unable to open source directory '{}{s}': {s}", .{ |
| 69 | b.build_root, src_dir_path, @errorName(err), | 68 | b.build_root, src_dir_path, @errorName(err), |
| ... | @@ -73,12 +72,12 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -73,12 +72,12 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 73 | var it = try src_dir.walk(arena); | 72 | var it = try src_dir.walk(arena); |
| 74 | var all_cached = true; | 73 | var all_cached = true; |
| 75 | next_entry: while (try it.next()) |entry| { | 74 | next_entry: while (try it.next()) |entry| { |
| 76 | for (self.options.exclude_extensions) |ext| { | 75 | for (install_dir.options.exclude_extensions) |ext| { |
| 77 | if (mem.endsWith(u8, entry.path, ext)) { | 76 | if (mem.endsWith(u8, entry.path, ext)) { |
| 78 | continue :next_entry; | 77 | continue :next_entry; |
| 79 | } | 78 | } |
| 80 | } | 79 | } |
| 81 | if (self.options.include_extensions) |incs| { | 80 | if (install_dir.options.include_extensions) |incs| { |
| 82 | var found = false; | 81 | var found = false; |
| 83 | for (incs) |inc| { | 82 | for (incs) |inc| { |
| 84 | if (mem.endsWith(u8, entry.path, inc)) { | 83 | if (mem.endsWith(u8, entry.path, inc)) { |
| ... | @@ -90,14 +89,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -90,14 +89,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 90 | } | 89 | } |
| 91 | 90 | ||
| 92 | // relative to src build root | 91 | // relative to src build root |
| 93 | const src_sub_path = try fs.path.join(arena, &.{ src_dir_path, entry.path }); | 92 | const src_sub_path = b.pathJoin(&.{ src_dir_path, entry.path }); |
| 94 | const dest_path = try fs.path.join(arena, &.{ dest_prefix, entry.path }); | 93 | const dest_path = b.pathJoin(&.{ dest_prefix, entry.path }); |
| 95 | const cwd = fs.cwd(); | 94 | const cwd = fs.cwd(); |
| 96 | 95 | ||
| 97 | switch (entry.kind) { | 96 | switch (entry.kind) { |
| 98 | .directory => try cwd.makePath(dest_path), | 97 | .directory => try cwd.makePath(dest_path), |
| 99 | .file => { | 98 | .file => { |
| 100 | for (self.options.blank_extensions) |ext| { | 99 | for (install_dir.options.blank_extensions) |ext| { |
| 101 | if (mem.endsWith(u8, entry.path, ext)) { | 100 | if (mem.endsWith(u8, entry.path, ext)) { |
| 102 | try b.truncateFile(dest_path); | 101 | try b.truncateFile(dest_path); |
| 103 | continue :next_entry; | 102 | continue :next_entry; |
lib/std/Build/Step/InstallFile.zig+8-8| ... | @@ -5,7 +5,7 @@ const InstallDir = std.Build.InstallDir; | ... | @@ -5,7 +5,7 @@ const InstallDir = std.Build.InstallDir; |
| 5 | const InstallFile = @This(); | 5 | const InstallFile = @This(); |
| 6 | const assert = std.debug.assert; | 6 | const assert = std.debug.assert; |
| 7 | 7 | ||
| 8 | pub const base_id = .install_file; | 8 | pub const base_id: Step.Id = .install_file; |
| 9 | 9 | ||
| 10 | step: Step, | 10 | step: Step, |
| 11 | source: LazyPath, | 11 | source: LazyPath, |
| ... | @@ -20,8 +20,8 @@ pub fn create( | ... | @@ -20,8 +20,8 @@ pub fn create( |
| 20 | ) *InstallFile { | 20 | ) *InstallFile { |
| 21 | assert(dest_rel_path.len != 0); | 21 | assert(dest_rel_path.len != 0); |
| 22 | owner.pushInstalledFile(dir, dest_rel_path); | 22 | owner.pushInstalledFile(dir, dest_rel_path); |
| 23 | const self = owner.allocator.create(InstallFile) catch @panic("OOM"); | 23 | const install_file = owner.allocator.create(InstallFile) catch @panic("OOM"); |
| 24 | self.* = .{ | 24 | install_file.* = .{ |
| 25 | .step = Step.init(.{ | 25 | .step = Step.init(.{ |
| 26 | .id = base_id, | 26 | .id = base_id, |
| 27 | .name = owner.fmt("install {s} to {s}", .{ source.getDisplayName(), dest_rel_path }), | 27 | .name = owner.fmt("install {s} to {s}", .{ source.getDisplayName(), dest_rel_path }), |
| ... | @@ -32,16 +32,16 @@ pub fn create( | ... | @@ -32,16 +32,16 @@ pub fn create( |
| 32 | .dir = dir.dupe(owner), | 32 | .dir = dir.dupe(owner), |
| 33 | .dest_rel_path = owner.dupePath(dest_rel_path), | 33 | .dest_rel_path = owner.dupePath(dest_rel_path), |
| 34 | }; | 34 | }; |
| 35 | source.addStepDependencies(&self.step); | 35 | source.addStepDependencies(&install_file.step); |
| 36 | return self; | 36 | return install_file; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 39 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 40 | _ = prog_node; | 40 | _ = prog_node; |
| 41 | const b = step.owner; | 41 | const b = step.owner; |
| 42 | const self: *InstallFile = @fieldParentPtr("step", step); | 42 | const install_file: *InstallFile = @fieldParentPtr("step", step); |
| 43 | const full_src_path = self.source.getPath2(b, step); | 43 | const full_src_path = install_file.source.getPath2(b, step); |
| 44 | const full_dest_path = b.getInstallPath(self.dir, self.dest_rel_path); | 44 | const full_dest_path = b.getInstallPath(install_file.dir, install_file.dest_rel_path); |
| 45 | const cwd = std.fs.cwd(); | 45 | const cwd = std.fs.cwd(); |
| 46 | const prev = std.fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| { | 46 | const prev = std.fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| { |
| 47 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | 47 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ |
lib/std/Build/Step/ObjCopy.zig+32-32| ... | @@ -58,8 +58,8 @@ pub fn create( | ... | @@ -58,8 +58,8 @@ pub fn create( |
| 58 | input_file: std.Build.LazyPath, | 58 | input_file: std.Build.LazyPath, |
| 59 | options: Options, | 59 | options: Options, |
| 60 | ) *ObjCopy { | 60 | ) *ObjCopy { |
| 61 | const self = owner.allocator.create(ObjCopy) catch @panic("OOM"); | 61 | const objcopy = owner.allocator.create(ObjCopy) catch @panic("OOM"); |
| 62 | self.* = ObjCopy{ | 62 | objcopy.* = ObjCopy{ |
| 63 | .step = Step.init(.{ | 63 | .step = Step.init(.{ |
| 64 | .id = base_id, | 64 | .id = base_id, |
| 65 | .name = owner.fmt("objcopy {s}", .{input_file.getDisplayName()}), | 65 | .name = owner.fmt("objcopy {s}", .{input_file.getDisplayName()}), |
| ... | @@ -68,31 +68,31 @@ pub fn create( | ... | @@ -68,31 +68,31 @@ pub fn create( |
| 68 | }), | 68 | }), |
| 69 | .input_file = input_file, | 69 | .input_file = input_file, |
| 70 | .basename = options.basename orelse input_file.getDisplayName(), | 70 | .basename = options.basename orelse input_file.getDisplayName(), |
| 71 | .output_file = std.Build.GeneratedFile{ .step = &self.step }, | 71 | .output_file = std.Build.GeneratedFile{ .step = &objcopy.step }, |
| 72 | .output_file_debug = if (options.strip != .none and options.extract_to_separate_file) std.Build.GeneratedFile{ .step = &self.step } else null, | 72 | .output_file_debug = if (options.strip != .none and options.extract_to_separate_file) std.Build.GeneratedFile{ .step = &objcopy.step } else null, |
| 73 | .format = options.format, | 73 | .format = options.format, |
| 74 | .only_sections = options.only_sections, | 74 | .only_sections = options.only_sections, |
| 75 | .pad_to = options.pad_to, | 75 | .pad_to = options.pad_to, |
| 76 | .strip = options.strip, | 76 | .strip = options.strip, |
| 77 | .compress_debug = options.compress_debug, | 77 | .compress_debug = options.compress_debug, |
| 78 | }; | 78 | }; |
| 79 | input_file.addStepDependencies(&self.step); | 79 | input_file.addStepDependencies(&objcopy.step); |
| 80 | return self; | 80 | return objcopy; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | /// deprecated: use getOutput | 83 | /// deprecated: use getOutput |
| 84 | pub const getOutputSource = getOutput; | 84 | pub const getOutputSource = getOutput; |
| 85 | 85 | ||
| 86 | pub fn getOutput(self: *const ObjCopy) std.Build.LazyPath { | 86 | pub fn getOutput(objcopy: *const ObjCopy) std.Build.LazyPath { |
| 87 | return .{ .generated = &self.output_file }; | 87 | return .{ .generated = &objcopy.output_file }; |
| 88 | } | 88 | } |
| 89 | pub fn getOutputSeparatedDebug(self: *const ObjCopy) ?std.Build.LazyPath { | 89 | pub fn getOutputSeparatedDebug(objcopy: *const ObjCopy) ?std.Build.LazyPath { |
| 90 | return if (self.output_file_debug) |*file| .{ .generated = file } else null; | 90 | return if (objcopy.output_file_debug) |*file| .{ .generated = file } else null; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 93 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 94 | const b = step.owner; | 94 | const b = step.owner; |
| 95 | const self: *ObjCopy = @fieldParentPtr("step", step); | 95 | const objcopy: *ObjCopy = @fieldParentPtr("step", step); |
| 96 | 96 | ||
| 97 | var man = b.graph.cache.obtain(); | 97 | var man = b.graph.cache.obtain(); |
| 98 | defer man.deinit(); | 98 | defer man.deinit(); |
| ... | @@ -101,24 +101,24 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -101,24 +101,24 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 101 | // bytes when ObjCopy implementation is modified incompatibly. | 101 | // bytes when ObjCopy implementation is modified incompatibly. |
| 102 | man.hash.add(@as(u32, 0xe18b7baf)); | 102 | man.hash.add(@as(u32, 0xe18b7baf)); |
| 103 | 103 | ||
| 104 | const full_src_path = self.input_file.getPath(b); | 104 | const full_src_path = objcopy.input_file.getPath2(b, step); |
| 105 | _ = try man.addFile(full_src_path, null); | 105 | _ = try man.addFile(full_src_path, null); |
| 106 | man.hash.addOptionalListOfBytes(self.only_sections); | 106 | man.hash.addOptionalListOfBytes(objcopy.only_sections); |
| 107 | man.hash.addOptional(self.pad_to); | 107 | man.hash.addOptional(objcopy.pad_to); |
| 108 | man.hash.addOptional(self.format); | 108 | man.hash.addOptional(objcopy.format); |
| 109 | man.hash.add(self.compress_debug); | 109 | man.hash.add(objcopy.compress_debug); |
| 110 | man.hash.add(self.strip); | 110 | man.hash.add(objcopy.strip); |
| 111 | man.hash.add(self.output_file_debug != null); | 111 | man.hash.add(objcopy.output_file_debug != null); |
| 112 | 112 | ||
| 113 | if (try step.cacheHit(&man)) { | 113 | if (try step.cacheHit(&man)) { |
| 114 | // Cache hit, skip subprocess execution. | 114 | // Cache hit, skip subprocess execution. |
| 115 | const digest = man.final(); | 115 | const digest = man.final(); |
| 116 | self.output_file.path = try b.cache_root.join(b.allocator, &.{ | 116 | objcopy.output_file.path = try b.cache_root.join(b.allocator, &.{ |
| 117 | "o", &digest, self.basename, | 117 | "o", &digest, objcopy.basename, |
| 118 | }); | 118 | }); |
| 119 | if (self.output_file_debug) |*file| { | 119 | if (objcopy.output_file_debug) |*file| { |
| 120 | file.path = try b.cache_root.join(b.allocator, &.{ | 120 | file.path = try b.cache_root.join(b.allocator, &.{ |
| 121 | "o", &digest, b.fmt("{s}.debug", .{self.basename}), | 121 | "o", &digest, b.fmt("{s}.debug", .{objcopy.basename}), |
| 122 | }); | 122 | }); |
| 123 | } | 123 | } |
| 124 | return; | 124 | return; |
| ... | @@ -126,8 +126,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -126,8 +126,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 126 | 126 | ||
| 127 | const digest = man.final(); | 127 | const digest = man.final(); |
| 128 | const cache_path = "o" ++ fs.path.sep_str ++ digest; | 128 | const cache_path = "o" ++ fs.path.sep_str ++ digest; |
| 129 | const full_dest_path = try b.cache_root.join(b.allocator, &.{ cache_path, self.basename }); | 129 | const full_dest_path = try b.cache_root.join(b.allocator, &.{ cache_path, objcopy.basename }); |
| 130 | const full_dest_path_debug = try b.cache_root.join(b.allocator, &.{ cache_path, b.fmt("{s}.debug", .{self.basename}) }); | 130 | const full_dest_path_debug = try b.cache_root.join(b.allocator, &.{ cache_path, b.fmt("{s}.debug", .{objcopy.basename}) }); |
| 131 | b.cache_root.handle.makePath(cache_path) catch |err| { | 131 | b.cache_root.handle.makePath(cache_path) catch |err| { |
| 132 | return step.fail("unable to make path {s}: {s}", .{ cache_path, @errorName(err) }); | 132 | return step.fail("unable to make path {s}: {s}", .{ cache_path, @errorName(err) }); |
| 133 | }; | 133 | }; |
| ... | @@ -135,28 +135,28 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -135,28 +135,28 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 135 | var argv = std.ArrayList([]const u8).init(b.allocator); | 135 | var argv = std.ArrayList([]const u8).init(b.allocator); |
| 136 | try argv.appendSlice(&.{ b.graph.zig_exe, "objcopy" }); | 136 | try argv.appendSlice(&.{ b.graph.zig_exe, "objcopy" }); |
| 137 | 137 | ||
| 138 | if (self.only_sections) |only_sections| { | 138 | if (objcopy.only_sections) |only_sections| { |
| 139 | for (only_sections) |only_section| { | 139 | for (only_sections) |only_section| { |
| 140 | try argv.appendSlice(&.{ "-j", only_section }); | 140 | try argv.appendSlice(&.{ "-j", only_section }); |
| 141 | } | 141 | } |
| 142 | } | 142 | } |
| 143 | switch (self.strip) { | 143 | switch (objcopy.strip) { |
| 144 | .none => {}, | 144 | .none => {}, |
| 145 | .debug => try argv.appendSlice(&.{"--strip-debug"}), | 145 | .debug => try argv.appendSlice(&.{"--strip-debug"}), |
| 146 | .debug_and_symbols => try argv.appendSlice(&.{"--strip-all"}), | 146 | .debug_and_symbols => try argv.appendSlice(&.{"--strip-all"}), |
| 147 | } | 147 | } |
| 148 | if (self.pad_to) |pad_to| { | 148 | if (objcopy.pad_to) |pad_to| { |
| 149 | try argv.appendSlice(&.{ "--pad-to", b.fmt("{d}", .{pad_to}) }); | 149 | try argv.appendSlice(&.{ "--pad-to", b.fmt("{d}", .{pad_to}) }); |
| 150 | } | 150 | } |
| 151 | if (self.format) |format| switch (format) { | 151 | if (objcopy.format) |format| switch (format) { |
| 152 | .bin => try argv.appendSlice(&.{ "-O", "binary" }), | 152 | .bin => try argv.appendSlice(&.{ "-O", "binary" }), |
| 153 | .hex => try argv.appendSlice(&.{ "-O", "hex" }), | 153 | .hex => try argv.appendSlice(&.{ "-O", "hex" }), |
| 154 | .elf => try argv.appendSlice(&.{ "-O", "elf" }), | 154 | .elf => try argv.appendSlice(&.{ "-O", "elf" }), |
| 155 | }; | 155 | }; |
| 156 | if (self.compress_debug) { | 156 | if (objcopy.compress_debug) { |
| 157 | try argv.appendSlice(&.{"--compress-debug-sections"}); | 157 | try argv.appendSlice(&.{"--compress-debug-sections"}); |
| 158 | } | 158 | } |
| 159 | if (self.output_file_debug != null) { | 159 | if (objcopy.output_file_debug != null) { |
| 160 | try argv.appendSlice(&.{b.fmt("--extract-to={s}", .{full_dest_path_debug})}); | 160 | try argv.appendSlice(&.{b.fmt("--extract-to={s}", .{full_dest_path_debug})}); |
| 161 | } | 161 | } |
| 162 | 162 | ||
| ... | @@ -165,7 +165,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -165,7 +165,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 165 | try argv.append("--listen=-"); | 165 | try argv.append("--listen=-"); |
| 166 | _ = try step.evalZigProcess(argv.items, prog_node); | 166 | _ = try step.evalZigProcess(argv.items, prog_node); |
| 167 | 167 | ||
| 168 | self.output_file.path = full_dest_path; | 168 | objcopy.output_file.path = full_dest_path; |
| 169 | if (self.output_file_debug) |*file| file.path = full_dest_path_debug; | 169 | if (objcopy.output_file_debug) |*file| file.path = full_dest_path_debug; |
| 170 | try man.writeManifest(); | 170 | try man.writeManifest(); |
| 171 | } | 171 | } |
lib/std/Build/Step/Options.zig+52-52| ... | @@ -7,7 +7,7 @@ const LazyPath = std.Build.LazyPath; | ... | @@ -7,7 +7,7 @@ const LazyPath = std.Build.LazyPath; |
| 7 | 7 | ||
| 8 | const Options = @This(); | 8 | const Options = @This(); |
| 9 | 9 | ||
| 10 | pub const base_id = .options; | 10 | pub const base_id: Step.Id = .options; |
| 11 | 11 | ||
| 12 | step: Step, | 12 | step: Step, |
| 13 | generated_file: GeneratedFile, | 13 | generated_file: GeneratedFile, |
| ... | @@ -17,8 +17,8 @@ args: std.ArrayList(Arg), | ... | @@ -17,8 +17,8 @@ args: std.ArrayList(Arg), |
| 17 | encountered_types: std.StringHashMap(void), | 17 | encountered_types: std.StringHashMap(void), |
| 18 | 18 | ||
| 19 | pub fn create(owner: *std.Build) *Options { | 19 | pub fn create(owner: *std.Build) *Options { |
| 20 | const self = owner.allocator.create(Options) catch @panic("OOM"); | 20 | const options = owner.allocator.create(Options) catch @panic("OOM"); |
| 21 | self.* = .{ | 21 | options.* = .{ |
| 22 | .step = Step.init(.{ | 22 | .step = Step.init(.{ |
| 23 | .id = base_id, | 23 | .id = base_id, |
| 24 | .name = "options", | 24 | .name = "options", |
| ... | @@ -30,21 +30,21 @@ pub fn create(owner: *std.Build) *Options { | ... | @@ -30,21 +30,21 @@ pub fn create(owner: *std.Build) *Options { |
| 30 | .args = std.ArrayList(Arg).init(owner.allocator), | 30 | .args = std.ArrayList(Arg).init(owner.allocator), |
| 31 | .encountered_types = std.StringHashMap(void).init(owner.allocator), | 31 | .encountered_types = std.StringHashMap(void).init(owner.allocator), |
| 32 | }; | 32 | }; |
| 33 | self.generated_file = .{ .step = &self.step }; | 33 | options.generated_file = .{ .step = &options.step }; |
| 34 | 34 | ||
| 35 | return self; | 35 | return options; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | pub fn addOption(self: *Options, comptime T: type, name: []const u8, value: T) void { | 38 | pub fn addOption(options: *Options, comptime T: type, name: []const u8, value: T) void { |
| 39 | return addOptionFallible(self, T, name, value) catch @panic("unhandled error"); | 39 | return addOptionFallible(options, T, name, value) catch @panic("unhandled error"); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | fn addOptionFallible(self: *Options, comptime T: type, name: []const u8, value: T) !void { | 42 | fn addOptionFallible(options: *Options, comptime T: type, name: []const u8, value: T) !void { |
| 43 | const out = self.contents.writer(); | 43 | const out = options.contents.writer(); |
| 44 | try printType(self, out, T, value, 0, name); | 44 | try printType(options, out, T, value, 0, name); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u8, name: ?[]const u8) !void { | 47 | fn printType(options: *Options, out: anytype, comptime T: type, value: T, indent: u8, name: ?[]const u8) !void { |
| 48 | switch (T) { | 48 | switch (T) { |
| 49 | []const []const u8 => { | 49 | []const []const u8 => { |
| 50 | if (name) |payload| { | 50 | if (name) |payload| { |
| ... | @@ -159,7 +159,7 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u | ... | @@ -159,7 +159,7 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u |
| 159 | try out.print("{s} {{\n", .{@typeName(T)}); | 159 | try out.print("{s} {{\n", .{@typeName(T)}); |
| 160 | for (value) |item| { | 160 | for (value) |item| { |
| 161 | try out.writeByteNTimes(' ', indent + 4); | 161 | try out.writeByteNTimes(' ', indent + 4); |
| 162 | try printType(self, out, @TypeOf(item), item, indent + 4, null); | 162 | try printType(options, out, @TypeOf(item), item, indent + 4, null); |
| 163 | } | 163 | } |
| 164 | try out.writeByteNTimes(' ', indent); | 164 | try out.writeByteNTimes(' ', indent); |
| 165 | try out.writeAll("}"); | 165 | try out.writeAll("}"); |
| ... | @@ -183,7 +183,7 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u | ... | @@ -183,7 +183,7 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u |
| 183 | try out.print("&[_]{s} {{\n", .{@typeName(p.child)}); | 183 | try out.print("&[_]{s} {{\n", .{@typeName(p.child)}); |
| 184 | for (value) |item| { | 184 | for (value) |item| { |
| 185 | try out.writeByteNTimes(' ', indent + 4); | 185 | try out.writeByteNTimes(' ', indent + 4); |
| 186 | try printType(self, out, @TypeOf(item), item, indent + 4, null); | 186 | try printType(options, out, @TypeOf(item), item, indent + 4, null); |
| 187 | } | 187 | } |
| 188 | try out.writeByteNTimes(' ', indent); | 188 | try out.writeByteNTimes(' ', indent); |
| 189 | try out.writeAll("}"); | 189 | try out.writeAll("}"); |
| ... | @@ -201,10 +201,10 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u | ... | @@ -201,10 +201,10 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | if (value) |inner| { | 203 | if (value) |inner| { |
| 204 | try printType(self, out, @TypeOf(inner), inner, indent + 4, null); | 204 | try printType(options, out, @TypeOf(inner), inner, indent + 4, null); |
| 205 | // Pop the '\n' and ',' chars | 205 | // Pop the '\n' and ',' chars |
| 206 | _ = self.contents.pop(); | 206 | _ = options.contents.pop(); |
| 207 | _ = self.contents.pop(); | 207 | _ = options.contents.pop(); |
| 208 | } else { | 208 | } else { |
| 209 | try out.writeAll("null"); | 209 | try out.writeAll("null"); |
| 210 | } | 210 | } |
| ... | @@ -231,7 +231,7 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u | ... | @@ -231,7 +231,7 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u |
| 231 | return; | 231 | return; |
| 232 | }, | 232 | }, |
| 233 | .Enum => |info| { | 233 | .Enum => |info| { |
| 234 | try printEnum(self, out, T, info, indent); | 234 | try printEnum(options, out, T, info, indent); |
| 235 | 235 | ||
| 236 | if (name) |some| { | 236 | if (name) |some| { |
| 237 | try out.print("pub const {}: {} = .{p_};\n", .{ | 237 | try out.print("pub const {}: {} = .{p_};\n", .{ |
| ... | @@ -243,14 +243,14 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u | ... | @@ -243,14 +243,14 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u |
| 243 | return; | 243 | return; |
| 244 | }, | 244 | }, |
| 245 | .Struct => |info| { | 245 | .Struct => |info| { |
| 246 | try printStruct(self, out, T, info, indent); | 246 | try printStruct(options, out, T, info, indent); |
| 247 | 247 | ||
| 248 | if (name) |some| { | 248 | if (name) |some| { |
| 249 | try out.print("pub const {}: {} = ", .{ | 249 | try out.print("pub const {}: {} = ", .{ |
| 250 | std.zig.fmtId(some), | 250 | std.zig.fmtId(some), |
| 251 | std.zig.fmtId(@typeName(T)), | 251 | std.zig.fmtId(@typeName(T)), |
| 252 | }); | 252 | }); |
| 253 | try printStructValue(self, out, info, value, indent); | 253 | try printStructValue(options, out, info, value, indent); |
| 254 | } | 254 | } |
| 255 | return; | 255 | return; |
| 256 | }, | 256 | }, |
| ... | @@ -258,20 +258,20 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u | ... | @@ -258,20 +258,20 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u |
| 258 | } | 258 | } |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | fn printUserDefinedType(self: *Options, out: anytype, comptime T: type, indent: u8) !void { | 261 | fn printUserDefinedType(options: *Options, out: anytype, comptime T: type, indent: u8) !void { |
| 262 | switch (@typeInfo(T)) { | 262 | switch (@typeInfo(T)) { |
| 263 | .Enum => |info| { | 263 | .Enum => |info| { |
| 264 | return try printEnum(self, out, T, info, indent); | 264 | return try printEnum(options, out, T, info, indent); |
| 265 | }, | 265 | }, |
| 266 | .Struct => |info| { | 266 | .Struct => |info| { |
| 267 | return try printStruct(self, out, T, info, indent); | 267 | return try printStruct(options, out, T, info, indent); |
| 268 | }, | 268 | }, |
| 269 | else => {}, | 269 | else => {}, |
| 270 | } | 270 | } |
| 271 | } | 271 | } |
| 272 | 272 | ||
| 273 | fn printEnum(self: *Options, out: anytype, comptime T: type, comptime val: std.builtin.Type.Enum, indent: u8) !void { | 273 | fn printEnum(options: *Options, out: anytype, comptime T: type, comptime val: std.builtin.Type.Enum, indent: u8) !void { |
| 274 | const gop = try self.encountered_types.getOrPut(@typeName(T)); | 274 | const gop = try options.encountered_types.getOrPut(@typeName(T)); |
| 275 | if (gop.found_existing) return; | 275 | if (gop.found_existing) return; |
| 276 | 276 | ||
| 277 | try out.writeByteNTimes(' ', indent); | 277 | try out.writeByteNTimes(' ', indent); |
| ... | @@ -291,8 +291,8 @@ fn printEnum(self: *Options, out: anytype, comptime T: type, comptime val: std.b | ... | @@ -291,8 +291,8 @@ fn printEnum(self: *Options, out: anytype, comptime T: type, comptime val: std.b |
| 291 | try out.writeAll("};\n"); | 291 | try out.writeAll("};\n"); |
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | fn printStruct(self: *Options, out: anytype, comptime T: type, comptime val: std.builtin.Type.Struct, indent: u8) !void { | 294 | fn printStruct(options: *Options, out: anytype, comptime T: type, comptime val: std.builtin.Type.Struct, indent: u8) !void { |
| 295 | const gop = try self.encountered_types.getOrPut(@typeName(T)); | 295 | const gop = try options.encountered_types.getOrPut(@typeName(T)); |
| 296 | if (gop.found_existing) return; | 296 | if (gop.found_existing) return; |
| 297 | 297 | ||
| 298 | try out.writeByteNTimes(' ', indent); | 298 | try out.writeByteNTimes(' ', indent); |
| ... | @@ -325,9 +325,9 @@ fn printStruct(self: *Options, out: anytype, comptime T: type, comptime val: std | ... | @@ -325,9 +325,9 @@ fn printStruct(self: *Options, out: anytype, comptime T: type, comptime val: std |
| 325 | switch (@typeInfo(@TypeOf(default_value))) { | 325 | switch (@typeInfo(@TypeOf(default_value))) { |
| 326 | .Enum => try out.print(".{s},\n", .{@tagName(default_value)}), | 326 | .Enum => try out.print(".{s},\n", .{@tagName(default_value)}), |
| 327 | .Struct => |info| { | 327 | .Struct => |info| { |
| 328 | try printStructValue(self, out, info, default_value, indent + 4); | 328 | try printStructValue(options, out, info, default_value, indent + 4); |
| 329 | }, | 329 | }, |
| 330 | else => try printType(self, out, @TypeOf(default_value), default_value, indent, null), | 330 | else => try printType(options, out, @TypeOf(default_value), default_value, indent, null), |
| 331 | } | 331 | } |
| 332 | } else { | 332 | } else { |
| 333 | try out.writeAll(",\n"); | 333 | try out.writeAll(",\n"); |
| ... | @@ -340,17 +340,17 @@ fn printStruct(self: *Options, out: anytype, comptime T: type, comptime val: std | ... | @@ -340,17 +340,17 @@ fn printStruct(self: *Options, out: anytype, comptime T: type, comptime val: std |
| 340 | try out.writeAll("};\n"); | 340 | try out.writeAll("};\n"); |
| 341 | 341 | ||
| 342 | inline for (val.fields) |field| { | 342 | inline for (val.fields) |field| { |
| 343 | try printUserDefinedType(self, out, field.type, 0); | 343 | try printUserDefinedType(options, out, field.type, 0); |
| 344 | } | 344 | } |
| 345 | } | 345 | } |
| 346 | 346 | ||
| 347 | fn printStructValue(self: *Options, out: anytype, comptime struct_val: std.builtin.Type.Struct, val: anytype, indent: u8) !void { | 347 | fn printStructValue(options: *Options, out: anytype, comptime struct_val: std.builtin.Type.Struct, val: anytype, indent: u8) !void { |
| 348 | try out.writeAll(".{\n"); | 348 | try out.writeAll(".{\n"); |
| 349 | 349 | ||
| 350 | if (struct_val.is_tuple) { | 350 | if (struct_val.is_tuple) { |
| 351 | inline for (struct_val.fields) |field| { | 351 | inline for (struct_val.fields) |field| { |
| 352 | try out.writeByteNTimes(' ', indent); | 352 | try out.writeByteNTimes(' ', indent); |
| 353 | try printType(self, out, @TypeOf(@field(val, field.name)), @field(val, field.name), indent, null); | 353 | try printType(options, out, @TypeOf(@field(val, field.name)), @field(val, field.name), indent, null); |
| 354 | } | 354 | } |
| 355 | } else { | 355 | } else { |
| 356 | inline for (struct_val.fields) |field| { | 356 | inline for (struct_val.fields) |field| { |
| ... | @@ -361,9 +361,9 @@ fn printStructValue(self: *Options, out: anytype, comptime struct_val: std.built | ... | @@ -361,9 +361,9 @@ fn printStructValue(self: *Options, out: anytype, comptime struct_val: std.built |
| 361 | switch (@typeInfo(@TypeOf(field_name))) { | 361 | switch (@typeInfo(@TypeOf(field_name))) { |
| 362 | .Enum => try out.print(".{s},\n", .{@tagName(field_name)}), | 362 | .Enum => try out.print(".{s},\n", .{@tagName(field_name)}), |
| 363 | .Struct => |struct_info| { | 363 | .Struct => |struct_info| { |
| 364 | try printStructValue(self, out, struct_info, field_name, indent + 4); | 364 | try printStructValue(options, out, struct_info, field_name, indent + 4); |
| 365 | }, | 365 | }, |
| 366 | else => try printType(self, out, @TypeOf(field_name), field_name, indent, null), | 366 | else => try printType(options, out, @TypeOf(field_name), field_name, indent, null), |
| 367 | } | 367 | } |
| 368 | } | 368 | } |
| 369 | } | 369 | } |
| ... | @@ -379,25 +379,25 @@ fn printStructValue(self: *Options, out: anytype, comptime struct_val: std.built | ... | @@ -379,25 +379,25 @@ fn printStructValue(self: *Options, out: anytype, comptime struct_val: std.built |
| 379 | /// The value is the path in the cache dir. | 379 | /// The value is the path in the cache dir. |
| 380 | /// Adds a dependency automatically. | 380 | /// Adds a dependency automatically. |
| 381 | pub fn addOptionPath( | 381 | pub fn addOptionPath( |
| 382 | self: *Options, | 382 | options: *Options, |
| 383 | name: []const u8, | 383 | name: []const u8, |
| 384 | path: LazyPath, | 384 | path: LazyPath, |
| 385 | ) void { | 385 | ) void { |
| 386 | self.args.append(.{ | 386 | options.args.append(.{ |
| 387 | .name = self.step.owner.dupe(name), | 387 | .name = options.step.owner.dupe(name), |
| 388 | .path = path.dupe(self.step.owner), | 388 | .path = path.dupe(options.step.owner), |
| 389 | }) catch @panic("OOM"); | 389 | }) catch @panic("OOM"); |
| 390 | path.addStepDependencies(&self.step); | 390 | path.addStepDependencies(&options.step); |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | /// Deprecated: use `addOptionPath(options, name, artifact.getEmittedBin())` instead. | 393 | /// Deprecated: use `addOptionPath(options, name, artifact.getEmittedBin())` instead. |
| 394 | pub fn addOptionArtifact(self: *Options, name: []const u8, artifact: *Step.Compile) void { | 394 | pub fn addOptionArtifact(options: *Options, name: []const u8, artifact: *Step.Compile) void { |
| 395 | return addOptionPath(self, name, artifact.getEmittedBin()); | 395 | return addOptionPath(options, name, artifact.getEmittedBin()); |
| 396 | } | 396 | } |
| 397 | 397 | ||
| 398 | pub fn createModule(self: *Options) *std.Build.Module { | 398 | pub fn createModule(options: *Options) *std.Build.Module { |
| 399 | return self.step.owner.createModule(.{ | 399 | return options.step.owner.createModule(.{ |
| 400 | .root_source_file = self.getOutput(), | 400 | .root_source_file = options.getOutput(), |
| 401 | }); | 401 | }); |
| 402 | } | 402 | } |
| 403 | 403 | ||
| ... | @@ -406,8 +406,8 @@ pub const getSource = getOutput; | ... | @@ -406,8 +406,8 @@ pub const getSource = getOutput; |
| 406 | 406 | ||
| 407 | /// Returns the main artifact of this Build Step which is a Zig source file | 407 | /// Returns the main artifact of this Build Step which is a Zig source file |
| 408 | /// generated from the key-value pairs of the Options. | 408 | /// generated from the key-value pairs of the Options. |
| 409 | pub fn getOutput(self: *Options) LazyPath { | 409 | pub fn getOutput(options: *Options) LazyPath { |
| 410 | return .{ .generated = &self.generated_file }; | 410 | return .{ .generated = &options.generated_file }; |
| 411 | } | 411 | } |
| 412 | 412 | ||
| 413 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 413 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| ... | @@ -415,13 +415,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -415,13 +415,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 415 | _ = prog_node; | 415 | _ = prog_node; |
| 416 | 416 | ||
| 417 | const b = step.owner; | 417 | const b = step.owner; |
| 418 | const self: *Options = @fieldParentPtr("step", step); | 418 | const options: *Options = @fieldParentPtr("step", step); |
| 419 | 419 | ||
| 420 | for (self.args.items) |item| { | 420 | for (options.args.items) |item| { |
| 421 | self.addOption( | 421 | options.addOption( |
| 422 | []const u8, | 422 | []const u8, |
| 423 | item.name, | 423 | item.name, |
| 424 | item.path.getPath(b), | 424 | item.path.getPath2(b, step), |
| 425 | ); | 425 | ); |
| 426 | } | 426 | } |
| 427 | 427 | ||
| ... | @@ -432,10 +432,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -432,10 +432,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 432 | // Random bytes to make unique. Refresh this with new random bytes when | 432 | // Random bytes to make unique. Refresh this with new random bytes when |
| 433 | // implementation is modified in a non-backwards-compatible way. | 433 | // implementation is modified in a non-backwards-compatible way. |
| 434 | hash.add(@as(u32, 0xad95e922)); | 434 | hash.add(@as(u32, 0xad95e922)); |
| 435 | hash.addBytes(self.contents.items); | 435 | hash.addBytes(options.contents.items); |
| 436 | const sub_path = "c" ++ fs.path.sep_str ++ hash.final() ++ fs.path.sep_str ++ basename; | 436 | const sub_path = "c" ++ fs.path.sep_str ++ hash.final() ++ fs.path.sep_str ++ basename; |
| 437 | 437 | ||
| 438 | self.generated_file.path = try b.cache_root.join(b.allocator, &.{sub_path}); | 438 | options.generated_file.path = try b.cache_root.join(b.allocator, &.{sub_path}); |
| 439 | 439 | ||
| 440 | // Optimize for the hot path. Stat the file, and if it already exists, | 440 | // Optimize for the hot path. Stat the file, and if it already exists, |
| 441 | // cache hit. | 441 | // cache hit. |
| ... | @@ -464,7 +464,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -464,7 +464,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 464 | }); | 464 | }); |
| 465 | }; | 465 | }; |
| 466 | 466 | ||
| 467 | b.cache_root.handle.writeFile(.{ .sub_path = tmp_sub_path, .data = self.contents.items }) catch |err| { | 467 | b.cache_root.handle.writeFile(.{ .sub_path = tmp_sub_path, .data = options.contents.items }) catch |err| { |
| 468 | return step.fail("unable to write options to '{}{s}': {s}", .{ | 468 | return step.fail("unable to write options to '{}{s}': {s}", .{ |
| 469 | b.cache_root, tmp_sub_path, @errorName(err), | 469 | b.cache_root, tmp_sub_path, @errorName(err), |
| 470 | }); | 470 | }); |
lib/std/Build/Step/RemoveDir.zig+9-9| ... | @@ -3,23 +3,23 @@ const fs = std.fs; | ... | @@ -3,23 +3,23 @@ const fs = std.fs; |
| 3 | const Step = std.Build.Step; | 3 | const Step = std.Build.Step; |
| 4 | const RemoveDir = @This(); | 4 | const RemoveDir = @This(); |
| 5 | 5 | ||
| 6 | pub const base_id = .remove_dir; | 6 | pub const base_id: Step.Id = .remove_dir; |
| 7 | 7 | ||
| 8 | step: Step, | 8 | step: Step, |
| 9 | dir_path: []const u8, | 9 | dir_path: []const u8, |
| 10 | 10 | ||
| 11 | pub fn create(owner: *std.Build, dir_path: []const u8) *RemoveDir { | 11 | pub fn create(owner: *std.Build, dir_path: []const u8) *RemoveDir { |
| 12 | const self = owner.allocator.create(RemoveDir) catch @panic("OOM"); | 12 | const remove_dir = owner.allocator.create(RemoveDir) catch @panic("OOM"); |
| 13 | self.* = .{ | 13 | remove_dir.* = .{ |
| 14 | .step = Step.init(.{ | 14 | .step = Step.init(.{ |
| 15 | .id = .remove_dir, | 15 | .id = base_id, |
| 16 | .name = owner.fmt("RemoveDir {s}", .{dir_path}), | 16 | .name = owner.fmt("RemoveDir {s}", .{dir_path}), |
| 17 | .owner = owner, | 17 | .owner = owner, |
| 18 | .makeFn = make, | 18 | .makeFn = make, |
| 19 | }), | 19 | }), |
| 20 | .dir_path = owner.dupePath(dir_path), | 20 | .dir_path = owner.dupePath(dir_path), |
| 21 | }; | 21 | }; |
| 22 | return self; | 22 | return remove_dir; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 25 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| ... | @@ -28,16 +28,16 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -28,16 +28,16 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 28 | _ = prog_node; | 28 | _ = prog_node; |
| 29 | 29 | ||
| 30 | const b = step.owner; | 30 | const b = step.owner; |
| 31 | const self: *RemoveDir = @fieldParentPtr("step", step); | 31 | const remove_dir: *RemoveDir = @fieldParentPtr("step", step); |
| 32 | 32 | ||
| 33 | b.build_root.handle.deleteTree(self.dir_path) catch |err| { | 33 | b.build_root.handle.deleteTree(remove_dir.dir_path) catch |err| { |
| 34 | if (b.build_root.path) |base| { | 34 | if (b.build_root.path) |base| { |
| 35 | return step.fail("unable to recursively delete path '{s}/{s}': {s}", .{ | 35 | return step.fail("unable to recursively delete path '{s}/{s}': {s}", .{ |
| 36 | base, self.dir_path, @errorName(err), | 36 | base, remove_dir.dir_path, @errorName(err), |
| 37 | }); | 37 | }); |
| 38 | } else { | 38 | } else { |
| 39 | return step.fail("unable to recursively delete path '{s}': {s}", .{ | 39 | return step.fail("unable to recursively delete path '{s}': {s}", .{ |
| 40 | self.dir_path, @errorName(err), | 40 | remove_dir.dir_path, @errorName(err), |
| 41 | }); | 41 | }); |
| 42 | } | 42 | } |
| 43 | }; | 43 | }; |
lib/std/Build/Step/Run.zig+195-196| ... | @@ -140,8 +140,8 @@ pub const Output = struct { | ... | @@ -140,8 +140,8 @@ pub const Output = struct { |
| 140 | }; | 140 | }; |
| 141 | 141 | ||
| 142 | pub fn create(owner: *std.Build, name: []const u8) *Run { | 142 | pub fn create(owner: *std.Build, name: []const u8) *Run { |
| 143 | const self = owner.allocator.create(Run) catch @panic("OOM"); | 143 | const run = owner.allocator.create(Run) catch @panic("OOM"); |
| 144 | self.* = .{ | 144 | run.* = .{ |
| 145 | .step = Step.init(.{ | 145 | .step = Step.init(.{ |
| 146 | .id = base_id, | 146 | .id = base_id, |
| 147 | .name = name, | 147 | .name = name, |
| ... | @@ -164,24 +164,24 @@ pub fn create(owner: *std.Build, name: []const u8) *Run { | ... | @@ -164,24 +164,24 @@ pub fn create(owner: *std.Build, name: []const u8) *Run { |
| 164 | .dep_output_file = null, | 164 | .dep_output_file = null, |
| 165 | .has_side_effects = false, | 165 | .has_side_effects = false, |
| 166 | }; | 166 | }; |
| 167 | return self; | 167 | return run; |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | pub fn setName(self: *Run, name: []const u8) void { | 170 | pub fn setName(run: *Run, name: []const u8) void { |
| 171 | self.step.name = name; | 171 | run.step.name = name; |
| 172 | self.rename_step_with_output_arg = false; | 172 | run.rename_step_with_output_arg = false; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | pub fn enableTestRunnerMode(self: *Run) void { | 175 | pub fn enableTestRunnerMode(run: *Run) void { |
| 176 | self.stdio = .zig_test; | 176 | run.stdio = .zig_test; |
| 177 | self.addArgs(&.{"--listen=-"}); | 177 | run.addArgs(&.{"--listen=-"}); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void { | 180 | pub fn addArtifactArg(run: *Run, artifact: *Step.Compile) void { |
| 181 | const b = self.step.owner; | 181 | const b = run.step.owner; |
| 182 | const bin_file = artifact.getEmittedBin(); | 182 | const bin_file = artifact.getEmittedBin(); |
| 183 | bin_file.addStepDependencies(&self.step); | 183 | bin_file.addStepDependencies(&run.step); |
| 184 | self.argv.append(b.allocator, Arg{ .artifact = artifact }) catch @panic("OOM"); | 184 | run.argv.append(b.allocator, Arg{ .artifact = artifact }) catch @panic("OOM"); |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | /// Provides a file path as a command line argument to the command being run. | 187 | /// Provides a file path as a command line argument to the command being run. |
| ... | @@ -192,8 +192,8 @@ pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void { | ... | @@ -192,8 +192,8 @@ pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void { |
| 192 | /// Related: | 192 | /// Related: |
| 193 | /// * `addPrefixedOutputFileArg` - same thing but prepends a string to the argument | 193 | /// * `addPrefixedOutputFileArg` - same thing but prepends a string to the argument |
| 194 | /// * `addFileArg` - for input files given to the child process | 194 | /// * `addFileArg` - for input files given to the child process |
| 195 | pub fn addOutputFileArg(self: *Run, basename: []const u8) std.Build.LazyPath { | 195 | pub fn addOutputFileArg(run: *Run, basename: []const u8) std.Build.LazyPath { |
| 196 | return self.addPrefixedOutputFileArg("", basename); | 196 | return run.addPrefixedOutputFileArg("", basename); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | /// Provides a file path as a command line argument to the command being run. | 199 | /// Provides a file path as a command line argument to the command being run. |
| ... | @@ -212,23 +212,23 @@ pub fn addOutputFileArg(self: *Run, basename: []const u8) std.Build.LazyPath { | ... | @@ -212,23 +212,23 @@ pub fn addOutputFileArg(self: *Run, basename: []const u8) std.Build.LazyPath { |
| 212 | /// * `addOutputFileArg` - same thing but without the prefix | 212 | /// * `addOutputFileArg` - same thing but without the prefix |
| 213 | /// * `addFileArg` - for input files given to the child process | 213 | /// * `addFileArg` - for input files given to the child process |
| 214 | pub fn addPrefixedOutputFileArg( | 214 | pub fn addPrefixedOutputFileArg( |
| 215 | self: *Run, | 215 | run: *Run, |
| 216 | prefix: []const u8, | 216 | prefix: []const u8, |
| 217 | basename: []const u8, | 217 | basename: []const u8, |
| 218 | ) std.Build.LazyPath { | 218 | ) std.Build.LazyPath { |
| 219 | const b = self.step.owner; | 219 | const b = run.step.owner; |
| 220 | if (basename.len == 0) @panic("basename must not be empty"); | 220 | if (basename.len == 0) @panic("basename must not be empty"); |
| 221 | 221 | ||
| 222 | const output = b.allocator.create(Output) catch @panic("OOM"); | 222 | const output = b.allocator.create(Output) catch @panic("OOM"); |
| 223 | output.* = .{ | 223 | output.* = .{ |
| 224 | .prefix = b.dupe(prefix), | 224 | .prefix = b.dupe(prefix), |
| 225 | .basename = b.dupe(basename), | 225 | .basename = b.dupe(basename), |
| 226 | .generated_file = .{ .step = &self.step }, | 226 | .generated_file = .{ .step = &run.step }, |
| 227 | }; | 227 | }; |
| 228 | self.argv.append(b.allocator, .{ .output = output }) catch @panic("OOM"); | 228 | run.argv.append(b.allocator, .{ .output = output }) catch @panic("OOM"); |
| 229 | 229 | ||
| 230 | if (self.rename_step_with_output_arg) { | 230 | if (run.rename_step_with_output_arg) { |
| 231 | self.setName(b.fmt("{s} ({s})", .{ self.step.name, basename })); | 231 | run.setName(b.fmt("{s} ({s})", .{ run.step.name, basename })); |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | return .{ .generated = &output.generated_file }; | 234 | return .{ .generated = &output.generated_file }; |
| ... | @@ -243,8 +243,8 @@ pub fn addPrefixedOutputFileArg( | ... | @@ -243,8 +243,8 @@ pub fn addPrefixedOutputFileArg( |
| 243 | /// Related: | 243 | /// Related: |
| 244 | /// * `addPrefixedFileArg` - same thing but prepends a string to the argument | 244 | /// * `addPrefixedFileArg` - same thing but prepends a string to the argument |
| 245 | /// * `addOutputFileArg` - for files generated by the child process | 245 | /// * `addOutputFileArg` - for files generated by the child process |
| 246 | pub fn addFileArg(self: *Run, lp: std.Build.LazyPath) void { | 246 | pub fn addFileArg(run: *Run, lp: std.Build.LazyPath) void { |
| 247 | self.addPrefixedFileArg("", lp); | 247 | run.addPrefixedFileArg("", lp); |
| 248 | } | 248 | } |
| 249 | 249 | ||
| 250 | /// Appends an input file to the command line arguments prepended with a string. | 250 | /// Appends an input file to the command line arguments prepended with a string. |
| ... | @@ -259,100 +259,98 @@ pub fn addFileArg(self: *Run, lp: std.Build.LazyPath) void { | ... | @@ -259,100 +259,98 @@ pub fn addFileArg(self: *Run, lp: std.Build.LazyPath) void { |
| 259 | /// Related: | 259 | /// Related: |
| 260 | /// * `addFileArg` - same thing but without the prefix | 260 | /// * `addFileArg` - same thing but without the prefix |
| 261 | /// * `addOutputFileArg` - for files generated by the child process | 261 | /// * `addOutputFileArg` - for files generated by the child process |
| 262 | pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, lp: std.Build.LazyPath) void { | 262 | pub fn addPrefixedFileArg(run: *Run, prefix: []const u8, lp: std.Build.LazyPath) void { |
| 263 | const b = self.step.owner; | 263 | const b = run.step.owner; |
| 264 | 264 | ||
| 265 | const prefixed_file_source: PrefixedLazyPath = .{ | 265 | const prefixed_file_source: PrefixedLazyPath = .{ |
| 266 | .prefix = b.dupe(prefix), | 266 | .prefix = b.dupe(prefix), |
| 267 | .lazy_path = lp.dupe(b), | 267 | .lazy_path = lp.dupe(b), |
| 268 | }; | 268 | }; |
| 269 | self.argv.append(b.allocator, .{ .lazy_path = prefixed_file_source }) catch @panic("OOM"); | 269 | run.argv.append(b.allocator, .{ .lazy_path = prefixed_file_source }) catch @panic("OOM"); |
| 270 | lp.addStepDependencies(&self.step); | 270 | lp.addStepDependencies(&run.step); |
| 271 | } | 271 | } |
| 272 | 272 | ||
| 273 | /// deprecated: use `addDirectoryArg` | 273 | /// deprecated: use `addDirectoryArg` |
| 274 | pub const addDirectorySourceArg = addDirectoryArg; | 274 | pub const addDirectorySourceArg = addDirectoryArg; |
| 275 | 275 | ||
| 276 | pub fn addDirectoryArg(self: *Run, directory_source: std.Build.LazyPath) void { | 276 | pub fn addDirectoryArg(run: *Run, directory_source: std.Build.LazyPath) void { |
| 277 | self.addPrefixedDirectoryArg("", directory_source); | 277 | run.addPrefixedDirectoryArg("", directory_source); |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | // deprecated: use `addPrefixedDirectoryArg` | 280 | // deprecated: use `addPrefixedDirectoryArg` |
| 281 | pub const addPrefixedDirectorySourceArg = addPrefixedDirectoryArg; | 281 | pub const addPrefixedDirectorySourceArg = addPrefixedDirectoryArg; |
| 282 | 282 | ||
| 283 | pub fn addPrefixedDirectoryArg(self: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void { | 283 | pub fn addPrefixedDirectoryArg(run: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void { |
| 284 | const b = self.step.owner; | 284 | const b = run.step.owner; |
| 285 | 285 | ||
| 286 | const prefixed_directory_source: PrefixedLazyPath = .{ | 286 | const prefixed_directory_source: PrefixedLazyPath = .{ |
| 287 | .prefix = b.dupe(prefix), | 287 | .prefix = b.dupe(prefix), |
| 288 | .lazy_path = directory_source.dupe(b), | 288 | .lazy_path = directory_source.dupe(b), |
| 289 | }; | 289 | }; |
| 290 | self.argv.append(b.allocator, .{ .directory_source = prefixed_directory_source }) catch @panic("OOM"); | 290 | run.argv.append(b.allocator, .{ .directory_source = prefixed_directory_source }) catch @panic("OOM"); |
| 291 | directory_source.addStepDependencies(&self.step); | 291 | directory_source.addStepDependencies(&run.step); |
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | /// Add a path argument to a dep file (.d) for the child process to write its | 294 | /// Add a path argument to a dep file (.d) for the child process to write its |
| 295 | /// discovered additional dependencies. | 295 | /// discovered additional dependencies. |
| 296 | /// Only one dep file argument is allowed by instance. | 296 | /// Only one dep file argument is allowed by instance. |
| 297 | pub fn addDepFileOutputArg(self: *Run, basename: []const u8) std.Build.LazyPath { | 297 | pub fn addDepFileOutputArg(run: *Run, basename: []const u8) std.Build.LazyPath { |
| 298 | return self.addPrefixedDepFileOutputArg("", basename); | 298 | return run.addPrefixedDepFileOutputArg("", basename); |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | /// Add a prefixed path argument to a dep file (.d) for the child process to | 301 | /// Add a prefixed path argument to a dep file (.d) for the child process to |
| 302 | /// write its discovered additional dependencies. | 302 | /// write its discovered additional dependencies. |
| 303 | /// Only one dep file argument is allowed by instance. | 303 | /// Only one dep file argument is allowed by instance. |
| 304 | pub fn addPrefixedDepFileOutputArg(self: *Run, prefix: []const u8, basename: []const u8) std.Build.LazyPath { | 304 | pub fn addPrefixedDepFileOutputArg(run: *Run, prefix: []const u8, basename: []const u8) std.Build.LazyPath { |
| 305 | const b = self.step.owner; | 305 | const b = run.step.owner; |
| 306 | assert(self.dep_output_file == null); | 306 | assert(run.dep_output_file == null); |
| 307 | 307 | ||
| 308 | const dep_file = b.allocator.create(Output) catch @panic("OOM"); | 308 | const dep_file = b.allocator.create(Output) catch @panic("OOM"); |
| 309 | dep_file.* = .{ | 309 | dep_file.* = .{ |
| 310 | .prefix = b.dupe(prefix), | 310 | .prefix = b.dupe(prefix), |
| 311 | .basename = b.dupe(basename), | 311 | .basename = b.dupe(basename), |
| 312 | .generated_file = .{ .step = &self.step }, | 312 | .generated_file = .{ .step = &run.step }, |
| 313 | }; | 313 | }; |
| 314 | 314 | ||
| 315 | self.dep_output_file = dep_file; | 315 | run.dep_output_file = dep_file; |
| 316 | 316 | ||
| 317 | self.argv.append(b.allocator, .{ .output = dep_file }) catch @panic("OOM"); | 317 | run.argv.append(b.allocator, .{ .output = dep_file }) catch @panic("OOM"); |
| 318 | 318 | ||
| 319 | return .{ .generated = &dep_file.generated_file }; | 319 | return .{ .generated = &dep_file.generated_file }; |
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | pub fn addArg(self: *Run, arg: []const u8) void { | 322 | pub fn addArg(run: *Run, arg: []const u8) void { |
| 323 | const b = self.step.owner; | 323 | const b = run.step.owner; |
| 324 | self.argv.append(b.allocator, .{ .bytes = self.step.owner.dupe(arg) }) catch @panic("OOM"); | 324 | run.argv.append(b.allocator, .{ .bytes = b.dupe(arg) }) catch @panic("OOM"); |
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | pub fn addArgs(self: *Run, args: []const []const u8) void { | 327 | pub fn addArgs(run: *Run, args: []const []const u8) void { |
| 328 | for (args) |arg| { | 328 | for (args) |arg| run.addArg(arg); |
| 329 | self.addArg(arg); | ||
| 330 | } | ||
| 331 | } | 329 | } |
| 332 | 330 | ||
| 333 | pub fn setStdIn(self: *Run, stdin: StdIn) void { | 331 | pub fn setStdIn(run: *Run, stdin: StdIn) void { |
| 334 | switch (stdin) { | 332 | switch (stdin) { |
| 335 | .lazy_path => |lazy_path| lazy_path.addStepDependencies(&self.step), | 333 | .lazy_path => |lazy_path| lazy_path.addStepDependencies(&run.step), |
| 336 | .bytes, .none => {}, | 334 | .bytes, .none => {}, |
| 337 | } | 335 | } |
| 338 | self.stdin = stdin; | 336 | run.stdin = stdin; |
| 339 | } | 337 | } |
| 340 | 338 | ||
| 341 | pub fn setCwd(self: *Run, cwd: Build.LazyPath) void { | 339 | pub fn setCwd(run: *Run, cwd: Build.LazyPath) void { |
| 342 | cwd.addStepDependencies(&self.step); | 340 | cwd.addStepDependencies(&run.step); |
| 343 | self.cwd = cwd; | 341 | run.cwd = cwd.dupe(run.step.owner); |
| 344 | } | 342 | } |
| 345 | 343 | ||
| 346 | pub fn clearEnvironment(self: *Run) void { | 344 | pub fn clearEnvironment(run: *Run) void { |
| 347 | const b = self.step.owner; | 345 | const b = run.step.owner; |
| 348 | const new_env_map = b.allocator.create(EnvMap) catch @panic("OOM"); | 346 | const new_env_map = b.allocator.create(EnvMap) catch @panic("OOM"); |
| 349 | new_env_map.* = EnvMap.init(b.allocator); | 347 | new_env_map.* = EnvMap.init(b.allocator); |
| 350 | self.env_map = new_env_map; | 348 | run.env_map = new_env_map; |
| 351 | } | 349 | } |
| 352 | 350 | ||
| 353 | pub fn addPathDir(self: *Run, search_path: []const u8) void { | 351 | pub fn addPathDir(run: *Run, search_path: []const u8) void { |
| 354 | const b = self.step.owner; | 352 | const b = run.step.owner; |
| 355 | const env_map = getEnvMapInternal(self); | 353 | const env_map = getEnvMapInternal(run); |
| 356 | 354 | ||
| 357 | const key = "PATH"; | 355 | const key = "PATH"; |
| 358 | const prev_path = env_map.get(key); | 356 | const prev_path = env_map.get(key); |
| ... | @@ -365,99 +363,99 @@ pub fn addPathDir(self: *Run, search_path: []const u8) void { | ... | @@ -365,99 +363,99 @@ pub fn addPathDir(self: *Run, search_path: []const u8) void { |
| 365 | } | 363 | } |
| 366 | } | 364 | } |
| 367 | 365 | ||
| 368 | pub fn getEnvMap(self: *Run) *EnvMap { | 366 | pub fn getEnvMap(run: *Run) *EnvMap { |
| 369 | return getEnvMapInternal(self); | 367 | return getEnvMapInternal(run); |
| 370 | } | 368 | } |
| 371 | 369 | ||
| 372 | fn getEnvMapInternal(self: *Run) *EnvMap { | 370 | fn getEnvMapInternal(run: *Run) *EnvMap { |
| 373 | const arena = self.step.owner.allocator; | 371 | const arena = run.step.owner.allocator; |
| 374 | return self.env_map orelse { | 372 | return run.env_map orelse { |
| 375 | const env_map = arena.create(EnvMap) catch @panic("OOM"); | 373 | const env_map = arena.create(EnvMap) catch @panic("OOM"); |
| 376 | env_map.* = process.getEnvMap(arena) catch @panic("unhandled error"); | 374 | env_map.* = process.getEnvMap(arena) catch @panic("unhandled error"); |
| 377 | self.env_map = env_map; | 375 | run.env_map = env_map; |
| 378 | return env_map; | 376 | return env_map; |
| 379 | }; | 377 | }; |
| 380 | } | 378 | } |
| 381 | 379 | ||
| 382 | pub fn setEnvironmentVariable(self: *Run, key: []const u8, value: []const u8) void { | 380 | pub fn setEnvironmentVariable(run: *Run, key: []const u8, value: []const u8) void { |
| 383 | const b = self.step.owner; | 381 | const b = run.step.owner; |
| 384 | const env_map = self.getEnvMap(); | 382 | const env_map = run.getEnvMap(); |
| 385 | env_map.put(b.dupe(key), b.dupe(value)) catch @panic("unhandled error"); | 383 | env_map.put(b.dupe(key), b.dupe(value)) catch @panic("unhandled error"); |
| 386 | } | 384 | } |
| 387 | 385 | ||
| 388 | pub fn removeEnvironmentVariable(self: *Run, key: []const u8) void { | 386 | pub fn removeEnvironmentVariable(run: *Run, key: []const u8) void { |
| 389 | self.getEnvMap().remove(key); | 387 | run.getEnvMap().remove(key); |
| 390 | } | 388 | } |
| 391 | 389 | ||
| 392 | /// Adds a check for exact stderr match. Does not add any other checks. | 390 | /// Adds a check for exact stderr match. Does not add any other checks. |
| 393 | pub fn expectStdErrEqual(self: *Run, bytes: []const u8) void { | 391 | pub fn expectStdErrEqual(run: *Run, bytes: []const u8) void { |
| 394 | const new_check: StdIo.Check = .{ .expect_stderr_exact = self.step.owner.dupe(bytes) }; | 392 | const new_check: StdIo.Check = .{ .expect_stderr_exact = run.step.owner.dupe(bytes) }; |
| 395 | self.addCheck(new_check); | 393 | run.addCheck(new_check); |
| 396 | } | 394 | } |
| 397 | 395 | ||
| 398 | /// Adds a check for exact stdout match as well as a check for exit code 0, if | 396 | /// Adds a check for exact stdout match as well as a check for exit code 0, if |
| 399 | /// there is not already an expected termination check. | 397 | /// there is not already an expected termination check. |
| 400 | pub fn expectStdOutEqual(self: *Run, bytes: []const u8) void { | 398 | pub fn expectStdOutEqual(run: *Run, bytes: []const u8) void { |
| 401 | const new_check: StdIo.Check = .{ .expect_stdout_exact = self.step.owner.dupe(bytes) }; | 399 | const new_check: StdIo.Check = .{ .expect_stdout_exact = run.step.owner.dupe(bytes) }; |
| 402 | self.addCheck(new_check); | 400 | run.addCheck(new_check); |
| 403 | if (!self.hasTermCheck()) { | 401 | if (!run.hasTermCheck()) { |
| 404 | self.expectExitCode(0); | 402 | run.expectExitCode(0); |
| 405 | } | 403 | } |
| 406 | } | 404 | } |
| 407 | 405 | ||
| 408 | pub fn expectExitCode(self: *Run, code: u8) void { | 406 | pub fn expectExitCode(run: *Run, code: u8) void { |
| 409 | const new_check: StdIo.Check = .{ .expect_term = .{ .Exited = code } }; | 407 | const new_check: StdIo.Check = .{ .expect_term = .{ .Exited = code } }; |
| 410 | self.addCheck(new_check); | 408 | run.addCheck(new_check); |
| 411 | } | 409 | } |
| 412 | 410 | ||
| 413 | pub fn hasTermCheck(self: Run) bool { | 411 | pub fn hasTermCheck(run: Run) bool { |
| 414 | for (self.stdio.check.items) |check| switch (check) { | 412 | for (run.stdio.check.items) |check| switch (check) { |
| 415 | .expect_term => return true, | 413 | .expect_term => return true, |
| 416 | else => continue, | 414 | else => continue, |
| 417 | }; | 415 | }; |
| 418 | return false; | 416 | return false; |
| 419 | } | 417 | } |
| 420 | 418 | ||
| 421 | pub fn addCheck(self: *Run, new_check: StdIo.Check) void { | 419 | pub fn addCheck(run: *Run, new_check: StdIo.Check) void { |
| 422 | const b = self.step.owner; | 420 | const b = run.step.owner; |
| 423 | 421 | ||
| 424 | switch (self.stdio) { | 422 | switch (run.stdio) { |
| 425 | .infer_from_args => { | 423 | .infer_from_args => { |
| 426 | self.stdio = .{ .check = .{} }; | 424 | run.stdio = .{ .check = .{} }; |
| 427 | self.stdio.check.append(b.allocator, new_check) catch @panic("OOM"); | 425 | run.stdio.check.append(b.allocator, new_check) catch @panic("OOM"); |
| 428 | }, | 426 | }, |
| 429 | .check => |*checks| checks.append(b.allocator, new_check) catch @panic("OOM"), | 427 | .check => |*checks| checks.append(b.allocator, new_check) catch @panic("OOM"), |
| 430 | else => @panic("illegal call to addCheck: conflicting helper method calls. Suggest to directly set stdio field of Run instead"), | 428 | else => @panic("illegal call to addCheck: conflicting helper method calls. Suggest to directly set stdio field of Run instead"), |
| 431 | } | 429 | } |
| 432 | } | 430 | } |
| 433 | 431 | ||
| 434 | pub fn captureStdErr(self: *Run) std.Build.LazyPath { | 432 | pub fn captureStdErr(run: *Run) std.Build.LazyPath { |
| 435 | assert(self.stdio != .inherit); | 433 | assert(run.stdio != .inherit); |
| 436 | 434 | ||
| 437 | if (self.captured_stderr) |output| return .{ .generated = &output.generated_file }; | 435 | if (run.captured_stderr) |output| return .{ .generated = &output.generated_file }; |
| 438 | 436 | ||
| 439 | const output = self.step.owner.allocator.create(Output) catch @panic("OOM"); | 437 | const output = run.step.owner.allocator.create(Output) catch @panic("OOM"); |
| 440 | output.* = .{ | 438 | output.* = .{ |
| 441 | .prefix = "", | 439 | .prefix = "", |
| 442 | .basename = "stderr", | 440 | .basename = "stderr", |
| 443 | .generated_file = .{ .step = &self.step }, | 441 | .generated_file = .{ .step = &run.step }, |
| 444 | }; | 442 | }; |
| 445 | self.captured_stderr = output; | 443 | run.captured_stderr = output; |
| 446 | return .{ .generated = &output.generated_file }; | 444 | return .{ .generated = &output.generated_file }; |
| 447 | } | 445 | } |
| 448 | 446 | ||
| 449 | pub fn captureStdOut(self: *Run) std.Build.LazyPath { | 447 | pub fn captureStdOut(run: *Run) std.Build.LazyPath { |
| 450 | assert(self.stdio != .inherit); | 448 | assert(run.stdio != .inherit); |
| 451 | 449 | ||
| 452 | if (self.captured_stdout) |output| return .{ .generated = &output.generated_file }; | 450 | if (run.captured_stdout) |output| return .{ .generated = &output.generated_file }; |
| 453 | 451 | ||
| 454 | const output = self.step.owner.allocator.create(Output) catch @panic("OOM"); | 452 | const output = run.step.owner.allocator.create(Output) catch @panic("OOM"); |
| 455 | output.* = .{ | 453 | output.* = .{ |
| 456 | .prefix = "", | 454 | .prefix = "", |
| 457 | .basename = "stdout", | 455 | .basename = "stdout", |
| 458 | .generated_file = .{ .step = &self.step }, | 456 | .generated_file = .{ .step = &run.step }, |
| 459 | }; | 457 | }; |
| 460 | self.captured_stdout = output; | 458 | run.captured_stdout = output; |
| 461 | return .{ .generated = &output.generated_file }; | 459 | return .{ .generated = &output.generated_file }; |
| 462 | } | 460 | } |
| 463 | 461 | ||
| ... | @@ -472,20 +470,20 @@ pub fn addFileInput(self: *Run, file_input: std.Build.LazyPath) void { | ... | @@ -472,20 +470,20 @@ pub fn addFileInput(self: *Run, file_input: std.Build.LazyPath) void { |
| 472 | } | 470 | } |
| 473 | 471 | ||
| 474 | /// Returns whether the Run step has side effects *other than* updating the output arguments. | 472 | /// Returns whether the Run step has side effects *other than* updating the output arguments. |
| 475 | fn hasSideEffects(self: Run) bool { | 473 | fn hasSideEffects(run: Run) bool { |
| 476 | if (self.has_side_effects) return true; | 474 | if (run.has_side_effects) return true; |
| 477 | return switch (self.stdio) { | 475 | return switch (run.stdio) { |
| 478 | .infer_from_args => !self.hasAnyOutputArgs(), | 476 | .infer_from_args => !run.hasAnyOutputArgs(), |
| 479 | .inherit => true, | 477 | .inherit => true, |
| 480 | .check => false, | 478 | .check => false, |
| 481 | .zig_test => false, | 479 | .zig_test => false, |
| 482 | }; | 480 | }; |
| 483 | } | 481 | } |
| 484 | 482 | ||
| 485 | fn hasAnyOutputArgs(self: Run) bool { | 483 | fn hasAnyOutputArgs(run: Run) bool { |
| 486 | if (self.captured_stdout != null) return true; | 484 | if (run.captured_stdout != null) return true; |
| 487 | if (self.captured_stderr != null) return true; | 485 | if (run.captured_stderr != null) return true; |
| 488 | for (self.argv.items) |arg| switch (arg) { | 486 | for (run.argv.items) |arg| switch (arg) { |
| 489 | .output => return true, | 487 | .output => return true, |
| 490 | else => continue, | 488 | else => continue, |
| 491 | }; | 489 | }; |
| ... | @@ -527,8 +525,8 @@ const IndexedOutput = struct { | ... | @@ -527,8 +525,8 @@ const IndexedOutput = struct { |
| 527 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 525 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 528 | const b = step.owner; | 526 | const b = step.owner; |
| 529 | const arena = b.allocator; | 527 | const arena = b.allocator; |
| 530 | const self: *Run = @fieldParentPtr("step", step); | 528 | const run: *Run = @fieldParentPtr("step", step); |
| 531 | const has_side_effects = self.hasSideEffects(); | 529 | const has_side_effects = run.hasSideEffects(); |
| 532 | 530 | ||
| 533 | var argv_list = std.ArrayList([]const u8).init(arena); | 531 | var argv_list = std.ArrayList([]const u8).init(arena); |
| 534 | var output_placeholders = std.ArrayList(IndexedOutput).init(arena); | 532 | var output_placeholders = std.ArrayList(IndexedOutput).init(arena); |
| ... | @@ -536,20 +534,20 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -536,20 +534,20 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 536 | var man = b.graph.cache.obtain(); | 534 | var man = b.graph.cache.obtain(); |
| 537 | defer man.deinit(); | 535 | defer man.deinit(); |
| 538 | 536 | ||
| 539 | for (self.argv.items) |arg| { | 537 | for (run.argv.items) |arg| { |
| 540 | switch (arg) { | 538 | switch (arg) { |
| 541 | .bytes => |bytes| { | 539 | .bytes => |bytes| { |
| 542 | try argv_list.append(bytes); | 540 | try argv_list.append(bytes); |
| 543 | man.hash.addBytes(bytes); | 541 | man.hash.addBytes(bytes); |
| 544 | }, | 542 | }, |
| 545 | .lazy_path => |file| { | 543 | .lazy_path => |file| { |
| 546 | const file_path = file.lazy_path.getPath(b); | 544 | const file_path = file.lazy_path.getPath2(b, step); |
| 547 | try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path })); | 545 | try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path })); |
| 548 | man.hash.addBytes(file.prefix); | 546 | man.hash.addBytes(file.prefix); |
| 549 | _ = try man.addFile(file_path, null); | 547 | _ = try man.addFile(file_path, null); |
| 550 | }, | 548 | }, |
| 551 | .directory_source => |file| { | 549 | .directory_source => |file| { |
| 552 | const file_path = file.lazy_path.getPath(b); | 550 | const file_path = file.lazy_path.getPath2(b, step); |
| 553 | try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path })); | 551 | try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path })); |
| 554 | man.hash.addBytes(file.prefix); | 552 | man.hash.addBytes(file.prefix); |
| 555 | man.hash.addBytes(file_path); | 553 | man.hash.addBytes(file_path); |
| ... | @@ -557,7 +555,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -557,7 +555,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 557 | .artifact => |artifact| { | 555 | .artifact => |artifact| { |
| 558 | if (artifact.rootModuleTarget().os.tag == .windows) { | 556 | if (artifact.rootModuleTarget().os.tag == .windows) { |
| 559 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH | 557 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH |
| 560 | self.addPathForDynLibs(artifact); | 558 | run.addPathForDynLibs(artifact); |
| 561 | } | 559 | } |
| 562 | const file_path = artifact.installed_path orelse artifact.generated_bin.?.path.?; // the path is guaranteed to be set | 560 | const file_path = artifact.installed_path orelse artifact.generated_bin.?.path.?; // the path is guaranteed to be set |
| 563 | 561 | ||
| ... | @@ -580,36 +578,36 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -580,36 +578,36 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 580 | } | 578 | } |
| 581 | } | 579 | } |
| 582 | 580 | ||
| 583 | switch (self.stdin) { | 581 | switch (run.stdin) { |
| 584 | .bytes => |bytes| { | 582 | .bytes => |bytes| { |
| 585 | man.hash.addBytes(bytes); | 583 | man.hash.addBytes(bytes); |
| 586 | }, | 584 | }, |
| 587 | .lazy_path => |lazy_path| { | 585 | .lazy_path => |lazy_path| { |
| 588 | const file_path = lazy_path.getPath(b); | 586 | const file_path = lazy_path.getPath2(b, step); |
| 589 | _ = try man.addFile(file_path, null); | 587 | _ = try man.addFile(file_path, null); |
| 590 | }, | 588 | }, |
| 591 | .none => {}, | 589 | .none => {}, |
| 592 | } | 590 | } |
| 593 | 591 | ||
| 594 | if (self.captured_stdout) |output| { | 592 | if (run.captured_stdout) |output| { |
| 595 | man.hash.addBytes(output.basename); | 593 | man.hash.addBytes(output.basename); |
| 596 | } | 594 | } |
| 597 | 595 | ||
| 598 | if (self.captured_stderr) |output| { | 596 | if (run.captured_stderr) |output| { |
| 599 | man.hash.addBytes(output.basename); | 597 | man.hash.addBytes(output.basename); |
| 600 | } | 598 | } |
| 601 | 599 | ||
| 602 | hashStdIo(&man.hash, self.stdio); | 600 | hashStdIo(&man.hash, run.stdio); |
| 603 | 601 | ||
| 604 | if (has_side_effects) { | 602 | if (has_side_effects) { |
| 605 | try runCommand(self, argv_list.items, has_side_effects, null, prog_node); | 603 | try runCommand(run, argv_list.items, has_side_effects, null, prog_node); |
| 606 | return; | 604 | return; |
| 607 | } | 605 | } |
| 608 | 606 | ||
| 609 | for (self.extra_file_dependencies) |file_path| { | 607 | for (run.extra_file_dependencies) |file_path| { |
| 610 | _ = try man.addFile(b.pathFromRoot(file_path), null); | 608 | _ = try man.addFile(b.pathFromRoot(file_path), null); |
| 611 | } | 609 | } |
| 612 | for (self.file_inputs.items) |lazy_path| { | 610 | for (run.file_inputs.items) |lazy_path| { |
| 613 | _ = try man.addFile(lazy_path.getPath2(b, step), null); | 611 | _ = try man.addFile(lazy_path.getPath2(b, step), null); |
| 614 | } | 612 | } |
| 615 | 613 | ||
| ... | @@ -620,8 +618,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -620,8 +618,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 620 | try populateGeneratedPaths( | 618 | try populateGeneratedPaths( |
| 621 | arena, | 619 | arena, |
| 622 | output_placeholders.items, | 620 | output_placeholders.items, |
| 623 | self.captured_stdout, | 621 | run.captured_stdout, |
| 624 | self.captured_stderr, | 622 | run.captured_stderr, |
| 625 | b.cache_root, | 623 | b.cache_root, |
| 626 | &digest, | 624 | &digest, |
| 627 | ); | 625 | ); |
| ... | @@ -635,7 +633,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -635,7 +633,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 635 | 633 | ||
| 636 | for (output_placeholders.items) |placeholder| { | 634 | for (output_placeholders.items) |placeholder| { |
| 637 | const output_components = .{ tmp_dir_path, placeholder.output.basename }; | 635 | const output_components = .{ tmp_dir_path, placeholder.output.basename }; |
| 638 | const output_sub_path = try fs.path.join(arena, &output_components); | 636 | const output_sub_path = b.pathJoin(&output_components); |
| 639 | const output_sub_dir_path = fs.path.dirname(output_sub_path).?; | 637 | const output_sub_dir_path = fs.path.dirname(output_sub_path).?; |
| 640 | b.cache_root.handle.makePath(output_sub_dir_path) catch |err| { | 638 | b.cache_root.handle.makePath(output_sub_dir_path) catch |err| { |
| 641 | return step.fail("unable to make path '{}{s}': {s}", .{ | 639 | return step.fail("unable to make path '{}{s}': {s}", .{ |
| ... | @@ -651,15 +649,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -651,15 +649,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 651 | argv_list.items[placeholder.index] = cli_arg; | 649 | argv_list.items[placeholder.index] = cli_arg; |
| 652 | } | 650 | } |
| 653 | 651 | ||
| 654 | try runCommand(self, argv_list.items, has_side_effects, tmp_dir_path, prog_node); | 652 | try runCommand(run, argv_list.items, has_side_effects, tmp_dir_path, prog_node); |
| 655 | 653 | ||
| 656 | if (self.dep_output_file) |dep_output_file| | 654 | if (run.dep_output_file) |dep_output_file| |
| 657 | try man.addDepFilePost(std.fs.cwd(), dep_output_file.generated_file.getPath()); | 655 | try man.addDepFilePost(std.fs.cwd(), dep_output_file.generated_file.getPath()); |
| 658 | 656 | ||
| 659 | const digest = man.final(); | 657 | const digest = man.final(); |
| 660 | 658 | ||
| 661 | const any_output = output_placeholders.items.len > 0 or | 659 | const any_output = output_placeholders.items.len > 0 or |
| 662 | self.captured_stdout != null or self.captured_stderr != null; | 660 | run.captured_stdout != null or run.captured_stderr != null; |
| 663 | 661 | ||
| 664 | // Rename into place | 662 | // Rename into place |
| 665 | if (any_output) { | 663 | if (any_output) { |
| ... | @@ -696,8 +694,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -696,8 +694,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 696 | try populateGeneratedPaths( | 694 | try populateGeneratedPaths( |
| 697 | arena, | 695 | arena, |
| 698 | output_placeholders.items, | 696 | output_placeholders.items, |
| 699 | self.captured_stdout, | 697 | run.captured_stdout, |
| 700 | self.captured_stderr, | 698 | run.captured_stderr, |
| 701 | b.cache_root, | 699 | b.cache_root, |
| 702 | &digest, | 700 | &digest, |
| 703 | ); | 701 | ); |
| ... | @@ -776,30 +774,30 @@ fn termMatches(expected: ?std.process.Child.Term, actual: std.process.Child.Term | ... | @@ -776,30 +774,30 @@ fn termMatches(expected: ?std.process.Child.Term, actual: std.process.Child.Term |
| 776 | } | 774 | } |
| 777 | 775 | ||
| 778 | fn runCommand( | 776 | fn runCommand( |
| 779 | self: *Run, | 777 | run: *Run, |
| 780 | argv: []const []const u8, | 778 | argv: []const []const u8, |
| 781 | has_side_effects: bool, | 779 | has_side_effects: bool, |
| 782 | tmp_dir_path: ?[]const u8, | 780 | tmp_dir_path: ?[]const u8, |
| 783 | prog_node: *std.Progress.Node, | 781 | prog_node: *std.Progress.Node, |
| 784 | ) !void { | 782 | ) !void { |
| 785 | const step = &self.step; | 783 | const step = &run.step; |
| 786 | const b = step.owner; | 784 | const b = step.owner; |
| 787 | const arena = b.allocator; | 785 | const arena = b.allocator; |
| 788 | 786 | ||
| 789 | const cwd: ?[]const u8 = if (self.cwd) |lazy_cwd| lazy_cwd.getPath(b) else null; | 787 | const cwd: ?[]const u8 = if (run.cwd) |lazy_cwd| lazy_cwd.getPath2(b, step) else null; |
| 790 | 788 | ||
| 791 | try step.handleChildProcUnsupported(cwd, argv); | 789 | try step.handleChildProcUnsupported(cwd, argv); |
| 792 | try Step.handleVerbose2(step.owner, cwd, self.env_map, argv); | 790 | try Step.handleVerbose2(step.owner, cwd, run.env_map, argv); |
| 793 | 791 | ||
| 794 | const allow_skip = switch (self.stdio) { | 792 | const allow_skip = switch (run.stdio) { |
| 795 | .check, .zig_test => self.skip_foreign_checks, | 793 | .check, .zig_test => run.skip_foreign_checks, |
| 796 | else => false, | 794 | else => false, |
| 797 | }; | 795 | }; |
| 798 | 796 | ||
| 799 | var interp_argv = std.ArrayList([]const u8).init(b.allocator); | 797 | var interp_argv = std.ArrayList([]const u8).init(b.allocator); |
| 800 | defer interp_argv.deinit(); | 798 | defer interp_argv.deinit(); |
| 801 | 799 | ||
| 802 | const result = spawnChildAndCollect(self, argv, has_side_effects, prog_node) catch |err| term: { | 800 | const result = spawnChildAndCollect(run, argv, has_side_effects, prog_node) catch |err| term: { |
| 803 | // InvalidExe: cpu arch mismatch | 801 | // InvalidExe: cpu arch mismatch |
| 804 | // FileNotFound: can happen with a wrong dynamic linker path | 802 | // FileNotFound: can happen with a wrong dynamic linker path |
| 805 | if (err == error.InvalidExe or err == error.FileNotFound) interpret: { | 803 | if (err == error.InvalidExe or err == error.FileNotFound) interpret: { |
| ... | @@ -807,7 +805,7 @@ fn runCommand( | ... | @@ -807,7 +805,7 @@ fn runCommand( |
| 807 | // relying on it being a Compile step. This will make this logic | 805 | // relying on it being a Compile step. This will make this logic |
| 808 | // work even for the edge case that the binary was produced by a | 806 | // work even for the edge case that the binary was produced by a |
| 809 | // third party. | 807 | // third party. |
| 810 | const exe = switch (self.argv.items[0]) { | 808 | const exe = switch (run.argv.items[0]) { |
| 811 | .artifact => |exe| exe, | 809 | .artifact => |exe| exe, |
| 812 | else => break :interpret, | 810 | else => break :interpret, |
| 813 | }; | 811 | }; |
| ... | @@ -832,14 +830,14 @@ fn runCommand( | ... | @@ -832,14 +830,14 @@ fn runCommand( |
| 832 | try interp_argv.append(bin_name); | 830 | try interp_argv.append(bin_name); |
| 833 | try interp_argv.appendSlice(argv); | 831 | try interp_argv.appendSlice(argv); |
| 834 | } else { | 832 | } else { |
| 835 | return failForeign(self, "-fwine", argv[0], exe); | 833 | return failForeign(run, "-fwine", argv[0], exe); |
| 836 | } | 834 | } |
| 837 | }, | 835 | }, |
| 838 | .qemu => |bin_name| { | 836 | .qemu => |bin_name| { |
| 839 | if (b.enable_qemu) { | 837 | if (b.enable_qemu) { |
| 840 | const glibc_dir_arg = if (need_cross_glibc) | 838 | const glibc_dir_arg = if (need_cross_glibc) |
| 841 | b.glibc_runtimes_dir orelse | 839 | b.glibc_runtimes_dir orelse |
| 842 | return failForeign(self, "--glibc-runtimes", argv[0], exe) | 840 | return failForeign(run, "--glibc-runtimes", argv[0], exe) |
| 843 | else | 841 | else |
| 844 | null; | 842 | null; |
| 845 | 843 | ||
| ... | @@ -867,7 +865,7 @@ fn runCommand( | ... | @@ -867,7 +865,7 @@ fn runCommand( |
| 867 | 865 | ||
| 868 | try interp_argv.appendSlice(argv); | 866 | try interp_argv.appendSlice(argv); |
| 869 | } else { | 867 | } else { |
| 870 | return failForeign(self, "-fqemu", argv[0], exe); | 868 | return failForeign(run, "-fqemu", argv[0], exe); |
| 871 | } | 869 | } |
| 872 | }, | 870 | }, |
| 873 | .darling => |bin_name| { | 871 | .darling => |bin_name| { |
| ... | @@ -875,7 +873,7 @@ fn runCommand( | ... | @@ -875,7 +873,7 @@ fn runCommand( |
| 875 | try interp_argv.append(bin_name); | 873 | try interp_argv.append(bin_name); |
| 876 | try interp_argv.appendSlice(argv); | 874 | try interp_argv.appendSlice(argv); |
| 877 | } else { | 875 | } else { |
| 878 | return failForeign(self, "-fdarling", argv[0], exe); | 876 | return failForeign(run, "-fdarling", argv[0], exe); |
| 879 | } | 877 | } |
| 880 | }, | 878 | }, |
| 881 | .wasmtime => |bin_name| { | 879 | .wasmtime => |bin_name| { |
| ... | @@ -886,7 +884,7 @@ fn runCommand( | ... | @@ -886,7 +884,7 @@ fn runCommand( |
| 886 | try interp_argv.append("--"); | 884 | try interp_argv.append("--"); |
| 887 | try interp_argv.appendSlice(argv[1..]); | 885 | try interp_argv.appendSlice(argv[1..]); |
| 888 | } else { | 886 | } else { |
| 889 | return failForeign(self, "-fwasmtime", argv[0], exe); | 887 | return failForeign(run, "-fwasmtime", argv[0], exe); |
| 890 | } | 888 | } |
| 891 | }, | 889 | }, |
| 892 | .bad_dl => |foreign_dl| { | 890 | .bad_dl => |foreign_dl| { |
| ... | @@ -915,13 +913,13 @@ fn runCommand( | ... | @@ -915,13 +913,13 @@ fn runCommand( |
| 915 | 913 | ||
| 916 | if (exe.rootModuleTarget().os.tag == .windows) { | 914 | if (exe.rootModuleTarget().os.tag == .windows) { |
| 917 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH | 915 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH |
| 918 | self.addPathForDynLibs(exe); | 916 | run.addPathForDynLibs(exe); |
| 919 | } | 917 | } |
| 920 | 918 | ||
| 921 | try Step.handleVerbose2(step.owner, cwd, self.env_map, interp_argv.items); | 919 | try Step.handleVerbose2(step.owner, cwd, run.env_map, interp_argv.items); |
| 922 | 920 | ||
| 923 | break :term spawnChildAndCollect(self, interp_argv.items, has_side_effects, prog_node) catch |e| { | 921 | break :term spawnChildAndCollect(run, interp_argv.items, has_side_effects, prog_node) catch |e| { |
| 924 | if (!self.failing_to_execute_foreign_is_an_error) return error.MakeSkipped; | 922 | if (!run.failing_to_execute_foreign_is_an_error) return error.MakeSkipped; |
| 925 | 923 | ||
| 926 | return step.fail("unable to spawn interpreter {s}: {s}", .{ | 924 | return step.fail("unable to spawn interpreter {s}: {s}", .{ |
| 927 | interp_argv.items[0], @errorName(e), | 925 | interp_argv.items[0], @errorName(e), |
| ... | @@ -943,11 +941,11 @@ fn runCommand( | ... | @@ -943,11 +941,11 @@ fn runCommand( |
| 943 | }; | 941 | }; |
| 944 | for ([_]Stream{ | 942 | for ([_]Stream{ |
| 945 | .{ | 943 | .{ |
| 946 | .captured = self.captured_stdout, | 944 | .captured = run.captured_stdout, |
| 947 | .bytes = result.stdio.stdout, | 945 | .bytes = result.stdio.stdout, |
| 948 | }, | 946 | }, |
| 949 | .{ | 947 | .{ |
| 950 | .captured = self.captured_stderr, | 948 | .captured = run.captured_stderr, |
| 951 | .bytes = result.stdio.stderr, | 949 | .bytes = result.stdio.stderr, |
| 952 | }, | 950 | }, |
| 953 | }) |stream| { | 951 | }) |stream| { |
| ... | @@ -956,7 +954,7 @@ fn runCommand( | ... | @@ -956,7 +954,7 @@ fn runCommand( |
| 956 | const output_path = try b.cache_root.join(arena, &output_components); | 954 | const output_path = try b.cache_root.join(arena, &output_components); |
| 957 | output.generated_file.path = output_path; | 955 | output.generated_file.path = output_path; |
| 958 | 956 | ||
| 959 | const sub_path = try fs.path.join(arena, &output_components); | 957 | const sub_path = b.pathJoin(&output_components); |
| 960 | const sub_path_dirname = fs.path.dirname(sub_path).?; | 958 | const sub_path_dirname = fs.path.dirname(sub_path).?; |
| 961 | b.cache_root.handle.makePath(sub_path_dirname) catch |err| { | 959 | b.cache_root.handle.makePath(sub_path_dirname) catch |err| { |
| 962 | return step.fail("unable to make path '{}{s}': {s}", .{ | 960 | return step.fail("unable to make path '{}{s}': {s}", .{ |
| ... | @@ -973,7 +971,7 @@ fn runCommand( | ... | @@ -973,7 +971,7 @@ fn runCommand( |
| 973 | 971 | ||
| 974 | const final_argv = if (interp_argv.items.len == 0) argv else interp_argv.items; | 972 | const final_argv = if (interp_argv.items.len == 0) argv else interp_argv.items; |
| 975 | 973 | ||
| 976 | switch (self.stdio) { | 974 | switch (run.stdio) { |
| 977 | .check => |checks| for (checks.items) |check| switch (check) { | 975 | .check => |checks| for (checks.items) |check| switch (check) { |
| 978 | .expect_stderr_exact => |expected_bytes| { | 976 | .expect_stderr_exact => |expected_bytes| { |
| 979 | if (!mem.eql(u8, expected_bytes, result.stdio.stderr.?)) { | 977 | if (!mem.eql(u8, expected_bytes, result.stdio.stderr.?)) { |
| ... | @@ -1094,56 +1092,56 @@ const ChildProcResult = struct { | ... | @@ -1094,56 +1092,56 @@ const ChildProcResult = struct { |
| 1094 | }; | 1092 | }; |
| 1095 | 1093 | ||
| 1096 | fn spawnChildAndCollect( | 1094 | fn spawnChildAndCollect( |
| 1097 | self: *Run, | 1095 | run: *Run, |
| 1098 | argv: []const []const u8, | 1096 | argv: []const []const u8, |
| 1099 | has_side_effects: bool, | 1097 | has_side_effects: bool, |
| 1100 | prog_node: *std.Progress.Node, | 1098 | prog_node: *std.Progress.Node, |
| 1101 | ) !ChildProcResult { | 1099 | ) !ChildProcResult { |
| 1102 | const b = self.step.owner; | 1100 | const b = run.step.owner; |
| 1103 | const arena = b.allocator; | 1101 | const arena = b.allocator; |
| 1104 | 1102 | ||
| 1105 | var child = std.process.Child.init(argv, arena); | 1103 | var child = std.process.Child.init(argv, arena); |
| 1106 | if (self.cwd) |lazy_cwd| { | 1104 | if (run.cwd) |lazy_cwd| { |
| 1107 | child.cwd = lazy_cwd.getPath(b); | 1105 | child.cwd = lazy_cwd.getPath2(b, &run.step); |
| 1108 | } else { | 1106 | } else { |
| 1109 | child.cwd = b.build_root.path; | 1107 | child.cwd = b.build_root.path; |
| 1110 | child.cwd_dir = b.build_root.handle; | 1108 | child.cwd_dir = b.build_root.handle; |
| 1111 | } | 1109 | } |
| 1112 | child.env_map = self.env_map orelse &b.graph.env_map; | 1110 | child.env_map = run.env_map orelse &b.graph.env_map; |
| 1113 | child.request_resource_usage_statistics = true; | 1111 | child.request_resource_usage_statistics = true; |
| 1114 | 1112 | ||
| 1115 | child.stdin_behavior = switch (self.stdio) { | 1113 | child.stdin_behavior = switch (run.stdio) { |
| 1116 | .infer_from_args => if (has_side_effects) .Inherit else .Ignore, | 1114 | .infer_from_args => if (has_side_effects) .Inherit else .Ignore, |
| 1117 | .inherit => .Inherit, | 1115 | .inherit => .Inherit, |
| 1118 | .check => .Ignore, | 1116 | .check => .Ignore, |
| 1119 | .zig_test => .Pipe, | 1117 | .zig_test => .Pipe, |
| 1120 | }; | 1118 | }; |
| 1121 | child.stdout_behavior = switch (self.stdio) { | 1119 | child.stdout_behavior = switch (run.stdio) { |
| 1122 | .infer_from_args => if (has_side_effects) .Inherit else .Ignore, | 1120 | .infer_from_args => if (has_side_effects) .Inherit else .Ignore, |
| 1123 | .inherit => .Inherit, | 1121 | .inherit => .Inherit, |
| 1124 | .check => |checks| if (checksContainStdout(checks.items)) .Pipe else .Ignore, | 1122 | .check => |checks| if (checksContainStdout(checks.items)) .Pipe else .Ignore, |
| 1125 | .zig_test => .Pipe, | 1123 | .zig_test => .Pipe, |
| 1126 | }; | 1124 | }; |
| 1127 | child.stderr_behavior = switch (self.stdio) { | 1125 | child.stderr_behavior = switch (run.stdio) { |
| 1128 | .infer_from_args => if (has_side_effects) .Inherit else .Pipe, | 1126 | .infer_from_args => if (has_side_effects) .Inherit else .Pipe, |
| 1129 | .inherit => .Inherit, | 1127 | .inherit => .Inherit, |
| 1130 | .check => .Pipe, | 1128 | .check => .Pipe, |
| 1131 | .zig_test => .Pipe, | 1129 | .zig_test => .Pipe, |
| 1132 | }; | 1130 | }; |
| 1133 | if (self.captured_stdout != null) child.stdout_behavior = .Pipe; | 1131 | if (run.captured_stdout != null) child.stdout_behavior = .Pipe; |
| 1134 | if (self.captured_stderr != null) child.stderr_behavior = .Pipe; | 1132 | if (run.captured_stderr != null) child.stderr_behavior = .Pipe; |
| 1135 | if (self.stdin != .none) { | 1133 | if (run.stdin != .none) { |
| 1136 | assert(self.stdio != .inherit); | 1134 | assert(run.stdio != .inherit); |
| 1137 | child.stdin_behavior = .Pipe; | 1135 | child.stdin_behavior = .Pipe; |
| 1138 | } | 1136 | } |
| 1139 | 1137 | ||
| 1140 | try child.spawn(); | 1138 | try child.spawn(); |
| 1141 | var timer = try std.time.Timer.start(); | 1139 | var timer = try std.time.Timer.start(); |
| 1142 | 1140 | ||
| 1143 | const result = if (self.stdio == .zig_test) | 1141 | const result = if (run.stdio == .zig_test) |
| 1144 | evalZigTest(self, &child, prog_node) | 1142 | evalZigTest(run, &child, prog_node) |
| 1145 | else | 1143 | else |
| 1146 | evalGeneric(self, &child); | 1144 | evalGeneric(run, &child); |
| 1147 | 1145 | ||
| 1148 | const term = try child.wait(); | 1146 | const term = try child.wait(); |
| 1149 | const elapsed_ns = timer.read(); | 1147 | const elapsed_ns = timer.read(); |
| ... | @@ -1164,12 +1162,12 @@ const StdIoResult = struct { | ... | @@ -1164,12 +1162,12 @@ const StdIoResult = struct { |
| 1164 | }; | 1162 | }; |
| 1165 | 1163 | ||
| 1166 | fn evalZigTest( | 1164 | fn evalZigTest( |
| 1167 | self: *Run, | 1165 | run: *Run, |
| 1168 | child: *std.process.Child, | 1166 | child: *std.process.Child, |
| 1169 | prog_node: *std.Progress.Node, | 1167 | prog_node: *std.Progress.Node, |
| 1170 | ) !StdIoResult { | 1168 | ) !StdIoResult { |
| 1171 | const gpa = self.step.owner.allocator; | 1169 | const gpa = run.step.owner.allocator; |
| 1172 | const arena = self.step.owner.allocator; | 1170 | const arena = run.step.owner.allocator; |
| 1173 | 1171 | ||
| 1174 | var poller = std.io.poll(gpa, enum { stdout, stderr }, .{ | 1172 | var poller = std.io.poll(gpa, enum { stdout, stderr }, .{ |
| 1175 | .stdout = child.stdout.?, | 1173 | .stdout = child.stdout.?, |
| ... | @@ -1208,7 +1206,7 @@ fn evalZigTest( | ... | @@ -1208,7 +1206,7 @@ fn evalZigTest( |
| 1208 | switch (header.tag) { | 1206 | switch (header.tag) { |
| 1209 | .zig_version => { | 1207 | .zig_version => { |
| 1210 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) { | 1208 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) { |
| 1211 | return self.step.fail( | 1209 | return run.step.fail( |
| 1212 | "zig version mismatch build runner vs compiler: '{s}' vs '{s}'", | 1210 | "zig version mismatch build runner vs compiler: '{s}' vs '{s}'", |
| 1213 | .{ builtin.zig_version_string, body }, | 1211 | .{ builtin.zig_version_string, body }, |
| 1214 | ); | 1212 | ); |
| ... | @@ -1266,9 +1264,9 @@ fn evalZigTest( | ... | @@ -1266,9 +1264,9 @@ fn evalZigTest( |
| 1266 | else | 1264 | else |
| 1267 | unreachable; | 1265 | unreachable; |
| 1268 | if (msg.len > 0) { | 1266 | if (msg.len > 0) { |
| 1269 | try self.step.addError("'{s}' {s}: {s}", .{ name, label, msg }); | 1267 | try run.step.addError("'{s}' {s}: {s}", .{ name, label, msg }); |
| 1270 | } else { | 1268 | } else { |
| 1271 | try self.step.addError("'{s}' {s}", .{ name, label }); | 1269 | try run.step.addError("'{s}' {s}", .{ name, label }); |
| 1272 | } | 1270 | } |
| 1273 | } | 1271 | } |
| 1274 | 1272 | ||
| ... | @@ -1282,7 +1280,7 @@ fn evalZigTest( | ... | @@ -1282,7 +1280,7 @@ fn evalZigTest( |
| 1282 | 1280 | ||
| 1283 | if (stderr.readableLength() > 0) { | 1281 | if (stderr.readableLength() > 0) { |
| 1284 | const msg = std.mem.trim(u8, try stderr.toOwnedSlice(), "\n"); | 1282 | const msg = std.mem.trim(u8, try stderr.toOwnedSlice(), "\n"); |
| 1285 | if (msg.len > 0) self.step.result_stderr = msg; | 1283 | if (msg.len > 0) run.step.result_stderr = msg; |
| 1286 | } | 1284 | } |
| 1287 | 1285 | ||
| 1288 | // Send EOF to stdin. | 1286 | // Send EOF to stdin. |
| ... | @@ -1350,25 +1348,26 @@ fn sendRunTestMessage(file: std.fs.File, index: u32) !void { | ... | @@ -1350,25 +1348,26 @@ fn sendRunTestMessage(file: std.fs.File, index: u32) !void { |
| 1350 | try file.writeAll(full_msg); | 1348 | try file.writeAll(full_msg); |
| 1351 | } | 1349 | } |
| 1352 | 1350 | ||
| 1353 | fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult { | 1351 | fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult { |
| 1354 | const arena = self.step.owner.allocator; | 1352 | const b = run.step.owner; |
| 1353 | const arena = b.allocator; | ||
| 1355 | 1354 | ||
| 1356 | switch (self.stdin) { | 1355 | switch (run.stdin) { |
| 1357 | .bytes => |bytes| { | 1356 | .bytes => |bytes| { |
| 1358 | child.stdin.?.writeAll(bytes) catch |err| { | 1357 | child.stdin.?.writeAll(bytes) catch |err| { |
| 1359 | return self.step.fail("unable to write stdin: {s}", .{@errorName(err)}); | 1358 | return run.step.fail("unable to write stdin: {s}", .{@errorName(err)}); |
| 1360 | }; | 1359 | }; |
| 1361 | child.stdin.?.close(); | 1360 | child.stdin.?.close(); |
| 1362 | child.stdin = null; | 1361 | child.stdin = null; |
| 1363 | }, | 1362 | }, |
| 1364 | .lazy_path => |lazy_path| { | 1363 | .lazy_path => |lazy_path| { |
| 1365 | const path = lazy_path.getPath(self.step.owner); | 1364 | const path = lazy_path.getPath2(b, &run.step); |
| 1366 | const file = self.step.owner.build_root.handle.openFile(path, .{}) catch |err| { | 1365 | const file = b.build_root.handle.openFile(path, .{}) catch |err| { |
| 1367 | return self.step.fail("unable to open stdin file: {s}", .{@errorName(err)}); | 1366 | return run.step.fail("unable to open stdin file: {s}", .{@errorName(err)}); |
| 1368 | }; | 1367 | }; |
| 1369 | defer file.close(); | 1368 | defer file.close(); |
| 1370 | child.stdin.?.writeFileAll(file, .{}) catch |err| { | 1369 | child.stdin.?.writeFileAll(file, .{}) catch |err| { |
| 1371 | return self.step.fail("unable to write file to stdin: {s}", .{@errorName(err)}); | 1370 | return run.step.fail("unable to write file to stdin: {s}", .{@errorName(err)}); |
| 1372 | }; | 1371 | }; |
| 1373 | child.stdin.?.close(); | 1372 | child.stdin.?.close(); |
| 1374 | child.stdin = null; | 1373 | child.stdin = null; |
| ... | @@ -1388,29 +1387,29 @@ fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult { | ... | @@ -1388,29 +1387,29 @@ fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult { |
| 1388 | defer poller.deinit(); | 1387 | defer poller.deinit(); |
| 1389 | 1388 | ||
| 1390 | while (try poller.poll()) { | 1389 | while (try poller.poll()) { |
| 1391 | if (poller.fifo(.stdout).count > self.max_stdio_size) | 1390 | if (poller.fifo(.stdout).count > run.max_stdio_size) |
| 1392 | return error.StdoutStreamTooLong; | 1391 | return error.StdoutStreamTooLong; |
| 1393 | if (poller.fifo(.stderr).count > self.max_stdio_size) | 1392 | if (poller.fifo(.stderr).count > run.max_stdio_size) |
| 1394 | return error.StderrStreamTooLong; | 1393 | return error.StderrStreamTooLong; |
| 1395 | } | 1394 | } |
| 1396 | 1395 | ||
| 1397 | stdout_bytes = try poller.fifo(.stdout).toOwnedSlice(); | 1396 | stdout_bytes = try poller.fifo(.stdout).toOwnedSlice(); |
| 1398 | stderr_bytes = try poller.fifo(.stderr).toOwnedSlice(); | 1397 | stderr_bytes = try poller.fifo(.stderr).toOwnedSlice(); |
| 1399 | } else { | 1398 | } else { |
| 1400 | stdout_bytes = try stdout.reader().readAllAlloc(arena, self.max_stdio_size); | 1399 | stdout_bytes = try stdout.reader().readAllAlloc(arena, run.max_stdio_size); |
| 1401 | } | 1400 | } |
| 1402 | } else if (child.stderr) |stderr| { | 1401 | } else if (child.stderr) |stderr| { |
| 1403 | stderr_bytes = try stderr.reader().readAllAlloc(arena, self.max_stdio_size); | 1402 | stderr_bytes = try stderr.reader().readAllAlloc(arena, run.max_stdio_size); |
| 1404 | } | 1403 | } |
| 1405 | 1404 | ||
| 1406 | if (stderr_bytes) |bytes| if (bytes.len > 0) { | 1405 | if (stderr_bytes) |bytes| if (bytes.len > 0) { |
| 1407 | // Treat stderr as an error message. | 1406 | // Treat stderr as an error message. |
| 1408 | const stderr_is_diagnostic = self.captured_stderr == null and switch (self.stdio) { | 1407 | const stderr_is_diagnostic = run.captured_stderr == null and switch (run.stdio) { |
| 1409 | .check => |checks| !checksContainStderr(checks.items), | 1408 | .check => |checks| !checksContainStderr(checks.items), |
| 1410 | else => true, | 1409 | else => true, |
| 1411 | }; | 1410 | }; |
| 1412 | if (stderr_is_diagnostic) { | 1411 | if (stderr_is_diagnostic) { |
| 1413 | self.step.result_stderr = bytes; | 1412 | run.step.result_stderr = bytes; |
| 1414 | } | 1413 | } |
| 1415 | }; | 1414 | }; |
| 1416 | 1415 | ||
| ... | @@ -1422,8 +1421,8 @@ fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult { | ... | @@ -1422,8 +1421,8 @@ fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult { |
| 1422 | }; | 1421 | }; |
| 1423 | } | 1422 | } |
| 1424 | 1423 | ||
| 1425 | fn addPathForDynLibs(self: *Run, artifact: *Step.Compile) void { | 1424 | fn addPathForDynLibs(run: *Run, artifact: *Step.Compile) void { |
| 1426 | const b = self.step.owner; | 1425 | const b = run.step.owner; |
| 1427 | var it = artifact.root_module.iterateDependencies(artifact, true); | 1426 | var it = artifact.root_module.iterateDependencies(artifact, true); |
| 1428 | while (it.next()) |item| { | 1427 | while (it.next()) |item| { |
| 1429 | const other = item.compile.?; | 1428 | const other = item.compile.?; |
| ... | @@ -1431,34 +1430,34 @@ fn addPathForDynLibs(self: *Run, artifact: *Step.Compile) void { | ... | @@ -1431,34 +1430,34 @@ fn addPathForDynLibs(self: *Run, artifact: *Step.Compile) void { |
| 1431 | if (item.module.resolved_target.?.result.os.tag == .windows and | 1430 | if (item.module.resolved_target.?.result.os.tag == .windows and |
| 1432 | other.isDynamicLibrary()) | 1431 | other.isDynamicLibrary()) |
| 1433 | { | 1432 | { |
| 1434 | addPathDir(self, fs.path.dirname(other.getEmittedBin().getPath(b)).?); | 1433 | addPathDir(run, fs.path.dirname(other.getEmittedBin().getPath2(b, &run.step)).?); |
| 1435 | } | 1434 | } |
| 1436 | } | 1435 | } |
| 1437 | } | 1436 | } |
| 1438 | } | 1437 | } |
| 1439 | 1438 | ||
| 1440 | fn failForeign( | 1439 | fn failForeign( |
| 1441 | self: *Run, | 1440 | run: *Run, |
| 1442 | suggested_flag: []const u8, | 1441 | suggested_flag: []const u8, |
| 1443 | argv0: []const u8, | 1442 | argv0: []const u8, |
| 1444 | exe: *Step.Compile, | 1443 | exe: *Step.Compile, |
| 1445 | ) error{ MakeFailed, MakeSkipped, OutOfMemory } { | 1444 | ) error{ MakeFailed, MakeSkipped, OutOfMemory } { |
| 1446 | switch (self.stdio) { | 1445 | switch (run.stdio) { |
| 1447 | .check, .zig_test => { | 1446 | .check, .zig_test => { |
| 1448 | if (self.skip_foreign_checks) | 1447 | if (run.skip_foreign_checks) |
| 1449 | return error.MakeSkipped; | 1448 | return error.MakeSkipped; |
| 1450 | 1449 | ||
| 1451 | const b = self.step.owner; | 1450 | const b = run.step.owner; |
| 1452 | const host_name = try b.host.result.zigTriple(b.allocator); | 1451 | const host_name = try b.host.result.zigTriple(b.allocator); |
| 1453 | const foreign_name = try exe.rootModuleTarget().zigTriple(b.allocator); | 1452 | const foreign_name = try exe.rootModuleTarget().zigTriple(b.allocator); |
| 1454 | 1453 | ||
| 1455 | return self.step.fail( | 1454 | return run.step.fail( |
| 1456 | \\unable to spawn foreign binary '{s}' ({s}) on host system ({s}) | 1455 | \\unable to spawn foreign binary '{s}' ({s}) on host system ({s}) |
| 1457 | \\ consider using {s} or enabling skip_foreign_checks in the Run step | 1456 | \\ consider using {s} or enabling skip_foreign_checks in the Run step |
| 1458 | , .{ argv0, foreign_name, host_name, suggested_flag }); | 1457 | , .{ argv0, foreign_name, host_name, suggested_flag }); |
| 1459 | }, | 1458 | }, |
| 1460 | else => { | 1459 | else => { |
| 1461 | return self.step.fail("unable to spawn foreign binary '{s}'", .{argv0}); | 1460 | return run.step.fail("unable to spawn foreign binary '{s}'", .{argv0}); |
| 1462 | }, | 1461 | }, |
| 1463 | } | 1462 | } |
| 1464 | } | 1463 | } |
lib/std/Build/Step/TranslateC.zig+42-45| ... | @@ -5,7 +5,7 @@ const mem = std.mem; | ... | @@ -5,7 +5,7 @@ const mem = std.mem; |
| 5 | 5 | ||
| 6 | const TranslateC = @This(); | 6 | const TranslateC = @This(); |
| 7 | 7 | ||
| 8 | pub const base_id = .translate_c; | 8 | pub const base_id: Step.Id = .translate_c; |
| 9 | 9 | ||
| 10 | step: Step, | 10 | step: Step, |
| 11 | source: std.Build.LazyPath, | 11 | source: std.Build.LazyPath, |
| ... | @@ -27,11 +27,11 @@ pub const Options = struct { | ... | @@ -27,11 +27,11 @@ pub const Options = struct { |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | pub fn create(owner: *std.Build, options: Options) *TranslateC { | 29 | pub fn create(owner: *std.Build, options: Options) *TranslateC { |
| 30 | const self = owner.allocator.create(TranslateC) catch @panic("OOM"); | 30 | const translate_c = owner.allocator.create(TranslateC) catch @panic("OOM"); |
| 31 | const source = options.root_source_file.dupe(owner); | 31 | const source = options.root_source_file.dupe(owner); |
| 32 | self.* = TranslateC{ | 32 | translate_c.* = TranslateC{ |
| 33 | .step = Step.init(.{ | 33 | .step = Step.init(.{ |
| 34 | .id = .translate_c, | 34 | .id = base_id, |
| 35 | .name = "translate-c", | 35 | .name = "translate-c", |
| 36 | .owner = owner, | 36 | .owner = owner, |
| 37 | .makeFn = make, | 37 | .makeFn = make, |
| ... | @@ -42,12 +42,12 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC { | ... | @@ -42,12 +42,12 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC { |
| 42 | .out_basename = undefined, | 42 | .out_basename = undefined, |
| 43 | .target = options.target, | 43 | .target = options.target, |
| 44 | .optimize = options.optimize, | 44 | .optimize = options.optimize, |
| 45 | .output_file = std.Build.GeneratedFile{ .step = &self.step }, | 45 | .output_file = std.Build.GeneratedFile{ .step = &translate_c.step }, |
| 46 | .link_libc = options.link_libc, | 46 | .link_libc = options.link_libc, |
| 47 | .use_clang = options.use_clang, | 47 | .use_clang = options.use_clang, |
| 48 | }; | 48 | }; |
| 49 | source.addStepDependencies(&self.step); | 49 | source.addStepDependencies(&translate_c.step); |
| 50 | return self; | 50 | return translate_c; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | pub const AddExecutableOptions = struct { | 53 | pub const AddExecutableOptions = struct { |
| ... | @@ -58,18 +58,18 @@ pub const AddExecutableOptions = struct { | ... | @@ -58,18 +58,18 @@ pub const AddExecutableOptions = struct { |
| 58 | linkage: ?std.builtin.LinkMode = null, | 58 | linkage: ?std.builtin.LinkMode = null, |
| 59 | }; | 59 | }; |
| 60 | 60 | ||
| 61 | pub fn getOutput(self: *TranslateC) std.Build.LazyPath { | 61 | pub fn getOutput(translate_c: *TranslateC) std.Build.LazyPath { |
| 62 | return .{ .generated = &self.output_file }; | 62 | return .{ .generated = &translate_c.output_file }; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | /// Creates a step to build an executable from the translated source. | 65 | /// Creates a step to build an executable from the translated source. |
| 66 | pub fn addExecutable(self: *TranslateC, options: AddExecutableOptions) *Step.Compile { | 66 | pub fn addExecutable(translate_c: *TranslateC, options: AddExecutableOptions) *Step.Compile { |
| 67 | return self.step.owner.addExecutable(.{ | 67 | return translate_c.step.owner.addExecutable(.{ |
| 68 | .root_source_file = self.getOutput(), | 68 | .root_source_file = translate_c.getOutput(), |
| 69 | .name = options.name orelse "translated_c", | 69 | .name = options.name orelse "translated_c", |
| 70 | .version = options.version, | 70 | .version = options.version, |
| 71 | .target = options.target orelse self.target, | 71 | .target = options.target orelse translate_c.target, |
| 72 | .optimize = options.optimize orelse self.optimize, | 72 | .optimize = options.optimize orelse translate_c.optimize, |
| 73 | .linkage = options.linkage, | 73 | .linkage = options.linkage, |
| 74 | }); | 74 | }); |
| 75 | } | 75 | } |
| ... | @@ -77,90 +77,87 @@ pub fn addExecutable(self: *TranslateC, options: AddExecutableOptions) *Step.Com | ... | @@ -77,90 +77,87 @@ pub fn addExecutable(self: *TranslateC, options: AddExecutableOptions) *Step.Com |
| 77 | /// Creates a module from the translated source and adds it to the package's | 77 | /// Creates a module from the translated source and adds it to the package's |
| 78 | /// module set making it available to other packages which depend on this one. | 78 | /// module set making it available to other packages which depend on this one. |
| 79 | /// `createModule` can be used instead to create a private module. | 79 | /// `createModule` can be used instead to create a private module. |
| 80 | pub fn addModule(self: *TranslateC, name: []const u8) *std.Build.Module { | 80 | pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module { |
| 81 | return self.step.owner.addModule(name, .{ | 81 | return translate_c.step.owner.addModule(name, .{ |
| 82 | .root_source_file = self.getOutput(), | 82 | .root_source_file = translate_c.getOutput(), |
| 83 | }); | 83 | }); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | /// Creates a private module from the translated source to be used by the | 86 | /// Creates a private module from the translated source to be used by the |
| 87 | /// current package, but not exposed to other packages depending on this one. | 87 | /// current package, but not exposed to other packages depending on this one. |
| 88 | /// `addModule` can be used instead to create a public module. | 88 | /// `addModule` can be used instead to create a public module. |
| 89 | pub fn createModule(self: *TranslateC) *std.Build.Module { | 89 | pub fn createModule(translate_c: *TranslateC) *std.Build.Module { |
| 90 | return self.step.owner.createModule(.{ | 90 | return translate_c.step.owner.createModule(.{ |
| 91 | .root_source_file = self.getOutput(), | 91 | .root_source_file = translate_c.getOutput(), |
| 92 | }); | 92 | }); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | pub fn addIncludeDir(self: *TranslateC, include_dir: []const u8) void { | 95 | pub fn addIncludeDir(translate_c: *TranslateC, include_dir: []const u8) void { |
| 96 | self.include_dirs.append(self.step.owner.dupePath(include_dir)) catch @panic("OOM"); | 96 | translate_c.include_dirs.append(translate_c.step.owner.dupePath(include_dir)) catch @panic("OOM"); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | pub fn addCheckFile(self: *TranslateC, expected_matches: []const []const u8) *Step.CheckFile { | 99 | pub fn addCheckFile(translate_c: *TranslateC, expected_matches: []const []const u8) *Step.CheckFile { |
| 100 | return Step.CheckFile.create( | 100 | return Step.CheckFile.create( |
| 101 | self.step.owner, | 101 | translate_c.step.owner, |
| 102 | self.getOutput(), | 102 | translate_c.getOutput(), |
| 103 | .{ .expected_matches = expected_matches }, | 103 | .{ .expected_matches = expected_matches }, |
| 104 | ); | 104 | ); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | /// If the value is omitted, it is set to 1. | 107 | /// If the value is omitted, it is set to 1. |
| 108 | /// `name` and `value` need not live longer than the function call. | 108 | /// `name` and `value` need not live longer than the function call. |
| 109 | pub fn defineCMacro(self: *TranslateC, name: []const u8, value: ?[]const u8) void { | 109 | pub fn defineCMacro(translate_c: *TranslateC, name: []const u8, value: ?[]const u8) void { |
| 110 | const macro = std.Build.constructCMacro(self.step.owner.allocator, name, value); | 110 | const macro = std.Build.constructranslate_cMacro(translate_c.step.owner.allocator, name, value); |
| 111 | self.c_macros.append(macro) catch @panic("OOM"); | 111 | translate_c.c_macros.append(macro) catch @panic("OOM"); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. | 114 | /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. |
| 115 | pub fn defineCMacroRaw(self: *TranslateC, name_and_value: []const u8) void { | 115 | pub fn defineCMacroRaw(translate_c: *TranslateC, name_and_value: []const u8) void { |
| 116 | self.c_macros.append(self.step.owner.dupe(name_and_value)) catch @panic("OOM"); | 116 | translate_c.c_macros.append(translate_c.step.owner.dupe(name_and_value)) catch @panic("OOM"); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 119 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 120 | const b = step.owner; | 120 | const b = step.owner; |
| 121 | const self: *TranslateC = @fieldParentPtr("step", step); | 121 | const translate_c: *TranslateC = @fieldParentPtr("step", step); |
| 122 | 122 | ||
| 123 | var argv_list = std.ArrayList([]const u8).init(b.allocator); | 123 | var argv_list = std.ArrayList([]const u8).init(b.allocator); |
| 124 | try argv_list.append(b.graph.zig_exe); | 124 | try argv_list.append(b.graph.zig_exe); |
| 125 | try argv_list.append("translate-c"); | 125 | try argv_list.append("translate-c"); |
| 126 | if (self.link_libc) { | 126 | if (translate_c.link_libc) { |
| 127 | try argv_list.append("-lc"); | 127 | try argv_list.append("-lc"); |
| 128 | } | 128 | } |
| 129 | if (!self.use_clang) { | 129 | if (!translate_c.use_clang) { |
| 130 | try argv_list.append("-fno-clang"); | 130 | try argv_list.append("-fno-clang"); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | try argv_list.append("--listen=-"); | 133 | try argv_list.append("--listen=-"); |
| 134 | 134 | ||
| 135 | if (!self.target.query.isNative()) { | 135 | if (!translate_c.target.query.isNative()) { |
| 136 | try argv_list.append("-target"); | 136 | try argv_list.append("-target"); |
| 137 | try argv_list.append(try self.target.query.zigTriple(b.allocator)); | 137 | try argv_list.append(try translate_c.target.query.zigTriple(b.allocator)); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | switch (self.optimize) { | 140 | switch (translate_c.optimize) { |
| 141 | .Debug => {}, // Skip since it's the default. | 141 | .Debug => {}, // Skip since it's the default. |
| 142 | else => try argv_list.append(b.fmt("-O{s}", .{@tagName(self.optimize)})), | 142 | else => try argv_list.append(b.fmt("-O{s}", .{@tagName(translate_c.optimize)})), |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | for (self.include_dirs.items) |include_dir| { | 145 | for (translate_c.include_dirs.items) |include_dir| { |
| 146 | try argv_list.append("-I"); | 146 | try argv_list.append("-I"); |
| 147 | try argv_list.append(include_dir); | 147 | try argv_list.append(include_dir); |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | for (self.c_macros.items) |c_macro| { | 150 | for (translate_c.c_macros.items) |c_macro| { |
| 151 | try argv_list.append("-D"); | 151 | try argv_list.append("-D"); |
| 152 | try argv_list.append(c_macro); | 152 | try argv_list.append(c_macro); |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | try argv_list.append(self.source.getPath(b)); | 155 | try argv_list.append(translate_c.source.getPath2(b, step)); |
| 156 | 156 | ||
| 157 | const output_path = try step.evalZigProcess(argv_list.items, prog_node); | 157 | const output_path = try step.evalZigProcess(argv_list.items, prog_node); |
| 158 | 158 | ||
| 159 | self.out_basename = fs.path.basename(output_path.?); | 159 | translate_c.out_basename = fs.path.basename(output_path.?); |
| 160 | const output_dir = fs.path.dirname(output_path.?).?; | 160 | const output_dir = fs.path.dirname(output_path.?).?; |
| 161 | 161 | ||
| 162 | self.output_file.path = try fs.path.join( | 162 | translate_c.output_file.path = b.pathJoin(&.{ output_dir, translate_c.out_basename }); |
| 163 | b.allocator, | ||
| 164 | &[_][]const u8{ output_dir, self.out_basename }, | ||
| 165 | ); | ||
| 166 | } | 163 | } |
lib/std/Build/Step/WriteFile.zig+58-58| ... | @@ -23,15 +23,15 @@ directories: std.ArrayListUnmanaged(*Directory), | ... | @@ -23,15 +23,15 @@ directories: std.ArrayListUnmanaged(*Directory), |
| 23 | output_source_files: std.ArrayListUnmanaged(OutputSourceFile), | 23 | output_source_files: std.ArrayListUnmanaged(OutputSourceFile), |
| 24 | generated_directory: std.Build.GeneratedFile, | 24 | generated_directory: std.Build.GeneratedFile, |
| 25 | 25 | ||
| 26 | pub const base_id = .write_file; | 26 | pub const base_id: Step.Id = .write_file; |
| 27 | 27 | ||
| 28 | pub const File = struct { | 28 | pub const File = struct { |
| 29 | generated_file: std.Build.GeneratedFile, | 29 | generated_file: std.Build.GeneratedFile, |
| 30 | sub_path: []const u8, | 30 | sub_path: []const u8, |
| 31 | contents: Contents, | 31 | contents: Contents, |
| 32 | 32 | ||
| 33 | pub fn getPath(self: *File) std.Build.LazyPath { | 33 | pub fn getPath(file: *File) std.Build.LazyPath { |
| 34 | return .{ .generated = &self.generated_file }; | 34 | return .{ .generated = &file.generated_file }; |
| 35 | } | 35 | } |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| ... | @@ -49,16 +49,16 @@ pub const Directory = struct { | ... | @@ -49,16 +49,16 @@ pub const Directory = struct { |
| 49 | /// `exclude_extensions` takes precedence over `include_extensions`. | 49 | /// `exclude_extensions` takes precedence over `include_extensions`. |
| 50 | include_extensions: ?[]const []const u8 = null, | 50 | include_extensions: ?[]const []const u8 = null, |
| 51 | 51 | ||
| 52 | pub fn dupe(self: Options, b: *std.Build) Options { | 52 | pub fn dupe(opts: Options, b: *std.Build) Options { |
| 53 | return .{ | 53 | return .{ |
| 54 | .exclude_extensions = b.dupeStrings(self.exclude_extensions), | 54 | .exclude_extensions = b.dupeStrings(opts.exclude_extensions), |
| 55 | .include_extensions = if (self.include_extensions) |incs| b.dupeStrings(incs) else null, | 55 | .include_extensions = if (opts.include_extensions) |incs| b.dupeStrings(incs) else null, |
| 56 | }; | 56 | }; |
| 57 | } | 57 | } |
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| 60 | pub fn getPath(self: *Directory) std.Build.LazyPath { | 60 | pub fn getPath(dir: *Directory) std.Build.LazyPath { |
| 61 | return .{ .generated = &self.generated_dir }; | 61 | return .{ .generated = &dir.generated_dir }; |
| 62 | } | 62 | } |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| ... | @@ -73,10 +73,10 @@ pub const Contents = union(enum) { | ... | @@ -73,10 +73,10 @@ pub const Contents = union(enum) { |
| 73 | }; | 73 | }; |
| 74 | 74 | ||
| 75 | pub fn create(owner: *std.Build) *WriteFile { | 75 | pub fn create(owner: *std.Build) *WriteFile { |
| 76 | const wf = owner.allocator.create(WriteFile) catch @panic("OOM"); | 76 | const write_file = owner.allocator.create(WriteFile) catch @panic("OOM"); |
| 77 | wf.* = .{ | 77 | write_file.* = .{ |
| 78 | .step = Step.init(.{ | 78 | .step = Step.init(.{ |
| 79 | .id = .write_file, | 79 | .id = base_id, |
| 80 | .name = "WriteFile", | 80 | .name = "WriteFile", |
| 81 | .owner = owner, | 81 | .owner = owner, |
| 82 | .makeFn = make, | 82 | .makeFn = make, |
| ... | @@ -84,22 +84,22 @@ pub fn create(owner: *std.Build) *WriteFile { | ... | @@ -84,22 +84,22 @@ pub fn create(owner: *std.Build) *WriteFile { |
| 84 | .files = .{}, | 84 | .files = .{}, |
| 85 | .directories = .{}, | 85 | .directories = .{}, |
| 86 | .output_source_files = .{}, | 86 | .output_source_files = .{}, |
| 87 | .generated_directory = .{ .step = &wf.step }, | 87 | .generated_directory = .{ .step = &write_file.step }, |
| 88 | }; | 88 | }; |
| 89 | return wf; | 89 | return write_file; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.LazyPath { | 92 | pub fn add(write_file: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.LazyPath { |
| 93 | const b = wf.step.owner; | 93 | const b = write_file.step.owner; |
| 94 | const gpa = b.allocator; | 94 | const gpa = b.allocator; |
| 95 | const file = gpa.create(File) catch @panic("OOM"); | 95 | const file = gpa.create(File) catch @panic("OOM"); |
| 96 | file.* = .{ | 96 | file.* = .{ |
| 97 | .generated_file = .{ .step = &wf.step }, | 97 | .generated_file = .{ .step = &write_file.step }, |
| 98 | .sub_path = b.dupePath(sub_path), | 98 | .sub_path = b.dupePath(sub_path), |
| 99 | .contents = .{ .bytes = b.dupe(bytes) }, | 99 | .contents = .{ .bytes = b.dupe(bytes) }, |
| 100 | }; | 100 | }; |
| 101 | wf.files.append(gpa, file) catch @panic("OOM"); | 101 | write_file.files.append(gpa, file) catch @panic("OOM"); |
| 102 | wf.maybeUpdateName(); | 102 | write_file.maybeUpdateName(); |
| 103 | return file.getPath(); | 103 | return file.getPath(); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| ... | @@ -110,19 +110,19 @@ pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.La | ... | @@ -110,19 +110,19 @@ pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.La |
| 110 | /// include sub-directories, in which case this step will ensure the | 110 | /// include sub-directories, in which case this step will ensure the |
| 111 | /// required sub-path exists. | 111 | /// required sub-path exists. |
| 112 | /// This is the option expected to be used most commonly with `addCopyFile`. | 112 | /// This is the option expected to be used most commonly with `addCopyFile`. |
| 113 | pub fn addCopyFile(wf: *WriteFile, source: std.Build.LazyPath, sub_path: []const u8) std.Build.LazyPath { | 113 | pub fn addCopyFile(write_file: *WriteFile, source: std.Build.LazyPath, sub_path: []const u8) std.Build.LazyPath { |
| 114 | const b = wf.step.owner; | 114 | const b = write_file.step.owner; |
| 115 | const gpa = b.allocator; | 115 | const gpa = b.allocator; |
| 116 | const file = gpa.create(File) catch @panic("OOM"); | 116 | const file = gpa.create(File) catch @panic("OOM"); |
| 117 | file.* = .{ | 117 | file.* = .{ |
| 118 | .generated_file = .{ .step = &wf.step }, | 118 | .generated_file = .{ .step = &write_file.step }, |
| 119 | .sub_path = b.dupePath(sub_path), | 119 | .sub_path = b.dupePath(sub_path), |
| 120 | .contents = .{ .copy = source }, | 120 | .contents = .{ .copy = source }, |
| 121 | }; | 121 | }; |
| 122 | wf.files.append(gpa, file) catch @panic("OOM"); | 122 | write_file.files.append(gpa, file) catch @panic("OOM"); |
| 123 | 123 | ||
| 124 | wf.maybeUpdateName(); | 124 | write_file.maybeUpdateName(); |
| 125 | source.addStepDependencies(&wf.step); | 125 | source.addStepDependencies(&write_file.step); |
| 126 | return file.getPath(); | 126 | return file.getPath(); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| ... | @@ -130,24 +130,24 @@ pub fn addCopyFile(wf: *WriteFile, source: std.Build.LazyPath, sub_path: []const | ... | @@ -130,24 +130,24 @@ pub fn addCopyFile(wf: *WriteFile, source: std.Build.LazyPath, sub_path: []const |
| 130 | /// relative to this step's generated directory. | 130 | /// relative to this step's generated directory. |
| 131 | /// The returned value is a lazy path to the generated subdirectory. | 131 | /// The returned value is a lazy path to the generated subdirectory. |
| 132 | pub fn addCopyDirectory( | 132 | pub fn addCopyDirectory( |
| 133 | wf: *WriteFile, | 133 | write_file: *WriteFile, |
| 134 | source: std.Build.LazyPath, | 134 | source: std.Build.LazyPath, |
| 135 | sub_path: []const u8, | 135 | sub_path: []const u8, |
| 136 | options: Directory.Options, | 136 | options: Directory.Options, |
| 137 | ) std.Build.LazyPath { | 137 | ) std.Build.LazyPath { |
| 138 | const b = wf.step.owner; | 138 | const b = write_file.step.owner; |
| 139 | const gpa = b.allocator; | 139 | const gpa = b.allocator; |
| 140 | const dir = gpa.create(Directory) catch @panic("OOM"); | 140 | const dir = gpa.create(Directory) catch @panic("OOM"); |
| 141 | dir.* = .{ | 141 | dir.* = .{ |
| 142 | .source = source.dupe(b), | 142 | .source = source.dupe(b), |
| 143 | .sub_path = b.dupePath(sub_path), | 143 | .sub_path = b.dupePath(sub_path), |
| 144 | .options = options.dupe(b), | 144 | .options = options.dupe(b), |
| 145 | .generated_dir = .{ .step = &wf.step }, | 145 | .generated_dir = .{ .step = &write_file.step }, |
| 146 | }; | 146 | }; |
| 147 | wf.directories.append(gpa, dir) catch @panic("OOM"); | 147 | write_file.directories.append(gpa, dir) catch @panic("OOM"); |
| 148 | 148 | ||
| 149 | wf.maybeUpdateName(); | 149 | write_file.maybeUpdateName(); |
| 150 | source.addStepDependencies(&wf.step); | 150 | source.addStepDependencies(&write_file.step); |
| 151 | return dir.getPath(); | 151 | return dir.getPath(); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| ... | @@ -156,13 +156,13 @@ pub fn addCopyDirectory( | ... | @@ -156,13 +156,13 @@ pub fn addCopyDirectory( |
| 156 | /// used as part of the normal build process, but as a utility occasionally | 156 | /// used as part of the normal build process, but as a utility occasionally |
| 157 | /// run by a developer with intent to modify source files and then commit | 157 | /// run by a developer with intent to modify source files and then commit |
| 158 | /// those changes to version control. | 158 | /// those changes to version control. |
| 159 | pub fn addCopyFileToSource(wf: *WriteFile, source: std.Build.LazyPath, sub_path: []const u8) void { | 159 | pub fn addCopyFileToSource(write_file: *WriteFile, source: std.Build.LazyPath, sub_path: []const u8) void { |
| 160 | const b = wf.step.owner; | 160 | const b = write_file.step.owner; |
| 161 | wf.output_source_files.append(b.allocator, .{ | 161 | write_file.output_source_files.append(b.allocator, .{ |
| 162 | .contents = .{ .copy = source }, | 162 | .contents = .{ .copy = source }, |
| 163 | .sub_path = sub_path, | 163 | .sub_path = sub_path, |
| 164 | }) catch @panic("OOM"); | 164 | }) catch @panic("OOM"); |
| 165 | source.addStepDependencies(&wf.step); | 165 | source.addStepDependencies(&write_file.step); |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | /// A path relative to the package root. | 168 | /// A path relative to the package root. |
| ... | @@ -170,9 +170,9 @@ pub fn addCopyFileToSource(wf: *WriteFile, source: std.Build.LazyPath, sub_path: | ... | @@ -170,9 +170,9 @@ pub fn addCopyFileToSource(wf: *WriteFile, source: std.Build.LazyPath, sub_path: |
| 170 | /// used as part of the normal build process, but as a utility occasionally | 170 | /// used as part of the normal build process, but as a utility occasionally |
| 171 | /// run by a developer with intent to modify source files and then commit | 171 | /// run by a developer with intent to modify source files and then commit |
| 172 | /// those changes to version control. | 172 | /// those changes to version control. |
| 173 | pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) void { | 173 | pub fn addBytesToSource(write_file: *WriteFile, bytes: []const u8, sub_path: []const u8) void { |
| 174 | const b = wf.step.owner; | 174 | const b = write_file.step.owner; |
| 175 | wf.output_source_files.append(b.allocator, .{ | 175 | write_file.output_source_files.append(b.allocator, .{ |
| 176 | .contents = .{ .bytes = bytes }, | 176 | .contents = .{ .bytes = bytes }, |
| 177 | .sub_path = sub_path, | 177 | .sub_path = sub_path, |
| 178 | }) catch @panic("OOM"); | 178 | }) catch @panic("OOM"); |
| ... | @@ -180,20 +180,20 @@ pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) | ... | @@ -180,20 +180,20 @@ pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) |
| 180 | 180 | ||
| 181 | /// Returns a `LazyPath` representing the base directory that contains all the | 181 | /// Returns a `LazyPath` representing the base directory that contains all the |
| 182 | /// files from this `WriteFile`. | 182 | /// files from this `WriteFile`. |
| 183 | pub fn getDirectory(wf: *WriteFile) std.Build.LazyPath { | 183 | pub fn getDirectory(write_file: *WriteFile) std.Build.LazyPath { |
| 184 | return .{ .generated = &wf.generated_directory }; | 184 | return .{ .generated = &write_file.generated_directory }; |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | fn maybeUpdateName(wf: *WriteFile) void { | 187 | fn maybeUpdateName(write_file: *WriteFile) void { |
| 188 | if (wf.files.items.len == 1 and wf.directories.items.len == 0) { | 188 | if (write_file.files.items.len == 1 and write_file.directories.items.len == 0) { |
| 189 | // First time adding a file; update name. | 189 | // First time adding a file; update name. |
| 190 | if (std.mem.eql(u8, wf.step.name, "WriteFile")) { | 190 | if (std.mem.eql(u8, write_file.step.name, "WriteFile")) { |
| 191 | wf.step.name = wf.step.owner.fmt("WriteFile {s}", .{wf.files.items[0].sub_path}); | 191 | write_file.step.name = write_file.step.owner.fmt("WriteFile {s}", .{write_file.files.items[0].sub_path}); |
| 192 | } | 192 | } |
| 193 | } else if (wf.directories.items.len == 1 and wf.files.items.len == 0) { | 193 | } else if (write_file.directories.items.len == 1 and write_file.files.items.len == 0) { |
| 194 | // First time adding a directory; update name. | 194 | // First time adding a directory; update name. |
| 195 | if (std.mem.eql(u8, wf.step.name, "WriteFile")) { | 195 | if (std.mem.eql(u8, write_file.step.name, "WriteFile")) { |
| 196 | wf.step.name = wf.step.owner.fmt("WriteFile {s}", .{wf.directories.items[0].sub_path}); | 196 | write_file.step.name = write_file.step.owner.fmt("WriteFile {s}", .{write_file.directories.items[0].sub_path}); |
| 197 | } | 197 | } |
| 198 | } | 198 | } |
| 199 | } | 199 | } |
| ... | @@ -201,14 +201,14 @@ fn maybeUpdateName(wf: *WriteFile) void { | ... | @@ -201,14 +201,14 @@ fn maybeUpdateName(wf: *WriteFile) void { |
| 201 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 201 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 202 | _ = prog_node; | 202 | _ = prog_node; |
| 203 | const b = step.owner; | 203 | const b = step.owner; |
| 204 | const wf: *WriteFile = @fieldParentPtr("step", step); | 204 | const write_file: *WriteFile = @fieldParentPtr("step", step); |
| 205 | 205 | ||
| 206 | // Writing to source files is kind of an extra capability of this | 206 | // Writing to source files is kind of an extra capability of this |
| 207 | // WriteFile - arguably it should be a different step. But anyway here | 207 | // WriteFile - arguably it should be a different step. But anyway here |
| 208 | // it is, it happens unconditionally and does not interact with the other | 208 | // it is, it happens unconditionally and does not interact with the other |
| 209 | // files here. | 209 | // files here. |
| 210 | var any_miss = false; | 210 | var any_miss = false; |
| 211 | for (wf.output_source_files.items) |output_source_file| { | 211 | for (write_file.output_source_files.items) |output_source_file| { |
| 212 | if (fs.path.dirname(output_source_file.sub_path)) |dirname| { | 212 | if (fs.path.dirname(output_source_file.sub_path)) |dirname| { |
| 213 | b.build_root.handle.makePath(dirname) catch |err| { | 213 | b.build_root.handle.makePath(dirname) catch |err| { |
| 214 | return step.fail("unable to make path '{}{s}': {s}", .{ | 214 | return step.fail("unable to make path '{}{s}': {s}", .{ |
| ... | @@ -226,7 +226,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -226,7 +226,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 226 | any_miss = true; | 226 | any_miss = true; |
| 227 | }, | 227 | }, |
| 228 | .copy => |file_source| { | 228 | .copy => |file_source| { |
| 229 | const source_path = file_source.getPath(b); | 229 | const source_path = file_source.getPath2(b, step); |
| 230 | const prev_status = fs.Dir.updateFile( | 230 | const prev_status = fs.Dir.updateFile( |
| 231 | fs.cwd(), | 231 | fs.cwd(), |
| 232 | source_path, | 232 | source_path, |
| ... | @@ -258,18 +258,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -258,18 +258,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 258 | // in a non-backwards-compatible way. | 258 | // in a non-backwards-compatible way. |
| 259 | man.hash.add(@as(u32, 0xd767ee59)); | 259 | man.hash.add(@as(u32, 0xd767ee59)); |
| 260 | 260 | ||
| 261 | for (wf.files.items) |file| { | 261 | for (write_file.files.items) |file| { |
| 262 | man.hash.addBytes(file.sub_path); | 262 | man.hash.addBytes(file.sub_path); |
| 263 | switch (file.contents) { | 263 | switch (file.contents) { |
| 264 | .bytes => |bytes| { | 264 | .bytes => |bytes| { |
| 265 | man.hash.addBytes(bytes); | 265 | man.hash.addBytes(bytes); |
| 266 | }, | 266 | }, |
| 267 | .copy => |file_source| { | 267 | .copy => |file_source| { |
| 268 | _ = try man.addFile(file_source.getPath(b), null); | 268 | _ = try man.addFile(file_source.getPath2(b, step), null); |
| 269 | }, | 269 | }, |
| 270 | } | 270 | } |
| 271 | } | 271 | } |
| 272 | for (wf.directories.items) |dir| { | 272 | for (write_file.directories.items) |dir| { |
| 273 | man.hash.addBytes(dir.source.getPath2(b, step)); | 273 | man.hash.addBytes(dir.source.getPath2(b, step)); |
| 274 | man.hash.addBytes(dir.sub_path); | 274 | man.hash.addBytes(dir.sub_path); |
| 275 | for (dir.options.exclude_extensions) |ext| man.hash.addBytes(ext); | 275 | for (dir.options.exclude_extensions) |ext| man.hash.addBytes(ext); |
| ... | @@ -278,19 +278,19 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -278,19 +278,19 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 278 | 278 | ||
| 279 | if (try step.cacheHit(&man)) { | 279 | if (try step.cacheHit(&man)) { |
| 280 | const digest = man.final(); | 280 | const digest = man.final(); |
| 281 | for (wf.files.items) |file| { | 281 | for (write_file.files.items) |file| { |
| 282 | file.generated_file.path = try b.cache_root.join(b.allocator, &.{ | 282 | file.generated_file.path = try b.cache_root.join(b.allocator, &.{ |
| 283 | "o", &digest, file.sub_path, | 283 | "o", &digest, file.sub_path, |
| 284 | }); | 284 | }); |
| 285 | } | 285 | } |
| 286 | wf.generated_directory.path = try b.cache_root.join(b.allocator, &.{ "o", &digest }); | 286 | write_file.generated_directory.path = try b.cache_root.join(b.allocator, &.{ "o", &digest }); |
| 287 | return; | 287 | return; |
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | const digest = man.final(); | 290 | const digest = man.final(); |
| 291 | const cache_path = "o" ++ fs.path.sep_str ++ digest; | 291 | const cache_path = "o" ++ fs.path.sep_str ++ digest; |
| 292 | 292 | ||
| 293 | wf.generated_directory.path = try b.cache_root.join(b.allocator, &.{ "o", &digest }); | 293 | write_file.generated_directory.path = try b.cache_root.join(b.allocator, &.{ "o", &digest }); |
| 294 | 294 | ||
| 295 | var cache_dir = b.cache_root.handle.makeOpenPath(cache_path, .{}) catch |err| { | 295 | var cache_dir = b.cache_root.handle.makeOpenPath(cache_path, .{}) catch |err| { |
| 296 | return step.fail("unable to make path '{}{s}': {s}", .{ | 296 | return step.fail("unable to make path '{}{s}': {s}", .{ |
| ... | @@ -301,7 +301,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -301,7 +301,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 301 | 301 | ||
| 302 | const cwd = fs.cwd(); | 302 | const cwd = fs.cwd(); |
| 303 | 303 | ||
| 304 | for (wf.files.items) |file| { | 304 | for (write_file.files.items) |file| { |
| 305 | if (fs.path.dirname(file.sub_path)) |dirname| { | 305 | if (fs.path.dirname(file.sub_path)) |dirname| { |
| 306 | cache_dir.makePath(dirname) catch |err| { | 306 | cache_dir.makePath(dirname) catch |err| { |
| 307 | return step.fail("unable to make path '{}{s}{c}{s}': {s}", .{ | 307 | return step.fail("unable to make path '{}{s}{c}{s}': {s}", .{ |
| ... | @@ -318,7 +318,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -318,7 +318,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 318 | }; | 318 | }; |
| 319 | }, | 319 | }, |
| 320 | .copy => |file_source| { | 320 | .copy => |file_source| { |
| 321 | const source_path = file_source.getPath(b); | 321 | const source_path = file_source.getPath2(b, step); |
| 322 | const prev_status = fs.Dir.updateFile( | 322 | const prev_status = fs.Dir.updateFile( |
| 323 | cwd, | 323 | cwd, |
| 324 | source_path, | 324 | source_path, |
| ... | @@ -347,7 +347,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -347,7 +347,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 347 | cache_path, file.sub_path, | 347 | cache_path, file.sub_path, |
| 348 | }); | 348 | }); |
| 349 | } | 349 | } |
| 350 | for (wf.directories.items) |dir| { | 350 | for (write_file.directories.items) |dir| { |
| 351 | const full_src_dir_path = dir.source.getPath2(b, step); | 351 | const full_src_dir_path = dir.source.getPath2(b, step); |
| 352 | const dest_dirname = dir.sub_path; | 352 | const dest_dirname = dir.sub_path; |
| 353 | 353 |
test/standalone/coff_dwarf/build.zig+2-2| ... | @@ -18,7 +18,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -18,7 +18,7 @@ pub fn build(b: *std.Build) void { |
| 18 | 18 | ||
| 19 | const exe = b.addExecutable(.{ | 19 | const exe = b.addExecutable(.{ |
| 20 | .name = "main", | 20 | .name = "main", |
| 21 | .root_source_file = .{ .path = "main.zig" }, | 21 | .root_source_file = b.path("main.zig"), |
| 22 | .optimize = optimize, | 22 | .optimize = optimize, |
| 23 | .target = target, | 23 | .target = target, |
| 24 | }); | 24 | }); |
| ... | @@ -28,7 +28,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -28,7 +28,7 @@ pub fn build(b: *std.Build) void { |
| 28 | .optimize = optimize, | 28 | .optimize = optimize, |
| 29 | .target = target, | 29 | .target = target, |
| 30 | }); | 30 | }); |
| 31 | lib.addCSourceFile(.{ .file = .{ .path = "shared_lib.c" }, .flags = &.{"-gdwarf"} }); | 31 | lib.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} }); |
| 32 | lib.linkLibC(); | 32 | lib.linkLibC(); |
| 33 | exe.linkLibrary(lib); | 33 | exe.linkLibrary(lib); |
| 34 | 34 |
test/standalone/emit_asm_and_bin/build.zig+1-1| ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const main = b.addTest(.{ | 7 | const main = b.addTest(.{ |
| 8 | .root_source_file = .{ .path = "main.zig" }, | 8 | .root_source_file = b.path("main.zig"), |
| 9 | .optimize = b.standardOptimizeOption(.{}), | 9 | .optimize = b.standardOptimizeOption(.{}), |
| 10 | }); | 10 | }); |
| 11 | // TODO: actually check these two artifacts for correctness | 11 | // TODO: actually check these two artifacts for correctness |
test/standalone/issue_12588/build.zig+1-1| ... | @@ -8,7 +8,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,7 +8,7 @@ pub fn build(b: *std.Build) void { |
| 8 | 8 | ||
| 9 | const obj = b.addObject(.{ | 9 | const obj = b.addObject(.{ |
| 10 | .name = "main", | 10 | .name = "main", |
| 11 | .root_source_file = .{ .path = "main.zig" }, | 11 | .root_source_file = b.path("main.zig"), |
| 12 | .optimize = optimize, | 12 | .optimize = optimize, |
| 13 | .target = b.host, | 13 | .target = b.host, |
| 14 | }); | 14 | }); |
test/standalone/issue_13970/build.zig+3-3| ... | @@ -5,15 +5,15 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,15 +5,15 @@ pub fn build(b: *std.Build) void { |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const test1 = b.addTest(.{ | 7 | const test1 = b.addTest(.{ |
| 8 | .root_source_file = .{ .path = "test_root/empty.zig" }, | 8 | .root_source_file = b.path("test_root/empty.zig"), |
| 9 | .test_runner = "src/main.zig", | 9 | .test_runner = "src/main.zig", |
| 10 | }); | 10 | }); |
| 11 | const test2 = b.addTest(.{ | 11 | const test2 = b.addTest(.{ |
| 12 | .root_source_file = .{ .path = "src/empty.zig" }, | 12 | .root_source_file = b.path("src/empty.zig"), |
| 13 | .test_runner = "src/main.zig", | 13 | .test_runner = "src/main.zig", |
| 14 | }); | 14 | }); |
| 15 | const test3 = b.addTest(.{ | 15 | const test3 = b.addTest(.{ |
| 16 | .root_source_file = .{ .path = "empty.zig" }, | 16 | .root_source_file = b.path("empty.zig"), |
| 17 | .test_runner = "src/main.zig", | 17 | .test_runner = "src/main.zig", |
| 18 | }); | 18 | }); |
| 19 | 19 |
test/standalone/issue_5825/build.zig+1-1| ... | @@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void { |
| 16 | const optimize: std.builtin.OptimizeMode = .Debug; | 16 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 17 | const obj = b.addObject(.{ | 17 | const obj = b.addObject(.{ |
| 18 | .name = "issue_5825", | 18 | .name = "issue_5825", |
| 19 | .root_source_file = .{ .path = "main.zig" }, | 19 | .root_source_file = b.path("main.zig"), |
| 20 | .optimize = optimize, | 20 | .optimize = optimize, |
| 21 | .target = target, | 21 | .target = target, |
| 22 | }); | 22 | }); |
test/standalone/options/build.zig+1-1| ... | @@ -2,7 +2,7 @@ const std = @import("std"); | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn build(b: *std.Build) void { | 3 | pub fn build(b: *std.Build) void { |
| 4 | const main = b.addTest(.{ | 4 | const main = b.addTest(.{ |
| 5 | .root_source_file = .{ .path = "src/main.zig" }, | 5 | .root_source_file = b.path("src/main.zig"), |
| 6 | .target = b.host, | 6 | .target = b.host, |
| 7 | .optimize = .Debug, | 7 | .optimize = .Debug, |
| 8 | }); | 8 | }); |
test/standalone/sigpipe/build.zig+1-1| ... | @@ -29,7 +29,7 @@ pub fn build(b: *std.build.Builder) !void { | ... | @@ -29,7 +29,7 @@ pub fn build(b: *std.build.Builder) !void { |
| 29 | options.addOption(bool, "keep_sigpipe", keep_sigpipe); | 29 | options.addOption(bool, "keep_sigpipe", keep_sigpipe); |
| 30 | const exe = b.addExecutable(.{ | 30 | const exe = b.addExecutable(.{ |
| 31 | .name = "breakpipe", | 31 | .name = "breakpipe", |
| 32 | .root_source_file = .{ .path = "breakpipe.zig" }, | 32 | .root_source_file = b.path("breakpipe.zig"), |
| 33 | }); | 33 | }); |
| 34 | exe.addOptions("build_options", options); | 34 | exe.addOptions("build_options", options); |
| 35 | const run = b.addRunArtifact(exe); | 35 | const run = b.addRunArtifact(exe); |
test/standalone/windows_argv/build.zig+5-5| ... | @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) !void { |
| 11 | 11 | ||
| 12 | const lib_gnu = b.addStaticLibrary(.{ | 12 | const lib_gnu = b.addStaticLibrary(.{ |
| 13 | .name = "toargv-gnu", | 13 | .name = "toargv-gnu", |
| 14 | .root_source_file = .{ .path = "lib.zig" }, | 14 | .root_source_file = b.path("lib.zig"), |
| 15 | .target = b.resolveTargetQuery(.{ | 15 | .target = b.resolveTargetQuery(.{ |
| 16 | .abi = .gnu, | 16 | .abi = .gnu, |
| 17 | }), | 17 | }), |
| ... | @@ -25,7 +25,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -25,7 +25,7 @@ pub fn build(b: *std.Build) !void { |
| 25 | .optimize = optimize, | 25 | .optimize = optimize, |
| 26 | }); | 26 | }); |
| 27 | verify_gnu.addCSourceFile(.{ | 27 | verify_gnu.addCSourceFile(.{ |
| 28 | .file = .{ .path = "verify.c" }, | 28 | .file = b.path("verify.c"), |
| 29 | .flags = &.{ "-DUNICODE", "-D_UNICODE" }, | 29 | .flags = &.{ "-DUNICODE", "-D_UNICODE" }, |
| 30 | }); | 30 | }); |
| 31 | verify_gnu.mingw_unicode_entry_point = true; | 31 | verify_gnu.mingw_unicode_entry_point = true; |
| ... | @@ -34,7 +34,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -34,7 +34,7 @@ pub fn build(b: *std.Build) !void { |
| 34 | 34 | ||
| 35 | const fuzz = b.addExecutable(.{ | 35 | const fuzz = b.addExecutable(.{ |
| 36 | .name = "fuzz", | 36 | .name = "fuzz", |
| 37 | .root_source_file = .{ .path = "fuzz.zig" }, | 37 | .root_source_file = b.path("fuzz.zig"), |
| 38 | .target = b.host, | 38 | .target = b.host, |
| 39 | .optimize = optimize, | 39 | .optimize = optimize, |
| 40 | }); | 40 | }); |
| ... | @@ -69,7 +69,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -69,7 +69,7 @@ pub fn build(b: *std.Build) !void { |
| 69 | if (has_msvc) { | 69 | if (has_msvc) { |
| 70 | const lib_msvc = b.addStaticLibrary(.{ | 70 | const lib_msvc = b.addStaticLibrary(.{ |
| 71 | .name = "toargv-msvc", | 71 | .name = "toargv-msvc", |
| 72 | .root_source_file = .{ .path = "lib.zig" }, | 72 | .root_source_file = b.path("lib.zig"), |
| 73 | .target = b.resolveTargetQuery(.{ | 73 | .target = b.resolveTargetQuery(.{ |
| 74 | .abi = .msvc, | 74 | .abi = .msvc, |
| 75 | }), | 75 | }), |
| ... | @@ -83,7 +83,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -83,7 +83,7 @@ pub fn build(b: *std.Build) !void { |
| 83 | .optimize = optimize, | 83 | .optimize = optimize, |
| 84 | }); | 84 | }); |
| 85 | verify_msvc.addCSourceFile(.{ | 85 | verify_msvc.addCSourceFile(.{ |
| 86 | .file = .{ .path = "verify.c" }, | 86 | .file = b.path("verify.c"), |
| 87 | .flags = &.{ "-DUNICODE", "-D_UNICODE" }, | 87 | .flags = &.{ "-DUNICODE", "-D_UNICODE" }, |
| 88 | }); | 88 | }); |
| 89 | verify_msvc.linkLibrary(lib_msvc); | 89 | verify_msvc.linkLibrary(lib_msvc); |
test/standalone/windows_spawn/build.zig+2-2| ... | @@ -12,14 +12,14 @@ pub fn build(b: *std.Build) void { | ... | @@ -12,14 +12,14 @@ pub fn build(b: *std.Build) void { |
| 12 | 12 | ||
| 13 | const hello = b.addExecutable(.{ | 13 | const hello = b.addExecutable(.{ |
| 14 | .name = "hello", | 14 | .name = "hello", |
| 15 | .root_source_file = .{ .path = "hello.zig" }, | 15 | .root_source_file = b.path("hello.zig"), |
| 16 | .optimize = optimize, | 16 | .optimize = optimize, |
| 17 | .target = target, | 17 | .target = target, |
| 18 | }); | 18 | }); |
| 19 | 19 | ||
| 20 | const main = b.addExecutable(.{ | 20 | const main = b.addExecutable(.{ |
| 21 | .name = "main", | 21 | .name = "main", |
| 22 | .root_source_file = .{ .path = "main.zig" }, | 22 | .root_source_file = b.path("main.zig"), |
| 23 | .optimize = optimize, | 23 | .optimize = optimize, |
| 24 | .target = target, | 24 | .target = target, |
| 25 | }); | 25 | }); |