glfw: workaround cImport self-hosted compiler bug ziglang/zig#12784
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
9755a609c4
commit
73efe2f5cb
5 changed files with 65948 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -16,3 +16,4 @@ zig-out/
|
|||
/build/
|
||||
/build-*/
|
||||
/docgen_tmp/
|
||||
src/c_native.zig
|
||||
|
|
13
build.zig
13
build.zig
|
@ -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);
|
||||
|
|
65917
src/cimport/c_darwin_native.zig
Normal file
65917
src/cimport/c_darwin_native.zig
Normal file
File diff suppressed because it is too large
Load diff
16
src/cimport/c_normal_native.zig
Normal file
16
src/cimport/c_normal_native.zig
Normal file
|
@ -0,0 +1,16 @@
|
|||
pub fn import(comptime options: anytype) type {
|
||||
return @cImport({
|
||||
@cDefine("GLFW_INCLUDE_VULKAN", "1");
|
||||
@cInclude("GLFW/glfw3.h");
|
||||
if (options.win32) @cDefine("GLFW_EXPOSE_NATIVE_WIN32", "1");
|
||||
if (options.wgl) @cDefine("GLFW_EXPOSE_NATIVE_WGL", "1");
|
||||
if (options.cocoa) @cDefine("GLFW_EXPOSE_NATIVE_COCOA", "1");
|
||||
if (options.nsgl) @cDefine("GLFW_EXPOSE_NATIVE_NGSL", "1");
|
||||
if (options.x11) @cDefine("GLFW_EXPOSE_NATIVE_X11", "1");
|
||||
if (options.glx) @cDefine("GLFW_EXPOSE_NATIVE_GLX", "1");
|
||||
if (options.wayland) @cDefine("GLFW_EXPOSE_NATIVE_WAYLAND", "1");
|
||||
if (options.egl) @cDefine("GLFW_EXPOSE_NATIVE_EGL", "1");
|
||||
if (options.osmesa) @cDefine("GLFW_EXPOSE_NATIVE_OSMESA", "1");
|
||||
@cInclude("GLFW/glfw3native.h");
|
||||
});
|
||||
}
|
|
@ -40,21 +40,7 @@ pub const BackendOptions = struct {
|
|||
/// The chosen backends must match those the library was compiled for. Failure to do so
|
||||
/// will cause a link-time error.
|
||||
pub fn Native(comptime options: BackendOptions) type {
|
||||
const native = @cImport({
|
||||
@cDefine("GLFW_INCLUDE_VULKAN", "1");
|
||||
@cInclude("GLFW/glfw3.h");
|
||||
|
||||
if (options.win32) @cDefine("GLFW_EXPOSE_NATIVE_WIN32", "1");
|
||||
if (options.wgl) @cDefine("GLFW_EXPOSE_NATIVE_WGL", "1");
|
||||
if (options.cocoa) @cDefine("GLFW_EXPOSE_NATIVE_COCOA", "1");
|
||||
if (options.nsgl) @cDefine("GLFW_EXPOSE_NATIVE_NGSL", "1");
|
||||
if (options.x11) @cDefine("GLFW_EXPOSE_NATIVE_X11", "1");
|
||||
if (options.glx) @cDefine("GLFW_EXPOSE_NATIVE_GLX", "1");
|
||||
if (options.wayland) @cDefine("GLFW_EXPOSE_NATIVE_WAYLAND", "1");
|
||||
if (options.egl) @cDefine("GLFW_EXPOSE_NATIVE_EGL", "1");
|
||||
if (options.osmesa) @cDefine("GLFW_EXPOSE_NATIVE_OSMESA", "1");
|
||||
@cInclude("GLFW/glfw3native.h");
|
||||
});
|
||||
const native = @import("c_native.zig").import(options);
|
||||
|
||||
return struct {
|
||||
/// Returns the adapter device name of the specified monitor.
|
||||
|
|
Loading…
Add table
Reference in a new issue