diff --git a/libs/glfw/build.zig b/libs/glfw/build.zig index e9453bf5..6b450174 100644 --- a/libs/glfw/build.zig +++ b/libs/glfw/build.zig @@ -77,21 +77,23 @@ pub fn module(b: *std.Build) *std.build.Module { return _module.?; } -pub const LinkError = error{FailedToLinkGPU} || BuildError; -pub fn link(b: *Build, step: *std.build.CompileStep, options: Options) LinkError!void { +pub fn link(b: *Build, step: *std.build.CompileStep, options: Options) !void { + if (options.shared) step.defineCMacro("GLFW_DLL", null); const lib = try buildLibrary(b, step.optimize, step.target, options); step.linkLibrary(lib); addGLFWIncludes(step); - if (options.shared) { - step.defineCMacro("GLFW_DLL", null); - system_sdk.include(b, step, options.system_sdk); - } else { - linkGLFWDependencies(b, step, options); + linkGLFWDependencies(b, step, options); + if (step.target_info.target.os.tag != .windows) system_sdk.include(b, step, options.system_sdk); + if (step.target_info.target.os.tag == .windows) { + step.linkLibrary(b.dependency("direct3d_headers", .{ + .target = step.target, + .optimize = step.optimize, + }).artifact("direct3d-headers")); + @import("direct3d_headers").addLibraryPath(step); } } -pub const BuildError = error{CannotEnsureDependency} || std.mem.Allocator.Error; -fn buildLibrary(b: *Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget, options: Options) BuildError!*std.build.CompileStep { +fn buildLibrary(b: *Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget, options: Options) !*std.build.CompileStep { // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 ensureDependencySubmodule(b.allocator, "upstream") catch return error.CannotEnsureDependency; @@ -161,7 +163,7 @@ fn addGLFWSources(b: *Build, lib: *std.build.CompileStep, options: Options) std. fn linkGLFWDependencies(b: *Build, step: *std.build.CompileStep, options: Options) void { step.linkLibC(); - system_sdk.include(b, step, options.system_sdk); + if (step.target_info.target.os.tag != .windows) system_sdk.include(b, step, options.system_sdk); switch (step.target_info.target.os.tag) { .windows => { step.linkSystemLibraryName("gdi32"); diff --git a/libs/glfw/build.zig.zon b/libs/glfw/build.zig.zon new file mode 100644 index 00000000..3a84c492 --- /dev/null +++ b/libs/glfw/build.zig.zon @@ -0,0 +1,10 @@ +.{ + .name = "mach-glfw", + .version = "0.2.0", + .dependencies = .{ + .direct3d_headers = .{ + .url = "https://github.com/hexops/direct3d-headers/archive/773dce3f079eecdccc7c71d1318a0741649d568b.tar.gz", + .hash = "12200d2155216c5eb5f111282cd355b5433cad6a68fd040294e695149cba329f7c12", + }, + }, +}