diff --git a/.gitignore b/.gitignore index 767d82fa088984e677270fe352e28b6970ab3674..bf8bf129af2bd67d6ca91184af376b57668dcbc8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /zig-cache -/deps.zig /.zigmod diff --git a/README.md b/README.md index 35782560d3b2c32617cf25b477701957dd2e0322..293b77498262df5e8efb3941f390fe8a2e215c5f 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ A package manager for the Zig programming language. Initially, ``` $ git clone https://github.com/nektro/zigmod --recursive +$ zig build -Dbootstrap +$ ./zig-cache/bin/zigmod fetch ``` To build, diff --git a/build.zig b/build.zig index 0f6bc5ef0196f2a45b047e64b3f3768b4df1892f..25359c6a01b05be2694104e389397023b92ff891 100644 --- a/build.zig +++ b/build.zig @@ -1,6 +1,7 @@ const std = @import("std"); const Builder = std.build.Builder; const builtin = std.builtin; +const deps = @import("./deps.zig"); pub fn build(b: *Builder) void { const target = b.standardTargetOptions(.{}); @@ -16,30 +17,34 @@ pub fn build(b: *Builder) void { exe.setTarget(target); exe.setBuildMode(mode); exe.addBuildOption([]const u8, "version", b.option([]const u8, "tag", "") orelse "dev"); + const bootstrap = b.option(bool, "bootstrap", "bootstrapping with just the zig compiler"); + exe.addBuildOption(bool, "bootstrap", bootstrap != null); - exe.linkLibC(); + if (bootstrap != null) { + exe.linkLibC(); - exe.addIncludeDir("./libs/yaml/include"); - exe.addCSourceFile("./libs/yaml/src/api.c", &[_][]const u8{ - // taken from https://github.com/yaml/libyaml/blob/0.2.5/CMakeLists.txt#L5-L8 - "-DYAML_VERSION_MAJOR=0", - "-DYAML_VERSION_MINOR=2", - "-DYAML_VERSION_PATCH=5", - "-DYAML_VERSION_STRING=\"0.2.5\"", - "-DYAML_DECLARE_STATIC=1", - }); - exe.addCSourceFile("./libs/yaml/src/dumper.c", &[_][]const u8{}); - exe.addCSourceFile("./libs/yaml/src/emitter.c", &[_][]const u8{}); - exe.addCSourceFile("./libs/yaml/src/loader.c", &[_][]const u8{}); - exe.addCSourceFile("./libs/yaml/src/parser.c", &[_][]const u8{}); - exe.addCSourceFile("./libs/yaml/src/reader.c", &[_][]const u8{}); - exe.addCSourceFile("./libs/yaml/src/scanner.c", &[_][]const u8{}); - exe.addCSourceFile("./libs/yaml/src/writer.c", &[_][]const u8{}); + exe.addIncludeDir("./libs/yaml/include"); + exe.addCSourceFile("./libs/yaml/src/api.c", &[_][]const u8{ + // taken from https://github.com/yaml/libyaml/blob/0.2.5/CMakeLists.txt#L5-L8 + "-DYAML_VERSION_MAJOR=0", + "-DYAML_VERSION_MINOR=2", + "-DYAML_VERSION_PATCH=5", + "-DYAML_VERSION_STRING=\"0.2.5\"", + "-DYAML_DECLARE_STATIC=1", + }); + exe.addCSourceFile("./libs/yaml/src/dumper.c", &[_][]const u8{}); + exe.addCSourceFile("./libs/yaml/src/emitter.c", &[_][]const u8{}); + exe.addCSourceFile("./libs/yaml/src/loader.c", &[_][]const u8{}); + exe.addCSourceFile("./libs/yaml/src/parser.c", &[_][]const u8{}); + exe.addCSourceFile("./libs/yaml/src/reader.c", &[_][]const u8{}); + exe.addCSourceFile("./libs/yaml/src/scanner.c", &[_][]const u8{}); + exe.addCSourceFile("./libs/yaml/src/writer.c", &[_][]const u8{}); - exe.addPackagePath("known-folders", "./libs/zig-known-folders/known-folders.zig"); - exe.addPackagePath("ansi", "./libs/zig-ansi/src/lib.zig"); - exe.addPackagePath("zuri", "./libs/zuri/src/zuri.zig"); - exe.addPackagePath("iguanatls", "./libs/iguanatls/src/main.zig"); + exe.addPackagePath("ansi", "./libs/zig-ansi/src/lib.zig"); + } + else { + deps.addAllTo(exe); + } exe.install(); diff --git a/deps.zig b/deps.zig new file mode 100644 index 0000000000000000000000000000000000000000..f573bbe5016842f6ce7df340225ef6cd2b77a45c --- /dev/null +++ b/deps.zig @@ -0,0 +1,94 @@ +const std = @import("std"); +const build = std.build; + +pub const cache = ".zigmod/deps"; + +pub fn addAllTo(exe: *build.LibExeObjStep) void { + @setEvalBranchQuota(1_000_000); + for (packages) |pkg| { + exe.addPackage(pkg); + } + if (c_include_dirs.len > 0 or c_source_files.len > 0) { + exe.linkLibC(); + } + for (c_include_dirs) |dir| { + exe.addIncludeDir(dir); + } + inline for (c_source_files) |fpath| { + exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0])); + } + for (system_libs) |lib| { + exe.linkSystemLibrary(lib); + } +} + +fn get_flags(comptime index: usize) []const u8 { + return @field(c_source_flags, _paths[index]); +} + +pub const _ids = .{ + "89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r", + "8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc", + "s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h", + "2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf", + "2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o", + "csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe", +}; + +pub const _paths = .{ + "", + "/v/git/github.com/yaml/libyaml/tag-0.2.5/", + "/v/git/github.com/nektro/zig-ansi/commit-25039ca/", + "/v/git/github.com/ziglibs/known-folders/commit-f0f4188/", + "/v/git/github.com/Vexu/zuri/commit-0f9cec8/", + "/v/git/github.com/alexnask/iguanaTLS/commit-58f72f6/", +}; + +pub const package_data = struct { + pub const _s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h = build.Pkg{ .name = "ansi", .path = cache ++ "/v/git/github.com/nektro/zig-ansi/commit-25039ca/src/lib.zig", .dependencies = &[_]build.Pkg{ } }; + pub const _2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf = build.Pkg{ .name = "known-folders", .path = cache ++ "/v/git/github.com/ziglibs/known-folders/commit-f0f4188/known-folders.zig", .dependencies = &[_]build.Pkg{ } }; + pub const _2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o = build.Pkg{ .name = "zuri", .path = cache ++ "/v/git/github.com/Vexu/zuri/commit-0f9cec8/src/zuri.zig", .dependencies = &[_]build.Pkg{ } }; + pub const _csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe = build.Pkg{ .name = "iguanatls", .path = cache ++ "/v/git/github.com/alexnask/iguanaTLS/commit-58f72f6/src/main.zig", .dependencies = &[_]build.Pkg{ } }; +}; + +pub const packages = &[_]build.Pkg{ + package_data._s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h, + package_data._2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf, + package_data._2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o, + package_data._csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe, +}; + +pub const pkgs = struct { + pub const ansi = packages[1]; + pub const known_folders = packages[2]; + pub const zuri = packages[3]; + pub const iguanatls = packages[4]; +}; + +pub const c_include_dirs = &[_][]const u8{ + cache ++ _paths[1] ++ "include", +}; + +pub const c_source_flags = struct { + pub const @"89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r" = &[_][]const u8{}; + pub const @"8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc" = &[_][]const u8{"-DYAML_VERSION_MAJOR=0","-DYAML_VERSION_MINOR=2","-DYAML_VERSION_PATCH=5","-DYAML_VERSION_STRING=\"0.2.5\"","-DYAML_DECLARE_STATIC=1",}; + pub const @"s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h" = &[_][]const u8{}; + pub const @"2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf" = &[_][]const u8{}; + pub const @"2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o" = &[_][]const u8{}; + pub const @"csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe" = &[_][]const u8{}; +}; + +pub const c_source_files = &[_][2][]const u8{ + [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/api.c"}, + [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/dumper.c"}, + [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/emitter.c"}, + [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/loader.c"}, + [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/parser.c"}, + [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/reader.c"}, + [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/scanner.c"}, + [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/writer.c"}, +}; + +pub const system_libs = &[_][]const u8{ +}; + diff --git a/src/main.zig b/src/main.zig index ad03ec169bb9c7786ce9ab569dbb6402583eb56d..e15ff035a329ed96136c384cdd35e4aa6acb4ede 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); +const build_options = @import("build_options"); pub const u = @import("./util/index.zig"); pub const common = @import("./common.zig"); @@ -7,6 +8,10 @@ pub const common = @import("./common.zig"); // // +pub const commands_to_bootstrap = struct { + const fetch = @import("./cmd_fetch.zig"); +}; + pub const commands = struct { const init = @import("./cmd_init.zig"); const fetch = @import("./cmd_fetch.zig"); @@ -31,9 +36,11 @@ pub fn main() !void { return; } - inline for (std.meta.declarations(commands)) |decl| { + const available = if (build_options.bootstrap) commands_to_bootstrap else commands; + + inline for (std.meta.declarations(available)) |decl| { if (std.mem.eql(u8, args[0], decl.name)) { - const cmd = @field(commands, decl.name); + const cmd = @field(available, decl.name); try cmd.execute(args[1..]); return; } diff --git a/zig.bootstrap.mod b/zig.bootstrap.mod deleted file mode 100644 index 22e4ede37d0c0caf28710a1d3a17e46369c6ba95..0000000000000000000000000000000000000000 --- a/zig.bootstrap.mod +++ /dev/null @@ -1,28 +0,0 @@ -id: 89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r -name: zigmod -main: src/main.zig -dependencies: - - src: git https://github.com/yaml/libyaml - version: tag-0.2.5 - c_include_dirs: - - include - c_source_flags: - - -DYAML_VERSION_MAJOR=0 - - -DYAML_VERSION_MINOR=2 - - -DYAML_VERSION_PATCH=5 - - -DYAML_VERSION_STRING="0.2.5" - - -DYAML_DECLARE_STATIC=1 - c_source_files: - - libs/yaml/src/dumper.c - - libs/yaml/src/emitter.c - - libs/yaml/src/loader.c - - libs/yaml/src/parser.c - - libs/yaml/src/reader.c - - libs/yaml/src/scanner.c - - libs/yaml/src/writer.c - - - src: git https://github.com/ziglibs/known-folders - version: commit-e1193f9ef5b3aad7a6071e9f5721934fe04a020e - - - src: git https://github.com/nektro/zig-ansi - version: commit-876c32c42044a5e1554f4662b4b9bdfad7ee5086 diff --git a/zig.mod b/zig.mod index 6aa31c4745c504cbe3ca5d5f2d6690b41a15b12b..38e947851c5754321c7143a5bc4c29924b9f071a 100644 --- a/zig.mod +++ b/zig.mod @@ -1,3 +1,40 @@ id: 89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r name: zigmod main: src/main.zig +dependencies: + - src: git https://github.com/yaml/libyaml + version: tag-0.2.5 + c_include_dirs: + - include + c_source_flags: + - -DYAML_VERSION_MAJOR=0 + - -DYAML_VERSION_MINOR=2 + - -DYAML_VERSION_PATCH=5 + - -DYAML_VERSION_STRING="0.2.5" + - -DYAML_DECLARE_STATIC=1 + c_source_files: + - src/api.c + - src/dumper.c + - src/emitter.c + - src/loader.c + - src/parser.c + - src/reader.c + - src/scanner.c + - src/writer.c + + - src: git https://github.com/nektro/zig-ansi + version: commit-25039ca + + # + + - src: git https://github.com/ziglibs/known-folders + version: commit-f0f4188 + + - src: git https://github.com/Vexu/zuri + version: commit-0f9cec8 + + - src: git https://github.com/alexnask/iguanaTLS + version: commit-58f72f6 + + # - src: git https://github.com/nektro/zig-licenses + # version: commit-a15ef9b