diff --git a/.cargo/config.toml b/.cargo/config.toml index cd923acbd..ac29baebb 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,3 @@ [alias] xcode = ["bin", "cargo-xcode"] +make = ["bin", "cargo-make"] 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/Android/shared/build.gradle b/examples/simple_counter/Android/shared/build.gradle index d3ec22a14..84e7d801b 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,27 +83,22 @@ afterEvaluate { } tasks.register('bindGen', Exec) { - def outDir = "${projectDir}/../../shared_types/generated/java" - workingDir "../../" + def outDir = "${projectDir}/../../shared/generated/java" + workingDir "../../shared" 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 make uniffi-gen-java") } else { commandLine("sh", "-c", - """\ - cargo build -p shared && \ - target/debug/uniffi-bindgen generate shared/src/shared.udl \ - --language kotlin \ - --out-dir $outDir - """) + "cargo make uniffi-gen-java") } } tasks.register('typesGen', Exec) { - workingDir "../../" + workingDir "../../shared" if (System.getProperty('os.name').toLowerCase().contains('windows')) { - commandLine("cmd", "/c", "cargo build -p shared_types") + commandLine("cmd", "/c", "cargo make generate-types") } else { - commandLine("sh", "-c", "cargo build -p shared_types") + commandLine("sh", "-c", "cargo make generate-types") } } diff --git a/examples/simple_counter/Cargo.lock b/examples/simple_counter/Cargo.lock index c97c27dc4..b49cf653f 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", @@ -2837,15 +2837,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 +3250,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 +3263,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 +3283,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 +3295,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 +3309,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 +3326,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 +3337,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 +3349,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 +3544,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 4feae9db0..55474ffc2 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] @@ -14,6 +14,8 @@ rust-version = "1.66" anyhow = "1.0.86" crux_core = "0.8" serde = "1.0.203" +uniffi = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" } [workspace.metadata.bin] cargo-xcode = { version = "=1.7.0" } +cargo-make = { version = "=0.37.14" } 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/config.toml b/examples/simple_counter/shared/.cargo/config.toml new file mode 100644 index 000000000..5066635a0 --- /dev/null +++ b/examples/simple_counter/shared/.cargo/config.toml @@ -0,0 +1,5 @@ +[alias] +generate-types = "run --bin generate-types --features typegen" +uniffi-bindgen = "run --bin uniffi-bindgen" +uniffi-gen-swift = "uniffi-bindgen generate --language swift" +uniffi-gen-kotlin = "uniffi-bindgen generate --language kotlin" diff --git a/examples/simple_counter/shared/Cargo.toml b/examples/simple_counter/shared/Cargo.toml index c92429932..25576ad26 100644 --- a/examples/simple_counter/shared/Cargo.toml +++ b/examples/simple_counter/shared/Cargo.toml @@ -8,18 +8,19 @@ rust-version = "1.66" crate-type = ["lib", "staticlib", "cdylib"] name = "shared" +[[bin]] +name = "generate-types" +required-features = ["typegen"] + [features] 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"] } - -[build-dependencies] -uniffi = { version = "0.28.0", features = ["build"] } +uniffi = { workspace = true, features = ["cli"] } diff --git a/examples/simple_counter/shared/Makefile.toml b/examples/simple_counter/shared/Makefile.toml new file mode 100644 index 000000000..88f6ceb5e --- /dev/null +++ b/examples/simple_counter/shared/Makefile.toml @@ -0,0 +1,36 @@ +[env] +CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true + +[tasks.build] +command = "cargo" +args = ["build", "-p", "shared", "--release"] + +[tasks.uniffi-gen-swift] +command = "cargo" +args = [ + "uniffi-gen-swift", + "--library", + "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/release/libshared.dylib", + "--out-dir", + "generated/swift/SharedFFI", +] +dependencies = ["build"] + +[tasks.build-android] +command = "cargo" +args = ["build", "-p", "shared", "--target", "aarch64-linux-android"] + +[tasks.uniffi-gen-java] +command = "cargo" +args = [ + "uniffi-gen-kotlin", + "--library", + "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/aarch64-linux-android/debug/libshared.so", + "--out-dir", + "generated/java", +] +dependencies = ["build-android"] + +[tasks.generate-types] +command = "cargo" +args = ["generate-types"] 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_types/build.rs b/examples/simple_counter/shared/src/bin/generate-types.rs similarity index 76% rename from examples/simple_counter/shared_types/build.rs rename to examples/simple_counter/shared/src/bin/generate-types.rs index c3187c1ad..ff233eec2 100644 --- a/examples/simple_counter/shared_types/build.rs +++ b/examples/simple_counter/shared/src/bin/generate-types.rs @@ -1,15 +1,15 @@ use crux_core::typegen::TypeGen; use shared::Counter; use std::path::PathBuf; +use uniffi::deps::anyhow; +#[cfg(feature = "typegen")] fn main() -> anyhow::Result<()> { - println!("cargo:rerun-if-changed=../shared"); - let mut gen = TypeGen::new(); gen.register_app::()?; - let output_root = PathBuf::from("./generated"); + let output_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("generated"); gen.swift("SharedTypes", output_root.join("swift"))?; 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/.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