admin管理员组

文章数量:1305987

I have a c header file where I define a c enum that I use in some swift code as well as in some metal shader code. The file is defined in a package like this:

import PackageDescription


let package = Package(
    name: "COREAPI",
    platforms: [
        .iOS("12.0"),  
        .macOS("10.10"),
        .tvOS("9.0"),
        .watchOS("2.0")
    ],
    products: [

        .library(
            name: "COREAPI",
            targets: ["COREAPI"]),
    ],
    dependencies: [],
    targets: [

        .systemLibrary(
            name: "SharedOpcodes",
            path: "Sources/SharedOpcodes"
        ),
        .target(
            name: "COREAPI",
            dependencies: ["SharedOpcodes"], 
            path: "Sources/COREAPI"
        ),
        .testTarget(
            name: "COREAPITests",
            dependencies: ["COREAPI"]),
    
    ]
)

Where the directory is set up kinda like this:

COREAPI
--Package file
--SOURCES
----COREApi
------**here's all the swift code. This can access shared c header file no problem
----SharedOpCodes
------module.modulemap
------sharedopcodes.h

When I import add this package to another project, I can easily access the sharedopcodes with a simple import statement. HOWEVER when I try to access it in my metal shader, I cannot import it. I tried to add it to the metal compiler's header search path, but all of the relevant environment variables pointing to packages in the derived data directory go to the product directories, but the header is only available in the source directory. I tried to do some workarounds with adding a run script, but Xcode's aggressive sandboxing got in the way of symlinks, creating directories and copying files.

Any thoughts on how to make the metal compiler see this header from my Swift package??

本文标签: xcodeCan I import a c header from a swift package into a metal fileStack Overflow