Conversation
swift test's default build system (--build-system swiftbuild) nests resource bundles inside the .xctest and runs tests through the toolchain's swiftpm-testing-helper. The running binary is therefore the toolchain helper, not the test bundle, so neither Bundle.main nor Bundle.allBundles names the .xctest and the existing SwiftPM bundle search can never reach it. MLX aborts the whole test process on the first GPU call instead of failing a single test. In that layout the metallib sits at a fixed offset from the binary (../Resources/<bundle>.bundle/Contents/Resources/default.metallib), so add that as an explicit colocated candidate under SWIFTPM_BUNDLE. swift test --build-system native is unaffected (flat layout, already covered by the first colocated candidate) but is deprecated in SwiftPM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
swift test's default build system (--build-system swiftbuild) nests resource bundles inside the.xctestand runs tests through the toolchain'sswiftpm-testing-helper. The running binary is the toolchain helper, not the test bundle, so neitherBundle.mainnorBundle.allBundlesnames the.xctest, and the existing SwiftPM bundle search inload_swiftpm_librarycan never reach it. MLX aborts the entire test process on the first GPU call rather than failing one test.fixes: ml-explore/mlx-swift#460
Reported downstream at ml-explore/mlx-swift#460, where a SwiftPM package with a test target hitting any MLX op takes down all 126 tests in the suite with:
Fix
In the Swift Build test layout, the metallib sits at a fixed offset from the binary:
../Resources/<bundle>.bundle/Contents/Resources/default.metallib. This adds that as one more colocated candidate, guarded bySWIFTPM_BUNDLEso it's a no-op for CMake/framework builds.swift test --build-system nativeis unaffected -- its flat layout was already covered by the first colocated candidate -- butnativeis marked deprecated by SwiftPM.Testing
Reproduced and fixed against a local project that consumes mlx-swift. I have a separate Swift package with a trait-gated target that depends on mlx-swift transitively (through mlx-swift-lm/MLXEmbedders), with its own
swift-testingtest target. On this machine's toolchain (Xcode 27.0, Swift 6.4.0.34.1):swift test --traits MLXEmbeddingwithMLX_RUNTIME_TESTS=1reproduces the exact reported failure:I also ran this against mlx-swift's own test suite (
swift test --filter 'MLXTests.MLXArrayTests|MLXTests.StreamTests', 36 tests, real GPU evals) with the patch applied -- all pass, no regressions.