Skip to content

Commit

Permalink
chore: update with latest changes from ffi & update build framework s…
Browse files Browse the repository at this point in the history
…cript
  • Loading branch information
cbrzn committed Jul 24, 2023
1 parent ff63d7a commit dabdf24
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 77 deletions.
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
included:
- Source
excluded:
- Source/PolywrapClientNativeLib.swift
line_length: 130
identifier_name:
min_length: 2
Expand Down
8 changes: 4 additions & 4 deletions Scripts/build_framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ set -e # Helps to give error info

LOCAL_UDL="src/polywrap_native.udl"
UDL_NAME="polywrap_native"
FRAMEWORK_NAME="PolywrapClientNative"
FRAMEWORK_NAME="libPolywrapClientNative"
SWIFT_INTERFACE="PolywrapClientNativeLib"

BUILD_PATH="${IOS_PROJ}/Native/Frameworks/PolywrapClientNative.xcframework"
BUILD_PATH="${IOS_PROJ}/Frameworks/PolywrapClientNative.xcframework"

cd "$RUST_PROJ"

Expand All @@ -27,7 +27,7 @@ rm -rf "$IOS_SIM_FRAMEWORK/Headers/${UDL_NAME}FFI.h"
rm -rf "$IOS_SIM_FRAMEWORK/$FRAMEWORK_NAME.a"
rm -rf "$MACOS_FRAMEWORK/Headers/${UDL_NAME}FFI.h"
rm -rf "$MACOS_FRAMEWORK/$FRAMEWORK_NAME.a"
rm "$IOS_PROJ/Native/$SWIFT_INTERFACE.swift"
rm -f "$IOS_PROJ/Source/$SWIFT_INTERFACE.swift"

rm -rf ../../target/universal.a
rm -rf include/ios/*
Expand Down Expand Up @@ -69,7 +69,7 @@ cp "../../target/universal_mac.a" \
"$MACOS_FRAMEWORK/$FRAMEWORK_NAME.a"

# Move swift interface
sed "s/${UDL_NAME}FFI/$FRAMEWORK_NAME/g" "$IOS_PROJ/Source/.cache/$UDL_NAME.swift" > "$IOS_PROJ/Native/$SWIFT_INTERFACE.swift"
sed "s/${UDL_NAME}FFI/PolywrapClientNative/g" "$IOS_PROJ/Source/.cache/$UDL_NAME.swift" > "$IOS_PROJ/Source/$SWIFT_INTERFACE.swift"

# Update include folder and remove unneeded files
rm -rf $IOS_PROJ/Source/.cache
357 changes: 290 additions & 67 deletions Source/PolywrapClientNativeLib.swift

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions Source/Wasm/WasmWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import Foundation
import PolywrapClientNative

public enum WasmWrapperError: Error {
case fromBytecodeError
}

/// A class representing a wrapper
public class WasmWrapper: FfiWrapper {

Expand All @@ -17,8 +21,12 @@ public class WasmWrapper: FfiWrapper {
/// Initializes a new WasmWrapper instance.
///
/// - Parameter module: A Wasm module represented as an array of bytes.
public init(module: [UInt8]) {
self.ffi = FfiWasmWrapper(wasmModule: module)
public init(module: [UInt8]) throws {
do {
self.ffi = try ffiWasmWrapperFromBytecode(bytes: module)
} catch {
throw WasmWrapperError.fromBytecodeError
}
}

/// Invokes a method on the Wasm module.
Expand Down
4 changes: 2 additions & 2 deletions Source/Wasm/WrapPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public class WasmPackage: FfiWrapPackage {
/// - Throws: `WasmPackageError` if there are issues creating the wrapper.
public func createWrapper() throws -> FfiWrapper {
if let module = self.module {
return WasmWrapper(module: module)
return try WasmWrapper(module: module)
} else {
let module = try self.getModule()
return WasmWrapper(module: module)
return try WasmWrapper(module: module)
}
}
}
2 changes: 1 addition & 1 deletion Tests/Wraps/Asyncify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class AsyncifyTest: XCTestCase {
let reader = ResourceReader(bundle: Bundle.module)

let bytes = try reader.readFile("Cases/asyncify/implementations/rs")
let embedded_wrapper = WasmWrapper(module: bytes)
let embedded_wrapper = try WasmWrapper(module: bytes)
let uri = try Uri("wrap://wrap/embedded")

let storagePlugin = MemoryStoragePlugin()
Expand Down
2 changes: 1 addition & 1 deletion Tests/Wraps/Feat/Invoke.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class InvokeTests: XCTestCase {
func testWrapInvoke() throws {
let reader = ResourceReader(bundle: Bundle.module)
let bytes = try reader.readFile("Cases/subinvoke/00-subinvoke/implementations/as")
let embedded_wrapper = WasmWrapper(module: bytes)
let embedded_wrapper = try WasmWrapper(module: bytes)
let uri = try Uri("wrap://wrap/embedded")
let builder = BuilderConfig().addWrapper(uri, embedded_wrapper)
let client = builder.build()
Expand Down

0 comments on commit dabdf24

Please sign in to comment.