glfw: pretranslate @cImport to workaround self-hosted compiler bug
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
eaf60a33d2
commit
569dd4b8d9
4 changed files with 80991 additions and 35 deletions
32
src/c.zig
32
src/c.zig
|
@ -1,21 +1,11 @@
|
||||||
//! The GLFW C import
|
pub const c = if (@import("builtin").zig_backend == .stage1)
|
||||||
//!
|
@cImport({
|
||||||
//! This is declared centrally in this module and imported in all usage locations, as otherwise
|
@cDefine("GLFW_INCLUDE_VULKAN", "1");
|
||||||
//! the underlying C import would be generated multiple times and e.g. struct types would be
|
@cInclude("GLFW/glfw3.h");
|
||||||
//! incompatible, e.g.:
|
})
|
||||||
//!
|
else
|
||||||
//! ```
|
// HACK: workaround https://github.com/ziglang/zig/issues/12483
|
||||||
//! ./src/Monitor.zig:207:46: error: expected type '.cimport:8:11.struct_GLFWvidmode', found '.cimport:6:11.struct_GLFWvidmode'
|
//
|
||||||
//! slice[i] = VideoMode{ .handle = modes[i] };
|
// Extracted from a build using stage1 from zig-cache/ (`cimport.zig`)
|
||||||
//! ^
|
// Then find+replace `= ?fn` -> `= ?*const fn`
|
||||||
//! ./zig-cache/o/07cfe6253b7dceb60e4bf24e3426d444/cimport.zig:783:32: note: .cimport:8:11.struct_GLFWvidmode declared here
|
@import("cimport2.zig");
|
||||||
//! pub const struct_GLFWvidmode = extern struct {
|
|
||||||
//! ^
|
|
||||||
//! ./zig-cache/o/07cfe6253b7dceb60e4bf24e3426d444/cimport.zig:783:32: note: .cimport:6:11.struct_GLFWvidmode declared here
|
|
||||||
//! pub const struct_GLFWvidmode = extern struct {
|
|
||||||
//! ^
|
|
||||||
//! ```
|
|
||||||
pub const c = @cImport({
|
|
||||||
@cDefine("GLFW_INCLUDE_VULKAN", "1");
|
|
||||||
@cInclude("GLFW/glfw3.h");
|
|
||||||
});
|
|
||||||
|
|
65914
src/cimport1.zig
Normal file
65914
src/cimport1.zig
Normal file
File diff suppressed because it is too large
Load diff
15045
src/cimport2.zig
Normal file
15045
src/cimport2.zig
Normal file
File diff suppressed because it is too large
Load diff
|
@ -40,21 +40,28 @@ pub const BackendOptions = struct {
|
||||||
/// The chosen backends must match those the library was compiled for. Failure to do so
|
/// The chosen backends must match those the library was compiled for. Failure to do so
|
||||||
/// will cause a link-time error.
|
/// will cause a link-time error.
|
||||||
pub fn Native(comptime options: BackendOptions) type {
|
pub fn Native(comptime options: BackendOptions) type {
|
||||||
const native = @cImport({
|
const native = if (@import("builtin").zig_backend == .stage1)
|
||||||
@cDefine("GLFW_INCLUDE_VULKAN", "1");
|
@cImport({
|
||||||
@cInclude("GLFW/glfw3.h");
|
@cDefine("GLFW_INCLUDE_VULKAN", "1");
|
||||||
|
@cInclude("GLFW/glfw3.h");
|
||||||
|
|
||||||
if (options.win32) @cDefine("GLFW_EXPOSE_NATIVE_WIN32", "1");
|
if (options.win32) @cDefine("GLFW_EXPOSE_NATIVE_WIN32", "1");
|
||||||
if (options.wgl) @cDefine("GLFW_EXPOSE_NATIVE_WGL", "1");
|
if (options.wgl) @cDefine("GLFW_EXPOSE_NATIVE_WGL", "1");
|
||||||
if (options.cocoa) @cDefine("GLFW_EXPOSE_NATIVE_COCOA", "1");
|
if (options.cocoa) @cDefine("GLFW_EXPOSE_NATIVE_COCOA", "1");
|
||||||
if (options.nsgl) @cDefine("GLFW_EXPOSE_NATIVE_NGSL", "1");
|
if (options.nsgl) @cDefine("GLFW_EXPOSE_NATIVE_NGSL", "1");
|
||||||
if (options.x11) @cDefine("GLFW_EXPOSE_NATIVE_X11", "1");
|
if (options.x11) @cDefine("GLFW_EXPOSE_NATIVE_X11", "1");
|
||||||
if (options.glx) @cDefine("GLFW_EXPOSE_NATIVE_GLX", "1");
|
if (options.glx) @cDefine("GLFW_EXPOSE_NATIVE_GLX", "1");
|
||||||
if (options.wayland) @cDefine("GLFW_EXPOSE_NATIVE_WAYLAND", "1");
|
if (options.wayland) @cDefine("GLFW_EXPOSE_NATIVE_WAYLAND", "1");
|
||||||
if (options.egl) @cDefine("GLFW_EXPOSE_NATIVE_EGL", "1");
|
if (options.egl) @cDefine("GLFW_EXPOSE_NATIVE_EGL", "1");
|
||||||
if (options.osmesa) @cDefine("GLFW_EXPOSE_NATIVE_OSMESA", "1");
|
if (options.osmesa) @cDefine("GLFW_EXPOSE_NATIVE_OSMESA", "1");
|
||||||
@cInclude("GLFW/glfw3native.h");
|
@cInclude("GLFW/glfw3native.h");
|
||||||
});
|
})
|
||||||
|
else
|
||||||
|
// HACK: workaround https://github.com/ziglang/zig/issues/12483
|
||||||
|
//
|
||||||
|
// Extracted from a build using stage1 from zig-cache/ (`cimport.zig`)
|
||||||
|
// Then find+replace `= ?fn` -> `= ?*const fn`
|
||||||
|
@import("cimport1.zig");
|
||||||
|
|
||||||
return struct {
|
return struct {
|
||||||
/// Returns the adapter device name of the specified monitor.
|
/// Returns the adapter device name of the specified monitor.
|
||||||
|
|
Loading…
Add table
Reference in a new issue