最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

xcode - Can I import a c header from a swift package into a .metal file? - Stack Overflow

programmeradmin1浏览0评论

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??

发布评论

评论列表(0)

  1. 暂无评论