Skip to content

Commit 2b62873

Browse files
committed
get zig fetch working with the new system
* start renaming "package" to "module" (see #14307) - build system gains `main_mod_path` and `main_pkg_path` is still there but it is deprecated. * eliminate the object-oriented memory management style of what was previously `*Package`. Now it is `*Package.Module` and all pointers point to externally managed memory. * fixes to get the new Fetch.zig code working. The previous commit was work-in-progress. There are still two commented out code paths, the one that leads to `Compilation.create` and the one for `zig build` that fetches the entire dependency tree and creates the required modules for the build runner.
1 parent 187ffb8 commit 2b62873

File tree

12 files changed

+883
-750
lines changed

12 files changed

+883
-750
lines changed

build.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn build(b: *std.Build) !void {
8888
.name = "check-case",
8989
.root_source_file = .{ .path = "test/src/Cases.zig" },
9090
.optimize = optimize,
91-
.main_pkg_path = .{ .path = "." },
91+
.main_mod_path = .{ .path = "." },
9292
});
9393
check_case_exe.stack_size = stack_size;
9494
check_case_exe.single_threaded = single_threaded;

lib/std/Build.zig

+20-5
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ pub const ExecutableOptions = struct {
634634
use_llvm: ?bool = null,
635635
use_lld: ?bool = null,
636636
zig_lib_dir: ?LazyPath = null,
637+
main_mod_path: ?LazyPath = null,
638+
639+
/// Deprecated; use `main_mod_path`.
637640
main_pkg_path: ?LazyPath = null,
638641
};
639642

@@ -652,7 +655,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
652655
.use_llvm = options.use_llvm,
653656
.use_lld = options.use_lld,
654657
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
655-
.main_pkg_path = options.main_pkg_path,
658+
.main_mod_path = options.main_mod_path orelse options.main_pkg_path,
656659
});
657660
}
658661

@@ -667,6 +670,9 @@ pub const ObjectOptions = struct {
667670
use_llvm: ?bool = null,
668671
use_lld: ?bool = null,
669672
zig_lib_dir: ?LazyPath = null,
673+
main_mod_path: ?LazyPath = null,
674+
675+
/// Deprecated; use `main_mod_path`.
670676
main_pkg_path: ?LazyPath = null,
671677
};
672678

@@ -683,7 +689,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
683689
.use_llvm = options.use_llvm,
684690
.use_lld = options.use_lld,
685691
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
686-
.main_pkg_path = options.main_pkg_path,
692+
.main_mod_path = options.main_mod_path orelse options.main_pkg_path,
687693
});
688694
}
689695

@@ -699,6 +705,9 @@ pub const SharedLibraryOptions = struct {
699705
use_llvm: ?bool = null,
700706
use_lld: ?bool = null,
701707
zig_lib_dir: ?LazyPath = null,
708+
main_mod_path: ?LazyPath = null,
709+
710+
/// Deprecated; use `main_mod_path`.
702711
main_pkg_path: ?LazyPath = null,
703712
};
704713

@@ -717,7 +726,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile
717726
.use_llvm = options.use_llvm,
718727
.use_lld = options.use_lld,
719728
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
720-
.main_pkg_path = options.main_pkg_path,
729+
.main_mod_path = options.main_mod_path orelse options.main_pkg_path,
721730
});
722731
}
723732

@@ -733,6 +742,9 @@ pub const StaticLibraryOptions = struct {
733742
use_llvm: ?bool = null,
734743
use_lld: ?bool = null,
735744
zig_lib_dir: ?LazyPath = null,
745+
main_mod_path: ?LazyPath = null,
746+
747+
/// Deprecated; use `main_mod_path`.
736748
main_pkg_path: ?LazyPath = null,
737749
};
738750

