authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-02-24 13:12:04-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-02-24 16:12:04-05:00
log3eacd1b2e56728a291b4e5dc443a56fa0b4cab14
treed66bdb000053f3bcd14844b21e08719d0ad87c40
parent70fbafacf2811a9d6db5637e91d3a165d2af84a8
signaturebadge-check Signed by PGP key B5690EEEBB952194

change `addCSourceFiles` to use `LazyPath` instead `Dependency` (#19017)

Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>

2 files changed, 10 insertions(+), 14 deletions(-)

lib/std/Build/Module.zig+6-6
...@@ -79,9 +79,9 @@ pub const SystemLib = struct {...@@ -79,9 +79,9 @@ pub const SystemLib = struct {
79};79};
8080
81pub const CSourceFiles = struct {81pub const CSourceFiles = struct {
82 dependency: ?*std.Build.Dependency,82 root: LazyPath,
83 /// If `dependency` is not null relative to it,83 /// `files` is relative to `root`, which is
84 /// else relative to the build root.84 /// the build root by default
85 files: []const []const u8,85 files: []const []const u8,
86 flags: []const []const u8,86 flags: []const []const u8,
87};87};
...@@ -453,9 +453,9 @@ pub fn linkFramework(m: *Module, name: []const u8, options: LinkFrameworkOptions...@@ -453,9 +453,9 @@ pub fn linkFramework(m: *Module, name: []const u8, options: LinkFrameworkOptions
453}453}
454454
455pub const AddCSourceFilesOptions = struct {455pub const AddCSourceFilesOptions = struct {
456 /// When provided, `files` are relative to `dependency` rather than the456 /// When provided, `files` are relative to `root` rather than the
457 /// package that owns the `Compile` step.457 /// package that owns the `Compile` step.
458 dependency: ?*std.Build.Dependency = null,458 root: LazyPath = .{ .path = "" },
459 files: []const []const u8,459 files: []const []const u8,
460 flags: []const []const u8 = &.{},460 flags: []const []const u8 = &.{},
461};461};
...@@ -466,7 +466,7 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void {...@@ -466,7 +466,7 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void {
466 const allocator = b.allocator;466 const allocator = b.allocator;
467 const c_source_files = allocator.create(CSourceFiles) catch @panic("OOM");467 const c_source_files = allocator.create(CSourceFiles) catch @panic("OOM");
468 c_source_files.* = .{468 c_source_files.* = .{
469 .dependency = options.dependency,469 .root = options.root,
470 .files = b.dupeStrings(options.files),470 .files = b.dupeStrings(options.files),
471 .flags = b.dupeStrings(options.flags),471 .flags = b.dupeStrings(options.flags),
472 };472 };
lib/std/Build/Step/Compile.zig+4-8
...@@ -1197,15 +1197,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1197,15 +1197,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1197 prev_has_cflags = true;1197 prev_has_cflags = true;
1198 }1198 }
11991199
1200 if (c_source_files.dependency) |dep| {1200 const root_path = c_source_files.root.getPath2(module.owner, step);
1201 for (c_source_files.files) |file| {1201 for (c_source_files.files) |file| {
1202 try zig_args.append(dep.builder.pathFromRoot(file));1202 try zig_args.append(b.pathJoin(&.{ root_path, file }));
1203 }
1204 } else {
1205 for (c_source_files.files) |file| {
1206 try zig_args.append(b.pathFromRoot(file));
1207 }
1208 }1203 }
1204
1209 total_linker_objects += c_source_files.files.len;1205 total_linker_objects += c_source_files.files.len;
1210 },1206 },
12111207