Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dependent packages when using build.zig #4343

Merged
merged 1 commit into from
Feb 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions lib/std/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,10 @@ pub const CrossTarget = std.Target.Cross;
/// Deprecated. Use `std.Target`.
pub const Target = std.Target;

const Pkg = struct {
pub const Pkg = struct {
name: []const u8,
path: []const u8,
dependencies: ?[]Pkg = null,
};

const CSourceFile = struct {
Expand Down Expand Up @@ -1742,6 +1743,10 @@ pub const LibExeObjStep = struct {
self.framework_dirs.append(self.builder.dupe(dir_path)) catch unreachable;
}

pub fn addPackage(self: *LibExeObjStep, package: Pkg) void {
self.packages.append(package) catch unreachable;
}

pub fn addPackagePath(self: *LibExeObjStep, name: []const u8, pkg_index_path: []const u8) void {
self.packages.append(Pkg{
.name = self.builder.dupe(name),
Expand Down Expand Up @@ -2091,10 +2096,20 @@ pub const LibExeObjStep = struct {
},
}
for (self.packages.toSliceConst()) |pkg| {
zig_args.append("--pkg-begin") catch unreachable;
zig_args.append(pkg.name) catch unreachable;
zig_args.append(builder.pathFromRoot(pkg.path)) catch unreachable;
zig_args.append("--pkg-end") catch unreachable;
try zig_args.append("--pkg-begin");
try zig_args.append(pkg.name);
try zig_args.append(builder.pathFromRoot(pkg.path));

if (pkg.dependencies) |dependencies| {
for (dependencies) |sub_pkg| {
try zig_args.append("--pkg-begin");
try zig_args.append(sub_pkg.name);
try zig_args.append(builder.pathFromRoot(sub_pkg.path));
try zig_args.append("--pkg-end");
}
}

try zig_args.append("--pkg-end");
}

for (self.include_dirs.toSliceConst()) |include_dir| {
Expand Down