authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2023-03-09 20:39:15+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-09 22:38:14-05:00
logb445bbfea205702770e4e9de4e456c3e8750f8ed
treedbb29397a922be4c1f6337f0e17fb3e0f40d7746
parent7c9ed45ac2fd580bbbb4b950ac350dd49fc7600e

Add ability to import dependencies from build.zig


2 files changed, 11 insertions(+), 8 deletions(-)

src/Package.zig+5-2
...@@ -215,6 +215,7 @@ pub const build_zig_basename = "build.zig";...@@ -215,6 +215,7 @@ pub const build_zig_basename = "build.zig";
215215
216pub fn fetchAndAddDependencies(216pub fn fetchAndAddDependencies(
217 pkg: *Package,217 pkg: *Package,
218 root_pkg: *Package,
218 arena: Allocator,219 arena: Allocator,
219 thread_pool: *ThreadPool,220 thread_pool: *ThreadPool,
220 http_client: *std.http.Client,221 http_client: *std.http.Client,
...@@ -295,7 +296,8 @@ pub fn fetchAndAddDependencies(...@@ -295,7 +296,8 @@ pub fn fetchAndAddDependencies(
295 all_modules,296 all_modules,
296 );297 );
297298
298 try pkg.fetchAndAddDependencies(299 try sub_pkg.fetchAndAddDependencies(
300 root_pkg,
299 arena,301 arena,
300 thread_pool,302 thread_pool,
301 http_client,303 http_client,
...@@ -309,7 +311,8 @@ pub fn fetchAndAddDependencies(...@@ -309,7 +311,8 @@ pub fn fetchAndAddDependencies(
309 all_modules,311 all_modules,
310 );312 );
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
314 try dependencies_source.writer().print(" pub const {s} = @import(\"{}\");\n", .{317 try dependencies_source.writer().print(" pub const {s} = @import(\"{}\");\n", .{
315 std.zig.fmtId(fqn), std.zig.fmtEscapes(fqn),318 std.zig.fmtId(fqn), std.zig.fmtEscapes(fqn),
src/main.zig+6-6
...@@ -4228,6 +4228,10 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -4228,6 +4228,10 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
4228 .root_src_path = "build_runner.zig",4228 .root_src_path = "build_runner.zig",
4229 };4229 };
42304230
4231 var build_pkg: Package = .{
4232 .root_src_directory = build_directory,
4233 .root_src_path = build_zig_basename,
4234 };
4231 if (!build_options.omit_pkg_fetching_code) {4235 if (!build_options.omit_pkg_fetching_code) {
4232 var http_client: std.http.Client = .{ .allocator = gpa };4236 var http_client: std.http.Client = .{ .allocator = gpa };
4233 defer http_client.deinit();4237 defer http_client.deinit();
...@@ -4249,7 +4253,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -4249,7 +4253,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
42494253
4250 // Here we borrow main package's table and will replace it with a fresh4254 // Here we borrow main package's table and will replace it with a fresh
4251 // one after this process completes.4255 // one after this process completes.
4252 main_pkg.fetchAndAddDependencies(4256 build_pkg.fetchAndAddDependencies(
4257 &main_pkg,
4253 arena,4258 arena,
4254 &thread_pool,4259 &thread_pool,
4255 &http_client,4260 &http_client,
...@@ -4280,11 +4285,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -4280,11 +4285,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
4280 mem.swap(Package.Table, &main_pkg.table, &deps_pkg.table);4285 mem.swap(Package.Table, &main_pkg.table, &deps_pkg.table);
4281 try main_pkg.add(gpa, "@dependencies", deps_pkg);4286 try main_pkg.add(gpa, "@dependencies", deps_pkg);
4282 }4287 }
4283
4284 var build_pkg: Package = .{
4285 .root_src_directory = build_directory,
4286 .root_src_path = build_zig_basename,
4287 };
4288 try main_pkg.add(gpa, "@build", &build_pkg);4288 try main_pkg.add(gpa, "@build", &build_pkg);
42894289
4290 const comp = Compilation.create(gpa, .{4290 const comp = Compilation.create(gpa, .{