Skip to content

feat: add RAYLIB_PLATFORM env var for cross-platform targeting#15

Open
tonyfettes wants to merge 4 commits intomainfrom
worktree-build-js
Open

feat: add RAYLIB_PLATFORM env var for cross-platform targeting#15
tonyfettes wants to merge 4 commits intomainfrom
worktree-build-js

Conversation

@tonyfettes
Copy link
Collaborator

Summary

  • Adds RAYLIB_PLATFORM env var to build.js so the target platform can be overridden instead of always auto-detecting from os.platform()
  • Extends the platform if/else chain with android, drm, and web branches with correct link libs and stub_cc_flags
  • Guards the entire body of internal/raylib/rglfw.c with #if defined(PLATFORM_DESKTOP_GLFW) so it compiles to nothing on non-GLFW platforms, preventing errors when GLFW sources are unavailable

Supported RAYLIB_PLATFORM values

Value Raylib platform Backend
darwin PLATFORM_DESKTOP_GLFW GLFW + Cocoa
linux PLATFORM_DESKTOP_GLFW GLFW + X11
win32 PLATFORM_DESKTOP_GLFW GLFW + Win32
android PLATFORM_ANDROID Android NDK EGL/GLES
drm PLATFORM_DRM Linux DRM/KMS
web PLATFORM_WEB Emscripten
(unset) Auto-detect via os.platform()

Test plan

  • node build.js — auto-detect macOS, output unchanged (-DPLATFORM_DESKTOP_GLFW -ObjC)
  • RAYLIB_PLATFORM=linux node build.js — correct GL/X11 libs
  • RAYLIB_PLATFORM=android node build.js — correct NDK libs, -DPLATFORM_ANDROID
  • RAYLIB_PLATFORM=drm node build.js — correct DRM/EGL libs, -DPLATFORM_DRM
  • RAYLIB_PLATFORM=web node build.js — no link_libs, -DPLATFORM_WEB
  • RAYLIB_PLATFORM=freebsd node build.js — throws Unsupported platform error
  • moon -C examples build --target native raylib_demo/ — builds successfully on macOS

🤖 Generated with Claude Code

@tonyfettes
Copy link
Collaborator Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@tonyfettes
Copy link
Collaborator Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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
Comment on lines +26 to +28
} else if (platform === 'web') {
// Emscripten handles linking; no link_libs needed
stub_cc_flags = '-DPLATFORM_WEB';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

tonyfettes and others added 2 commits March 4, 2026 12:56
…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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via process.env.RAYLIB_PLATFORM in build.js.
  • Add android, drm, and web platform branches with updated link libraries and stub compile flags.
  • Wrap all of internal/raylib/rglfw.c in #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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +20 to +28
} 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';
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
…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>
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

Successfully merging this pull request may close these issues.

2 participants