From a037de84ce4fa6042bbc31cff11112fe9a4ddfef Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Tue, 12 Jul 2022 11:06:10 +0100 Subject: [PATCH] Add first draft of iOS code and docs --- Makefile | 12 +++++- bindings/wysiwyg-ffi/README.md | 69 ++++++++++++++++++++++++++++++++ bindings/wysiwyg-ffi/uniffi.toml | 2 + 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 bindings/wysiwyg-ffi/uniffi.toml diff --git a/Makefile b/Makefile index 689b665b..74f10190 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,17 @@ android-x86_64: echo - bindings/wysiwyg-ffi/src/wysiwyg_composer.udl ios: - # TODO + cd bindings/ffi && \ + cargo build --target aarch64-apple-ios && \ + cargo build --target aarch64-apple-ios-sim && \ + cargo build --target x86_64-apple-ios && \ + mkdir -p ../../target/ios-combined && \ + lipo -create \ + ../../target/x86_64-apple-ios/debug/libwysiwyg_composer.a \ + ../../target/aarch64-apple-ios-sim/debug/libwysiwyg_composer.a \ + -output ../../target/ios-combined/libwysiwyg_composer.a + echo Outputs for iOS: + echo - target/ios-combined/libwysiwyg_composer.a web: cd bindings/wysiwyg-wasm && \ diff --git a/bindings/wysiwyg-ffi/README.md b/bindings/wysiwyg-ffi/README.md index 5ad422ef..693b426b 100644 --- a/bindings/wysiwyg-ffi/README.md +++ b/bindings/wysiwyg-ffi/README.md @@ -5,6 +5,8 @@ wysiwyg-rust. ## Building +### Android + * [Install Rust](https://www.rust-lang.org/tools/install) * [Install Android NDK](https://developer.android.com/ndk/downloads) - download android-ndk-r22b-linux-x86_64.zip and unzip it e.g.: @@ -111,3 +113,70 @@ which will then allow you to use the Rust code in your Kotlin like this: ```kotlin val y = uniffi.wysiwyg_composer.someMethod() ``` + +See +[Example Rust Bindings](https://gitlab.com/andybalaam/example-rust-bindings/) +for a full example of how it all fits together. + +### iOS + +* Build shared object: + +```bash +cd bindings/ffi +cargo build --target aarch64-apple-ios +cargo build --target aarch64-apple-ios-sim +cargo build --target x86_64-apple-ios + +mkdir -p ../../target/ios-combined +lipo -create \ + ../../target/x86_64-apple-ios/debug/libwysiwyg_composer.a \ + ../../target/aarch64-apple-ios-sim/debug/libwysiwyg_composer.a \ + -output ../../target/ios-combined/libwysiwyg_composer.a +``` + +This will create: + +``` +../../target/x86_64-apple-ios/debug/libwysiwyg_composer.a +../../target/aarch64-apple-ios-sim/debug/libwysiwyg_composer.a +../../target/ios-combined/libwysiwyg_composer.a +``` + +* Copy the shared object into your XCode project + +```bash +cp ../../target/ios-combined/libwysiwyg_composer.a MY_XCODE_PROJECT/ +``` + +(Where MY_XCODE_PROJECT is the location of the XCode project.) + +* Generate the bindings: + +```bash +uniffi-bindgen \ + generate src/wysiwyg_composer.udl \ + --language swift \ + --config uniffi.toml \ + --out-dir MY_XCODE_PROJECT + +cd MY_XCODE_PROJECT +mv *.h headers/ +mv *.modulemap headers/ +mv *.swift Sources/ +``` + +* Generate the .xcframework file: + +```bash +xcodebuild -create-xcframework \ + -library ../../target/aarch64-apple-ios/debug/libwysiwyg_composer.a" \ + -headers MY_XCODE_PROJECT/headers \ + -library MY_XCODE_PROJECT/libwysiwyg_composer.a" \ + -headers MY_XCODE_PROJECT/headers \ + -output MY_XCODE_PROJECT/ExampleRustBindings.xcframework" +``` + +Now you can use the code in your XCode project. See +[Example Rust Bindings](https://gitlab.com/andybalaam/example-rust-bindings/) +for a full example of how it all fits together. diff --git a/bindings/wysiwyg-ffi/uniffi.toml b/bindings/wysiwyg-ffi/uniffi.toml new file mode 100644 index 00000000..0042eac5 --- /dev/null +++ b/bindings/wysiwyg-ffi/uniffi.toml @@ -0,0 +1,2 @@ +[bindings.swift] +module_name = "WysiwygComposer"