Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metal files *not* silently compiled #7716

Open
1 task done
rgov opened this issue Jun 26, 2024 · 1 comment
Open
1 task done

Metal files *not* silently compiled #7716

rgov opened this issue Jun 26, 2024 · 1 comment
Labels

Comments

@rgov
Copy link

rgov commented Jun 26, 2024

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

#5822 discusses that "[r]esources of known types are automatically handled, as per the resources proposal", such that "all .metal files in a package are compiled into a default.metallib file".

There's also a Apple Developer Forums post from 2020 that claims this behavior exists.

However, I do not see this occurring with my project. (Admittedly, this is my first time using SwiftPM.)

Expected behavior

The add.metal file is processed and default.metallib is produced, such that it can be loaded by MTLDevice.makeDefaultLibrary(bundle:).

Actual behavior

Library loading fails because default.metallib does not exist.

The add.metal file is simply copied to .build/arm64-apple-macosx/debug/example_tool.bundle/add.metal.

Steps to reproduce

Here's Package.swift:

let package = Package(
    name: "example",

    platforms: [
        .macOS(.v10_14),
    ],

    targets: [
        .executableTarget(
            name: "tool",
            resources: [
                .process("Kernels/add.metal"),
            ]
        ),
    ]
)

And Sources/main.swift could look something like:

import Foundation
import Metal

let device = MTLCopyAllDevices().first!
let library = try! device.makeDefaultLibrary(bundle: Bundle.module)

The command swift run should succeed.

Note

I am not able to locate any documentation about what process rules exist, and whether the behavior of compiling Metal is actually an officially-supported feature.

Swift Package Manager version/commit hash

Swift Package Manager - Swift 5.10.0-dev

Swift & OS version

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
Darwin Midnight-One.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 arm64
@rgov rgov added the bug label Jun 26, 2024
@rgov
Copy link
Author

rgov commented Jun 26, 2024

The default.metallib is produced only if I use Xcode to build the package, but not SwiftPM from the command line.

It's unclear to me as a novice user why these should behave differently, and what the full matrix of supported features between a "pure" SwiftPM project vs an Xcode project is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant