feat: add RAYLIB_PLATFORM env var for cross-platform targeting#15
feat: add RAYLIB_PLATFORM env var for cross-platform targeting#15tonyfettes wants to merge 4 commits intomainfrom
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b8ae2e54e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
6b8ae2e to
1e4ae83
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 68e6a2669b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
build.js
Outdated
| } else if (platform === 'web') { | ||
| // Emscripten handles linking; no link_libs needed | ||
| stub_cc_flags = '-DPLATFORM_WEB'; |
There was a problem hiding this comment.
Enable Emscripten GLFW shim for web target
When RAYLIB_PLATFORM=web, this branch emits no link flags, but rglfw.c is now compiled out unless PLATFORM_DESKTOP_GLFW is defined, so the glfw* symbols used by internal/raylib/platforms/rcore_web.c must come from Emscripten’s GLFW port. The repository’s own web build script (tools/build_web_native_emcc.sh) passes -sUSE_GLFW=3 for this reason; without emitting an equivalent flag here, builds that rely on build.js config will hit unresolved GLFW symbols at link time.
Useful? React with 👍 / 👎.
build.js
Outdated
| stub_cc_flags = '-DPLATFORM_DRM'; | ||
| } else if (platform === 'web') { | ||
| // Emscripten handles linking; no link_libs needed | ||
| stub_cc_flags = '-DPLATFORM_WEB'; |
There was a problem hiding this comment.
Define WebGL graphics API for web builds
This sets only -DPLATFORM_WEB, but rlgl.h defaults to GRAPHICS_API_OPENGL_33 when no graphics API macro is provided, which drives the desktop GL path instead of WebGL/ES2. The repo’s validated web pipeline (tools/build_web_native_emcc.sh) explicitly adds -DGRAPHICS_API_OPENGL_ES2; without that define here, the new web platform mode can compile/link against the wrong GL backend and fail at runtime or during compilation depending on toolchain settings.
Useful? React with 👍 / 👎.
68e6a26 to
eb69d02
Compare
…eting Allow overriding the target platform via RAYLIB_PLATFORM env var instead of always auto-detecting from os.platform(). Adds support for android, drm, and web platforms with appropriate link_libs and stub_cc_flags. Guards rglfw.c body with #if defined(PLATFORM_DESKTOP_GLFW) so it compiles to nothing on non-GLFW platforms (android/drm/web), preventing link errors when GLFW sources are absent. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
eb69d02 to
bdfb27f
Compare
There was a problem hiding this comment.
Pull request overview
Adds an override (RAYLIB_PLATFORM) to the prebuild/link configuration so the raylib native build can target non-host platforms (and avoids compiling bundled GLFW sources when GLFW isn’t the selected backend).
Changes:
- Allow overriding
os.platform()detection viaprocess.env.RAYLIB_PLATFORMinbuild.js. - Add
android,drm, andwebplatform branches with updated link libraries and stub compile flags. - Wrap all of
internal/raylib/rglfw.cin#if defined(PLATFORM_DESKTOP_GLFW)to compile it out on non-GLFW platforms.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| build.js | Adds RAYLIB_PLATFORM override and new platform branches for link/stub flags. |
| internal/raylib/rglfw.c | Compiles bundled GLFW aggregator only when PLATFORM_DESKTOP_GLFW is defined. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Without this flag, rlgl.h defaults to GRAPHICS_API_OPENGL_33 (desktop OpenGL), which is incorrect for these platforms that require OpenGL ES. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else if (platform === 'android') { | ||
| link_config.link_libs = ['log', 'android', 'OpenSLES', 'EGL', 'GLESv2', 'm', 'dl']; | ||
| stub_cc_flags = '-DPLATFORM_ANDROID -DGRAPHICS_API_OPENGL_ES2'; | ||
| } else if (platform === 'drm') { | ||
| link_config.link_libs = ['drm', 'gbm', 'EGL', 'GLESv2', 'm', 'pthread', 'dl', 'rt']; | ||
| stub_cc_flags = '-DPLATFORM_DRM -DGRAPHICS_API_OPENGL_ES2'; | ||
| } else if (platform === 'web') { | ||
| // Emscripten handles linking; no link_libs needed | ||
| stub_cc_flags = '-DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2'; |
There was a problem hiding this comment.
For the new non-desktop branches, stub_cc_flags is reassigned (dropping -DPLATFORM_DESKTOP_GLFW). That matches the intent here, but it makes existing repo documentation inaccurate (e.g. CLAUDE.md says stub-cc-flags always includes -DPLATFORM_DESKTOP_GLFW). Please update the docs to reflect the new platform-dependent behavior so contributors don’t rely on the old invariant.
…forms The previous description said stub-cc-flags always includes -DPLATFORM_DESKTOP_GLFW, which is no longer true after adding android, drm, and web platform support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
RAYLIB_PLATFORMenv var tobuild.jsso the target platform can be overridden instead of always auto-detecting fromos.platform()if/elsechain withandroid,drm, andwebbranches with correct link libs andstub_cc_flagsinternal/raylib/rglfw.cwith#if defined(PLATFORM_DESKTOP_GLFW)so it compiles to nothing on non-GLFW platforms, preventing errors when GLFW sources are unavailableSupported
RAYLIB_PLATFORMvaluesdarwinPLATFORM_DESKTOP_GLFWlinuxPLATFORM_DESKTOP_GLFWwin32PLATFORM_DESKTOP_GLFWandroidPLATFORM_ANDROIDdrmPLATFORM_DRMwebPLATFORM_WEBos.platform()Test plan
node build.js— auto-detect macOS, output unchanged (-DPLATFORM_DESKTOP_GLFW -ObjC)RAYLIB_PLATFORM=linux node build.js— correct GL/X11 libsRAYLIB_PLATFORM=android node build.js— correct NDK libs,-DPLATFORM_ANDROIDRAYLIB_PLATFORM=drm node build.js— correct DRM/EGL libs,-DPLATFORM_DRMRAYLIB_PLATFORM=web node build.js— no link_libs,-DPLATFORM_WEBRAYLIB_PLATFORM=freebsd node build.js— throwsUnsupported platformerrormoon -C examples build --target native raylib_demo/— builds successfully on macOS🤖 Generated with Claude Code