Skip to content

Add wgpu-mojo - #341

Open
Hundo1018 wants to merge 1 commit into
modular:mainfrom
Hundo1018:add-wgpu-mojo
Open

Add wgpu-mojo#341
Hundo1018 wants to merge 1 commit into
modular:mainfrom
Hundo1018:add-wgpu-mojo

Conversation

@Hundo1018

Copy link
Copy Markdown

Add wgpu-mojo — pure Mojo bindings for wgpu-native (WebGPU).

Compute and graphics on every backend Vulkan / Metal / DX12 supports, from a single
Mojo program: RAII wrappers that release their native handle on scope exit,
strongly-typed handle newtypes instead of raw pointers, a high-level GPU facade
that does compile + dispatch + read-back in a few lines, and a GLFW-backed
RenderCanvas for windowed rendering.

Checklist

  • My recipe.yaml file specifies which version(s) of MAX is compatible with my project. — This package does not depend on max at all. It pins mojo-compiler =1.0.0 in build/host and uses pin_compatible('mojo-compiler') at run time, per the packaging guide. The MAX interop bridge lives in a separate top-level package that is deliberately excluded from the build, precisely so max stays off every consumer's dependency path.
  • License file is packaged. — license_file: LICENSE; verified present as info/licenses/LICENSE in the built artifact.
  • Set the build number to 0. — New package.
  • Bumped the build number (if the version is unchanged). — N/A, first submission.

Notes for reviewers

Platforms. The recipe skips everything except linux-64 and osx-arm64,
including the linux-aarch64 this repo's CI builds. Nothing in the binding is
architecture-specific and conda-forge ships wgpu-native for aarch64, but no one
has run wgpu-mojo there, so I would rather not publish a package nobody has
exercised. I checked that the skip expression resolves correctly on all five
targets, so the aarch64 leg exits cleanly rather than failing your build.

Native dependency. wgpu-native and glfw are declared host/run
dependencies resolved from conda-forge — the build script downloads nothing. It
compiles the two C callback bridges from source in the repo (wgpu-native's async
API needs real C function pointers, which Mojo cannot yet produce) and links
against the host environment.

ABI pin. wgpu-native is pinned exactly, not as a range. Upstream renumbered
the whole 0x0003xxxx SType enum in the v29.0.0.0 → v29.0.1.1 patch release; a
mismatched library still loads and still runs, it just misreads every extras
chain. Beyond the version constraint, conda.recipe/build.sh compares the
installed $PREFIX/include/wgpu.h byte-for-byte against the copy vendored in the
source repo and fails the build on any difference.

CodeQL is enabled on the source repository (it contains C and Python
alongside Mojo) and the badge is in the README.

Test. test_package.mojo runs in a bare environment and asserts three things:
that lib/mojo/wgpu.mojoc is discoverable without an -I flag, that both native
libraries load, and that the installed wgpu-native exports the drift-prone entry
points this binding targets. It requests no adapter, so it passes on a build
machine with no GPU and no display server.

Verification performed

Built from this exact recipe and revision, then installed from a local channel
into a throwaway pixi project with no source checkout on the path, no -I flag
and no inherited LD_LIBRARY_PATH:

==> pixi add wgpu-mojo
✔ Added wgpu-mojo >=0.2.1,<0.3

==> Assertion 1: package resolves, native libraries load
wgpu preflight OK
  wgpu-native version: 486539264
  symbol check: OK (25 critical symbols present)
  adapters found: 4

==> Assertion 2: compute round trip on a real adapter
compute round trip OK — all 1024 elements correct

The same was repeated against the published .conda downloaded back from the
GitHub Release, and the package test passes standalone via
rattler-build test --package-file. Both checks run in the source repo's CI on
ubuntu-latest and macos-14.

Pure Mojo bindings for wgpu-native (WebGPU): RAII GPU objects, strongly-typed
handle newtypes, and a high-level GPU facade. Builds for linux-64 and osx-arm64.

wgpu-native and glfw are declared host/run dependencies from conda-forge, so the
build script downloads nothing; it compiles the two C callback bridges from
source and links against the host environment. wgpu-native is pinned exactly
because upstream renumbered the whole 0x0003xxxx SType enum in a patch release,
and the build script additionally compares the installed wgpu.h byte-for-byte
against the copy vendored in the source repository.
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.

1 participant