@@ -1556,6 +1556,15 @@ pub const Dependency = struct {
15561556 panic ("unable to find module '{s}'" , .{name });
15571557 };
15581558 }
1559+
1560+ pub fn path (d : * Dependency , sub_path : []const u8 ) LazyPath {
1561+ return .{
1562+ .dependency = .{
1563+ .dependency = d ,
1564+ .sub_path = sub_path ,
1565+ },
1566+ };
1567+ }
15591568};
15601569
15611570pub fn dependency (b : * Build , name : []const u8 , args : anytype ) * Dependency {
@@ -1573,6 +1582,16 @@ pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency {
15731582 }
15741583 }
15751584
1585+ inline for (@typeInfo (deps .build_root ).Struct .decls ) | decl | {
1586+ if (mem .startsWith (u8 , decl .name , b .dep_prefix ) and
1587+ mem .endsWith (u8 , decl .name , name ) and
1588+ decl .name .len == b .dep_prefix .len + name .len )
1589+ {
1590+ const build_root = @field (deps .build_root , decl .name );
1591+ return dependencyInner (b , name , build_root , null , args );
1592+ }
1593+ }
1594+
15761595 const full_path = b .pathFromRoot ("build.zig.zon" );
15771596 std .debug .print ("no dependency named '{s}' in '{s}'. All packages used in build.zig must be declared in this file.\n " , .{ name , full_path });
15781597 process .exit (1 );
@@ -1601,7 +1620,7 @@ pub fn dependencyInner(
16011620 b : * Build ,
16021621 name : []const u8 ,
16031622 build_root_string : []const u8 ,
1604- comptime build_zig : type ,
1623+ comptime maybe_build_zig : ? type ,
16051624 args : anytype ,
16061625) * Dependency {
16071626 if (b .initialized_deps .get (build_root_string )) | dep | {
@@ -1619,10 +1638,12 @@ pub fn dependencyInner(
16191638 },
16201639 };
16211640 const sub_builder = b .createChild (name , build_root , args ) catch @panic ("unhandled error" );
1622- sub_builder .runBuild (build_zig ) catch @panic ("unhandled error" );
1641+ if (maybe_build_zig ) | build_zig | {
1642+ sub_builder .runBuild (build_zig ) catch @panic ("unhandled error" );
16231643
1624- if (sub_builder .validateUserInputDidItFail ()) {
1625- std .debug .dumpCurrentStackTrace (@returnAddress ());
1644+ if (sub_builder .validateUserInputDidItFail ()) {
1645+ std .debug .dumpCurrentStackTrace (@returnAddress ());
1646+ }
16261647 }
16271648
16281649 const dep = b .allocator .create (Dependency ) catch @panic ("OOM" );
@@ -1687,6 +1708,11 @@ pub const LazyPath = union(enum) {
16871708 /// Use of this tag indicates a dependency on the host system.
16881709 cwd_relative : []const u8 ,
16891710
1711+ dependency : struct {
1712+ dependency : * Dependency ,
1713+ sub_path : []const u8 ,
1714+ },
1715+
16901716 /// Returns a new file source that will have a relative path to the build root guaranteed.
16911717 /// Asserts the parameter is not an absolute path.
16921718 pub fn relative (path : []const u8 ) LazyPath {
@@ -1700,13 +1726,14 @@ pub const LazyPath = union(enum) {
17001726 return switch (self ) {
17011727 .path , .cwd_relative = > self .path ,
17021728 .generated = > "generated" ,
1729+ .dependency = > "dependency" ,
17031730 };
17041731 }
17051732
17061733 /// Adds dependencies this file source implies to the given step.
17071734 pub fn addStepDependencies (self : LazyPath , other_step : * Step ) void {
17081735 switch (self ) {
1709- .path , .cwd_relative = > {},
1736+ .path , .cwd_relative , .dependency = > {},
17101737 .generated = > | gen | other_step .dependOn (gen .step ),
17111738 }
17121739 }
@@ -1732,6 +1759,12 @@ pub const LazyPath = union(enum) {
17321759 dumpBadGetPathHelp (gen .step , stderr , src_builder , asking_step ) catch {};
17331760 @panic ("misconfigured build script" );
17341761 },
1762+ .dependency = > | dep | {
1763+ return dep .dependency .builder .pathJoin (&[_ ][]const u8 {
1764+ dep .dependency .builder .build_root .path .? ,
1765+ dep .sub_path ,
1766+ });
1767+ },
17351768 }
17361769 }
17371770
@@ -1741,6 +1774,7 @@ pub const LazyPath = union(enum) {
17411774 .path = > | p | .{ .path = b .dupePath (p ) },
17421775 .cwd_relative = > | p | .{ .cwd_relative = b .dupePath (p ) },
17431776 .generated = > | gen | .{ .generated = gen },
1777+ .dependency = > | dep | .{ .dependency = dep },
17441778 };
17451779 }
17461780};
0 commit comments