From 2caee211b7d3742b4f68449ee322e16f472262b5 Mon Sep 17 00:00:00 2001 From: Binlogo Date: Thu, 18 Jul 2024 10:30:57 +0800 Subject: [PATCH] Initial replacing *.udl with use of Uniffi proc macro --- examples/hello_world/shared/build.rs | 3 - examples/hello_world/shared/src/lib.rs | 9 +- examples/hello_world/shared/src/shared.udl | 5 - examples/simple_counter/.cargo/config.toml | 3 + .../Android/shared/build.gradle | 12 +- examples/simple_counter/Cargo.lock | 65 +++------- examples/simple_counter/Cargo.toml | 3 +- .../SimpleCounter.xcodeproj/project.pbxproj | 114 +++++++++--------- .../iOS/SimpleCounter/core.swift | 2 +- examples/simple_counter/iOS/project.yml | 31 +---- examples/simple_counter/shared/Cargo.toml | 8 +- examples/simple_counter/shared/build.rs | 3 - .../shared/shared.xcodeproj/project.pbxproj | 2 +- examples/simple_counter/shared/src/lib.rs | 9 +- examples/simple_counter/shared/src/shared.udl | 5 - .../build.rs => shared/tests/typegen.rs} | 4 +- .../simple_counter/shared_types/.gitignore | 1 - .../simple_counter/shared_types/Cargo.toml | 16 --- .../simple_counter/shared_types/src/lib.rs | 1 - 19 files changed, 107 insertions(+), 189 deletions(-) delete mode 100644 examples/hello_world/shared/build.rs delete mode 100644 examples/hello_world/shared/src/shared.udl create mode 100644 examples/simple_counter/.cargo/config.toml delete mode 100644 examples/simple_counter/shared/build.rs delete mode 100644 examples/simple_counter/shared/src/shared.udl rename examples/simple_counter/{shared_types/build.rs => shared/tests/typegen.rs} (87%) delete mode 100644 examples/simple_counter/shared_types/.gitignore delete mode 100644 examples/simple_counter/shared_types/Cargo.toml delete mode 100644 examples/simple_counter/shared_types/src/lib.rs diff --git a/examples/hello_world/shared/build.rs b/examples/hello_world/shared/build.rs deleted file mode 100644 index 592061fb7..000000000 --- a/examples/hello_world/shared/build.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - uniffi::generate_scaffolding("./src/shared.udl").unwrap(); -} diff --git a/examples/hello_world/shared/src/lib.rs b/examples/hello_world/shared/src/lib.rs index 166765cf2..29fb8006b 100644 --- a/examples/hello_world/shared/src/lib.rs +++ b/examples/hello_world/shared/src/lib.rs @@ -1,3 +1,5 @@ +uniffi::setup_scaffolding!(); + pub mod app; // not exposed so you can remove this in your project use lazy_static::lazy_static; @@ -7,24 +9,23 @@ pub use crux_core::{bridge::Bridge, Core, Request}; pub use app::*; -// TODO hide this plumbing - -uniffi::include_scaffolding!("shared"); - lazy_static! { static ref CORE: Bridge = Bridge::new(Core::new()); } +#[uniffi::export] #[wasm_bindgen] pub fn process_event(data: &[u8]) -> Vec { CORE.process_event(data) } +#[uniffi::export] #[wasm_bindgen] pub fn handle_response(id: u32, data: &[u8]) -> Vec { CORE.handle_response(id, data) } +#[uniffi::export] #[wasm_bindgen] pub fn view() -> Vec { CORE.view() diff --git a/examples/hello_world/shared/src/shared.udl b/examples/hello_world/shared/src/shared.udl deleted file mode 100644 index db535214b..000000000 --- a/examples/hello_world/shared/src/shared.udl +++ /dev/null @@ -1,5 +0,0 @@ -namespace shared { - bytes process_event([ByRef] bytes msg); - bytes handle_response(u32 id, [ByRef] bytes res); - bytes view(); -}; diff --git a/examples/simple_counter/.cargo/config.toml b/examples/simple_counter/.cargo/config.toml new file mode 100644 index 000000000..4dd630322 --- /dev/null +++ b/examples/simple_counter/.cargo/config.toml @@ -0,0 +1,3 @@ +[alias] +uniffi-gen-swift = "run --bin uniffi-bindgen generate --library target/release/libshared.dylib --language swift --out-dir shared/generated/swift/SharedFFI" +uniffi-gen-java = "run --bin uniffi-bindgen generate --library target/release/libshared.dylib --language kotlin --out-dir shared/generated/java" diff --git a/examples/simple_counter/Android/shared/build.gradle b/examples/simple_counter/Android/shared/build.gradle index d3ec22a14..6bb902a49 100644 --- a/examples/simple_counter/Android/shared/build.gradle +++ b/examples/simple_counter/Android/shared/build.gradle @@ -36,7 +36,7 @@ android { } sourceSets { - main.java.srcDirs += "${projectDir}/../../shared_types/generated/java" + main.java.srcDirs += "${projectDir}/../../shared/generated/java" } } @@ -83,16 +83,16 @@ afterEvaluate { } tasks.register('bindGen', Exec) { - def outDir = "${projectDir}/../../shared_types/generated/java" + def outDir = "${projectDir}/../../shared/generated/java" workingDir "../../" if (System.getProperty('os.name').toLowerCase().contains('windows')) { commandLine("cmd", "/c", - "cargo build -p shared && " + "target\\debug\\uniffi-bindgen generate shared\\src\\shared.udl " + "--language kotlin " + "--out-dir " + outDir.replace('/', '\\')) + "cargo build -p shared && " + "target\\debug\\uniffi-bindgen generate --library target\\debug\\libshared.dylib " + "--language kotlin " + "--out-dir " + outDir.replace('/', '\\')) } else { commandLine("sh", "-c", """\ cargo build -p shared && \ - target/debug/uniffi-bindgen generate shared/src/shared.udl \ + target/debug/uniffi-bindgen generate --library target/debug/libshared.dylib \ --language kotlin \ --out-dir $outDir """) @@ -102,8 +102,8 @@ tasks.register('bindGen', Exec) { tasks.register('typesGen', Exec) { workingDir "../../" if (System.getProperty('os.name').toLowerCase().contains('windows')) { - commandLine("cmd", "/c", "cargo build -p shared_types") + commandLine("cmd", "/c", "cargo test -p shared --features typegen") } else { - commandLine("sh", "-c", "cargo build -p shared_types") + commandLine("sh", "-c", "cargo test -p shared --features typegen") } } diff --git a/examples/simple_counter/Cargo.lock b/examples/simple_counter/Cargo.lock index c97c27dc4..3e678b37b 100644 --- a/examples/simple_counter/Cargo.lock +++ b/examples/simple_counter/Cargo.lock @@ -409,9 +409,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.7" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" +checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" dependencies = [ "clap_builder", "clap_derive", @@ -419,9 +419,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.7" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" +checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" dependencies = [ "anstream", "anstyle", @@ -431,9 +431,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.5" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" +checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -2052,9 +2052,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mime_guess" -version = "2.0.4" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" dependencies = [ "mime", "unicase", @@ -2830,6 +2830,7 @@ dependencies = [ name = "shared" version = "0.1.0" dependencies = [ + "anyhow", "crux_core", "lazy_static", "serde", @@ -2837,15 +2838,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "shared_types" -version = "0.1.0" -dependencies = [ - "anyhow", - "crux_core", - "shared", -] - [[package]] name = "siphasher" version = "0.3.11" @@ -3259,14 +3251,12 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uniffi" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31bff6daf87277a9014bcdefbc2842b0553392919d1096843c5aad899ca4588" +source = "git+https://github.com/mozilla/uniffi-rs.git?branch=main#ca3f9d2facbfe1ce8648a2cda3ad855d7e6b2979" dependencies = [ "anyhow", "camino", "clap", "uniffi_bindgen", - "uniffi_build", "uniffi_core", "uniffi_macros", ] @@ -3274,8 +3264,7 @@ dependencies = [ [[package]] name = "uniffi_bindgen" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96061d7e01b185aa405f7c9b134741ab3e50cc6796a47d6fd8ab9a5364b5feed" +source = "git+https://github.com/mozilla/uniffi-rs.git?branch=main#ca3f9d2facbfe1ce8648a2cda3ad855d7e6b2979" dependencies = [ "anyhow", "askama", @@ -3295,22 +3284,10 @@ dependencies = [ "uniffi_udl", ] -[[package]] -name = "uniffi_build" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6b86f9b221046af0c533eafe09ece04e2f1ded04ccdc9bba0ec09aec1c52bd" -dependencies = [ - "anyhow", - "camino", - "uniffi_bindgen", -] - [[package]] name = "uniffi_checksum_derive" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fcfa22f55829d3aaa7acfb1c5150224188fe0f27c59a8a3eddcaa24d1ffbe58" +source = "git+https://github.com/mozilla/uniffi-rs.git?branch=main#ca3f9d2facbfe1ce8648a2cda3ad855d7e6b2979" dependencies = [ "quote", "syn 2.0.68", @@ -3319,8 +3296,7 @@ dependencies = [ [[package]] name = "uniffi_core" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3210d57d6ab6065ab47a2898dacdb7c606fd6a4156196831fa3bf82e34ac58a6" +source = "git+https://github.com/mozilla/uniffi-rs.git?branch=main#ca3f9d2facbfe1ce8648a2cda3ad855d7e6b2979" dependencies = [ "anyhow", "bytes", @@ -3334,8 +3310,7 @@ dependencies = [ [[package]] name = "uniffi_macros" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b58691741080935437dc862122e68d7414432a11824ac1137868de46181a0bd2" +source = "git+https://github.com/mozilla/uniffi-rs.git?branch=main#ca3f9d2facbfe1ce8648a2cda3ad855d7e6b2979" dependencies = [ "bincode", "camino", @@ -3352,8 +3327,7 @@ dependencies = [ [[package]] name = "uniffi_meta" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7663eacdbd9fbf4a88907ddcfe2e6fa85838eb6dc2418a7d91eebb3786f8e20b" +source = "git+https://github.com/mozilla/uniffi-rs.git?branch=main#ca3f9d2facbfe1ce8648a2cda3ad855d7e6b2979" dependencies = [ "anyhow", "bytes", @@ -3364,8 +3338,7 @@ dependencies = [ [[package]] name = "uniffi_testing" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f922465f7566f25f8fe766920205fdfa9a3fcdc209c6bfb7557f0b5bf45b04dd" +source = "git+https://github.com/mozilla/uniffi-rs.git?branch=main#ca3f9d2facbfe1ce8648a2cda3ad855d7e6b2979" dependencies = [ "anyhow", "camino", @@ -3377,8 +3350,7 @@ dependencies = [ [[package]] name = "uniffi_udl" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cef408229a3a407fafa4c36dc4f6ece78a6fb258ab28d2b64bddd49c8cb680f6" +source = "git+https://github.com/mozilla/uniffi-rs.git?branch=main#ca3f9d2facbfe1ce8648a2cda3ad855d7e6b2979" dependencies = [ "anyhow", "textwrap 0.16.1", @@ -3573,8 +3545,7 @@ dependencies = [ [[package]] name = "weedle2" version = "5.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "998d2c24ec099a87daf9467808859f9d82b61f1d9c9701251aea037f514eae0e" +source = "git+https://github.com/mozilla/uniffi-rs.git?branch=main#ca3f9d2facbfe1ce8648a2cda3ad855d7e6b2979" dependencies = [ "nom", ] diff --git a/examples/simple_counter/Cargo.toml b/examples/simple_counter/Cargo.toml index a7e4f5afb..e0dc274b3 100644 --- a/examples/simple_counter/Cargo.toml +++ b/examples/simple_counter/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["shared", "shared_types", "web-dioxus", "web-leptos", "web-yew"] +members = ["shared", "web-dioxus", "web-leptos", "web-yew"] resolver = "1" [workspace.package] @@ -15,6 +15,7 @@ anyhow = "1.0.86" crux_core = "0.8" # crux_core = { path = "../../crux_core" } serde = "1.0.203" +uniffi = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" } [workspace.metadata.bin] cargo-xcode = { version = "=1.7.0" } diff --git a/examples/simple_counter/iOS/SimpleCounter.xcodeproj/project.pbxproj b/examples/simple_counter/iOS/SimpleCounter.xcodeproj/project.pbxproj index 191942747..1b1430792 100644 --- a/examples/simple_counter/iOS/SimpleCounter.xcodeproj/project.pbxproj +++ b/examples/simple_counter/iOS/SimpleCounter.xcodeproj/project.pbxproj @@ -3,41 +3,29 @@ archiveVersion = 1; classes = { }; - objectVersion = 56; + objectVersion = 60; objects = { /* Begin PBXBuildFile section */ 1989BD3C863A9FB37C889B6D /* SharedTypes in Frameworks */ = {isa = PBXBuildFile; productRef = ADFA4530638891CDAA6FCC5D /* SharedTypes */; }; 2AD69AC61D674BB2BC300FC2 /* uniffi-bindgen in Resources */ = {isa = PBXBuildFile; fileRef = E75E53B837C6A0E03FDCEC5A /* uniffi-bindgen */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 401EA3CBD0D2AD8D475C10AF /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842F8D01CC76E9BFCDBD2862 /* ContentView.swift */; }; + 5776AB3F6BDB21968CE9543A /* shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33C72B2EF6A68B351BB022 /* shared.swift */; }; + 8291B7EC6C593FA8E5BB4F36 /* sharedFFI.h in Sources */ = {isa = PBXBuildFile; fileRef = 07EC71797B0B95DAD077436C /* sharedFFI.h */; }; 94DCD6C97BBC86B89673CA0E /* core.swift in Sources */ = {isa = PBXBuildFile; fileRef = 258EC994D7C693E3141C4563 /* core.swift */; }; - A022BC4B1B16254762ED55B3 /* shared.udl in Sources */ = {isa = PBXBuildFile; fileRef = 8B8EC4C63F3ECC2B26BBAEC2 /* shared.udl */; }; + ACEED4C684566162EAB9CB48 /* SimpleCounterApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02DCFFA8F642585B6E57DA81 /* SimpleCounterApp.swift */; }; C26A1E5DDAB1ED32518E8F2A /* libshared_static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2EA4D4AAE1A6C4D3400A9A06 /* libshared_static.a */; }; - D39A72610E7E3BD191DBDC06 /* SimpleCounterApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF52C000453302D743B48803 /* SimpleCounterApp.swift */; }; + C52E639D2187D4C22DDEF776 /* sharedFFI.modulemap in Sources */ = {isa = PBXBuildFile; fileRef = 98924D54C7B6BFCB1E503C2E /* sharedFFI.modulemap */; }; /* End PBXBuildFile section */ -/* Begin PBXBuildRule section */ - A7015E42CE7FE365402B3A57 /* PBXBuildRule */ = { - isa = PBXBuildRule; - compilerSpec = com.apple.compilers.proxy.script; - filePatterns = "*.udl"; - fileType = pattern.proxy; - inputFiles = ( - ); - isEditable = 1; - name = "Generate FFI"; - outputFiles = ( - "$(PROJECT_DIR)/generated/$(INPUT_FILE_BASE).swift", - "$(PROJECT_DIR)/generated/$(INPUT_FILE_BASE)FFI.h", - ); - outputFilesCompilerFlags = ( - ); - runOncePerArchitecture = 0; - script = "#!/bin/bash\nset -e\n\n# Skip during indexing phase in XCode 13+\nif [ \"$ACTION\" == \"indexbuild\" ]; then\n echo \"Not building *.udl files during indexing.\"\n exit 0\nfi\n\n# Skip for preview builds\nif [ \"$ENABLE_PREVIEWS\" = \"YES\" ]; then\n echo \"Not building *.udl files during preview builds.\"\n exit 0\nfi\n\ncd \"${INPUT_FILE_DIR}/..\"\n\"${BUILD_DIR}/debug/uniffi-bindgen\" generate \"src/${INPUT_FILE_NAME}\" --language swift --out-dir \"${PROJECT_DIR}/generated\"\n"; - }; -/* End PBXBuildRule section */ - /* Begin PBXContainerItemProxy section */ + 076D837A2C49634600D2EEF1 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8EA6E09EE87596B896068D0E /* Shared */; + proxyType = 2; + remoteGlobalIDString = CA60D2B4E60D10F7F7FCAC5B; + remoteInfo = "shared-cdylib"; + }; 4579D0264028B49513DBCDA5 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 8EA6E09EE87596B896068D0E /* Shared */; @@ -59,13 +47,6 @@ remoteGlobalIDString = CA607A8B44DC564A772C0BD1; remoteInfo = "shared-staticlib"; }; - CCE0790C2AA1F71400CD4B57 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8EA6E09EE87596B896068D0E /* Shared */; - proxyType = 2; - remoteGlobalIDString = CA60D2B4E60D10F7F7FCAC5B; - remoteInfo = "shared-cdylib"; - }; EC190C8522C4065CF4E41954 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 8EA6E09EE87596B896068D0E /* Shared */; @@ -76,14 +57,16 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 02DCFFA8F642585B6E57DA81 /* SimpleCounterApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleCounterApp.swift; sourceTree = ""; }; + 07EC71797B0B95DAD077436C /* sharedFFI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sharedFFI.h; sourceTree = ""; }; 1974E5BC3D6D22A1D5676B40 /* SimpleCounter.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = SimpleCounter.app; sourceTree = BUILT_PRODUCTS_DIR; }; 258EC994D7C693E3141C4563 /* core.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = core.swift; sourceTree = ""; }; - 642CF26F4B57B0FF7348C6BF /* SharedTypes */ = {isa = PBXFileReference; lastKnownFileType = folder; name = SharedTypes; path = ../shared_types/generated/swift/SharedTypes; sourceTree = SOURCE_ROOT; }; + 642CF26F4B57B0FF7348C6BF /* SharedTypes */ = {isa = PBXFileReference; lastKnownFileType = folder; name = SharedTypes; path = ../shared/generated/swift/SharedTypes; sourceTree = SOURCE_ROOT; }; 842F8D01CC76E9BFCDBD2862 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; - 8B8EC4C63F3ECC2B26BBAEC2 /* shared.udl */ = {isa = PBXFileReference; lastKnownFileType = text; path = shared.udl; sourceTree = ""; }; 8EA6E09EE87596B896068D0E /* Shared */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Shared; path = ../shared/shared.xcodeproj; sourceTree = ""; }; - BF52C000453302D743B48803 /* SimpleCounterApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleCounterApp.swift; sourceTree = ""; }; + 98924D54C7B6BFCB1E503C2E /* sharedFFI.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = sharedFFI.modulemap; sourceTree = ""; }; CF5BE0317D54587DCCF48AF4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + EA33C72B2EF6A68B351BB022 /* shared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = shared.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -103,30 +86,32 @@ isa = PBXGroup; children = ( E551F092584A1E0A747C2BEB /* Packages */, + 37E66549D321172F287501B5 /* SharedFFI */, E6F6A75B1B8366C3D868D1E4 /* SimpleCounter */, - A58FEB50EA86B3FEA463FCF0 /* src */, D4D259F256E0F508B61E0EA9 /* Products */, B6068D7E9E67CAA3B5F4F827 /* Projects */, ); sourceTree = ""; }; - 64DA90BC973EE8B5939308C2 /* Products */ = { + 37E66549D321172F287501B5 /* SharedFFI */ = { isa = PBXGroup; children = ( - 2EA4D4AAE1A6C4D3400A9A06 /* libshared_static.a */, - CCE0790D2AA1F71400CD4B57 /* shared.dylib */, - E75E53B837C6A0E03FDCEC5A /* uniffi-bindgen */, + EA33C72B2EF6A68B351BB022 /* shared.swift */, + 07EC71797B0B95DAD077436C /* sharedFFI.h */, + 98924D54C7B6BFCB1E503C2E /* sharedFFI.modulemap */, ); - name = Products; + name = SharedFFI; + path = ../shared/generated/swift/SharedFFI; sourceTree = ""; }; - A58FEB50EA86B3FEA463FCF0 /* src */ = { + 64DA90BC973EE8B5939308C2 /* Products */ = { isa = PBXGroup; children = ( - 8B8EC4C63F3ECC2B26BBAEC2 /* shared.udl */, + 2EA4D4AAE1A6C4D3400A9A06 /* libshared_static.a */, + 076D837B2C49634600D2EEF1 /* shared.dylib */, + E75E53B837C6A0E03FDCEC5A /* uniffi-bindgen */, ); - name = src; - path = ../shared/src; + name = Products; sourceTree = ""; }; B6068D7E9E67CAA3B5F4F827 /* Projects */ = { @@ -151,15 +136,15 @@ 642CF26F4B57B0FF7348C6BF /* SharedTypes */, ); name = Packages; - sourceTree = SOURCE_ROOT; + sourceTree = ""; }; E6F6A75B1B8366C3D868D1E4 /* SimpleCounter */ = { isa = PBXGroup; children = ( 842F8D01CC76E9BFCDBD2862 /* ContentView.swift */, 258EC994D7C693E3141C4563 /* core.swift */, - BF52C000453302D743B48803 /* SimpleCounterApp.swift */, CF5BE0317D54587DCCF48AF4 /* Info.plist */, + 02DCFFA8F642585B6E57DA81 /* SimpleCounterApp.swift */, ); path = SimpleCounter; sourceTree = ""; @@ -176,7 +161,6 @@ 593C7A3AEAC5E5C614E32E14 /* Frameworks */, ); buildRules = ( - A7015E42CE7FE365402B3A57 /* PBXBuildRule */, ); dependencies = ( 2FF352CA5059B90A12956273 /* PBXTargetDependency */, @@ -208,6 +192,9 @@ en, ); mainGroup = 1B8911D02E90EF25A711F2BE; + packageReferences = ( + 828D8D7B0DA5553163A5E024 /* XCLocalSwiftPackageReference "../shared/generated/swift/SharedTypes" */, + ); projectDirPath = ""; projectReferences = ( { @@ -223,6 +210,13 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ + 076D837B2C49634600D2EEF1 /* shared.dylib */ = { + isa = PBXReferenceProxy; + fileType = "compiled.mach-o.dylib"; + path = shared.dylib; + remoteRef = 076D837A2C49634600D2EEF1 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; 2EA4D4AAE1A6C4D3400A9A06 /* libshared_static.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -230,13 +224,6 @@ remoteRef = 6EC78E6AA13637C891278065 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - CCE0790D2AA1F71400CD4B57 /* shared.dylib */ = { - isa = PBXReferenceProxy; - fileType = "compiled.mach-o.dylib"; - path = shared.dylib; - remoteRef = CCE0790C2AA1F71400CD4B57 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; E75E53B837C6A0E03FDCEC5A /* uniffi-bindgen */ = { isa = PBXReferenceProxy; fileType = "compiled.mach-o.executable"; @@ -263,9 +250,11 @@ buildActionMask = 2147483647; files = ( 401EA3CBD0D2AD8D475C10AF /* ContentView.swift in Sources */, - D39A72610E7E3BD191DBDC06 /* SimpleCounterApp.swift in Sources */, + ACEED4C684566162EAB9CB48 /* SimpleCounterApp.swift in Sources */, 94DCD6C97BBC86B89673CA0E /* core.swift in Sources */, - A022BC4B1B16254762ED55B3 /* shared.udl in Sources */, + 5776AB3F6BDB21968CE9543A /* shared.swift in Sources */, + 8291B7EC6C593FA8E5BB4F36 /* sharedFFI.h in Sources */, + C52E639D2187D4C22DDEF776 /* sharedFFI.modulemap in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -290,6 +279,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; + ENABLE_USER_SCRIPT_SANDBOXING = NO; INFOPLIST_FILE = SimpleCounter/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; LD_RUNPATH_SEARCH_PATHS = ( @@ -302,7 +292,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.example.simple_counter.SimpleCounter; SDKROOT = iphoneos; - SWIFT_OBJC_BRIDGING_HEADER = generated/sharedFFI.h; + SWIFT_OBJC_BRIDGING_HEADER = ../shared/generated/swift/SharedFFI/sharedFFI.h; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -312,6 +302,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; + ENABLE_USER_SCRIPT_SANDBOXING = NO; INFOPLIST_FILE = SimpleCounter/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; LD_RUNPATH_SEARCH_PATHS = ( @@ -324,7 +315,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.example.simple_counter.SimpleCounter; SDKROOT = iphoneos; - SWIFT_OBJC_BRIDGING_HEADER = generated/sharedFFI.h; + SWIFT_OBJC_BRIDGING_HEADER = ../shared/generated/swift/SharedFFI/sharedFFI.h; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -469,6 +460,13 @@ }; /* End XCConfigurationList section */ +/* Begin XCLocalSwiftPackageReference section */ + 828D8D7B0DA5553163A5E024 /* XCLocalSwiftPackageReference "../shared/generated/swift/SharedTypes" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = ../shared/generated/swift/SharedTypes; + }; +/* End XCLocalSwiftPackageReference section */ + /* Begin XCSwiftPackageProductDependency section */ ADFA4530638891CDAA6FCC5D /* SharedTypes */ = { isa = XCSwiftPackageProductDependency; diff --git a/examples/simple_counter/iOS/SimpleCounter/core.swift b/examples/simple_counter/iOS/SimpleCounter/core.swift index bbe1cb366..a870ec4f5 100644 --- a/examples/simple_counter/iOS/SimpleCounter/core.swift +++ b/examples/simple_counter/iOS/SimpleCounter/core.swift @@ -10,7 +10,7 @@ class Core: ObservableObject { } func update(_ event: Event) { - let effects = [UInt8](processEvent(Data(try! event.bincodeSerialize()))) + let effects = [UInt8](processEvent(data: Data(try! event.bincodeSerialize()))) let requests: [Request] = try! .bincodeDeserialize(input: effects) for request in requests { diff --git a/examples/simple_counter/iOS/project.yml b/examples/simple_counter/iOS/project.yml index 313924f76..51a1f673c 100644 --- a/examples/simple_counter/iOS/project.yml +++ b/examples/simple_counter/iOS/project.yml @@ -4,7 +4,7 @@ projectReferences: path: ../shared/shared.xcodeproj packages: SharedTypes: - path: ../shared_types/generated/swift/SharedTypes + path: ../shared/generated/swift/SharedTypes options: bundleIdPrefix: com.example.simple_counter attributes: @@ -16,7 +16,7 @@ targets: deploymentTarget: "15.0" sources: - SimpleCounter - - path: ../shared/src/shared.udl + - path: ../shared/generated/swift/SharedFFI buildPhase: sources dependencies: - target: Shared/uniffi-bindgen-bin @@ -32,30 +32,5 @@ targets: UILaunchScreen: {} settings: OTHER_LDFLAGS: [-w] - SWIFT_OBJC_BRIDGING_HEADER: generated/sharedFFI.h + SWIFT_OBJC_BRIDGING_HEADER: ../shared/generated/swift/SharedFFI/sharedFFI.h ENABLE_USER_SCRIPT_SANDBOXING: NO - buildRules: - - name: Generate FFI - filePattern: "*.udl" - script: | - #!/bin/bash - set -e - - # Skip during indexing phase in XCode 13+ - if [ "$ACTION" == "indexbuild" ]; then - echo "Not building *.udl files during indexing." - exit 0 - fi - - # Skip for preview builds - if [ "$ENABLE_PREVIEWS" = "YES" ]; then - echo "Not building *.udl files during preview builds." - exit 0 - fi - - cd "${INPUT_FILE_DIR}/.." - "${BUILD_DIR}/debug/uniffi-bindgen" generate "src/${INPUT_FILE_NAME}" --language swift --out-dir "${PROJECT_DIR}/generated" - outputFiles: - - $(PROJECT_DIR)/generated/$(INPUT_FILE_BASE).swift - - $(PROJECT_DIR)/generated/$(INPUT_FILE_BASE)FFI.h - runOncePerArchitecture: false diff --git a/examples/simple_counter/shared/Cargo.toml b/examples/simple_counter/shared/Cargo.toml index c92429932..5094207c5 100644 --- a/examples/simple_counter/shared/Cargo.toml +++ b/examples/simple_counter/shared/Cargo.toml @@ -12,14 +12,14 @@ name = "shared" typegen = ["crux_core/typegen"] [dependencies] +uniffi.workspace = true crux_core.workspace = true serde = { workspace = true, features = ["derive"] } lazy_static = "1.5.0" -uniffi = "0.28.0" wasm-bindgen = "0.2.92" [target.uniffi-bindgen.dependencies] -uniffi = { version = "0.28.0", features = ["cli"] } +uniffi = { workspace = true, features = ["cli"] } -[build-dependencies] -uniffi = { version = "0.28.0", features = ["build"] } +[dev-dependencies] +anyhow.workspace = true diff --git a/examples/simple_counter/shared/build.rs b/examples/simple_counter/shared/build.rs deleted file mode 100644 index 592061fb7..000000000 --- a/examples/simple_counter/shared/build.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - uniffi::generate_scaffolding("./src/shared.udl").unwrap(); -} diff --git a/examples/simple_counter/shared/shared.xcodeproj/project.pbxproj b/examples/simple_counter/shared/shared.xcodeproj/project.pbxproj index 09665f34d..52c2b869a 100644 --- a/examples/simple_counter/shared/shared.xcodeproj/project.pbxproj +++ b/examples/simple_counter/shared/shared.xcodeproj/project.pbxproj @@ -190,7 +190,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "# generated with cargo-xcode 1.5.0\n\n set -eux; cat \"$DERIVED_FILE_DIR/$ARCHS-$EXECUTABLE_NAME.xcfilelist\" | tr '\\n' '\\0' | xargs -0 lipo -create -output \"$TARGET_BUILD_DIR/$EXECUTABLE_PATH\"\n if [ ${LD_DYLIB_INSTALL_NAME:+1} ]; then\n install_name_tool -id \"$LD_DYLIB_INSTALL_NAME\" \"$TARGET_BUILD_DIR/$EXECUTABLE_PATH\"\n fi\n "; + shellScript = "# generated with cargo-xcode 1.5.0\n\n set -eux; cat \"$DERIVED_FILE_DIR/$ARCHS-$EXECUTABLE_NAME.xcfilelist\" | tr '\\n' '\\0' | xargs -0 lipo -create -output \"$TARGET_BUILD_DIR/$EXECUTABLE_PATH\"\n if [ ${LD_DYLIB_INSTALL_NAME:+1} ]; then\n install_name_tool -id \"$LD_DYLIB_INSTALL_NAME\" \"$TARGET_BUILD_DIR/$EXECUTABLE_PATH\"\n fi\n \n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/examples/simple_counter/shared/src/lib.rs b/examples/simple_counter/shared/src/lib.rs index e3786ef3b..66cdae634 100644 --- a/examples/simple_counter/shared/src/lib.rs +++ b/examples/simple_counter/shared/src/lib.rs @@ -1,3 +1,5 @@ +uniffi::setup_scaffolding!(); + pub mod app; use lazy_static::lazy_static; @@ -7,24 +9,23 @@ pub use crux_core::{bridge::Bridge, Core, Request}; pub use app::*; -// TODO hide this plumbing - -uniffi::include_scaffolding!("shared"); - lazy_static! { static ref CORE: Bridge = Bridge::new(Core::new()); } +#[uniffi::export] #[wasm_bindgen] pub fn process_event(data: &[u8]) -> Vec { CORE.process_event(data) } +#[uniffi::export] #[wasm_bindgen] pub fn handle_response(id: u32, data: &[u8]) -> Vec { CORE.handle_response(id, data) } +#[uniffi::export] #[wasm_bindgen] pub fn view() -> Vec { CORE.view() diff --git a/examples/simple_counter/shared/src/shared.udl b/examples/simple_counter/shared/src/shared.udl deleted file mode 100644 index db535214b..000000000 --- a/examples/simple_counter/shared/src/shared.udl +++ /dev/null @@ -1,5 +0,0 @@ -namespace shared { - bytes process_event([ByRef] bytes msg); - bytes handle_response(u32 id, [ByRef] bytes res); - bytes view(); -}; diff --git a/examples/simple_counter/shared_types/build.rs b/examples/simple_counter/shared/tests/typegen.rs similarity index 87% rename from examples/simple_counter/shared_types/build.rs rename to examples/simple_counter/shared/tests/typegen.rs index c3187c1ad..251451129 100644 --- a/examples/simple_counter/shared_types/build.rs +++ b/examples/simple_counter/shared/tests/typegen.rs @@ -2,7 +2,9 @@ use crux_core::typegen::TypeGen; use shared::Counter; use std::path::PathBuf; -fn main() -> anyhow::Result<()> { +#[cfg(feature = "typegen")] +#[test] +fn typegen() -> anyhow::Result<()> { println!("cargo:rerun-if-changed=../shared"); let mut gen = TypeGen::new(); diff --git a/examples/simple_counter/shared_types/.gitignore b/examples/simple_counter/shared_types/.gitignore deleted file mode 100644 index e324eac91..000000000 --- a/examples/simple_counter/shared_types/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/generated diff --git a/examples/simple_counter/shared_types/Cargo.toml b/examples/simple_counter/shared_types/Cargo.toml deleted file mode 100644 index f878f9b0f..000000000 --- a/examples/simple_counter/shared_types/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "shared_types" -version = "0.1.0" -authors.workspace = true -repository.workspace = true -edition.workspace = true -license.workspace = true -keywords.workspace = true -rust-version.workspace = true - -[dependencies] - -[build-dependencies] -anyhow.workspace = true -crux_core = { workspace = true, features = ["typegen"] } -shared = { path = "../shared", features = ["typegen"] } diff --git a/examples/simple_counter/shared_types/src/lib.rs b/examples/simple_counter/shared_types/src/lib.rs deleted file mode 100644 index cd215e13f..000000000 --- a/examples/simple_counter/shared_types/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -// see build.rs