zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3eacd1b2e56728a291b4e5dc443a56fa0b4cab14 (tree)
parent 70fbafacf2811a9d6db5637e91d3a165d2af84a8
Author: David Rubin <87927264+Rexicon226@users.noreply.github.com>
Date:   Sat, 24 Feb 2024 13:12:04 -0800

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

Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
Diffstat:
Mlib/std/Build/Module.zig | 12++++++------
Mlib/std/Build/Step/Compile.zig | 12++++--------
2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig @@ -79,9 +79,9 @@ pub const SystemLib = struct { }; pub const CSourceFiles = struct { - dependency: ?*std.Build.Dependency, - /// If `dependency` is not null relative to it, - /// else relative to the build root. + root: LazyPath, + /// `files` is relative to `root`, which is + /// the build root by default files: []const []const u8, flags: []const []const u8, }; @@ -453,9 +453,9 @@ pub fn linkFramework(m: *Module, name: []const u8, options: LinkFrameworkOptions } pub const AddCSourceFilesOptions = struct { - /// When provided, `files` are relative to `dependency` rather than the + /// When provided, `files` are relative to `root` rather than the /// package that owns the `Compile` step. - dependency: ?*std.Build.Dependency = null, + root: LazyPath = .{ .path = "" }, files: []const []const u8, flags: []const []const u8 = &.{}, }; @@ -466,7 +466,7 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void { const allocator = b.allocator; const c_source_files = allocator.create(CSourceFiles) catch @panic("OOM"); c_source_files.* = .{ - .dependency = options.dependency, + .root = options.root, .files = b.dupeStrings(options.files), .flags = b.dupeStrings(options.flags), }; diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig @@ -1197,15 +1197,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { prev_has_cflags = true; } - if (c_source_files.dependency) |dep| { - for (c_source_files.files) |file| { - try zig_args.append(dep.builder.pathFromRoot(file)); - } - } else { - for (c_source_files.files) |file| { - try zig_args.append(b.pathFromRoot(file)); - } + const root_path = c_source_files.root.getPath2(module.owner, step); + for (c_source_files.files) |file| { + try zig_args.append(b.pathJoin(&.{ root_path, file })); } + total_linker_objects += c_source_files.files.len; },