Skip to content

Build SwiftPM default Metal library resource#430

Draft
RNT56 wants to merge 2 commits into
ml-explore:mainfrom
RNT56:upstream-pr/swiftpm-metal-library-resource
Draft

Build SwiftPM default Metal library resource#430
RNT56 wants to merge 2 commits into
ml-explore:mainfrom
RNT56:upstream-pr/swiftpm-metal-library-resource

Conversation

@RNT56

@RNT56 RNT56 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a SwiftPM build-tool plugin that compiles the default Metal library into a package resource bundle
  • wire the MLX target to use the generated metallib resource during package builds
  • use URL-based PackagePlugin APIs and platform-aware Metal SDK/deployment flags

Draft status

This PR should stay draft while the runtime-loading path is reworked around the explicit metallib path API preferred upstream.

The previous automatic MLX bundle lookup dependency was closed/superseded. The intended route is now:

I prepared a local proof branch at RNT56/mlx-swift:prep/swiftpm-metallib-via-path-api that combines this SwiftPM resource packaging with the explicit path API route. That proof branch finds mlx-swift_Cmlx.bundle/default.metallib, calls GPU.setMetallibPath(...) before the first GPU stream is created, and passes the runtime-loading smoke tests.

This PR should not be marked ready until the API chain above is available through upstream-owned commits/submodule pins. Once that is true, this branch can be rebuilt as a clean final PR containing only the resource packaging plus the SwiftPM resource-path hook and tests.

Validation so far

Current PR branch:

  • swift build --target MLX
  • bash -n tools/build-swiftpm-metallib.sh
  • SDK_NAME=macosx tools/build-swiftpm-metallib.sh /tmp/mlx-swift-default-macos.metallib
  • SDK_NAME=iphoneos tools/build-swiftpm-metallib.sh /tmp/mlx-swift-default-ios.metallib
  • SDK_NAME=xros tools/build-swiftpm-metallib.sh /tmp/mlx-swift-default-xros.metallib
  • git diff --check

Local proof branch:

  • swift build --target MLX
  • swift test --filter SwiftPMMetallibResourceTests
  • swift test --filter StreamTests/testDeviceType
  • git diff --check

@RNT56 RNT56 marked this pull request as draft June 25, 2026 13:53
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