authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-02 02:10:15 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-02 02:10:15 -08:00
logfaaff1a93bde6a1bbfaa2e45cb6531879ed6550b
tree72dda3a84b5156891755850a26a626fb3051d2f3
parent58041d5fbe372a58bf345d81c14769fd4fb1560a

add Dep.vcpkg flag


6 files changed, 28 insertions(+), 0 deletions(-)

deps.zig+4
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const Pkg = std.build.Pkg;3const Pkg = std.build.Pkg;
3const string = []const u8;4const string = []const u8;
45
...@@ -10,6 +11,7 @@ pub fn addAllTo(exe: *std.build.LibExeObjStep) void {...@@ -10,6 +11,7 @@ pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
10 exe.addPackage(pkg.pkg.?);11 exe.addPackage(pkg.pkg.?);
11 }12 }
12 var llc = false;13 var llc = false;
14 var vcpkg = false;
13 inline for (std.meta.declarations(package_data)) |decl| {15 inline for (std.meta.declarations(package_data)) |decl| {
14 const pkg = @as(Package, @field(package_data, decl.name));16 const pkg = @as(Package, @field(package_data, decl.name));
15 inline for (pkg.system_libs) |item| {17 inline for (pkg.system_libs) |item| {
...@@ -26,6 +28,7 @@ pub fn addAllTo(exe: *std.build.LibExeObjStep) void {...@@ -26,6 +28,7 @@ pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
26 }28 }
27 }29 }
28 if (llc) exe.linkLibC();30 if (llc) exe.linkLibC();
31 if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err));
29}32}
3033
31pub const Package = struct {34pub const Package = struct {
...@@ -35,6 +38,7 @@ pub const Package = struct {...@@ -35,6 +38,7 @@ pub const Package = struct {
35 c_source_files: []const string = &.{},38 c_source_files: []const string = &.{},
36 c_source_flags: []const string = &.{},39 c_source_flags: []const string = &.{},
37 system_libs: []const string = &.{},40 system_libs: []const string = &.{},
41 vcpkg: bool = false,
38};42};
3943
40const dirs = struct {44const dirs = struct {
docs/zig.mod.md+5
...@@ -104,5 +104,10 @@ This attribute specifies a way to filter when the dependency will be generated i...@@ -104,5 +104,10 @@ This attribute specifies a way to filter when the dependency will be generated i
104- Example: `true`|any104- Example: `true`|any
105This attribute is a manual override for having an external repo that contains no Zig or C code but other files be managed through Zigmod and `deps.zig`. `true` is the only value that will enable this flag.105This attribute is a manual override for having an external repo that contains no Zig or C code but other files be managed through Zigmod and `deps.zig`. `true` is the only value that will enable this flag.
106106
107#### Dep `vcpkg`
108- Type: `string`
109- Example: `true`|any
110This attribute is a flag to call `try exe.addVcpkgPaths(.static);` when on Windows. Likely used in conjunction with adding system libraries/C code. `true` is the only value that will enable this flag.
111
107#### Dep Overrides112#### Dep Overrides
108There are a number of fields you can add to a `Dep` object that will override it's top-level value. This is most useful in the case where a project you want to use does not have a `zig.mod` manifest. You can then use overrides to define the values for them. The only top-level value you can not override is `dependencies`.113There are a number of fields you can add to a `Dep` object that will override it's top-level value. This is most useful in the case where a project you want to use does not have a `zig.mod` manifest. You can then use overrides to define the values for them. The only top-level value you can not override is `dependencies`.
src/cmd/fetch.zig+7
...@@ -46,6 +46,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod...@@ -46,6 +46,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod
4646
47 const w = f.writer();47 const w = f.writer();
48 try w.writeAll("const std = @import(\"std\");\n");48 try w.writeAll("const std = @import(\"std\");\n");
49 try w.writeAll("const builtin = @import(\"builtin\");\n");
49 try w.writeAll("const Pkg = std.build.Pkg;\n");50 try w.writeAll("const Pkg = std.build.Pkg;\n");
50 try w.writeAll("const string = []const u8;\n");51 try w.writeAll("const string = []const u8;\n");
51 try w.writeAll("\n");52 try w.writeAll("\n");
...@@ -58,6 +59,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod...@@ -58,6 +59,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod
58 \\ exe.addPackage(pkg.pkg.?);59 \\ exe.addPackage(pkg.pkg.?);
59 \\ }60 \\ }
60 \\ var llc = false;61 \\ var llc = false;
62 \\ var vcpkg = false;
61 \\ inline for (std.meta.declarations(package_data)) |decl| {63 \\ inline for (std.meta.declarations(package_data)) |decl| {
62 \\ const pkg = @as(Package, @field(package_data, decl.name));64 \\ const pkg = @as(Package, @field(package_data, decl.name));
63 \\ inline for (pkg.system_libs) |item| {65 \\ inline for (pkg.system_libs) |item| {
...@@ -74,6 +76,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod...@@ -74,6 +76,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod
74 \\ }76 \\ }
75 \\ }77 \\ }
76 \\ if (llc) exe.linkLibC();78 \\ if (llc) exe.linkLibC();
79 \\ if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err));
77 \\}80 \\}
78 \\81 \\
79 \\pub const Package = struct {82 \\pub const Package = struct {
...@@ -83,6 +86,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod...@@ -83,6 +86,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod
83 \\ c_source_files: []const string = &.{},86 \\ c_source_files: []const string = &.{},
84 \\ c_source_flags: []const string = &.{},87 \\ c_source_flags: []const string = &.{},
85 \\ system_libs: []const string = &.{},88 \\ system_libs: []const string = &.{},
89 \\ vcpkg: bool = false,
86 \\};90 \\};
87 \\91 \\
88 \\92 \\
...@@ -314,6 +318,9 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul...@@ -314,6 +318,9 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
314 }318 }
315 try w.writeAll(" },\n");319 try w.writeAll(" },\n");
316 }320 }
321 if (mod.has_vcpkg_deps()) {
322 try w.writeAll(" .vcpkg = true,\n");
323 }
317 try w.writeAll(" };\n");324 try w.writeAll(" };\n");
318325
319 try done.append(mod);326 try done.append(mod);
src/util/dep.zig+1
...@@ -27,6 +27,7 @@ pub const Dep = struct {...@@ -27,6 +27,7 @@ pub const Dep = struct {
27 yaml: ?yaml.Mapping,27 yaml: ?yaml.Mapping,
28 deps: []zigmod.Dep,28 deps: []zigmod.Dep,
29 keep: bool = false,29 keep: bool = false,
30 vcpkg: bool = false,
3031
31 pub fn clean_path(self: Dep) !string {32 pub fn clean_path(self: Dep) !string {
32 if (self.type == .local) {33 if (self.type == .local) {
src/util/modfile.zig+1
...@@ -126,6 +126,7 @@ pub const ModFile = struct {...@@ -126,6 +126,7 @@ pub const ModFile = struct {
126 .yaml = item.mapping,126 .yaml = item.mapping,
127 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}),127 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}),
128 .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep")),128 .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep")),
129 .vcpkg = std.mem.eql(u8, "true", item.mapping.get_string("vcpkg")),
129 });130 });
130 }131 }
131 }132 }
src/util/module.zig+10
...@@ -119,6 +119,16 @@ pub const Module = struct {...@@ -119,6 +119,16 @@ pub const Module = struct {
119 return false;119 return false;
120 }120 }
121121
122 pub fn has_vcpkg_deps(self: Module) bool {
123 for (self.deps) |d| {
124 const dd = d.dep orelse continue;
125 if (dd.vcpkg) {
126 return true;
127 }
128 }
129 return false;
130 }
131
122 pub fn short_id(self: Module) string {132 pub fn short_id(self: Module) string {
123 return u.slice(u8, self.id, 0, 12);133 return u.slice(u8, self.id, 0, 12);
124 }134 }