Skip to content

Commit

Permalink
update to Zig 2024.1.0-mach
Browse files Browse the repository at this point in the history
helps hexops/mach#1135

Signed-off-by: Stephen Gutekanst <[email protected]>
  • Loading branch information
slimsag committed Jan 13, 2024
1 parent 52a8e8e commit 139a01a
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,35 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
},
});

lib.addIncludePath(.{ .path = "include" });
lib.linkLibC();

if (shared) {
lib.defineCMacro("_GLFW_BUILD_DLL", "1");
}
if (shared) lib.defineCMacro("_GLFW_BUILD_DLL", "1");

lib.installHeadersDirectory("include/GLFW", "GLFW");
// GLFW headers depend on these headers, so they must be distributed too.
const vulkan_headers_dep = b.dependency("vulkan_headers", .{
.target = target,
.optimize = optimize,
});
lib.installLibraryHeaders(vulkan_headers_dep.artifact("vulkan-headers"));
if (target.result.os.tag == .linux) {
const x11_headers_dep = b.dependency("x11_headers", .{
.target = target,
.optimize = optimize,
});
const wayland_headers_dep = b.dependency("wayland_headers", .{
.target = target,
.optimize = optimize,
});
lib.linkLibrary(x11_headers_dep.artifact("x11-headers"));
lib.linkLibrary(wayland_headers_dep.artifact("wayland-headers"));
lib.installLibraryHeaders(x11_headers_dep.artifact("x11-headers"));
lib.installLibraryHeaders(wayland_headers_dep.artifact("wayland-headers"));
}

link(b, lib);

if (target.result.os.tag == .macos) {
if (target.result.isDarwin()) {
// MacOS: this must be defined for macOS 13.3 and older.
// Critically, this MUST NOT be included as a -D__kernel_ptr_semantics flag. If it is,
// then this macro will not be defined even if `defineCMacro` was also called!
lib.defineCMacro("__kernel_ptr_semantics", "");
@import("xcode_frameworks").addPaths(lib);
}
Expand Down Expand Up @@ -137,24 +151,14 @@ pub fn build(b: *std.Build) void {
}

pub fn link(b: *std.Build, step: *std.Build.Step.Compile) void {
step.addIncludePath(.{ .path = sdkPath("/include") });
if (step.rootModuleTarget().isDarwin()) @import("xcode_frameworks").addPaths(step);
const target_triple: []const u8 = step.rootModuleTarget().zigTriple(b.allocator) catch @panic("OOM");
const cpu_opts: []const u8 = step.root_module.resolved_target.?.query.serializeCpuAlloc(b.allocator) catch @panic("OOM");
step.linkLibrary(b.dependency("vulkan_headers", .{
.target = target_triple,
.cpu = cpu_opts,
.optimize = step.root_module.optimize.?,
}).artifact("vulkan-headers"));
step.linkLibrary(b.dependency("x11_headers", .{
.target = target_triple,
.optimize = step.root_module.optimize.?,
}).artifact("x11-headers"));
step.linkLibrary(b.dependency("wayland_headers", .{
.target = target_triple,
.cpu = cpu_opts,
.optimize = step.root_module.optimize.?,
}).artifact("wayland-headers"));
_ = b;
_ = step;

@panic(".link(b, step) has been replaced by .addPaths(step)");
}

pub fn addPaths(step: *std.Build.Step.Compile) void {
@import("xcode_frameworks").addPaths(step);
}

const base_sources = [_][]const u8{
Expand Down

0 comments on commit 139a01a

Please sign in to comment.