From 21683f9329aa22ed8a2d0e3cdff48a398521b65c Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 2 Jun 2024 15:51:41 -0700 Subject: [PATCH] upgrade to Zig 0.12.0 --- .github/workflows/nightly.yml | 2 +- .github/workflows/push.yml | 2 +- README.md | 2 +- build.zig | 15 ++- deps.zig | 215 +++++++++++++++++----------------- docs/README.md | 2 +- docs/deps.zig.md | 7 +- docs/zig.mod.md | 10 -- src/cmd/fetch.zig | 154 ++++++++++++------------ src/cmd/generate.zig | 141 +++++++++++----------- src/common.zig | 15 +-- src/main.zig | 4 +- src/util/dep.zig | 1 - src/util/funcs.zig | 8 +- src/util/modfile.zig | 3 - src/util/module.zig | 2 - zig.mod | 7 +- zigmod.lock | 16 +-- 18 files changed, 292 insertions(+), 314 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index b3a23594ec93474f4e1c6bae31686505ceb03465..1b50e9de3b7c8c5be88e5ea536775e6a18389627 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -26,7 +26,7 @@ jobs: - name: Setup Zig uses: goto-bus-stop/setup-zig@v2 with: - version: "0.11.0" + version: "0.12.0" - run: zig version - run: zig env diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 1be3d07c8b0612dcc2c1b98ef17211938a0ac89f..74ddb8259ada4d8b3a23334538c6d9da280e15bd 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -19,7 +19,7 @@ jobs: - name: Setup Zig uses: goto-bus-stop/setup-zig@v2 with: - version: "0.11.0" + version: "0.12.0" - run: zig version - run: zig env diff --git a/README.md b/README.md index 97bfc9795751203278a4e6803f8aa1e9cbc2160b..a7d20896cd88920ba8b388d3fba4e60884e1b75b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ A package manager for the Zig programming language. - https://github.com/nektro/zigmod/releases ## Built With -- Zig master (at least `0.11.0`) +- Zig master (at least `0.12.0`) - See [`zig.mod`](./zig.mod) and [`zigmod.lock`](./zigmod.lock) ### Build from Source diff --git a/build.zig b/build.zig index 7a5ed9ded30b96f25138e891071828039465fe1d..cabb618f4a23e445461657e75773d528c03ead4a 100644 --- a/build.zig +++ b/build.zig @@ -3,22 +3,27 @@ const string = []const u8; const builtin = @import("builtin"); const deps = @import("./deps.zig"); -pub fn build(b: *std.build.Builder) void { +pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug; const use_full_name = b.option(bool, "use-full-name", "") orelse false; - const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.cpu_arch orelse builtin.cpu.arch), @tagName(target.os_tag orelse builtin.os.tag) }); + const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.result.cpu.arch), @tagName(target.result.os.tag) }); const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" }); - const exe = b.addExecutable(.{ .name = exe_name, .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = mode }); + const exe = b.addExecutable(.{ + .name = exe_name, + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = mode, + }); const tag = b.option(string, "tag", "") orelse "dev"; const strip = b.option(bool, "strip", "Build without debug info.") orelse false; const exe_options = b.addOptions(); - exe.addOptions("build_options", exe_options); + exe.root_module.addImport("build_options", exe_options.createModule()); exe_options.addOption(string, "version", tag); deps.addAllTo(exe); - exe.strip = strip; + exe.root_module.strip = strip; b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); diff --git a/deps.zig b/deps.zig index 2b7b9903319ff9f1a9b6ccfda757e5eb7cd28f3e..f39742fa65afd12b171f6de7a5e63b1ef7300a66 100644 --- a/deps.zig +++ b/deps.zig @@ -1,19 +1,18 @@ // zig fmt: off const std = @import("std"); const builtin = @import("builtin"); -const ModuleDependency = std.build.ModuleDependency; const string = []const u8; pub const GitExactStep = struct { - step: std.build.Step, - builder: *std.build.Builder, + step: std.Build.Step, + builder: *std.Build, url: string, commit: string, - pub fn create(b: *std.build.Builder, url: string, commit: string) *GitExactStep { + pub fn create(b: *std.Build, url: string, commit: string) *GitExactStep { var result = b.allocator.create(GitExactStep) catch @panic("memory"); result.* = GitExactStep{ - .step = std.build.Step.init(.{ + .step = std.Build.Step.init(.{ .id = .custom, .name = b.fmt("git clone {s} @ {s}", .{ url, commit }), .owner = b, @@ -30,11 +29,11 @@ pub const GitExactStep = struct { const repopath = b.fmt("{s}/zigmod/deps/git/{s}/{s}", .{ b.cache_root.path.?, urlpath, commit }); flip(std.fs.cwd().access(repopath, .{})) catch return result; - var clonestep = std.build.RunStep.create(b, "clone"); + var clonestep = std.Build.Step.Run.create(b, "clone"); clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath }); result.step.dependOn(&clonestep.step); - var checkoutstep = std.build.RunStep.create(b, "checkout"); + var checkoutstep = std.Build.Step.Run.create(b, "checkout"); checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit }); result.step.dependOn(&checkoutstep.step); checkoutstep.step.dependOn(&clonestep.step); @@ -42,35 +41,35 @@ pub const GitExactStep = struct { return result; } - fn make(step: *std.build.Step, prog_node: *std.Progress.Node) !void { + fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) !void { _ = step; _ = prog_node; } }; -pub fn fetch(exe: *std.build.LibExeObjStep) void { +pub fn fetch(exe: *std.Build.Step.Compile) void { const b = exe.step.owner; inline for (comptime std.meta.declarations(package_data)) |decl| { - const path = &@field(package_data, decl.name).entry; - const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else "."; - if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? }); + const path = &@field(package_data, decl.name).entry; + const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else "."; + if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? }); } - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/marlersoft/zigwin32", "6777f1db221d0cb50322842f558f03e3c3a4099f").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/arqv-ini", "ddbe89bb0d9085e939bcbc713caeb2b7cf852bae").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/iguanaTLS", "f5c7c3fe880c5a23fbcdc21dfcb83c2776931f40").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zfetch", "f51277414a2309f776fb79f3d55f26e37f9a54da").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "ac607e4e7ac36d46cc67c8786262578330543a36").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/marlersoft/zigwin32", "c778640d3dc153e900fbe37e2816b5176af3c802").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/arqv-ini", "38a018ad3a19d5b4663a5364d2d31271f250846b").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/iguanaTLS", "4dc8850883b49e4a452871298788b06b1af9fe24").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zfetch", "863be236188e5f24d16554f9dcd7df96dd254a13").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "c3e439f86b0484e4428f38c4d8b07b7b5ae1634b").step); exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "3ff57d0681b7bd7f8ca9bd092afa0b4bfe2f1afd").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "05f0e90a185cb04a09b96f686dffc6375c420e9b").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "5cc2a5565d04fe2c0085f0d6818590e800d9dcf7").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "550cabd5a18ace5e67761bc5b867c10e926f4314").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "c9b8cbf3565675a056ad4e9b57cb4f84020e7680").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "3c07c6e4eb0965dafd0b029c632f823631b3169c").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "74f0ddb0a4dfa7921739b88cc381951a6b6e73ce").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "9e1d873db79e9ffa6ae6e06bd372428c9be85d97").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "e548b0bcc7b6f34f636c0b6b905928d31254c54d").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "f46d9f774df929885eef66c733a1e2a46bf16aec").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "b01e5a2dffcc564bddd8f514fe64bab9b5c52572").step); exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-range", "4b2f12808aa09be4b27a163efc424dd4e0415992").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "12fad367a5282827aad7e12f0e9cd36f672c4010").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "ba546bbf2e8438c9b2325f36f392c9d95b432e8e").step); exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "0d17fb99cba338aedc1abac12d78d5e5f04f0b6b").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/truemedian/hzzp", "92e6072d8a385d8b08fdcae3ae2021fe5293528f").step); - exe.step.dependOn(&GitExactStep.create(b, "https://github.com/ziglibs/known-folders", "855473062efac722624737f1adc56f9c0dd92017").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/truemedian/hzzp", "a7f03a1e652abe8c89b376d090cec50acb0d2a1a").step); + exe.step.dependOn(&GitExactStep.create(b, "https://github.com/ziglibs/known-folders", "0ad514dcfb7525e32ae349b9acc0a53976f3a9fa").step); exe.step.dependOn(&GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6").step); } @@ -86,48 +85,17 @@ fn flip(foo: anytype) !void { return error.ExpectedError; } -pub fn addAllTo(exe: *std.build.LibExeObjStep) void { +pub fn addAllTo(exe: *std.Build.Step.Compile) void { checkMinZig(builtin.zig_version, exe); fetch(exe); - const b = exe.step.owner; @setEvalBranchQuota(1_000_000); for (packages) |pkg| { - const moddep = pkg.zp(b); - exe.addModule(moddep.name, moddep.module); + const module = pkg.module(exe); + exe.root_module.addImport(pkg.name, module); } - addAllLibrariesTo(exe); -} - -pub fn addAllLibrariesTo(exe: *std.build.LibExeObjStep) void { - const b = exe.step.owner; - var llc = false; - var vcpkg = false; - inline for (comptime std.meta.declarations(package_data)) |decl| { - const pkg = @as(Package, @field(package_data, decl.name)); - const root = if (pkg.store) |st| b.fmt("{s}/zigmod/deps/{s}", .{ b.cache_root.path.?, st }) else "."; - for (pkg.system_libs) |item| { - exe.linkSystemLibrary(item); - llc = true; - } - for (pkg.frameworks) |item| { - if (!builtin.target.isDarwin()) @panic(exe.step.owner.fmt("a dependency is attempting to link to the framework {s}, which is only possible under Darwin", .{item})); - exe.linkFramework(item); - llc = true; - } - for (pkg.c_include_dirs) |item| { - exe.addIncludePath(.{.path = b.fmt("{s}/{s}", .{ root, item })}); - llc = true; - } - for (pkg.c_source_files) |item| { - exe.addCSourceFile(.{ .file = .{ .path = b.fmt("{s}/{s}", .{ root, item }) }, .flags = pkg.c_source_flags }); - llc = true; - } - vcpkg = vcpkg or pkg.vcpkg; - } - if (llc) exe.linkLibC(); - if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err)); } +var link_lib_c = false; pub const Package = struct { name: string = "", entry: ?string = null, @@ -138,69 +106,102 @@ pub const Package = struct { c_source_flags: []const string = &.{}, system_libs: []const string = &.{}, frameworks: []const string = &.{}, - vcpkg: bool = false, - module: ?ModuleDependency = null, + module_memo: ?*std.Build.Module = null, - pub fn zp(self: *Package, b: *std.build.Builder) ModuleDependency { - var temp: [100]ModuleDependency = undefined; - for (self.deps, 0..) |item, i| { - temp[i] = item.zp(b); - } - if (self.module) |mod| { - return mod; - } - const result = ModuleDependency{ - .name = self.name, - .module = b.createModule(.{ - .source_file = .{ .path = self.entry.? }, - .dependencies = b.allocator.dupe(ModuleDependency, temp[0..self.deps.len]) catch @panic("oom"), - }), - }; - self.module = result; + pub fn module(self: *Package, exe: *std.Build.Step.Compile) *std.Build.Module { + if (self.module_memo) |cached| { + return cached; + } + const b = exe.step.owner; + + const result = b.createModule(.{}); + const dummy_library = b.addStaticLibrary(.{ + .name = "dummy", + .target = exe.root_module.resolved_target orelse b.host, + .optimize = exe.root_module.optimize.?, + }); + if (self.entry) |capture| { + result.root_source_file = .{ .path = capture }; + } + for (self.deps) |item| { + const module_dep = item.module(exe); + if (module_dep.root_source_file != null) { + result.addImport(item.name, module_dep); + } + for (module_dep.include_dirs.items) |jtem| { + switch (jtem) { + .path => result.addIncludePath(jtem.path), + .path_system, .path_after, .framework_path, .framework_path_system, .other_step, .config_header_step => {}, + } + } + } + for (self.c_include_dirs) |item| { + result.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }); + dummy_library.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }); + link_lib_c = true; + } + for (self.c_source_files) |item| { + dummy_library.addCSourceFile(.{ .file = .{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }, .flags = self.c_source_flags }); + } + for (self.system_libs) |item| { + dummy_library.linkSystemLibrary(item); + } + for (self.frameworks) |item| { + dummy_library.linkFramework(item); + } + if (self.c_source_files.len > 0 or self.system_libs.len > 0 or self.frameworks.len > 0) { + dummy_library.linkLibC(); + exe.root_module.linkLibrary(dummy_library); + link_lib_c = true; + } + if (link_lib_c) { + result.link_libc = true; + } + self.module_memo = result; return result; } }; -fn checkMinZig(current: std.SemanticVersion, exe: *std.build.LibExeObjStep) void { - const min = std.SemanticVersion.parse("0.11.0") catch return; +fn checkMinZig(current: std.SemanticVersion, exe: *std.Build.Step.Compile) void { + const min = std.SemanticVersion.parse("0.12.0") catch return; if (current.order(min).compare(.lt)) @panic(exe.step.owner.fmt("Your Zig version v{} does not meet the minimum build requirement of v{}", .{current, min})); } pub const package_data = struct { pub var _o6ogpor87xc2 = Package{ - .store = "/git/github.com/marlersoft/zigwin32/6777f1db221d0cb50322842f558f03e3c3a4099f", + .store = "/git/github.com/marlersoft/zigwin32/c778640d3dc153e900fbe37e2816b5176af3c802", .name = "win32", - .entry = "/git/github.com/marlersoft/zigwin32/6777f1db221d0cb50322842f558f03e3c3a4099f/win32.zig", + .entry = "/git/github.com/marlersoft/zigwin32/c778640d3dc153e900fbe37e2816b5176af3c802/win32.zig", }; pub var _u7sysdckdymi = Package{ - .store = "/git/github.com/nektro/arqv-ini/ddbe89bb0d9085e939bcbc713caeb2b7cf852bae", + .store = "/git/github.com/nektro/arqv-ini/38a018ad3a19d5b4663a5364d2d31271f250846b", .name = "ini", - .entry = "/git/github.com/nektro/arqv-ini/ddbe89bb0d9085e939bcbc713caeb2b7cf852bae/src/ini.zig", + .entry = "/git/github.com/nektro/arqv-ini/38a018ad3a19d5b4663a5364d2d31271f250846b/src/ini.zig", }; pub var _csbnipaad8n7 = Package{ - .store = "/git/github.com/nektro/iguanaTLS/f5c7c3fe880c5a23fbcdc21dfcb83c2776931f40", + .store = "/git/github.com/nektro/iguanaTLS/4dc8850883b49e4a452871298788b06b1af9fe24", .name = "iguanaTLS", - .entry = "/git/github.com/nektro/iguanaTLS/f5c7c3fe880c5a23fbcdc21dfcb83c2776931f40/src/main.zig", + .entry = "/git/github.com/nektro/iguanaTLS/4dc8850883b49e4a452871298788b06b1af9fe24/src/main.zig", }; pub var _s84v9o48ucb0 = Package{ - .store = "/git/github.com/nektro/zig-ansi/ac607e4e7ac36d46cc67c8786262578330543a36", + .store = "/git/github.com/nektro/zig-ansi/c3e439f86b0484e4428f38c4d8b07b7b5ae1634b", .name = "ansi", - .entry = "/git/github.com/nektro/zig-ansi/ac607e4e7ac36d46cc67c8786262578330543a36/src/lib.zig", + .entry = "/git/github.com/nektro/zig-ansi/c3e439f86b0484e4428f38c4d8b07b7b5ae1634b/src/lib.zig", }; pub var _f7dubzb7cyqe = Package{ - .store = "/git/github.com/nektro/zig-extras/05f0e90a185cb04a09b96f686dffc6375c420e9b", + .store = "/git/github.com/nektro/zig-extras/74f0ddb0a4dfa7921739b88cc381951a6b6e73ce", .name = "extras", - .entry = "/git/github.com/nektro/zig-extras/05f0e90a185cb04a09b96f686dffc6375c420e9b/src/lib.zig", + .entry = "/git/github.com/nektro/zig-extras/74f0ddb0a4dfa7921739b88cc381951a6b6e73ce/src/lib.zig", }; pub var _0npcrzfdlrvk = Package{ - .store = "/git/github.com/nektro/zig-licenses/c9b8cbf3565675a056ad4e9b57cb4f84020e7680", + .store = "/git/github.com/nektro/zig-licenses/f46d9f774df929885eef66c733a1e2a46bf16aec", .name = "licenses", - .entry = "/git/github.com/nektro/zig-licenses/c9b8cbf3565675a056ad4e9b57cb4f84020e7680/src/lib.zig", + .entry = "/git/github.com/nektro/zig-licenses/f46d9f774df929885eef66c733a1e2a46bf16aec/src/lib.zig", }; pub var _pt88y5d80m25 = Package{ - .store = "/git/github.com/nektro/zig-licenses-text/3c07c6e4eb0965dafd0b029c632f823631b3169c", + .store = "/git/github.com/nektro/zig-licenses-text/b01e5a2dffcc564bddd8f514fe64bab9b5c52572", .name = "licenses-text", - .entry = "/git/github.com/nektro/zig-licenses-text/3c07c6e4eb0965dafd0b029c632f823631b3169c/src/lib.zig", + .entry = "/git/github.com/nektro/zig-licenses-text/b01e5a2dffcc564bddd8f514fe64bab9b5c52572/src/lib.zig", }; pub var _tnj3qf44tpeq = Package{ .store = "/git/github.com/nektro/zig-range/4b2f12808aa09be4b27a163efc424dd4e0415992", @@ -208,15 +209,15 @@ pub const package_data = struct { .entry = "/git/github.com/nektro/zig-range/4b2f12808aa09be4b27a163efc424dd4e0415992/src/lib.zig", }; pub var _c1xirp1ota5p = Package{ - .store = "/git/github.com/nektro/zig-inquirer/5cc2a5565d04fe2c0085f0d6818590e800d9dcf7", + .store = "/git/github.com/nektro/zig-inquirer/9e1d873db79e9ffa6ae6e06bd372428c9be85d97", .name = "inquirer", - .entry = "/git/github.com/nektro/zig-inquirer/5cc2a5565d04fe2c0085f0d6818590e800d9dcf7/src/lib.zig", + .entry = "/git/github.com/nektro/zig-inquirer/9e1d873db79e9ffa6ae6e06bd372428c9be85d97/src/lib.zig", .deps = &[_]*Package{ &_s84v9o48ucb0, &_tnj3qf44tpeq }, }; pub var _96h80ezrvj7i = Package{ - .store = "/git/github.com/nektro/zig-leven/550cabd5a18ace5e67761bc5b867c10e926f4314", + .store = "/git/github.com/nektro/zig-leven/e548b0bcc7b6f34f636c0b6b905928d31254c54d", .name = "leven", - .entry = "/git/github.com/nektro/zig-leven/550cabd5a18ace5e67761bc5b867c10e926f4314/src/lib.zig", + .entry = "/git/github.com/nektro/zig-leven/e548b0bcc7b6f34f636c0b6b905928d31254c54d/src/lib.zig", .deps = &[_]*Package{ &_tnj3qf44tpeq }, }; pub var _2ovav391ivak = Package{ @@ -226,32 +227,32 @@ pub const package_data = struct { .deps = &[_]*Package{ &_pt88y5d80m25, &_96h80ezrvj7i }, }; pub var _iecwp4b3bsfm = Package{ - .store = "/git/github.com/nektro/zig-time/12fad367a5282827aad7e12f0e9cd36f672c4010", + .store = "/git/github.com/nektro/zig-time/ba546bbf2e8438c9b2325f36f392c9d95b432e8e", .name = "time", - .entry = "/git/github.com/nektro/zig-time/12fad367a5282827aad7e12f0e9cd36f672c4010/time.zig", + .entry = "/git/github.com/nektro/zig-time/ba546bbf2e8438c9b2325f36f392c9d95b432e8e/time.zig", .deps = &[_]*Package{ &_f7dubzb7cyqe }, }; pub var _g982zq6e8wsv = Package{ .store = "/git/github.com/nektro/zig-yaml/0d17fb99cba338aedc1abac12d78d5e5f04f0b6b", .name = "yaml", .entry = "/git/github.com/nektro/zig-yaml/0d17fb99cba338aedc1abac12d78d5e5f04f0b6b/yaml.zig", - .deps = &[_]*Package{ &_f7dubzb7cyqe }, + .deps = &[_]*Package{ &_8mdbh0zuneb0, &_f7dubzb7cyqe }, }; pub var _9k24gimke1an = Package{ - .store = "/git/github.com/truemedian/hzzp/92e6072d8a385d8b08fdcae3ae2021fe5293528f", + .store = "/git/github.com/truemedian/hzzp/a7f03a1e652abe8c89b376d090cec50acb0d2a1a", .name = "hzzp", - .entry = "/git/github.com/truemedian/hzzp/92e6072d8a385d8b08fdcae3ae2021fe5293528f/src/main.zig", + .entry = "/git/github.com/truemedian/hzzp/a7f03a1e652abe8c89b376d090cec50acb0d2a1a/src/main.zig", }; pub var _ejw82j2ipa0e = Package{ - .store = "/git/github.com/nektro/zfetch/f51277414a2309f776fb79f3d55f26e37f9a54da", + .store = "/git/github.com/nektro/zfetch/863be236188e5f24d16554f9dcd7df96dd254a13", .name = "zfetch", - .entry = "/git/github.com/nektro/zfetch/f51277414a2309f776fb79f3d55f26e37f9a54da/src/main.zig", + .entry = "/git/github.com/nektro/zfetch/863be236188e5f24d16554f9dcd7df96dd254a13/src/main.zig", .deps = &[_]*Package{ &_9k24gimke1an, &_csbnipaad8n7 }, }; pub var _2ta738wrqbaq = Package{ - .store = "/git/github.com/ziglibs/known-folders/855473062efac722624737f1adc56f9c0dd92017", + .store = "/git/github.com/ziglibs/known-folders/0ad514dcfb7525e32ae349b9acc0a53976f3a9fa", .name = "known-folders", - .entry = "/git/github.com/ziglibs/known-folders/855473062efac722624737f1adc56f9c0dd92017/known-folders.zig", + .entry = "/git/github.com/ziglibs/known-folders/0ad514dcfb7525e32ae349b9acc0a53976f3a9fa/known-folders.zig", }; pub var _89ujp8gq842x = Package{ .name = "zigmod", diff --git a/docs/README.md b/docs/README.md index 3bf00ec03cd0de3836f3283d660b44aa14167f8d..7fb65fbd2eefd8ee793809a0157acff0a476c752 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,7 +10,7 @@ The rest of this documentation will assume you already have Zig installed. As Zig is still in development itself, if you plan to contribute to Zigmod you will need a master download of Zig. Those can be obtained from https://ziglang.org/download/#release-master. -The earliest Zig release this Zigmod was verified to work with is `0.11.0`. +The earliest Zig release this Zigmod was verified to work with is `0.12.0`. ## Download You may download a precompiled binary from https://github.com/nektro/zigmod/releases or build the project from source. diff --git a/docs/deps.zig.md b/docs/deps.zig.md index dc99cf0594811544cbd068d6c88b26f67e71fe30..56759600fd1ea5e48af5c007750ff0f896073318 100644 --- a/docs/deps.zig.md +++ b/docs/deps.zig.md @@ -15,10 +15,6 @@ A helper function to automatically pull in dependencies, purely from the `zig bu - Type: `pub fn (exe: *std.build.LibExeObjStep) void` A helper function to add all of the packages, C files, and system libraries to the passed exectuable. It will also automatically link libC in the event that any C files are found in the dependency tree. -### `addAllLibrariesTo` -- Type: `pub fn (exe: *std.build.LibExeObjStep) void` -A helper function called by `addAllTo` that adds the C files and libraries. - ### `Package` ```zig pub const Package = struct { @@ -29,7 +25,6 @@ pub const Package = struct { c_source_flags: []const string = &.{}, system_libs: []const string = &.{}, frameworks: []const string = &.{}, - vcpkg: bool = false, }; ``` @@ -43,7 +38,7 @@ This is a an array of all of the items in `package_data`, but only contains the ### `pkgs` - Type: `struct` -This is a struct that associates the package name to the relavant `Package`. The only packages listed are the dependencies of the root project. +This is a struct that associates the package name to the relavant `Package`. The only packages listed are the dependencies of the root project. ### `imports` - Type: `struct` diff --git a/docs/zig.mod.md b/docs/zig.mod.md index 69434592d1967a04a7afb9ae25a0293761c2bfc9..739ebd5814ac62a234a1999802e43894cb2a98eb 100644 --- a/docs/zig.mod.md +++ b/docs/zig.mod.md @@ -58,11 +58,6 @@ Similar to `dependencies` but will only get added to the project if the current - Type: `string` Parsed as a `std.SemanticVersion`, this attribute refers to the minimum compatible Zig version for this package/application and will cause `zig build` to panic if violated. -#### `vcpkg` -- Type: `bool` -- 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 Object @@ -124,10 +119,5 @@ 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 `zigmod.yml` 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 f3b646d64b56a9a11096284e4e0dd292d09dc191..c35093216172b9fa0f3cacba28c7707362991055 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -52,94 +52,89 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D try w.writeAll("const std = @import(\"std\");\n"); try w.writeAll("const builtin = @import(\"builtin\");\n"); try w.writeAll("const string = []const u8;\n"); - try w.writeAll("const ModuleDependency = std.build.ModuleDependency;\n"); try w.writeAll("\n"); try w.print("pub const cache = \"{}\";\n", .{std.zig.fmtEscapes(cachepath)}); try w.writeAll("\n"); try w.writeAll( - \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void { + \\pub fn addAllTo(exe: *std.Build.Step.Compile) void { \\ checkMinZig(builtin.zig_version, exe); - \\ const b = exe.step.owner; \\ @setEvalBranchQuota(1_000_000); \\ for (packages) |pkg| { - \\ const moddep = pkg.zp(b); - \\ exe.addModule(moddep.name, moddep.module); + \\ const module = pkg.module(exe); + \\ exe.root_module.addImport(pkg.import.?[0], module); \\ } - \\ addAllLibrariesTo(exe); - \\} - \\ - \\pub fn addAllLibrariesTo(exe: *std.build.LibExeObjStep) void { - \\ const b = exe.step.owner; - \\ var llc = false; - \\ var vcpkg = false; - \\ inline for (comptime std.meta.declarations(package_data)) |decl| { - \\ const pkg = @as(Package, @field(package_data, decl.name)); - \\ for (pkg.system_libs) |item| { - \\ exe.linkSystemLibrary(item); - \\ llc = true; - \\ } - \\ for (pkg.frameworks) |item| { - \\ if (!builtin.target.isDarwin()) @panic(b.fmt("a dependency is attempting to link to the framework {s}, which is only possible under Darwin", .{item})); - \\ exe.linkFramework(item); - \\ llc = true; - \\ } - \\ for (pkg.c_include_dirs) |item| { - \\ exe.addIncludePath(.{.path = b.fmt("{s}/{s}", .{ @field(dirs, decl.name), item })}); - \\ llc = true; - \\ } - \\ for (pkg.c_source_files) |item| { - \\ exe.addCSourceFile(.{ .file = .{ .path = b.fmt("{s}/{s}", .{ @field(dirs, decl.name), item }) }, .flags = pkg.c_source_flags }); - \\ llc = true; - \\ } - \\ vcpkg = vcpkg or pkg.vcpkg; - \\ } - \\ if (llc) exe.linkLibC(); - \\ if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err)); \\} \\ + \\var link_lib_c = false; \\pub const Package = struct { \\ directory: string, - \\ pkg: ?Pkg = null, + \\ import: ?struct { string, std.Build.LazyPath } = null, + \\ dependencies: []const *Package, \\ c_include_dirs: []const string = &.{}, \\ c_source_files: []const string = &.{}, \\ c_source_flags: []const string = &.{}, \\ system_libs: []const string = &.{}, \\ frameworks: []const string = &.{}, - \\ vcpkg: bool = false, - \\ module: ?ModuleDependency = null, + \\ module_memo: ?*std.Build.Module = null, \\ - \\ pub fn zp(self: *Package, b: *std.build.Builder) ModuleDependency { - \\ var temp: [100]ModuleDependency = undefined; - \\ const pkg = self.pkg.?; - \\ for (pkg.dependencies, 0..) |item, i| { - \\ temp[i] = item.zp(b); - \\ } - \\ if (self.module) |mod| { - \\ return mod; - \\ } - \\ const result = ModuleDependency{ - \\ .name = pkg.name, - \\ .module = b.createModule(.{ - \\ .source_file = pkg.source, - \\ .dependencies = b.allocator.dupe(ModuleDependency, temp[0..pkg.dependencies.len]) catch @panic("oom"), - \\ }), - \\ }; - \\ self.module = result; + \\ pub fn module(self: *Package, exe: *std.Build.Step.Compile) *std.Build.Module { + \\ if (self.module_memo) |cached| { + \\ return cached; + \\ } + \\ const b = exe.step.owner; + \\ const result = b.createModule(.{}); + \\ const dummy_library = b.addStaticLibrary(.{ + \\ .name = "dummy", + \\ .target = exe.root_module.resolved_target orelse b.host, + \\ .optimize = exe.root_module.optimize.?, + \\ }); + \\ if (self.import) |capture| { + \\ result.root_source_file = capture[1]; + \\ } + \\ for (self.dependencies) |item| { + \\ const module_dep = item.module(exe); + \\ if (module_dep.root_source_file != null) { + \\ result.addImport(item.import.?[0], module_dep); + \\ } + \\ for (module_dep.include_dirs.items) |jtem| { + \\ switch (jtem) { + \\ .path => result.addIncludePath(jtem.path), + \\ .path_system, .path_after, .framework_path, .framework_path_system, .other_step, .config_header_step => {}, + \\ } + \\ } + \\ } + \\ for (self.c_include_dirs) |item| { + \\ result.addIncludePath(b.path(b.fmt("{s}/{s}", .{ self.directory, item }))); + \\ dummy_library.addIncludePath(b.path(b.fmt("{s}/{s}", .{ self.directory, item }))); + \\ link_lib_c = true; + \\ } + \\ for (self.c_source_files) |item| { + \\ dummy_library.addCSourceFile(.{ .file = b.path(b.fmt("{s}/{s}", .{ self.directory, item })), .flags = self.c_source_flags }); + \\ } + \\ for (self.system_libs) |item| { + \\ dummy_library.linkSystemLibrary(item); + \\ } + \\ for (self.frameworks) |item| { + \\ dummy_library.linkFramework(item); + \\ } + \\ if (self.c_source_files.len > 0 or self.system_libs.len > 0 or self.frameworks.len > 0) { + \\ dummy_library.linkLibC(); + \\ exe.root_module.linkLibrary(dummy_library); + \\ link_lib_c = true; + \\ } + \\ if (link_lib_c) { + \\ result.link_libc = true; + \\ } + \\ self.module_memo = result; \\ return result; \\ } \\}; \\ - \\pub const Pkg = struct { - \\ name: string, - \\ source: std.build.FileSource, - \\ dependencies: []const *Package, - \\}; - \\ \\ ); try w.print( - \\fn checkMinZig(current: std.SemanticVersion, exe: *std.build.LibExeObjStep) void {{ + \\fn checkMinZig(current: std.SemanticVersion, exe: *std.Build.Step.Compile) void {{ \\ const min = std.SemanticVersion.parse("{?}") catch return; \\ if (current.order(min).compare(.lt)) @panic(exe.step.owner.fmt("Your Zig version v{{}} does not meet the minimum build requirement of v{{}}", .{{current, min}})); \\}} @@ -148,7 +143,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D , .{top_module.minZigVersion()}); try w.writeAll("pub const dirs = struct {\n"); - try print_dirs(w, list.items); + try print_dirs(w, list.items, alloc); try w.writeAll("};\n\n"); try w.writeAll("pub const package_data = struct {\n"); @@ -215,7 +210,7 @@ fn diff_lockfile(alloc: std.mem.Allocator) !void { while (try r.readUntilDelimiterOrEofAlloc(alloc, '\n', max)) |line| { if (line[0] == ' ') continue; if (line[0] == '-') try rems.append(line[1..]); - if (line[0] == '+') if (line[1] == '2') continue else try adds.append(line[1..]); + if (line[0] == '+') if (line[1] == '2') break else try adds.append(line[1..]); } var changes = std.StringHashMap(DiffChange).init(alloc); @@ -287,13 +282,18 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item: return false; } -fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void { +fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module, alloc: std.mem.Allocator) !void { for (list) |mod| { if (mod.type == .system_lib or mod.type == .framework) continue; if (std.mem.eql(u8, mod.id, "root")) { try w.writeAll(" pub const _root = \"\";\n"); continue; } + if (std.mem.eql(u8, mod.clean_path, "../..")) { + const cwd_realpath = try std.fs.cwd().realpathAlloc(alloc, "."); + try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(cwd_realpath) }); + continue; + } try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(mod.clean_path) }); } } @@ -327,23 +327,22 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul }); if (mod.main.len > 0 and !std.mem.eql(u8, mod.id, "root")) { try w.print( - \\ .pkg = Pkg{{ .name = "{s}", .source = .{{ .path = dirs._{s} ++ "/{s}" }}, .dependencies = + \\ .import = .{{ "{s}", .{{ .path = dirs._{s} ++ "/{s}" }} }}, + \\ , .{ mod.name, mod.short_id(), mod.main, }); - if (mod.has_no_zig_deps()) { - try w.writeAll(" &.{} },\n"); - } else { - try w.writeAll(" &.{"); - for (mod.deps, 0..) |moddep, j| { - if (moddep.main.len == 0) continue; - try w.print(" &_{s}", .{moddep.id[0..12]}); - if (j != mod.deps.len - 1) try w.writeAll(","); - } - try w.writeAll(" } },\n"); + } + { + try w.writeAll(" .dependencies ="); + try w.writeAll(" &.{"); + for (mod.deps, 0..) |moddep, j| { + try w.print(" &_{s}", .{moddep.id[0..12]}); + if (j != mod.deps.len - 1) try w.writeAll(","); } + try w.writeAll(" },\n"); } if (mod.c_include_dirs.len > 0) { try w.writeAll(" .c_include_dirs = &.{"); @@ -387,9 +386,6 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul } try w.writeAll(" },\n"); } - if (mod.vcpkg) { - try w.writeAll(" .vcpkg = true,\n"); - } try w.writeAll(" };\n"); try done.append(mod); diff --git a/src/cmd/generate.zig b/src/cmd/generate.zig index 0bf78bd08eab0d8659e887896603db47388673a5..4d2338470715e98c5e113dd34fb7609e78773cdc 100644 --- a/src/cmd/generate.zig +++ b/src/cmd/generate.zig @@ -41,20 +41,19 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D try w.writeAll("// zig fmt: off\n"); try w.writeAll("const std = @import(\"std\");\n"); try w.writeAll("const builtin = @import(\"builtin\");\n"); - try w.writeAll("const ModuleDependency = std.build.ModuleDependency;\n"); try w.writeAll("const string = []const u8;\n"); try w.writeAll("\n"); try w.writeAll( \\pub const GitExactStep = struct { - \\ step: std.build.Step, - \\ builder: *std.build.Builder, + \\ step: std.Build.Step, + \\ builder: *std.Build, \\ url: string, \\ commit: string, \\ - \\ pub fn create(b: *std.build.Builder, url: string, commit: string) *GitExactStep { + \\ pub fn create(b: *std.Build, url: string, commit: string) *GitExactStep { \\ var result = b.allocator.create(GitExactStep) catch @panic("memory"); \\ result.* = GitExactStep{ - \\ .step = std.build.Step.init(.{ + \\ .step = std.Build.Step.init(.{ \\ .id = .custom, \\ .name = b.fmt("git clone {s} @ {s}", .{ url, commit }), \\ .owner = b, @@ -71,11 +70,11 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D \\ const repopath = b.fmt("{s}/zigmod/deps/git/{s}/{s}", .{ b.cache_root.path.?, urlpath, commit }); \\ flip(std.fs.cwd().access(repopath, .{})) catch return result; \\ - \\ var clonestep = std.build.RunStep.create(b, "clone"); + \\ var clonestep = std.Build.Step.Run.create(b, "clone"); \\ clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath }); \\ result.step.dependOn(&clonestep.step); \\ - \\ var checkoutstep = std.build.RunStep.create(b, "checkout"); + \\ var checkoutstep = std.Build.Step.Run.create(b, "checkout"); \\ checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit }); \\ result.step.dependOn(&checkoutstep.step); \\ checkoutstep.step.dependOn(&clonestep.step); @@ -85,18 +84,18 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D \\ return result; \\ } \\ - \\ fn make(step: *std.build.Step, prog_node: *std.Progress.Node) !void { + \\ fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) !void { \\ _ = step; \\ _ = prog_node; \\ } \\}; \\ - \\pub fn fetch(exe: *std.build.LibExeObjStep) void { + \\pub fn fetch(exe: *std.Build.Step.Compile) void { \\ const b = exe.step.owner; \\ inline for (comptime std.meta.declarations(package_data)) |decl| { - \\ const path = &@field(package_data, decl.name).entry; - \\ const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else "."; - \\ if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? }); + \\ const path = &@field(package_data, decl.name).entry; + \\ const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else "."; + \\ if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? }); \\ } \\ ); @@ -125,48 +124,17 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D \\ return error.ExpectedError; \\} \\ - \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void { + \\pub fn addAllTo(exe: *std.Build.Step.Compile) void { \\ checkMinZig(builtin.zig_version, exe); \\ fetch(exe); - \\ const b = exe.step.owner; \\ @setEvalBranchQuota(1_000_000); \\ for (packages) |pkg| { - \\ const moddep = pkg.zp(b); - \\ exe.addModule(moddep.name, moddep.module); + \\ const module = pkg.module(exe); + \\ exe.root_module.addImport(pkg.name, module); \\ } - \\ addAllLibrariesTo(exe); - \\} - \\ - \\pub fn addAllLibrariesTo(exe: *std.build.LibExeObjStep) void { - \\ const b = exe.step.owner; - \\ var llc = false; - \\ var vcpkg = false; - \\ inline for (comptime std.meta.declarations(package_data)) |decl| { - \\ const pkg = @as(Package, @field(package_data, decl.name)); - \\ const root = if (pkg.store) |st| b.fmt("{s}/zigmod/deps/{s}", .{ b.cache_root.path.?, st }) else "."; - \\ for (pkg.system_libs) |item| { - \\ exe.linkSystemLibrary(item); - \\ llc = true; - \\ } - \\ for (pkg.frameworks) |item| { - \\ if (!builtin.target.isDarwin()) @panic(exe.step.owner.fmt("a dependency is attempting to link to the framework {s}, which is only possible under Darwin", .{item})); - \\ exe.linkFramework(item); - \\ llc = true; - \\ } - \\ for (pkg.c_include_dirs) |item| { - \\ exe.addIncludePath(.{.path = b.fmt("{s}/{s}", .{ root, item })}); - \\ llc = true; - \\ } - \\ for (pkg.c_source_files) |item| { - \\ exe.addCSourceFile(.{ .file = .{ .path = b.fmt("{s}/{s}", .{ root, item }) }, .flags = pkg.c_source_flags }); - \\ llc = true; - \\ } - \\ vcpkg = vcpkg or pkg.vcpkg; - \\ } - \\ if (llc) exe.linkLibC(); - \\ if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err)); \\} \\ + \\var link_lib_c = false; \\pub const Package = struct { \\ name: string = "", \\ entry: ?string = null, @@ -177,25 +145,58 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D \\ c_source_flags: []const string = &.{}, \\ system_libs: []const string = &.{}, \\ frameworks: []const string = &.{}, - \\ vcpkg: bool = false, - \\ module: ?ModuleDependency = null, + \\ module_memo: ?*std.Build.Module = null, \\ - \\ pub fn zp(self: *Package, b: *std.build.Builder) ModuleDependency { - \\ var temp: [100]ModuleDependency = undefined; - \\ for (self.deps, 0..) |item, i| { - \\ temp[i] = item.zp(b); - \\ } - \\ if (self.module) |mod| { - \\ return mod; - \\ } - \\ const result = ModuleDependency{ - \\ .name = self.name, - \\ .module = b.createModule(.{ - \\ .source_file = .{ .path = self.entry.? }, - \\ .dependencies = b.allocator.dupe(ModuleDependency, temp[0..self.deps.len]) catch @panic("oom"), - \\ }), - \\ }; - \\ self.module = result; + \\ pub fn module(self: *Package, exe: *std.Build.Step.Compile) *std.Build.Module { + \\ if (self.module_memo) |cached| { + \\ return cached; + \\ } + \\ const b = exe.step.owner; + \\ + \\ const result = b.createModule(.{}); + \\ const dummy_library = b.addStaticLibrary(.{ + \\ .name = "dummy", + \\ .target = exe.root_module.resolved_target orelse b.host, + \\ .optimize = exe.root_module.optimize.?, + \\ }); + \\ if (self.entry) |capture| { + \\ result.root_source_file = .{ .path = capture }; + \\ } + \\ for (self.deps) |item| { + \\ const module_dep = item.module(exe); + \\ if (module_dep.root_source_file != null) { + \\ result.addImport(item.name, module_dep); + \\ } + \\ for (module_dep.include_dirs.items) |jtem| { + \\ switch (jtem) { + \\ .path => result.addIncludePath(jtem.path), + \\ .path_system, .path_after, .framework_path, .framework_path_system, .other_step, .config_header_step => {}, + \\ } + \\ } + \\ } + \\ for (self.c_include_dirs) |item| { + \\ result.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }); + \\ dummy_library.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }); + \\ link_lib_c = true; + \\ } + \\ for (self.c_source_files) |item| { + \\ dummy_library.addCSourceFile(.{ .file = .{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }, .flags = self.c_source_flags }); + \\ } + \\ for (self.system_libs) |item| { + \\ dummy_library.linkSystemLibrary(item); + \\ } + \\ for (self.frameworks) |item| { + \\ dummy_library.linkFramework(item); + \\ } + \\ if (self.c_source_files.len > 0 or self.system_libs.len > 0 or self.frameworks.len > 0) { + \\ dummy_library.linkLibC(); + \\ exe.root_module.linkLibrary(dummy_library); + \\ link_lib_c = true; + \\ } + \\ if (link_lib_c) { + \\ result.link_libc = true; + \\ } + \\ self.module_memo = result; \\ return result; \\ } \\}; @@ -204,7 +205,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D ); try w.print( - \\fn checkMinZig(current: std.SemanticVersion, exe: *std.build.LibExeObjStep) void {{ + \\fn checkMinZig(current: std.SemanticVersion, exe: *std.Build.Step.Compile) void {{ \\ const min = std.SemanticVersion.parse("{?}") catch return; \\ if (current.order(min).compare(.lt)) @panic(exe.step.owner.fmt("Your Zig version v{{}} does not meet the minimum build requirement of v{{}}", .{{current, min}})); \\}} @@ -273,7 +274,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath: , .{ mod.short_id(), }); - var fixed_path = if (std.mem.startsWith(u8, mod.clean_path, "v/")) mod.clean_path[2..std.mem.lastIndexOfScalar(u8, mod.clean_path, '/').?] else mod.clean_path; + const fixed_path = if (std.mem.startsWith(u8, mod.clean_path, "v/")) mod.clean_path[2..std.mem.lastIndexOfScalar(u8, mod.clean_path, '/').?] else mod.clean_path; switch (mod.type) { .system_lib, .framework => {}, .local => {}, @@ -285,10 +286,9 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath: try w.print(" .name = \"{s}\",\n", .{mod.name}); try w.print(" .entry = \"/{}/{s}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath), mod.main }); - if (!mod.has_no_zig_deps()) { + if (mod.deps.len != 0) { try w.writeAll(" .deps = &[_]*Package{"); for (mod.deps, 0..) |moddep, j| { - if (moddep.main.len == 0) continue; try w.print(" &_{s}", .{moddep.id[0..12]}); if (j != mod.deps.len - 1) try w.writeAll(","); } @@ -337,9 +337,6 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath: } try w.writeAll(" },\n"); } - if (mod.vcpkg) { - try w.writeAll(" .vcpkg = true,\n"); - } try w.writeAll(" };\n"); try done.append(mod); diff --git a/src/common.zig b/src/common.zig index 808fa2e8b04cd68e5a8b806b72c9eefe9b03417e..5bbe38bdbe90d1b141acf3ae207b82d9ea810724 100644 --- a/src/common.zig +++ b/src/common.zig @@ -54,7 +54,6 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO .yaml = m.yaml, .dep = null, .min_zig_version = m.min_zig_version, - .vcpkg = m.vcpkg, }; } @@ -85,7 +84,6 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, dtype: zigmod.Dep.Type, .yaml = m.yaml, .dep = null, .min_zig_version = m.min_zig_version, - .vcpkg = m.vcpkg, }; } @@ -153,7 +151,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! defer pvd.close(); try pvd.deleteTree(".git"); } - var pvd = try std.fs.cwd().openIterableDir(pv, .{}); + var pvd = try std.fs.cwd().openDir(pv, .{ .iterate = true }); defer pvd.close(); try setTreeReadOnly(pvd, options.alloc); return pv; @@ -190,7 +188,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! try d.type.pull(options.alloc, d.path, pv); if (try u.validate_hash(options.alloc, d.version, file_path)) { try std.fs.cwd().deleteFile(file_path); - var pvd = try std.fs.cwd().openIterableDir(pv, .{}); + var pvd = try std.fs.cwd().openDir(pv, .{ .iterate = true }); defer pvd.close(); try setTreeReadOnly(pvd, options.alloc); return pv; @@ -243,7 +241,6 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO .dep = d.*, .for_build = d.for_build, .min_zig_version = null, - .vcpkg = false, }; }, else => { @@ -297,7 +294,7 @@ pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std. defer map.deinit(); for (dirs) |dir_path| { - const dir = try mdir.openIterableDir(dir_path, .{}); + const dir = try mdir.openDir(dir_path, .{ .iterate = true }); var walker = try dir.walk(alloc); defer walker.deinit(); while (try walker.next()) |p| { @@ -377,13 +374,13 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str return list.toOwnedSlice(); } -fn setTreeReadOnly(idir: std.fs.IterableDir, alloc: std.mem.Allocator) !void { - var walker = try idir.walk(alloc); +fn setTreeReadOnly(dir: std.fs.Dir, alloc: std.mem.Allocator) !void { + var walker = try dir.walk(alloc); defer walker.deinit(); while (try walker.next()) |entry| { if (entry.kind != .file) continue; - var file = try idir.dir.openFile(entry.path, .{}); + var file = try dir.openFile(entry.path, .{}); defer file.close(); var metadata = try file.metadata(); var perms = metadata.permissions(); diff --git a/src/main.zig b/src/main.zig index 465e421cff2a25d3fe6bf2517f2e2d7174a6981f..d014711b77fc3be374b3a30d1bc655a23711585a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -56,7 +56,7 @@ pub fn main() !void { for (args[1..]) |item| { try sub_cmd_args.append(item); } - const result = std.ChildProcess.exec(.{ .allocator = gpa, .argv = sub_cmd_args.items }) catch |e| switch (e) { + const result = std.ChildProcess.run(.{ .allocator = gpa, .argv = sub_cmd_args.items }) catch |e| switch (e) { else => |ee| return ee, error.FileNotFound => { fail("unknown command \"{s}\" for \"zigmod\"", .{args[0]}); @@ -75,7 +75,7 @@ const ansi_reset = "\x1B[39m"; pub fn assert(ok: bool, comptime fmt: string, args: anytype) void { if (!ok) { std.debug.print(ansi_red ++ fmt ++ ansi_reset ++ "\n", args); - std.os.exit(1); + std.process.exit(1); } } diff --git a/src/util/dep.zig b/src/util/dep.zig index b16b2ba14945fd3b97cfa087cbb0c585cb3dbb33..e2c9ed154b09a49121e1de3f6cd6d0aa8cdd1bde 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -27,7 +27,6 @@ pub const Dep = struct { yaml: ?yaml.Mapping, deps: []zigmod.Dep, keep: bool = false, - vcpkg: bool = false, for_build: bool = false, parent_id: string, diff --git a/src/util/funcs.zig b/src/util/funcs.zig index d5833b2a1c6e8fd8b5ec69d41d593a952c1f5753..94d6004a37ed79ffe0d29cd5844a5944c47d8e0f 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -19,7 +19,7 @@ const ansi_reset = "\x1B[39m"; pub fn assert(ok: bool, comptime fmt: string, args: anytype) void { if (!ok) { std.debug.print(ansi_red ++ fmt ++ ansi_reset ++ "\n", args); - std.os.exit(1); + std.process.exit(1); } } @@ -47,13 +47,13 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: string) ![]string { } pub fn file_list(alloc: std.mem.Allocator, dpath: string) ![]const string { - var dir = try std.fs.cwd().openIterableDir(dpath, .{}); + var dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true }); defer dir.close(); return try extras.fileList(alloc, dir); } -pub fn run_cmd_raw(alloc: std.mem.Allocator, dir: ?string, args: []const string) !std.ChildProcess.ExecResult { - return std.ChildProcess.exec(.{ .allocator = alloc, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) { +pub fn run_cmd_raw(alloc: std.mem.Allocator, dir: ?string, args: []const string) !std.ChildProcess.RunResult { + return std.ChildProcess.run(.{ .allocator = alloc, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) { error.FileNotFound => { u.fail("\"{s}\" command not found", .{args[0]}); }, diff --git a/src/util/modfile.zig b/src/util/modfile.zig index 2072fe81b26eb02b2c513f59f10111926c22be42..8025a0e7703d32c583778e5db14a39c18a0d59e9 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -28,7 +28,6 @@ pub const ModFile = struct { rootdeps: []zigmod.Dep, builddeps: []zigmod.Dep, min_zig_version: ?std.SemanticVersion, - vcpkg: bool, pub fn openFile(dir: std.fs.Dir, ops: std.fs.File.OpenFlags) !std.fs.File { return dir.openFile("zig.mod", ops) catch |err| switch (err) { @@ -75,7 +74,6 @@ pub const ModFile = struct { .rootdeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "root_dependencies" }, false), .builddeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "build_dependencies" }, true), .min_zig_version = std.SemanticVersion.parse(mapping.get_string("min_zig_version") orelse "") catch null, - .vcpkg = std.mem.eql(u8, "true", mapping.get_string("vcpkg") orelse ""), }; } @@ -137,7 +135,6 @@ pub const ModFile = struct { .yaml = item.mapping, .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}, for_build), .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep") orelse ""), - .vcpkg = std.mem.eql(u8, "true", item.mapping.get_string("vcpkg") orelse ""), .for_build = for_build, .parent_id = mapping.get_string("id") orelse "", }); diff --git a/src/util/module.zig b/src/util/module.zig index 412ecdb9927760018da2d02fbfaad9bc9cda1a2b..9f2ff87a6735641eb43ae6d74970f7eb09492fa1 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -27,7 +27,6 @@ pub const Module = struct { dep: ?zigmod.Dep, for_build: bool = false, min_zig_version: ?std.SemanticVersion, - vcpkg: bool, pub fn from(alloc: std.mem.Allocator, dep: zigmod.Dep, cachepath: string, options: *common.CollectOptions) !Module { var moddeps = std.ArrayList(Module).init(alloc); @@ -54,7 +53,6 @@ pub const Module = struct { .dep = dep, .for_build = dep.for_build, .min_zig_version = null, - .vcpkg = dep.vcpkg, }; } diff --git a/zig.mod b/zig.mod index 6da29d9c62474f338a87197e7fd03744100d2b12..55c824d6dbbe86711ac6a30dd7be031271195fcc 100644 --- a/zig.mod +++ b/zig.mod @@ -3,7 +3,7 @@ name: zigmod main: src/lib.zig license: MIT description: A package manager for the Zig programming language. -min_zig_version: 0.11.0 +min_zig_version: 0.12.0 dependencies: - src: git https://github.com/nektro/zig-yaml - src: git https://github.com/nektro/zig-ansi @@ -18,7 +18,10 @@ dependencies: root_dependencies: - src: git https://github.com/marlersoft/zigwin32 - id: zg4wbiyyfn2fdpmia0jjh2d5k0xb7v1l7zn3xcyv + id: o6ogpor87xc23o863qaqfciqqdnt48nlj0395dk1xt4m9b34 keep: true + name: win32 + main: win32.zig + license: MIT - src: git https://github.com/nektro/zig-extras - src: git https://github.com/nektro/zig-ansi diff --git a/zigmod.lock b/zigmod.lock index 41cf5230734f9f593b52cd5c8401b12a10769b83..535436c9e528b3e348f833668cadfcb58b97e206 100644 --- a/zigmod.lock +++ b/zigmod.lock @@ -1,18 +1,18 @@ 2 git https://github.com/marlersoft/zigwin32 commit-c778640d3dc153e900fbe37e2816b5176af3c802 -git https://github.com/nektro/arqv-ini commit-ddbe89bb0d9085e939bcbc713caeb2b7cf852bae -git https://github.com/nektro/iguanaTLS commit-f5c7c3fe880c5a23fbcdc21dfcb83c2776931f40 -git https://github.com/nektro/zfetch commit-478031843703fef875ca347898208c01869c7c9d -git https://github.com/nektro/zig-ansi commit-407a70207ee818f6920096f40779e3fb52db49b0 +git https://github.com/nektro/arqv-ini commit-38a018ad3a19d5b4663a5364d2d31271f250846b +git https://github.com/nektro/iguanaTLS commit-4dc8850883b49e4a452871298788b06b1af9fe24 +git https://github.com/nektro/zfetch commit-863be236188e5f24d16554f9dcd7df96dd254a13 +git https://github.com/nektro/zig-ansi commit-c3e439f86b0484e4428f38c4d8b07b7b5ae1634b git https://github.com/nektro/zig-detect-license commit-3ff57d0681b7bd7f8ca9bd092afa0b4bfe2f1afd -git https://github.com/nektro/zig-extras commit-c95c2301565603856ff6fcaecaa63bdcdd689bc1 +git https://github.com/nektro/zig-extras commit-74f0ddb0a4dfa7921739b88cc381951a6b6e73ce git https://github.com/nektro/zig-inquirer commit-9e1d873db79e9ffa6ae6e06bd372428c9be85d97 git https://github.com/nektro/zig-leven commit-e548b0bcc7b6f34f636c0b6b905928d31254c54d git https://github.com/nektro/zig-licenses commit-f46d9f774df929885eef66c733a1e2a46bf16aec git https://github.com/nektro/zig-licenses-text commit-b01e5a2dffcc564bddd8f514fe64bab9b5c52572 git https://github.com/nektro/zig-range commit-4b2f12808aa09be4b27a163efc424dd4e0415992 -git https://github.com/nektro/zig-time commit-913d3ff01878326955bb3b265dcb3fdb3607d232 +git https://github.com/nektro/zig-time commit-ba546bbf2e8438c9b2325f36f392c9d95b432e8e git https://github.com/nektro/zig-yaml commit-0d17fb99cba338aedc1abac12d78d5e5f04f0b6b -git https://github.com/truemedian/hzzp commit-31563ce8173038aff326f83b18d49d84e2737255 -git https://github.com/ziglibs/known-folders commit-bf79988adcfce166f848e4b11e718c1966365329 +git https://github.com/truemedian/hzzp commit-a7f03a1e652abe8c89b376d090cec50acb0d2a1a +git https://github.com/ziglibs/known-folders commit-0ad514dcfb7525e32ae349b9acc0a53976f3a9fa git https://github.com/yaml/libyaml tag-0.2.5 -- 2.54.0