Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] build.zig, cannot change desktop platform backend for Linux #4457

Open
Ar1gin opened this issue Nov 1, 2024 · 7 comments
Open

[build] build.zig, cannot change desktop platform backend for Linux #4457

Ar1gin opened this issue Nov 1, 2024 · 7 comments

Comments

@Ar1gin
Copy link

Ar1gin commented Nov 1, 2024

Issue description

It's impossible to choose any backend other than GLFW if building with zig.

PLATFORM_DESKTOP is set together with the platform backend you chose (PLATFORM_DESKTOP_SDL in my case)

raylib/build.zig

Lines 44 to 53 in 9e2591e

fn setDesktopPlatform(raylib: *std.Build.Step.Compile, platform: PlatformBackend) void {
raylib.defineCMacro("PLATFORM_DESKTOP", null);
switch (platform) {
.glfw => raylib.defineCMacro("PLATFORM_DESKTOP_GLFW", null),
.rgfw => raylib.defineCMacro("PLATFORM_DESKTOP_RGFW", null),
.sdl => raylib.defineCMacro("PLATFORM_DESKTOP_SDL", null),
else => {},
}
}

PLATFORM_DESKTOP defaults to PLATFORM_DESKTOP_GLFW.
Then, platforms/rcore_desktop_glfw.c gets included without any regard to the backend choice.

raylib/src/rcore.c

Lines 511 to 519 in 9e2591e

#if defined(PLATFORM_DESKTOP)
#define PLATFORM_DESKTOP_GLFW
#endif
// Include platform-specific submodules
#if defined(PLATFORM_DESKTOP_GLFW)
#include "platforms/rcore_desktop_glfw.c"
#elif defined(PLATFORM_DESKTOP_SDL)
#include "platforms/rcore_desktop_sdl.c"

Possible fix

I got it to work by doing following changes to build.zig:

  • remove raylib.defineCMacro("PLATFORM_DESKTOP", null); from setDesktopPlatform() (why was it there in the first place?)
  • add raylib.linkSystemLibrary("SDL2"); to compileRaylib() (SDL2 is not linked even with -Dplatform=sdl!)

Not opening a PR as I am unsure how to properly fix the problem.

Also, I may be missing something, I just need raylib to work with touchscreens (which are only supported by SDL backend) in my little zig project.

@wwderw
Copy link

wwderw commented Nov 1, 2024

My work around for linux and changing the backend (I use Angle), is to make changes to the make file (platform, gl version, and CC and AR) and run Make with Zig that way.

Just an option.

@raysan5
Copy link
Owner

raysan5 commented Nov 2, 2024

@Ar1gin Good catch! Reviewing it know!

EDIT: Checking the code, it seems you can just define PLATFORM_DESKTOP_* with desired desktop backend, instead of defining PLATFORM_DEKTOP and it should work.

EDIT 2: Ok, if I understand correctly, this is a build.zig issue, right?

@Ar1gin
Copy link
Author

Ar1gin commented Nov 3, 2024

EDIT 2: Ok, if I understand correctly, this is a build.zig issue, right?

Sure is. Looks like build.zig was written before other backends were added because it doesn't even link anything else other than GLFW libraries (Has to be fixed too), and judging by the code, the issue is not limited to Linux only.

@raysan5
Copy link
Owner

raysan5 commented Nov 3, 2024

@Ar1gin Thanks for the confirmation! Please note that some of the required libraries for some of the available Desktop backends are not included with raylib, so, it's up to the user to provide them or configure paths for those libraries. Here a summary:

  • GLFW: Included with raylib, compiled into a single module: rglfw
  • SDL: Not provided by raylib, must be provided by users, include paths and library for linkage
  • RGFW: Included with raylib, external library, single-file header-only: RGFW

@raysan5 raysan5 changed the title [build] Cannot change platform backend when building raylib with Zig for Linux [build] build.zig, cannot change desktop platform backend for Linux Nov 3, 2024
@jestarray
Copy link
Contributor

The cmake build has sdl support, -DPLATFORM=SDL. I use rust bindings and I toggle that on and link to sdl and it works

@Ar1gin
Copy link
Author

Ar1gin commented Nov 3, 2024

Thanks for your solution suggestions, but I need raylib to be built with build.zig because it's used as a dependency of another wrapper (https://github.com/Not-Nik/raylib-zig)

If build.zig is not gonna be fixed any time soon, I'll make a PR to fix it together with many other issues I've encountered with touch support 👍

@raysan5
Copy link
Owner

raysan5 commented Nov 3, 2024

@Ar1gin Feel free to send several PRs, but please, keep PRs focused on topics, do not mix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants