Skip to content

Fix libopenmpt WASM builds: STATIC_LIB=1 and tarball vendor#263

Merged
ford442 merged 1 commit into
mainfrom
cursor/fix-libopenmpt-wasm-build-3043
Jun 12, 2026
Merged

Fix libopenmpt WASM builds: STATIC_LIB=1 and tarball vendor#263
ford442 merged 1 commit into
mainfrom
cursor/fix-libopenmpt-wasm-build-3043

Conversation

@ford442

@ford442 ford442 commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Problem

WASM builds failed at the libopenmpt stage with:

❌ libopenmpt headers or static library still missing after build.

Root causes:

  1. No static library — OpenMPT's config-emscripten.mk sets STATIC_LIB=0, so make CONFIG=emscripten builds shared .js outputs but not bin/libopenmpt.a, which emcc -lopenmpt requires.
  2. Broken git vendor tree — incomplete vendor/libopenmpt checkouts had no usable headers/libs.
  3. Wrong tarball directory (build:worklet) — libopenmpt-0.8.4+release.makefile.tar.gz extracts to libopenmpt-0.8.4+release/.

Fix

  • Build with STATIC_LIB=1 SHARED_LIB=0 and target bin/libopenmpt.a explicitly
  • scripts/build-wasm.sh downloads the 0.8.4 release tarball to vendor/libopenmpt-0.8.4+release
  • Auto-removes broken vendor/libopenmpt legacy trees
  • Clearer errors for missing headers vs missing .a
  • Same STATIC_LIB=1 fix applied to root build-wasm.sh

How to verify

source /path/to/emsdk/emsdk_env.sh
rm -rf vendor/libopenmpt vendor/libopenmpt-0.8.4+release
npm run build:emcc
npm run build:worklet
Open in Web Open in Cursor 

Summary by CodeRabbit

  • Chores
    • Improved WebAssembly build process with enhanced dependency acquisition and static library configuration.
    • Strengthened build failure diagnostics and error reporting for better troubleshooting.

OpenMPT's emscripten config sets STATIC_LIB=0, so make produced shared
.js artifacts but never bin/libopenmpt.a. scripts/build-wasm.sh then
failed path resolution even when headers were present.

- Force STATIC_LIB=1 and build bin/libopenmpt.a explicitly
- Switch scripts/build-wasm.sh to the 0.8.4 release tarball (not git clone)
- Remove/replace broken vendor/libopenmpt trees automatically
- Improve missing-header vs missing-lib diagnostics
- Apply the same STATIC_LIB fix to root build-wasm.sh

Co-authored-by: Noah Cohn <noahc42@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8d711db5-c87c-4b24-b77b-1fde9a6dab6a

📥 Commits

Reviewing files that changed from the base of the PR and between 19db117 and 57e1ba5.

📒 Files selected for processing (2)
  • build-wasm.sh
  • scripts/build-wasm.sh

📝 Walkthrough

Walkthrough

This PR refactors the libopenmpt acquisition strategy for Emscripten builds from GitHub cloning to a vendored, version-pinned tarball download approach. It introduces environment and make-flag standardization, new validation and download helpers, configurable override support, and centralizes failure diagnostics.

Changes

Libopenmpt Emscripten Build Refactor

Layer / File(s) Summary
Vendor configuration and acquisition infrastructure
scripts/build-wasm.sh
Updated documentation, expanded Emscripten sourcing to include /opt/emsdk/emsdk_env.sh, vendor directory and version pinning under vendor/, standardized make flags with STATIC_LIB=1, SHARED_LIB=0, DYNLINK=0, and example disabling. New helpers: is_valid_openmpt_source() validates OpenMPT source trees, download_libopenmpt_tarball() acquires and extracts the pinned tarball from lib.openmpt.org with error exits, and find_libopenmpt_lib_dir() enhanced for static library discovery.
Build orchestration and invocation harmonization
scripts/build-wasm.sh, build-wasm.sh
Refactored ensure_libopenmpt() orchestrates: attempt path resolution first, prefer valid external LIBOPENMPT_DIR override, otherwise validate and remove incomplete vendor/legacy trees before downloading the pinned tarball, build bin/libopenmpt.a in-place via build_libopenmpt_in_place() when missing, centralize post-failure diagnostics in report_libopenmpt_failure(). Updated build-wasm.sh make invocation with matching static-library configuration flags instead of minimal CONFIG=emscripten baseline.

Sequence Diagram(s)

sequenceDiagram
  participant Build as build-wasm.sh<br/>entry point
  participant Ensure as ensure_libopenmpt()
  participant Resolve as resolve_libopenmpt_paths()
  participant Validate as is_valid_openmpt_source()
  participant Download as download_libopenmpt_tarball()
  participant BuildInPlace as build_libopenmpt_in_place()
  participant Report as report_libopenmpt_failure()
  Build->>Ensure: call ensure_libopenmpt
  Ensure->>Resolve: check LIBOPENMPT_DIR and vendor paths
  Resolve-->>Ensure: return found or missing paths
  alt External LIBOPENMPT_DIR valid
    Ensure->>Ensure: use external source
  else Vendor tree exists
    Ensure->>Validate: check source validity
    Validate-->>Ensure: valid or incomplete
    alt Incomplete vendor
      Ensure->>Ensure: remove vendor/legacy dirs
    end
  else Vendor missing or invalid
    Ensure->>Download: fetch pinned tarball from lib.openmpt.org
    Download-->>Ensure: extracted to vendor
  end
  Ensure->>Ensure: check if libopenmpt.a exists
  alt Library missing
    Ensure->>BuildInPlace: build with STATIC_LIB=1 flags
    BuildInPlace-->>Ensure: library created
  end
  alt Path resolution or build fails
    Ensure->>Report: send failure with diagnostics
    Report-->>Build: error exit
  else Success
    Ensure-->>Build: resolved include/lib paths
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

codex

Poem

A rabbit hops through vendor trees,
Pinned versions flutter on the breeze,
Tarballs downloaded, static built,
Emscripten flows without a guilt,
Build once, resolve all paths with ease! 🐰📦

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/fix-libopenmpt-wasm-build-3043

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ford442 ford442 marked this pull request as ready for review June 12, 2026 19:28
@ford442 ford442 merged commit 4662be0 into main Jun 12, 2026
3 checks passed
@ford442 ford442 deleted the cursor/fix-libopenmpt-wasm-build-3043 branch June 12, 2026 19:28
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