| author | |
| committer | |
| log | 301c7eab635d4eca9ca1f8423b00c793e6de992d |
| tree | e4e45d5c8a9d908034478f303b51414a90fce807 |
| parent | 04e84627095aafad3278f8ec93ba17b385a71049 |
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(); |
| 13 | 13 | ||
| 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); |
| 19 | 18 | ||
| 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 | } |
| 29 | 28 | ||
| 30 | fn makeExe(b: *std.build.Builder, exe_name: string, target: std.zig.CrossTarget, mode: std.builtin.Mode, bootstrap: ?bool) *std.build.LibExeObjStep { | 29 | fn 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 | } | ||
| 70 | 37 | ||
| 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 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const string = []const u8; | 2 | const string = []const u8; |
| 3 | const ansi = @import("ansi"); | 3 | const ansi = @import("ansi"); |
| 4 | const root = @import("root"); | ||
| 5 | 4 | ||
| 6 | const zigmod = @import("../lib.zig"); | 5 | const zigmod = @import("../lib.zig"); |
| 7 | const u = @import("./../util/index.zig"); | 6 | const u = @import("./../util/index.zig"); |
| 8 | const common = @import("./../common.zig"); | 7 | const common = @import("./../common.zig"); |
| 9 | 8 | ||
| 10 | const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {}; | ||
| 11 | const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootstrap else false; | ||
| 12 | |||
| 13 | // | 9 | // |
| 14 | // | 10 | // |
| 15 | 11 | ||
| ... | @@ -32,8 +28,6 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -32,8 +28,6 @@ pub fn execute(args: [][]u8) !void { |
| 32 | 28 | ||
| 33 | try create_depszig(gpa, cachepath, dir, top_module, &list); | 29 | try create_depszig(gpa, cachepath, dir, top_module, &list); |
| 34 | 30 | ||
| 35 | if (bootstrap) return; | ||
| 36 | |||
| 37 | try create_lockfile(gpa, &list, cachepath, dir); | 31 | try create_lockfile(gpa, &list, cachepath, dir); |
| 38 | 32 | ||
| 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"); |
| 2 | const string = []const u8; | 2 | const string = []const u8; |
| 3 | const builtin = @import("builtin"); | 3 | const builtin = @import("builtin"); |
| 4 | const ansi = @import("ansi"); | 4 | const ansi = @import("ansi"); |
| 5 | const root = @import("root"); | ||
| 6 | 5 | ||
| 7 | const zigmod = @import("./lib.zig"); | 6 | const zigmod = @import("./lib.zig"); |
| 8 | const u = @import("./util/index.zig"); | 7 | const u = @import("./util/index.zig"); |
| 9 | 8 | ||
| 10 | const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {}; | ||
| 11 | const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootstrap else false; | ||
| 12 | |||
| 13 | // | 9 | // |
| 14 | // | 10 | // |
| 15 | 11 | ||
| ... | @@ -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..]; |
| 19 | 19 | ||
| 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 | } |
| 36 | 34 | ||
| 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(); |
| 49 | 47 | ||
| 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 | } |