microsoft / onnxruntime-swift-package-manager

A light-weight repository for providing Swift Package Manager support for ONNX Runtime.
MIT License
30 stars 10 forks source link

Unable to import onnxruntime #2

Closed anthonydito closed 1 year ago

anthonydito commented 1 year ago

I know this is a new package, but it would awesome if there is a simple example for using this. I am running into an error where I can't import onnxruntime. However, without an example usage, I'm not sure if I am doing something wrong.

For reference, how I am using this package.

import PackageDescription

let package = Package(
    name: "MyTestPackage",
    platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)],
    products: [
        .library(
            name: "MyTestPackage",
            targets: ["MyTestPackage"]),
    ],
    dependencies: [
        .package(url: "https://github.com/microsoft/onnxruntime-swift-package-manager", branch: "main")
    ],
    targets: [
        .target(name: "MyTestPackage"),
        .testTarget(
            name: "MyTestPackage",
            dependencies: ["MyTestPackage"]),
    ]
)
YUNQIUGUO commented 1 year ago

Hi, thanks for raising this issue. We can consider adding some simple examples for demonstrating SPM usage.

Regarding your issue, currently there's no guarantee that using ORT SPM package as a dependency of secondary swift package can work.

However, we did test the usage to consume ORT as a swift package in an iOS app. https://github.com/YUNQIUGUO/ORT-SPM-Test-App/blob/main/ORT-SPM-Test-App/ORT-SPM-Test-App/ContentView.swift#L10-L40. Here's a simple test app where it can import OnnxRuntimeBindings target and call basic create inference session functionality calls, etc.

And here's a link for how to add package dependencies to your app: https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app

Mind sharing what's your use case?

anthonydito commented 1 year ago

Thank you! That example helped a lot.

I was able to get it working for an XCode app. However, I was having trouble adding the dependency as a dependency of another swift package. For those who might find it helpful, here is my Package.swift for my dependency that works now.

import PackageDescription

let package = Package(
    name: "MyTestPackage",
    products: [
        .library(
            name: "MyTestPackage",
            targets: ["MyTestPackage"]),
    ],
   dependencies: [
       .package(url: "https://github.com/microsoft/onnxruntime-swift-package-manager", branch: "main")
   ],
    targets: [
        .target(name: "MyTestPackage", dependencies: [
            .productItem(name: "onnxruntime", package: "onnxruntime-swift-package-manager", moduleAliases: nil, condition: nil)
        ]),
        .testTarget(
            name: "MyTestPackageTests",
            dependencies: ["MyTestPackage"]),
    ]
)