authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-09-17 13:30:52 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-09-17 13:30:52 -07:00
log301c7eab635d4eca9ca1f8423b00c793e6de992d
treee4e45d5c8a9d908034478f303b51414a90fce807
parent04e84627095aafad3278f8ec93ba17b385a71049

bootstrap step is no longer necessary


4 files changed, 8 insertions(+), 52 deletions(-)

build.zig+3-35
......@@ -11,11 +11,10 @@ pub fn build(b: *std.build.Builder) void {
1111 b.setPreferredReleaseMode(.ReleaseSafe);
1212 const mode = b.standardReleaseOptions();
1313
14 const bootstrap = b.option(bool, "bootstrap", "bootstrapping with just the zig compiler");
1514 const use_full_name = b.option(bool, "use-full-name", "") orelse false;
1615 const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.cpu_arch orelse builtin.cpu.arch), @tagName(target.os_tag orelse builtin.os.tag) });
1716 const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" });
18 const exe = makeExe(b, exe_name, target, mode, bootstrap);
17 const exe = makeExe(b, exe_name, target, mode);
1918
2019 const run_cmd = exe.run();
2120 run_cmd.step.dependOn(b.getInstallStep());
......@@ -27,7 +26,7 @@ pub fn build(b: *std.build.Builder) void {
2726 run_step.dependOn(&run_cmd.step);
2827}
2928
30fn makeExe(b: *std.build.Builder, exe_name: string, target: std.zig.CrossTarget, mode: std.builtin.Mode, bootstrap: ?bool) *std.build.LibExeObjStep {
29fn makeExe(b: *std.build.Builder, exe_name: string, target: std.zig.CrossTarget, mode: std.builtin.Mode) *std.build.LibExeObjStep {
3130 const exe = b.addExecutable(exe_name, "src/main.zig");
3231 exe.setTarget(target);
3332 exe.setBuildMode(mode);
......@@ -35,39 +34,8 @@ fn makeExe(b: *std.build.Builder, exe_name: string, target: std.zig.CrossTarget,
3534 const exe_options = b.addOptions();
3635 exe.addOptions("build_options", exe_options);
3736 exe_options.addOption(string, "version", b.option(string, "tag", "") orelse "dev");
38 exe_options.addOption(bool, "bootstrap", bootstrap != null);
39
40 if (bootstrap != null) {
41 exe.linkLibC();
42
43 exe.addIncludeDir("./libs/yaml/include");
44 exe.addCSourceFile("./libs/yaml/src/api.c", &.{
45 // taken from https://github.com/yaml/libyaml/blob/0.2.5/CMakeLists.txt#L5-L8
46 "-DYAML_VERSION_MAJOR=0",
47 "-DYAML_VERSION_MINOR=2",
48 "-DYAML_VERSION_PATCH=5",
49 "-DYAML_VERSION_STRING=\"0.2.5\"",
50 "-DYAML_DECLARE_STATIC=1",
51 });
52 exe.addCSourceFile("./libs/yaml/src/dumper.c", &.{});
53 exe.addCSourceFile("./libs/yaml/src/emitter.c", &.{});
54 exe.addCSourceFile("./libs/yaml/src/loader.c", &.{});
55 exe.addCSourceFile("./libs/yaml/src/parser.c", &.{});
56 exe.addCSourceFile("./libs/yaml/src/reader.c", &.{});
57 exe.addCSourceFile("./libs/yaml/src/scanner.c", &.{});
58 exe.addCSourceFile("./libs/yaml/src/writer.c", &.{});
59
60 exe.addPackage(.{
61 .name = "zigmod",
62 .source = .{ .path = "./src/lib.zig" },
63 .dependencies = &[_]std.build.Pkg{
64 .{ .name = "zfetch", .source = .{ .path = "src/zfetch_stub.zig" } },
65 },
66 });
67 } else {
68 deps.addAllTo(exe);
69 }
7037
38 deps.addAllTo(exe);
7139 exe.install();
7240 return exe;
7341}
src/cmd/fetch.zig-6
......@@ -1,15 +1,11 @@
11const std = @import("std");
22const string = []const u8;
33const ansi = @import("ansi");
4const root = @import("root");
54
65const zigmod = @import("../lib.zig");
76const u = @import("./../util/index.zig");
87const common = @import("./../common.zig");
98
10const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {};
11const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootstrap else false;
12
139//
1410//
1511
......@@ -32,8 +28,6 @@ pub fn execute(args: [][]u8) !void {
3228
3329 try create_depszig(gpa, cachepath, dir, top_module, &list);
3430
35 if (bootstrap) return;
36
3731 try create_lockfile(gpa, &list, cachepath, dir);
3832
3933 try diff_lockfile(gpa);
src/common.zig+1-5
......@@ -2,14 +2,10 @@ const std = @import("std");
22const string = []const u8;
33const builtin = @import("builtin");
44const ansi = @import("ansi");
5const root = @import("root");
65
76const zigmod = @import("./lib.zig");
87const u = @import("./util/index.zig");
98
10const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {};
11const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootstrap else false;
12
139//
1410//
1511
......@@ -114,7 +110,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
114110 std.debug.print("fetch: {s}: {s}\n", .{ @tagName(d.type), d.path });
115111 }
116112 defer {
117 if (!bootstrap and options.log and d.type != .local) {
113 if (options.log and d.type != .local) {
118114 std.debug.print("{s}", .{ansi.csi.CursorUp(1)});
119115 std.debug.print("{s}", .{ansi.csi.EraseInLine(0)});
120116 }
src/main.zig+4-6
......@@ -17,8 +17,6 @@ pub fn main() !void {
1717 const proc_args = try std.process.argsAlloc(gpa);
1818 const args = proc_args[1..];
1919
20 const available = if (build_options.bootstrap) zigmod.commands_to_bootstrap else zigmod.commands;
21
2220 if (args.len == 0) {
2321 std.debug.print("zigmod {s} {s} {s} {s}\n", .{
2422 build_options.version,
......@@ -28,13 +26,13 @@ pub fn main() !void {
2826 });
2927 std.debug.print("\n", .{});
3028 std.debug.print("The commands available are:\n", .{});
31 inline for (comptime std.meta.declarations(available)) |decl| {
29 inline for (comptime std.meta.declarations(zigmod.commands)) |decl| {
3230 std.debug.print(" - {s}\n", .{decl.name});
3331 }
3432 return;
3533 }
3634
37 if (!build_options.bootstrap and builtin.os.tag == .windows) {
35 if (builtin.os.tag == .windows) {
3836 const console = win32.system.console;
3937 const h_out = console.GetStdHandle(console.STD_OUTPUT_HANDLE);
4038 _ = console.SetConsoleMode(h_out, console.CONSOLE_MODE.initFlags(.{
......@@ -47,9 +45,9 @@ pub fn main() !void {
4745 try zigmod.init();
4846 defer zigmod.deinit();
4947
50 inline for (comptime std.meta.declarations(available)) |decl| {
48 inline for (comptime std.meta.declarations(zigmod.commands)) |decl| {
5149 if (std.mem.eql(u8, args[0], decl.name)) {
52 const cmd = @field(available, decl.name);
50 const cmd = @field(zigmod.commands, decl.name);
5351 try cmd.execute(args[1..]);
5452 return;
5553 }