Skip to content

Commit b445bbf

Browse files
antliljaandrewrk
authored andcommitted
Add ability to import dependencies from build.zig
1 parent 7c9ed45 commit b445bbf

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/Package.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ pub const build_zig_basename = "build.zig";
215215

216216
pub fn fetchAndAddDependencies(
217217
pkg: *Package,
218+
root_pkg: *Package,
218219
arena: Allocator,
219220
thread_pool: *ThreadPool,
220221
http_client: *std.http.Client,
@@ -295,7 +296,8 @@ pub fn fetchAndAddDependencies(
295296
all_modules,
296297
);
297298

298-
try pkg.fetchAndAddDependencies(
299+
try sub_pkg.fetchAndAddDependencies(
300+
root_pkg,
299301
arena,
300302
thread_pool,
301303
http_client,
@@ -309,7 +311,8 @@ pub fn fetchAndAddDependencies(
309311
all_modules,
310312
);
311313

312-
try add(pkg, gpa, fqn, sub_pkg);
314+
try pkg.add(gpa, name, sub_pkg);
315+
try root_pkg.add(gpa, fqn, sub_pkg);
313316

314317
try dependencies_source.writer().print(" pub const {s} = @import(\"{}\");\n", .{
315318
std.zig.fmtId(fqn), std.zig.fmtEscapes(fqn),

src/main.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4228,6 +4228,10 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
42284228
.root_src_path = "build_runner.zig",
42294229
};
42304230

4231+
var build_pkg: Package = .{
4232+
.root_src_directory = build_directory,
4233+
.root_src_path = build_zig_basename,
4234+
};
42314235
if (!build_options.omit_pkg_fetching_code) {
42324236
var http_client: std.http.Client = .{ .allocator = gpa };
42334237
defer http_client.deinit();
@@ -4249,7 +4253,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
42494253

42504254
// Here we borrow main package's table and will replace it with a fresh
42514255
// one after this process completes.
4252-
main_pkg.fetchAndAddDependencies(
4256+
build_pkg.fetchAndAddDependencies(
4257+
&main_pkg,
42534258
arena,
42544259
&thread_pool,
42554260
&http_client,
@@ -4280,11 +4285,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
42804285
mem.swap(Package.Table, &main_pkg.table, &deps_pkg.table);
42814286
try main_pkg.add(gpa, "@dependencies", deps_pkg);
42824287
}
4283-
4284-
var build_pkg: Package = .{
4285-
.root_src_directory = build_directory,
4286-
.root_src_path = build_zig_basename,
4287-
};
42884288
try main_pkg.add(gpa, "@build", &build_pkg);
42894289

42904290
const comp = Compilation.create(gpa, .{

0 commit comments

Comments
 (0)