glfw: workaround cImport self-hosted compiler bug ziglang/zig#12784

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-09-08 07:19:36 -07:00
parent 06b0609ada
commit 98860a67fa
5 changed files with 65948 additions and 15 deletions

View file

@ -1,3 +1,4 @@
const builtin = @import("builtin");
const std = @import("std");
const Builder = std.build.Builder;
@ -68,7 +69,19 @@ pub const pkg = std.build.Pkg{
.source = .{ .path = thisDir() ++ "/src/main.zig" },
};
// TODO(self-hosted): HACK: workaround https://github.com/ziglang/zig/issues/12784
//
// Extracted from a build using stage1 from zig-cache/ (`cimport/c_darwin_native.zig`)
// Then find+replace `= ?fn` -> `= ?*const fn`
fn cimportWorkaround() void {
const dest_dir = std.fs.cwd().openDir(thisDir() ++ "/src", .{}) catch unreachable;
const cn_path = thisDir() ++ "/src/cimport/" ++ if (builtin.os.tag == .macos) "c_darwin_native.zig" else "c_normal_native.zig";
std.fs.cwd().copyFile(cn_path, dest_dir, thisDir() ++ "/src/c_native.zig", .{}) catch unreachable;
}
pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
cimportWorkaround();
const lib = buildLibrary(b, step.build_mode, step.target, options);
step.linkLibrary(lib);
addGLFWIncludes(step);