From 3359c6163b23d1a873470060b205491c4d211de5 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 7 Jul 2023 06:32:36 -0700 Subject: [PATCH] all: use mach-glfw via package manager Signed-off-by: Stephen Gutekanst --- build.zig | 2 +- build.zig.zon | 4 +++ libs/core/build.zig | 2 +- libs/core/build.zig.zon | 4 +++ libs/glfw/README.md | 53 +++++++++++-------------------------- libs/gpu-dawn/build.zig.zon | 4 +++ libs/gpu/build.zig | 2 +- libs/gpu/build.zig.zon | 4 +++ 8 files changed, 35 insertions(+), 40 deletions(-) diff --git a/build.zig b/build.zig index 37a44f4c..97532c75 100644 --- a/build.zig +++ b/build.zig @@ -1,7 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); const freetype = @import("libs/freetype/build.zig"); -const glfw = @import("libs/glfw/build.zig"); +const glfw = @import("mach_glfw"); const sysaudio = @import("mach_sysaudio"); pub const gpu_dawn = @import("libs/gpu-dawn/build.zig"); // TODO(build-system): make this private const gpu = @import("libs/gpu/build.zig").Sdk(.{ diff --git a/build.zig.zon b/build.zig.zon index 6a14c1f7..3c3c6938 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -30,6 +30,10 @@ .url = "https://github.com/hexops/mach-sysaudio/archive/bc03624694ddf3a7d348efdeccf82404eb019236.tar.gz", .hash = "12203830507ce345848f27ffd27369e726c35ce115edb66f9ba9ee524d8a46c0a87a", }, + .mach_glfw = .{ + .url = "https://github.com/hexops/mach-glfw/archive/98418ac4dc7d21ffbfebdee8045473fa2e35d528.tar.gz", + .hash = "1220d685dabe227073aa11a8b7bb9eecfc8cbe5a08e128c23c173c2baddf8da9258e", + }, .direct3d_headers = .{ .url = "https://github.com/hexops/direct3d-headers/archive/773dce3f079eecdccc7c71d1318a0741649d568b.tar.gz", .hash = "12200d2155216c5eb5f111282cd355b5433cad6a68fd040294e695149cba329f7c12", diff --git a/libs/core/build.zig b/libs/core/build.zig index 8e66313b..316e8ab8 100644 --- a/libs/core/build.zig +++ b/libs/core/build.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const glfw = @import("libs/mach-glfw/build.zig"); +const glfw = @import("mach_glfw"); const gpu_dawn = @import("libs/mach-gpu-dawn/build.zig"); const gpu = @import("libs/mach-gpu/build.zig").Sdk(.{ .gpu_dawn = gpu_dawn, diff --git a/libs/core/build.zig.zon b/libs/core/build.zig.zon index e2a2d790..3844ddd0 100644 --- a/libs/core/build.zig.zon +++ b/libs/core/build.zig.zon @@ -10,6 +10,10 @@ .url = "https://github.com/hexops/mach-gamemode/archive/6e71d19d7eecbf0230e5c445dbe9281e45393245.tar.gz", .hash = "1220ff812193615e03375a342a7c8a52f368eab219bceab3039de1915f9c945f2a66", }, + .mach_glfw = .{ + .url = "https://github.com/hexops/mach-glfw/archive/98418ac4dc7d21ffbfebdee8045473fa2e35d528.tar.gz", + .hash = "1220d685dabe227073aa11a8b7bb9eecfc8cbe5a08e128c23c173c2baddf8da9258e", + }, .direct3d_headers = .{ .url = "https://github.com/hexops/direct3d-headers/archive/773dce3f079eecdccc7c71d1318a0741649d568b.tar.gz", .hash = "12200d2155216c5eb5f111282cd355b5433cad6a68fd040294e695149cba329f7c12", diff --git a/libs/glfw/README.md b/libs/glfw/README.md index 5dd33be2..b1454e26 100644 --- a/libs/glfw/README.md +++ b/libs/glfw/README.md @@ -42,19 +42,29 @@ A minimal Vulkan example can be found in the [mach-glfw-vulkan-example](https:// ## Getting started -### Adding dependency (using Git) +### Adding dependency -In a `libs` subdirectory of the root of your project: +Create a `build.zig.zon` file in your project (replace `$LATEST_COMMIT` with the latest commit hash): -```sh -git clone https://github.com/hexops/mach-glfw +``` +.{ + .name = "mypkg", + .version = "0.1.0", + .dependencies = .{ + .mach_glfw = .{ + .url = "https://github.com/hexops/mach-glfw/archive/$LATEST_COMMIT.tar.gz", + }, + }, +} ``` -Then in your `build.zig` add: +Run `zig build` in your project, and the compiler instruct you to add a `.hash = "..."` field next to `.url`. + +Then use the dependency in your `build.zig`: ```zig ... -const glfw = @import("libs/mach-glfw/build.zig"); +const glfw = @import("mach_glfw"); pub fn build(b: *Build) !void { ... @@ -63,37 +73,6 @@ pub fn build(b: *Build) !void { } ``` -
- - -### (optional) Adding dependency using Gyro - - - -```sh -gyro add --src github hexops/mach-glfw --root src/main.zig --alias glfw -gyro add --build_dep --src github hexops/mach-glfw --root build.zig --alias build-glfw -``` - -Then in your `build.zig` add: - -```zig -... -const pkgs = @import("deps.zig").pkgs; -const glfw = @import("build-glfw"); - -pub fn build(b: *Build) !void { - ... - - exe.addModule("glfw", pkgs.glfw); - try glfw.link(b, exe, .{}); -} -``` - -**Note: You should use `gyro build` instead of `zig build` to use gyro** - -
- # Next steps Now in your code you may import and use GLFW: diff --git a/libs/gpu-dawn/build.zig.zon b/libs/gpu-dawn/build.zig.zon index 06c090cb..3328c3b0 100644 --- a/libs/gpu-dawn/build.zig.zon +++ b/libs/gpu-dawn/build.zig.zon @@ -2,6 +2,10 @@ .name = "mach-gpu-dawn", .version = "0.2.0", .dependencies = .{ + .mach_glfw = .{ + .url = "https://github.com/hexops/mach-glfw/archive/98418ac4dc7d21ffbfebdee8045473fa2e35d528.tar.gz", + .hash = "1220d685dabe227073aa11a8b7bb9eecfc8cbe5a08e128c23c173c2baddf8da9258e", + }, .direct3d_headers = .{ .url = "https://github.com/hexops/direct3d-headers/archive/773dce3f079eecdccc7c71d1318a0741649d568b.tar.gz", .hash = "12200d2155216c5eb5f111282cd355b5433cad6a68fd040294e695149cba329f7c12", diff --git a/libs/gpu/build.zig b/libs/gpu/build.zig index c4922576..46112d05 100644 --- a/libs/gpu/build.zig +++ b/libs/gpu/build.zig @@ -3,7 +3,7 @@ const std = @import("std"); pub fn build(b: *std.Build) !void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); - const glfw = @import("libs/mach-glfw/build.zig"); + const glfw = @import("mach_glfw"); const gpu_dawn = @import("libs/mach-gpu-dawn/build.zig"); const gpu = Sdk(.{ .gpu_dawn = gpu_dawn, diff --git a/libs/gpu/build.zig.zon b/libs/gpu/build.zig.zon index f46a934b..0701c6fc 100644 --- a/libs/gpu/build.zig.zon +++ b/libs/gpu/build.zig.zon @@ -2,6 +2,10 @@ .name = "mach-gpu", .version = "0.2.0", .dependencies = .{ + .mach_glfw = .{ + .url = "https://github.com/hexops/mach-glfw/archive/98418ac4dc7d21ffbfebdee8045473fa2e35d528.tar.gz", + .hash = "1220d685dabe227073aa11a8b7bb9eecfc8cbe5a08e128c23c173c2baddf8da9258e", + }, .direct3d_headers = .{ .url = "https://github.com/hexops/direct3d-headers/archive/773dce3f079eecdccc7c71d1318a0741649d568b.tar.gz", .hash = "12200d2155216c5eb5f111282cd355b5433cad6a68fd040294e695149cba329f7c12",