glfw: use package manager for direct3d-headers

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-07-03 07:03:57 -07:00
parent 70ff87ba8a
commit 4c7824fc75
2 changed files with 22 additions and 10 deletions

View file

@ -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");

10
build.zig.zon Normal file
View file

@ -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",
},
},
}