diff --git a/glfw/src/Monitor.zig b/glfw/src/Monitor.zig index 934a3580..a9e7e270 100644 --- a/glfw/src/Monitor.zig +++ b/glfw/src/Monitor.zig @@ -3,7 +3,7 @@ const std = @import("std"); const mem = std.mem; const testing = std.testing; -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; pub const Error = @import("errors.zig").Error; const getError = @import("errors.zig").getError; diff --git a/glfw/src/VideoMode.zig b/glfw/src/VideoMode.zig index f7e46c1c..c4176e88 100644 --- a/glfw/src/VideoMode.zig +++ b/glfw/src/VideoMode.zig @@ -5,7 +5,7 @@ const std = @import("std"); const mem = std.mem; const testing = std.testing; -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; pub const Error = @import("errors.zig").Error; const getError = @import("errors.zig").getError; diff --git a/glfw/src/action.zig b/glfw/src/action.zig index 80af85a3..a183156b 100644 --- a/glfw/src/action.zig +++ b/glfw/src/action.zig @@ -1,6 +1,6 @@ //! Key and button actions -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; /// The key or mouse button was released. pub const release = C.GLFW_RELEASE; diff --git a/glfw/src/c.zig b/glfw/src/c.zig new file mode 100644 index 00000000..9fd080ab --- /dev/null +++ b/glfw/src/c.zig @@ -0,0 +1,18 @@ +//! The GLFW C import +//! +//! This is declared centrally in this module and imported in all usage locations, as otherwise +//! the underlying C import would be generated multiple times and e.g. struct types would be +//! incompatible, e.g.: +//! +//! ``` +//! ./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] }; +//! ^ +//! ./zig-cache/o/07cfe6253b7dceb60e4bf24e3426d444/cimport.zig:783:32: note: .cimport:8:11.struct_GLFWvidmode declared here +//! 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(@cInclude("GLFW/glfw3.h")); \ No newline at end of file diff --git a/glfw/src/consts.zig b/glfw/src/consts.zig index cea1ec8b..49bae0d7 100644 --- a/glfw/src/consts.zig +++ b/glfw/src/consts.zig @@ -1,6 +1,6 @@ //! General constants -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; // Input focus window hint and attribute diff --git a/glfw/src/errors.zig b/glfw/src/errors.zig index 240133ff..72750dd2 100644 --- a/glfw/src/errors.zig +++ b/glfw/src/errors.zig @@ -1,6 +1,6 @@ //! Errors -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; /// Errors that GLFW can produce. pub const Error = error{ diff --git a/glfw/src/gamepad_axis.zig b/glfw/src/gamepad_axis.zig index f3ed379d..a66d6647 100644 --- a/glfw/src/gamepad_axis.zig +++ b/glfw/src/gamepad_axis.zig @@ -2,7 +2,7 @@ //! //! See glfw.getGamepadState for how these are used. -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; pub const left_x = C.GLFW_GAMEPAD_AXIS_LEFT_X; pub const left_y = C.GLFW_GAMEPAD_AXIS_LEFT_Y; diff --git a/glfw/src/gamepad_button.zig b/glfw/src/gamepad_button.zig index 09c54d51..c0d8a0f7 100644 --- a/glfw/src/gamepad_button.zig +++ b/glfw/src/gamepad_button.zig @@ -2,7 +2,7 @@ //! //! See glfw.getGamepadState for how these are used. -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; pub const a = C.GLFW_GAMEPAD_BUTTON_A; pub const b = C.GLFW_GAMEPAD_BUTTON_B; diff --git a/glfw/src/hat.zig b/glfw/src/hat.zig index bb555336..586cfa6e 100644 --- a/glfw/src/hat.zig +++ b/glfw/src/hat.zig @@ -2,7 +2,7 @@ //! //! See glfw.getJoystickHats for how these are used. -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; pub const centered = C.GLFW_HAT_CENTERED; pub const up = C.GLFW_HAT_UP; diff --git a/glfw/src/joystick.zig b/glfw/src/joystick.zig index 639bf030..abf1feb0 100644 --- a/glfw/src/joystick.zig +++ b/glfw/src/joystick.zig @@ -2,7 +2,7 @@ //! //! See glfw.setJoystickCallback for how these are used. -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; pub const one = C.GLFW_JOYSTICK_1; pub const two = C.GLFW_JOYSTICK_2; diff --git a/glfw/src/main.zig b/glfw/src/main.zig index 0ab6aa2d..daa464ec 100644 --- a/glfw/src/main.zig +++ b/glfw/src/main.zig @@ -1,7 +1,7 @@ const std = @import("std"); const testing = std.testing; -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; pub usingnamespace @import("consts.zig"); pub const Error = @import("errors.zig").Error; diff --git a/glfw/src/mod.zig b/glfw/src/mod.zig index c6482734..19c9b6a2 100644 --- a/glfw/src/mod.zig +++ b/glfw/src/mod.zig @@ -2,7 +2,7 @@ //! //! See glfw.setKeyCallback for how these are used. -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; /// If this bit is set one or more Shift keys were held down. pub const shift = C.GLFW_MOD_SHIFT; diff --git a/glfw/src/mouse_button.zig b/glfw/src/mouse_button.zig index 904726aa..8ef60cd5 100644 --- a/glfw/src/mouse_button.zig +++ b/glfw/src/mouse_button.zig @@ -2,7 +2,7 @@ //! //! See glfw.setMouseButtonCallback for how these are used. -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; pub const one = C.GLFW_MOUSE_BUTTON_1; pub const two = C.GLFW_MOUSE_BUTTON_2; diff --git a/glfw/src/version.zig b/glfw/src/version.zig index 61e9eb69..e83a4d70 100644 --- a/glfw/src/version.zig +++ b/glfw/src/version.zig @@ -1,6 +1,6 @@ //! GLFW version info -const c = @cImport(@cInclude("GLFW/glfw3.h")); +const c = @import("c.zig").c; /// The major version number of the GLFW library. ///