diff --git a/Package.swift b/Package.swift index 94acfc4cd7b..1322b918c07 100644 --- a/Package.swift +++ b/Package.swift @@ -82,5 +82,24 @@ let package = Package( (value["libraries"] as? [String] ?? []).map { .linkedLibrary($0) } ), ] - } + } + [ + .testTarget( + name: "tests", + dependencies: [ + .target(name: "executorch_debug"), + .target(name: "kernels_portable"), + ], + path: "extension/apple/ExecuTorch/__tests__", + resources: [ + .copy("resources/add.pte") + ], + linkerSettings: [ + .linkedLibrary("c++"), + .unsafeFlags([ + "-Xlinker", "-force_load", + "-Xlinker", "cmake-out/kernels_portable.xcframework/macos-arm64/libkernels_portable_macos.a", + ]) + ] + ) + ] ) diff --git a/extension/apple/ExecuTorch/__tests__/ModuleTest.swift b/extension/apple/ExecuTorch/__tests__/ModuleTest.swift index 609727ec93f..03299cad991 100644 --- a/extension/apple/ExecuTorch/__tests__/ModuleTest.swift +++ b/extension/apple/ExecuTorch/__tests__/ModuleTest.swift @@ -11,9 +11,16 @@ import XCTest class ModuleTest: XCTestCase { + var resourceBundle: Bundle { +#if SWIFT_PACKAGE + return Bundle.module +#else + return Bundle(for: type(of: self)) +#endif + } + func test() throws { - let bundle = Bundle(for: type(of: self)) - guard let modelPath = bundle.path(forResource: "add", ofType: "pte") else { + guard let modelPath = resourceBundle.path(forResource: "add", ofType: "pte") else { XCTFail("Couldn't find the model file") return } diff --git a/scripts/build_apple_frameworks.sh b/scripts/build_apple_frameworks.sh index c473d13cf50..aae67b586ea 100755 --- a/scripts/build_apple_frameworks.sh +++ b/scripts/build_apple_frameworks.sh @@ -204,7 +204,7 @@ cmake_build() { cmake --build . \ --config "$mode" \ --verbose - cd .. + cd - } for index in ${!PLATFORMS[*]}; do @@ -283,4 +283,9 @@ done rm -rf "$HEADERS_PATH" +echo "Running tests" + +cd "$SOURCE_ROOT_DIR" +swift test + echo "Build succeeded!"