From 01c16aaeeb674622f4a0e715aeeb16c8ce0bc30e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 3 Aug 2023 16:53:26 -0700 Subject: [PATCH] use zig package manager --- .gitmodules | 3 --- build.zig | 26 ++++---------------------- build.zig.zon | 10 ++++++++++ flake.lock | 14 +++++++------- vendor/mach-glfw | 1 - 5 files changed, 21 insertions(+), 33 deletions(-) create mode 100644 build.zig.zon delete mode 160000 vendor/mach-glfw diff --git a/.gitmodules b/.gitmodules index d886933..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "vendor/mach-glfw"] - path = vendor/mach-glfw - url = https://github.com/hexops/mach-glfw.git diff --git a/build.zig b/build.zig index 0e2bf9b..b76f2d4 100644 --- a/build.zig +++ b/build.zig @@ -1,26 +1,12 @@ const std = @import("std"); -const system_sdk = @import("vendor/mach-glfw/system_sdk.zig"); - -/// Use this with addPackage in your project. -pub const pkg = std.build.Pkg{ - .name = "objc", - .source = .{ .path = thisDir() ++ "/src/main.zig" }, -}; - -/// Returns the module for libxev. The recommended approach is to depend -/// on libxev in your build.zig.zon file, then use -/// `b.dependency("libxev").module("xev")`. But if you're not using -/// a build.zig.zon yet this will work. -pub fn module(b: *std.Build) *std.Build.Module { - return b.createModule(.{ - .source_file = .{ .path = (comptime thisDir()) ++ "/src/main.zig" }, - }); -} +const xcode_frameworks = @import("xcode_frameworks"); pub fn build(b: *std.Build) !void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); + _ = b.addModule("objc", .{ .source_file = .{ .path = "src/main.zig" } }); + const tests = b.addTest(.{ .name = "objc-test", .root_source_file = .{ .path = "src/main.zig" }, @@ -28,14 +14,10 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, }); tests.linkSystemLibrary("objc"); - system_sdk.include(b, tests, .{}); + try xcode_frameworks.addPaths(b, tests); b.installArtifact(tests); const test_step = b.step("test", "Run tests"); const tests_run = b.addRunArtifact(tests); test_step.dependOn(&tests_run.step); } - -fn thisDir() []const u8 { - return std.fs.path.dirname(@src().file) orelse "."; -} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..7b15c8a --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,10 @@ +.{ + .name = "zig-objc", + .version = "0.0.0", + .dependencies = .{ + .xcode_frameworks = .{ + .url = "https://github.com/mitchellh/zig-build-xcode-frameworks/archive/8a5fac6c4e7110be073b93cdbb317264731b2e14.tar.gz", + .hash = "122057e2244209296c552203b246870f6bc0326f9bd8eb41bc1e9e1de5c2a62c5be3", + }, + }, +} diff --git a/flake.lock b/flake.lock index c3551db..f5c2221 100644 --- a/flake.lock +++ b/flake.lock @@ -80,16 +80,16 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1661151577, - "narHash": "sha256-++S0TuJtuz9IpqP8rKktWyHZKpgdyrzDFUXVY07MTRI=", + "lastModified": 1689088367, + "narHash": "sha256-Y2tl2TlKCWEHrOeM9ivjCLlRAKH3qoPUE/emhZECU14=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "54060e816971276da05970a983487a25810c38a7", + "rev": "5c9ddb86679c400d6b7360797b8a22167c2053f8", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixpkgs-unstable", + "ref": "release-23.05", "repo": "nixpkgs", "type": "github" } @@ -109,11 +109,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1688126918, - "narHash": "sha256-A4j6rWShGZf2wf7RwTd1sWhN9qLAINDYsExqZD6N09k=", + "lastModified": 1691064519, + "narHash": "sha256-kGl2GigkW6O7uVc5W4mFdn9SN2fOBpKdvbhSxZj/huQ=", "owner": "mitchellh", "repo": "zig-overlay", - "rev": "601ed4533722f87b9e97580d30ddd687e58c6b16", + "rev": "8a0bae25fcebaacdd117df045271778ffbb10735", "type": "github" }, "original": { diff --git a/vendor/mach-glfw b/vendor/mach-glfw deleted file mode 160000 index 70ff87b..0000000 --- a/vendor/mach-glfw +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 70ff87ba8af0820bbcfdbdf3b15555cb4c19f7ab