Skip to content

Add support for Wasm/emscripten target#27

Open
radoslawg wants to merge 1 commit into
ewpratten:masterfrom
radoslawg:wasm-support
Open

Add support for Wasm/emscripten target#27
radoslawg wants to merge 1 commit into
ewpratten:masterfrom
radoslawg:wasm-support

Conversation

@radoslawg
Copy link
Copy Markdown

Added support for emscripten to build raylib for wasm target

emsdk needs to be setup correctly i.e.

emsdk install latest
emsdk activate latest
source "/usr/lib/emsdk/emsdk_env.sh"

or simillar.
Then building with cargo build --target wasm32-unknown-emscripten works and generates correct bindings.

Also, updated bindgen as I suspected some errors were because of it - didn't hurt - it turned out to be clang issue.

Copilot AI review requested due to automatic review settings April 6, 2026 20:22
@radoslawg radoslawg requested a review from ewpratten as a code owner April 6, 2026 20:22
Copy link
Copy Markdown

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 initial support for building the raylib-ffi crate against the wasm32-unknown-emscripten target by adjusting the CMake configuration and bindgen/clang invocation.

Changes:

  • Bump bindgen build-dependency version.
  • Set raylib CMake PLATFORM=Web when targeting Emscripten.
  • Add an Emscripten-specific bindgen clang argument (-fvisibility=default).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Cargo.toml Updates bindgen build dependency version.
build/bind.rs Adds Emscripten target detection and adjusts CMake + bindgen configuration accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread build/bind.rs
Comment on lines 81 to 85
if cfg!(feature = "dylib") {
println!("cargo:rustc-link-lib=dylib=raylib");
}
else {
} else {
println!("cargo:rustc-link-lib=static=raylib");
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

link_libs() uses cfg!(windows), cfg!(target_os = "macos"), and cfg!(unix) to decide which system libraries to link. In a build script those cfg! values reflect the host (where the build script runs), not the Cargo target. When building wasm32-unknown-emscripten from a Unix host this will still emit -lX11/etc, which should not be linked for Emscripten and can break the build. Use CARGO_CFG_TARGET_OS (and/or CARGO_CFG_TARGET_ENV) to branch on the target and add an emscripten path that avoids the desktop-only link directives.

Copilot uses AI. Check for mistakes.
Comment thread build/bind.rs
Comment on lines +17 to +21
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();

if target_os == "emscripten" {
cmake_config.define("PLATFORM", "Web");
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The new Emscripten-specific behavior is introduced here, but the repo CI currently only builds/tests native targets (Linux/Windows/macOS). Without a CI job that at least runs cargo build --target wasm32-unknown-emscripten (with emsdk installed), regressions to the Web path are likely to go unnoticed.

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