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 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const Pkg = std.build.Pkg;
34const string = []const u8;
45
......@@ -10,6 +11,7 @@ pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
1011 exe.addPackage(pkg.pkg.?);
1112 }
1213 var llc = false;
14 var vcpkg = false;
1315 inline for (std.meta.declarations(package_data)) |decl| {
1416 const pkg = @as(Package, @field(package_data, decl.name));
1517 inline for (pkg.system_libs) |item| {
......@@ -26,6 +28,7 @@ pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
2628 }
2729 }
2830 if (llc) exe.linkLibC();
31 if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err));
2932}
3033
3134pub const Package = struct {
......@@ -35,6 +38,7 @@ pub const Package = struct {
3538 c_source_files: []const string = &.{},
3639 c_source_flags: []const string = &.{},
3740 system_libs: []const string = &.{},
41 vcpkg: bool = false,
3842};
3943
4044const 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
104104- Example: `true`|any
105105This 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
107112#### Dep Overrides
108113There 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
4646
4747 const w = f.writer();
4848 try w.writeAll("const std = @import(\"std\");\n");
49 try w.writeAll("const builtin = @import(\"builtin\");\n");
4950 try w.writeAll("const Pkg = std.build.Pkg;\n");
5051 try w.writeAll("const string = []const u8;\n");
5152 try w.writeAll("\n");
......@@ -58,6 +59,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod
5859 \\ exe.addPackage(pkg.pkg.?);
5960 \\ }
6061 \\ var llc = false;
62 \\ var vcpkg = false;
6163 \\ inline for (std.meta.declarations(package_data)) |decl| {
6264 \\ const pkg = @as(Package, @field(package_data, decl.name));
6365 \\ inline for (pkg.system_libs) |item| {
......@@ -74,6 +76,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod
7476 \\ }
7577 \\ }
7678 \\ if (llc) exe.linkLibC();
79 \\ if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err));
7780 \\}
7881 \\
7982 \\pub const Package = struct {
......@@ -83,6 +86,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod
8386 \\ c_source_files: []const string = &.{},
8487 \\ c_source_flags: []const string = &.{},
8588 \\ system_libs: []const string = &.{},
89 \\ vcpkg: bool = false,
8690 \\};
8791 \\
8892 \\
......@@ -314,6 +318,9 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
314318 }
315319 try w.writeAll(" },\n");
316320 }
321 if (mod.has_vcpkg_deps()) {
322 try w.writeAll(" .vcpkg = true,\n");
323 }
317324 try w.writeAll(" };\n");
318325
319326 try done.append(mod);
src/util/dep.zig+1
......@@ -27,6 +27,7 @@ pub const Dep = struct {
2727 yaml: ?yaml.Mapping,
2828 deps: []zigmod.Dep,
2929 keep: bool = false,
30 vcpkg: bool = false,
3031
3132 pub fn clean_path(self: Dep) !string {
3233 if (self.type == .local) {
src/util/modfile.zig+1
......@@ -126,6 +126,7 @@ pub const ModFile = struct {
126126 .yaml = item.mapping,
127127 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}),
128128 .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep")),
129 .vcpkg = std.mem.eql(u8, "true", item.mapping.get_string("vcpkg")),
129130 });
130131 }
131132 }
src/util/module.zig+10
......@@ -119,6 +119,16 @@ pub const Module = struct {
119119 return false;
120120 }
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
122132 pub fn short_id(self: Module) string {
123133 return u.slice(u8, self.id, 0, 12);
124134 }