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 {...@@ -11,11 +11,10 @@ pub fn build(b: *std.build.Builder) void {
11 b.setPreferredReleaseMode(.ReleaseSafe);11 b.setPreferredReleaseMode(.ReleaseSafe);
12 const mode = b.standardReleaseOptions();12 const mode = b.standardReleaseOptions();
1313
14 const bootstrap = b.option(bool, "bootstrap", "bootstrapping with just the zig compiler");
15 const use_full_name = b.option(bool, "use-full-name", "") orelse false;14 const use_full_name = b.option(bool, "use-full-name", "") orelse false;
16 const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.cpu_arch orelse builtin.cpu.arch), @tagName(target.os_tag orelse builtin.os.tag) });15 const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.cpu_arch orelse builtin.cpu.arch), @tagName(target.os_tag orelse builtin.os.tag) });
17 const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" });16 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
20 const run_cmd = exe.run();19 const run_cmd = exe.run();
21 run_cmd.step.dependOn(b.getInstallStep());20 run_cmd.step.dependOn(b.getInstallStep());
...@@ -27,7 +26,7 @@ pub fn build(b: *std.build.Builder) void {...@@ -27,7 +26,7 @@ pub fn build(b: *std.build.Builder) void {
27 run_step.dependOn(&run_cmd.step);26 run_step.dependOn(&run_cmd.step);
28}27}
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 {
31 const exe = b.addExecutable(exe_name, "src/main.zig");30 const exe = b.addExecutable(exe_name, "src/main.zig");
32 exe.setTarget(target);31 exe.setTarget(target);
33 exe.setBuildMode(mode);32 exe.setBuildMode(mode);
...@@ -35,39 +34,8 @@ fn makeExe(b: *std.build.Builder, exe_name: string, target: std.zig.CrossTarget,...@@ -35,39 +34,8 @@ fn makeExe(b: *std.build.Builder, exe_name: string, target: std.zig.CrossTarget,
35 const exe_options = b.addOptions();34 const exe_options = b.addOptions();
36 exe.addOptions("build_options", exe_options);35 exe.addOptions("build_options", exe_options);
37 exe_options.addOption(string, "version", b.option(string, "tag", "") orelse "dev");36 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);
71 exe.install();39 exe.install();
72 return exe;40 return exe;
73}41}
src/cmd/fetch.zig-6
...@@ -1,15 +1,11 @@...@@ -1,15 +1,11 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const ansi = @import("ansi");3const ansi = @import("ansi");
4const root = @import("root");
54
6const zigmod = @import("../lib.zig");5const zigmod = @import("../lib.zig");
7const u = @import("./../util/index.zig");6const u = @import("./../util/index.zig");
8const common = @import("./../common.zig");7const 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
13//9//
14//10//
1511
...@@ -32,8 +28,6 @@ pub fn execute(args: [][]u8) !void {...@@ -32,8 +28,6 @@ pub fn execute(args: [][]u8) !void {
3228
33 try create_depszig(gpa, cachepath, dir, top_module, &list);29 try create_depszig(gpa, cachepath, dir, top_module, &list);
3430
35 if (bootstrap) return;
36
37 try create_lockfile(gpa, &list, cachepath, dir);31 try create_lockfile(gpa, &list, cachepath, dir);
3832
39 try diff_lockfile(gpa);33 try diff_lockfile(gpa);
src/common.zig+1-5
...@@ -2,14 +2,10 @@ const std = @import("std");...@@ -2,14 +2,10 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const ansi = @import("ansi");4const ansi = @import("ansi");
5const root = @import("root");
65
7const zigmod = @import("./lib.zig");6const zigmod = @import("./lib.zig");
8const u = @import("./util/index.zig");7const 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
13//9//
14//10//
1511
...@@ -114,7 +110,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !...@@ -114,7 +110,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
114 std.debug.print("fetch: {s}: {s}\n", .{ @tagName(d.type), d.path });110 std.debug.print("fetch: {s}: {s}\n", .{ @tagName(d.type), d.path });
115 }111 }
116 defer {112 defer {
117 if (!bootstrap and options.log and d.type != .local) {113 if (options.log and d.type != .local) {
118 std.debug.print("{s}", .{ansi.csi.CursorUp(1)});114 std.debug.print("{s}", .{ansi.csi.CursorUp(1)});
119 std.debug.print("{s}", .{ansi.csi.EraseInLine(0)});115 std.debug.print("{s}", .{ansi.csi.EraseInLine(0)});
120 }116 }
src/main.zig+4-6
...@@ -17,8 +17,6 @@ pub fn main() !void {...@@ -17,8 +17,6 @@ pub fn main() !void {
17 const proc_args = try std.process.argsAlloc(gpa);17 const proc_args = try std.process.argsAlloc(gpa);
18 const args = proc_args[1..];18 const args = proc_args[1..];
1919
20 const available = if (build_options.bootstrap) zigmod.commands_to_bootstrap else zigmod.commands;
21
22 if (args.len == 0) {20 if (args.len == 0) {
23 std.debug.print("zigmod {s} {s} {s} {s}\n", .{21 std.debug.print("zigmod {s} {s} {s} {s}\n", .{
24 build_options.version,22 build_options.version,
...@@ -28,13 +26,13 @@ pub fn main() !void {...@@ -28,13 +26,13 @@ pub fn main() !void {
28 });26 });
29 std.debug.print("\n", .{});27 std.debug.print("\n", .{});
30 std.debug.print("The commands available are:\n", .{});28 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| {
32 std.debug.print(" - {s}\n", .{decl.name});30 std.debug.print(" - {s}\n", .{decl.name});
33 }31 }
34 return;32 return;
35 }33 }
3634
37 if (!build_options.bootstrap and builtin.os.tag == .windows) {35 if (builtin.os.tag == .windows) {
38 const console = win32.system.console;36 const console = win32.system.console;
39 const h_out = console.GetStdHandle(console.STD_OUTPUT_HANDLE);37 const h_out = console.GetStdHandle(console.STD_OUTPUT_HANDLE);
40 _ = console.SetConsoleMode(h_out, console.CONSOLE_MODE.initFlags(.{38 _ = console.SetConsoleMode(h_out, console.CONSOLE_MODE.initFlags(.{
...@@ -47,9 +45,9 @@ pub fn main() !void {...@@ -47,9 +45,9 @@ pub fn main() !void {
47 try zigmod.init();45 try zigmod.init();
48 defer zigmod.deinit();46 defer zigmod.deinit();
4947
50 inline for (comptime std.meta.declarations(available)) |decl| {48 inline for (comptime std.meta.declarations(zigmod.commands)) |decl| {
51 if (std.mem.eql(u8, args[0], decl.name)) {49 if (std.mem.eql(u8, args[0], decl.name)) {
52 const cmd = @field(available, decl.name);50 const cmd = @field(zigmod.commands, decl.name);
53 try cmd.execute(args[1..]);51 try cmd.execute(args[1..]);
54 return;52 return;
55 }53 }