authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-02-15 09:10:30 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-02-15 09:10:30 -08:00
log8e57f30531510eea3ba45e7e5f2fc789b7c40ba9
tree829321cbb91179ed99c31fe4447e0c5ccdf06bc2
parent34951666f74f8b91b68d6f6435b4b618fd8da60a

allow zigmod to bootstrap itself


7 files changed, 171 insertions(+), 55 deletions(-)

.gitignore-1
...@@ -1,3 +1,2 @@...@@ -1,3 +1,2 @@
1/zig-cache1/zig-cache
2/deps.zig
3/.zigmod2/.zigmod
README.md+2
...@@ -24,6 +24,8 @@ A package manager for the Zig programming language....@@ -24,6 +24,8 @@ A package manager for the Zig programming language.
24Initially,24Initially,
25```25```
26$ git clone https://github.com/nektro/zigmod --recursive26$ git clone https://github.com/nektro/zigmod --recursive
27$ zig build -Dbootstrap
28$ ./zig-cache/bin/zigmod fetch
27```29```
2830
29To build,31To build,
build.zig+29-24
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const Builder = std.build.Builder;2const Builder = std.build.Builder;
3const builtin = std.builtin;3const builtin = std.builtin;
4const deps = @import("./deps.zig");
45
5pub fn build(b: *Builder) void {6pub fn build(b: *Builder) void {
6 const target = b.standardTargetOptions(.{});7 const target = b.standardTargetOptions(.{});
...@@ -16,30 +17,34 @@ pub fn build(b: *Builder) void {...@@ -16,30 +17,34 @@ pub fn build(b: *Builder) void {
16 exe.setTarget(target);17 exe.setTarget(target);
17 exe.setBuildMode(mode);18 exe.setBuildMode(mode);
18 exe.addBuildOption([]const u8, "version", b.option([]const u8, "tag", "") orelse "dev");19 exe.addBuildOption([]const u8, "version", b.option([]const u8, "tag", "") orelse "dev");
1920 const bootstrap = b.option(bool, "bootstrap", "bootstrapping with just the zig compiler");
20 exe.linkLibC();21 exe.addBuildOption(bool, "bootstrap", bootstrap != null);
2122
22 exe.addIncludeDir("./libs/yaml/include");23 if (bootstrap != null) {
23 exe.addCSourceFile("./libs/yaml/src/api.c", &[_][]const u8{24 exe.linkLibC();
24 // taken from https://github.com/yaml/libyaml/blob/0.2.5/CMakeLists.txt#L5-L825
25 "-DYAML_VERSION_MAJOR=0",26 exe.addIncludeDir("./libs/yaml/include");
26 "-DYAML_VERSION_MINOR=2",27 exe.addCSourceFile("./libs/yaml/src/api.c", &[_][]const u8{
27 "-DYAML_VERSION_PATCH=5",28 // taken from https://github.com/yaml/libyaml/blob/0.2.5/CMakeLists.txt#L5-L8
28 "-DYAML_VERSION_STRING=\"0.2.5\"",29 "-DYAML_VERSION_MAJOR=0",
29 "-DYAML_DECLARE_STATIC=1",30 "-DYAML_VERSION_MINOR=2",
30 });31 "-DYAML_VERSION_PATCH=5",
31 exe.addCSourceFile("./libs/yaml/src/dumper.c", &[_][]const u8{});32 "-DYAML_VERSION_STRING=\"0.2.5\"",
32 exe.addCSourceFile("./libs/yaml/src/emitter.c", &[_][]const u8{});33 "-DYAML_DECLARE_STATIC=1",
33 exe.addCSourceFile("./libs/yaml/src/loader.c", &[_][]const u8{});34 });
34 exe.addCSourceFile("./libs/yaml/src/parser.c", &[_][]const u8{});35 exe.addCSourceFile("./libs/yaml/src/dumper.c", &[_][]const u8{});
35 exe.addCSourceFile("./libs/yaml/src/reader.c", &[_][]const u8{});36 exe.addCSourceFile("./libs/yaml/src/emitter.c", &[_][]const u8{});
36 exe.addCSourceFile("./libs/yaml/src/scanner.c", &[_][]const u8{});37 exe.addCSourceFile("./libs/yaml/src/loader.c", &[_][]const u8{});
37 exe.addCSourceFile("./libs/yaml/src/writer.c", &[_][]const u8{});38 exe.addCSourceFile("./libs/yaml/src/parser.c", &[_][]const u8{});
3839 exe.addCSourceFile("./libs/yaml/src/reader.c", &[_][]const u8{});
39 exe.addPackagePath("known-folders", "./libs/zig-known-folders/known-folders.zig");40 exe.addCSourceFile("./libs/yaml/src/scanner.c", &[_][]const u8{});
40 exe.addPackagePath("ansi", "./libs/zig-ansi/src/lib.zig");41 exe.addCSourceFile("./libs/yaml/src/writer.c", &[_][]const u8{});
41 exe.addPackagePath("zuri", "./libs/zuri/src/zuri.zig");42
42 exe.addPackagePath("iguanatls", "./libs/iguanatls/src/main.zig");43 exe.addPackagePath("ansi", "./libs/zig-ansi/src/lib.zig");
44 }
45 else {
46 deps.addAllTo(exe);
47 }
4348
44 exe.install();49 exe.install();
4550
deps.zig created+94
...@@ -0,0 +1,94 @@
1const std = @import("std");
2const build = std.build;
3
4pub const cache = ".zigmod/deps";
5
6pub fn addAllTo(exe: *build.LibExeObjStep) void {
7 @setEvalBranchQuota(1_000_000);
8 for (packages) |pkg| {
9 exe.addPackage(pkg);
10 }
11 if (c_include_dirs.len > 0 or c_source_files.len > 0) {
12 exe.linkLibC();
13 }
14 for (c_include_dirs) |dir| {
15 exe.addIncludeDir(dir);
16 }
17 inline for (c_source_files) |fpath| {
18 exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0]));
19 }
20 for (system_libs) |lib| {
21 exe.linkSystemLibrary(lib);
22 }
23}
24
25fn get_flags(comptime index: usize) []const u8 {
26 return @field(c_source_flags, _paths[index]);
27}
28
29pub const _ids = .{
30 "89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r",
31 "8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc",
32 "s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h",
33 "2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf",
34 "2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o",
35 "csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe",
36};
37
38pub const _paths = .{
39 "",
40 "/v/git/github.com/yaml/libyaml/tag-0.2.5/",
41 "/v/git/github.com/nektro/zig-ansi/commit-25039ca/",
42 "/v/git/github.com/ziglibs/known-folders/commit-f0f4188/",
43 "/v/git/github.com/Vexu/zuri/commit-0f9cec8/",
44 "/v/git/github.com/alexnask/iguanaTLS/commit-58f72f6/",
45};
46
47pub const package_data = struct {
48 pub const _s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h = build.Pkg{ .name = "ansi", .path = cache ++ "/v/git/github.com/nektro/zig-ansi/commit-25039ca/src/lib.zig", .dependencies = &[_]build.Pkg{ } };
49 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{ } };
50 pub const _2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o = build.Pkg{ .name = "zuri", .path = cache ++ "/v/git/github.com/Vexu/zuri/commit-0f9cec8/src/zuri.zig", .dependencies = &[_]build.Pkg{ } };
51 pub const _csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe = build.Pkg{ .name = "iguanatls", .path = cache ++ "/v/git/github.com/alexnask/iguanaTLS/commit-58f72f6/src/main.zig", .dependencies = &[_]build.Pkg{ } };
52};
53
54pub const packages = &[_]build.Pkg{
55 package_data._s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h,
56 package_data._2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf,
57 package_data._2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o,
58 package_data._csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe,
59};
60
61pub const pkgs = struct {
62 pub const ansi = packages[1];
63 pub const known_folders = packages[2];
64 pub const zuri = packages[3];
65 pub const iguanatls = packages[4];
66};
67
68pub const c_include_dirs = &[_][]const u8{
69 cache ++ _paths[1] ++ "include",
70};
71
72pub const c_source_flags = struct {
73 pub const @"89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r" = &[_][]const u8{};
74 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",};
75 pub const @"s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h" = &[_][]const u8{};
76 pub const @"2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf" = &[_][]const u8{};
77 pub const @"2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o" = &[_][]const u8{};
78 pub const @"csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe" = &[_][]const u8{};
79};
80
81pub const c_source_files = &[_][2][]const u8{
82 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/api.c"},
83 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/dumper.c"},
84 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/emitter.c"},
85 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/loader.c"},
86 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/parser.c"},
87 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/reader.c"},
88 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/scanner.c"},
89 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/writer.c"},
90};
91
92pub const system_libs = &[_][]const u8{
93};
94
src/main.zig+9-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const build_options = @import("build_options");
34
4pub const u = @import("./util/index.zig");5pub const u = @import("./util/index.zig");
5pub const common = @import("./common.zig");6pub const common = @import("./common.zig");
...@@ -7,6 +8,10 @@ pub const common = @import("./common.zig");...@@ -7,6 +8,10 @@ pub const common = @import("./common.zig");
7//8//
8//9//
910
11pub const commands_to_bootstrap = struct {
12 const fetch = @import("./cmd_fetch.zig");
13};
14
10pub const commands = struct {15pub const commands = struct {
11 const init = @import("./cmd_init.zig");16 const init = @import("./cmd_init.zig");
12 const fetch = @import("./cmd_fetch.zig");17 const fetch = @import("./cmd_fetch.zig");
...@@ -31,9 +36,11 @@ pub fn main() !void {...@@ -31,9 +36,11 @@ pub fn main() !void {
31 return;36 return;
32 }37 }
3338
34 inline for (std.meta.declarations(commands)) |decl| {39 const available = if (build_options.bootstrap) commands_to_bootstrap else commands;
40
41 inline for (std.meta.declarations(available)) |decl| {
35 if (std.mem.eql(u8, args[0], decl.name)) {42 if (std.mem.eql(u8, args[0], decl.name)) {
36 const cmd = @field(commands, decl.name);43 const cmd = @field(available, decl.name);
37 try cmd.execute(args[1..]);44 try cmd.execute(args[1..]);
38 return;45 return;
39 }46 }
zig.bootstrap.mod deleted-28
...@@ -1,28 +0,0 @@
1id: 89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r
2name: zigmod
3main: src/main.zig
4dependencies:
5 - src: git https://github.com/yaml/libyaml
6 version: tag-0.2.5
7 c_include_dirs:
8 - include
9 c_source_flags:
10 - -DYAML_VERSION_MAJOR=0
11 - -DYAML_VERSION_MINOR=2
12 - -DYAML_VERSION_PATCH=5
13 - -DYAML_VERSION_STRING="0.2.5"
14 - -DYAML_DECLARE_STATIC=1
15 c_source_files:
16 - libs/yaml/src/dumper.c
17 - libs/yaml/src/emitter.c
18 - libs/yaml/src/loader.c
19 - libs/yaml/src/parser.c
20 - libs/yaml/src/reader.c
21 - libs/yaml/src/scanner.c
22 - libs/yaml/src/writer.c
23
24 - src: git https://github.com/ziglibs/known-folders
25 version: commit-e1193f9ef5b3aad7a6071e9f5721934fe04a020e
26
27 - src: git https://github.com/nektro/zig-ansi
28 version: commit-876c32c42044a5e1554f4662b4b9bdfad7ee5086
zig.mod+37
...@@ -1,3 +1,40 @@...@@ -1,3 +1,40 @@
1id: 89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r1id: 89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r
2name: zigmod2name: zigmod
3main: src/main.zig3main: src/main.zig
4dependencies:
5 - src: git https://github.com/yaml/libyaml
6 version: tag-0.2.5
7 c_include_dirs:
8 - include
9 c_source_flags:
10 - -DYAML_VERSION_MAJOR=0
11 - -DYAML_VERSION_MINOR=2
12 - -DYAML_VERSION_PATCH=5
13 - -DYAML_VERSION_STRING="0.2.5"
14 - -DYAML_DECLARE_STATIC=1
15 c_source_files:
16 - src/api.c
17 - src/dumper.c
18 - src/emitter.c
19 - src/loader.c
20 - src/parser.c
21 - src/reader.c
22 - src/scanner.c
23 - src/writer.c
24
25 - src: git https://github.com/nektro/zig-ansi
26 version: commit-25039ca
27
28 #
29
30 - src: git https://github.com/ziglibs/known-folders
31 version: commit-f0f4188
32
33 - src: git https://github.com/Vexu/zuri
34 version: commit-0f9cec8
35
36 - src: git https://github.com/alexnask/iguanaTLS
37 version: commit-58f72f6
38
39 # - src: git https://github.com/nektro/zig-licenses
40 # version: commit-a15ef9b