Not-Nik / raylib-zig

Manually tweaked, auto-generated raylib bindings for zig. https://github.com/raysan5/raylib
MIT License
517 stars 102 forks source link

Building examples on windows #8

Closed anaanook closed 2 years ago

anaanook commented 3 years ago

I'm sure I'm just doing something wrong in the set up but something is going wrong when its pulling in the raylib module and compiling it. Here's an excerpt:

This is from just cloning the repo and following the 'getting started' steps to build the examples

attempting to fetch submodule(s)...
error(compilation): clang failed with stderr: In file included from C:\TSHEngine\Zig\raylib-zig\raylib\src\rglfw.c:54:
In file included from C:\folder\raylib-zig\raylib\src/external/glfw/src/context.c:30:
In file included from C:\folder\raylib-zig\raylib\src/external/glfw/src/internal.h:186:
In file included from C:\folder\raylib-zig\raylib\src/external/glfw/src/win32_platform.h:70:
C:\folder\raylib-zig\raylib\src\external\glfw\deps\mingw\xinput.h:227:26: error: a parameter list without types is only allowed in a function definition
In file included from C:\folder\raylib-zig\raylib\src\rglfw.c:54:
C:\folder\raylib-zig\raylib\src/external/glfw/src/context.c:407:10: warning: 'sscanf' is deprecated: This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]
anaanook commented 3 years ago

Just for the record, I am able to get things working by manually building and linking raylib, but it would seem that something isn't quite functioning with the automated build.

Not-Nik commented 3 years ago

I don't have a Windows system to test and debug this, but from what I can see this seems to be a zig cc error. Can you try creating a zig build script only for GLFW? If the issue persists when only building that, please create an issue over in the zig repo.

anaanook commented 3 years ago

Hey I've got an update here.. so as it turns out the reason its not working is that the default target on windows is set to "-target native-native-msvc". If you set the target to "-target native-native-gnu" it builds just fine. Here's what I added to the build file, I'm still pretty green with this stuff... so forgive me if there's a better way of setting this up:

pub fn build(b: *Builder) void {
    const mode = b.standardReleaseOptions();
    const target = b.standardTargetOptions(.{.default_target = .{ .abi=.gnu}});

and then down in the examples

    for (examples) |ex| {
        const exe = b.addExecutable(ex.name, ex.path);
        exe.setBuildMode(mode);
        exe.setTarget(target);

I got the idea from this suggestion: https://github.com/ziglang/zig/issues/6565 , apparently this default target causes other issues too.

andrewrk commented 3 years ago

https://github.com/ziglang/zig/issues/6565 is solved now; the workaround will not be necessary in the upcoming 0.8.0 release.