@@ -751,7 +763,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile
751763
.use_llvm = options.use_llvm,
752764
.use_lld = options.use_lld,
753765
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
754-
.main_pkg_path = options.main_pkg_path,
766+
.main_mod_path = options.main_mod_path orelse options.main_pkg_path,
755767
});
756768
}
757769

@@ -769,6 +781,9 @@ pub const TestOptions = struct {
769781
use_llvm: ?bool = null,
770782
use_lld: ?bool = null,
771783
zig_lib_dir: ?LazyPath = null,
784+
main_mod_path: ?LazyPath = null,
785+
786+
/// Deprecated; use `main_mod_path`.
772787
main_pkg_path: ?LazyPath = null,
773788
};
774789

@@ -787,7 +802,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
787802
.use_llvm = options.use_llvm,
788803
.use_lld = options.use_lld,
789804
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
790-
.main_pkg_path = options.main_pkg_path,
805+
.main_mod_path = options.main_mod_path orelse options.main_pkg_path,
791806
});
792807
}
793808

lib/std/Build/Cache.zig

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ pub const Directory = struct {
99
path: ?[]const u8,
1010
handle: fs.Dir,
1111

12+
pub fn cwd() Directory {
13+
return .{
14+
.path = null,
15+
.handle = fs.cwd(),
16+
};
17+
}
18+
1219
pub fn join(self: Directory, allocator: Allocator, paths: []const []const u8) ![]u8 {
1320
if (self.path) |p| {
1421
// TODO clean way to do this with only 1 allocation
@@ -53,6 +60,10 @@ pub const Directory = struct {
5360
try writer.writeAll(fs.path.sep_str);
5461
}
5562
}
63+
64+
pub fn eql(self: Directory, other: Directory) bool {
65+
return self.handle.fd == other.handle.fd;
66+
}
5667
};
5768

5869
gpa: Allocator,

lib/std/Build/Step/Compile.zig

+9-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ c_std: std.Build.CStd,
6868
/// Set via options; intended to be read-only after that.
6969
zig_lib_dir: ?LazyPath,
7070
/// Set via options; intended to be read-only after that.
71-
main_pkg_path: ?LazyPath,
71+
main_mod_path: ?LazyPath,
7272
exec_cmd_args: ?[]const ?[]const u8,
7373
filter: ?[]const u8,
7474
test_evented_io: bool = false,
@@ -316,6 +316,9 @@ pub const Options = struct {
316316
use_llvm: ?bool = null,
317317
use_lld: ?bool = null,
318318
zig_lib_dir: ?LazyPath = null,
319+
main_mod_path: ?LazyPath = null,
320+
321+
/// deprecated; use `main_mod_path`.
319322
main_pkg_path: ?LazyPath = null,
320323
};
321324

@@ -480,7 +483,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
480483
.installed_headers = ArrayList(*Step).init(owner.allocator),
481484
.c_std = std.Build.CStd.C99,
482485
.zig_lib_dir = null,
483-
.main_pkg_path = null,
486+
.main_mod_path = null,
484487
.exec_cmd_args = null,
485488
.filter = options.filter,
486489
.test_runner = options.test_runner,
@@ -515,8 +518,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
515518
lp.addStepDependencies(&self.step);
516519
}
517520

518-
if (options.main_pkg_path) |lp| {
519-
self.main_pkg_path = lp.dupe(self.step.owner);
521+
if (options.main_mod_path orelse options.main_pkg_path) |lp| {
522+
self.main_mod_path = lp.dupe(self.step.owner);
520523
lp.addStepDependencies(&self.step);
521524
}
522525

@@ -1998,8 +2001,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
19982001
try zig_args.append(dir.getPath(b));
19992002
}
20002003

2001-
if (self.main_pkg_path) |dir| {
2002-
try zig_args.append("--main-pkg-path");
2004+
if (self.main_mod_path) |dir| {
2005+
try zig_args.append("--main-mod-path");
20032006
try zig_args.append(dir.getPath(b));
20042007
}
20052008

0 commit comments

Comments
 (0)