From faaff1a93bde6a1bbfaa2e45cb6531879ed6550b Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 2 Dec 2021 02:10:15 -0800 Subject: [PATCH] add Dep.vcpkg flag --- deps.zig | 4 ++++ docs/zig.mod.md | 5 +++++ src/cmd/fetch.zig | 7 +++++++ src/util/dep.zig | 1 + src/util/modfile.zig | 1 + src/util/module.zig | 10 ++++++++++ 6 files changed, 28 insertions(+) diff --git a/deps.zig b/deps.zig index 6924eb82780af5ec287e80b225c0fce02af131ba..9bc700aa1e0a18dd7197f434a480590ef258f559 100644 --- a/deps.zig +++ b/deps.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const Pkg = std.build.Pkg; const string = []const u8; @@ -10,6 +11,7 @@ pub fn addAllTo(exe: *std.build.LibExeObjStep) void { exe.addPackage(pkg.pkg.?); } var llc = false; + var vcpkg = false; inline for (std.meta.declarations(package_data)) |decl| { const pkg = @as(Package, @field(package_data, decl.name)); inline for (pkg.system_libs) |item| { @@ -26,6 +28,7 @@ pub fn addAllTo(exe: *std.build.LibExeObjStep) void { } } if (llc) exe.linkLibC(); + if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err)); } pub const Package = struct { @@ -35,6 +38,7 @@ pub const Package = struct { c_source_files: []const string = &.{}, c_source_flags: []const string = &.{}, system_libs: []const string = &.{}, + vcpkg: bool = false, }; const dirs = struct { diff --git a/docs/zig.mod.md b/docs/zig.mod.md index aaaf898f18bc7037f59152b747c611a6ac0d9722..b29e2eed4d9a7d982d62f7b3fa8bd40f85f87900 100644 --- a/docs/zig.mod.md +++ b/docs/zig.mod.md @@ -104,5 +104,10 @@ This attribute specifies a way to filter when the dependency will be generated i - Example: `true`|any This 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. +#### Dep `vcpkg` +- Type: `string` +- Example: `true`|any +This 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. + #### Dep Overrides There 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`. diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 42510d30089ca7be4e537cdbf02cd6621f09de0b..5cc8003fcc09112ffcdda92c68a894d731d5cc8d 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -46,6 +46,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod const w = f.writer(); try w.writeAll("const std = @import(\"std\");\n"); + try w.writeAll("const builtin = @import(\"builtin\");\n"); try w.writeAll("const Pkg = std.build.Pkg;\n"); try w.writeAll("const string = []const u8;\n"); try w.writeAll("\n"); @@ -58,6 +59,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod \\ exe.addPackage(pkg.pkg.?); \\ } \\ var llc = false; + \\ var vcpkg = false; \\ inline for (std.meta.declarations(package_data)) |decl| { \\ const pkg = @as(Package, @field(package_data, decl.name)); \\ inline for (pkg.system_libs) |item| { @@ -74,6 +76,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod \\ } \\ } \\ if (llc) exe.linkLibC(); + \\ if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err)); \\} \\ \\pub const Package = struct { @@ -83,6 +86,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod \\ c_source_files: []const string = &.{}, \\ c_source_flags: []const string = &.{}, \\ system_libs: []const string = &.{}, + \\ vcpkg: bool = false, \\}; \\ \\ @@ -314,6 +318,9 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul } try w.writeAll(" },\n"); } + if (mod.has_vcpkg_deps()) { + try w.writeAll(" .vcpkg = true,\n"); + } try w.writeAll(" };\n"); try done.append(mod); diff --git a/src/util/dep.zig b/src/util/dep.zig index 0578c6d64dbb136ffcc86515c512e26389f08912..74c42d8487c6e7feb557704698ab6aa3ac394773 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -27,6 +27,7 @@ pub const Dep = struct { yaml: ?yaml.Mapping, deps: []zigmod.Dep, keep: bool = false, + vcpkg: bool = false, pub fn clean_path(self: Dep) !string { if (self.type == .local) { diff --git a/src/util/modfile.zig b/src/util/modfile.zig index 440e8f56b873224d9b4e462f13b360bb6f6efbbc..61dc8b0606f686de9baec91ae68dec6a24f2172c 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -126,6 +126,7 @@ pub const ModFile = struct { .yaml = item.mapping, .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}), .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep")), + .vcpkg = std.mem.eql(u8, "true", item.mapping.get_string("vcpkg")), }); } } diff --git a/src/util/module.zig b/src/util/module.zig index 3986c7be4fe21fca4cc14290983a4d7426745613..ab44eaff3b6e9bdeafebb1cd1dfbcaa33a053728 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -119,6 +119,16 @@ pub const Module = struct { return false; } + pub fn has_vcpkg_deps(self: Module) bool { + for (self.deps) |d| { + const dd = d.dep orelse continue; + if (dd.vcpkg) { + return true; + } + } + return false; + } + pub fn short_id(self: Module) string { return u.slice(u8, self.id, 0, 12); } -- 2.54.0