diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 86497ea785..685a1a9142 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -197,4 +197,4 @@ jobs: - uses: taiki-e/install-action@cargo-hack - uses: Swatinem/rust-cache@v2 - name: cargo/hack (verify features compile in isolation) - run: cargo hack check --each-feature --no-dev-deps + run: cargo hack check --each-feature --exclude-features uniffi --no-dev-deps diff --git a/.gitignore b/.gitignore index 329f2ebec4..b417c4551e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,10 @@ crypto-ffi/bindings/*/build crypto-ffi/bindings/*/.swiftpm crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto/CoreCrypto.swift crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto/core_crypto_ffi.swift +crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto/core_crypto.swift crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto/core_cryptoFFI.h +crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto/core_crypto_ffiFFI.h +crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto/core_cryptoFFI.modulemap DerivedData/ *.moved-aside *.pbxuser @@ -33,6 +36,7 @@ sample-projects/ios/.swiftpm # Kotlin crypto-ffi/bindings/jvm/src/main/kotlin/com/wire/crypto/CoreCrypto.kt crypto-ffi/bindings/jvm/src/main/kotlin/com/wire/crypto/core_crypto_ffi.kt +crypto-ffi/bindings/jvm/src/main/kotlin/uniffi/core_crypto/core_crypto.kt crypto-ffi/bindings/local.properties # Test databases leftovers diff --git a/CHANGELOG.tpl b/CHANGELOG.tpl index 459a96b463..3da6a292e1 100644 --- a/CHANGELOG.tpl +++ b/CHANGELOG.tpl @@ -7,11 +7,22 @@ Platform support legends: * Note: the papercuts will majorly be with the build process. Things might be very rough to integrate as no polish at all has been given yet. * ❌ = tier 3 support. It doesn't work just yet, but we plan to make it work. + +## [1.0.0-rc.11] - 2023-08-31 + +
+ git-conventional changelog +{{git-cliff tag="v1.0.0-rc.11" unreleased=true}} +
+ +* fix!: Fix Kotlin & Swift FFI errors + * This includes a breaking change where CoreCrypto and E2EI errors are separated, so change accordingly + ## [1.0.0-rc.10] - 2023-08-31
git-conventional changelog -{{git-cliff tag="v1.0.0-rc.10" unreleased=true}} +{{git-cliff tag="v1.0.0-rc.10"}}
* fix: Fix Kotin & Swift wrappers by producing correct symbols diff --git a/Cargo.toml b/Cargo.toml index 4ac6d7da83..3f02b00719 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,11 @@ resolver = "2" [workspace.dependencies] tls_codec = "0.3.0" +[workspace.dependencies.uniffi] +version = "0.24" +git = "https://github.com/wireapp/uniffi-rs.git" +branch = "wire/uniffi-stable" + [patch.crates-io.schnellru] git = "https://github.com/wireapp/schnellru" branch = "feat/try-insert" diff --git a/crypto-ffi/Cargo.toml b/crypto-ffi/Cargo.toml index a864cdb251..107d39297f 100644 --- a/crypto-ffi/Cargo.toml +++ b/crypto-ffi/Cargo.toml @@ -21,7 +21,6 @@ default = ["proteus"] proteus = ["core-crypto/proteus", "core-crypto/cryptobox-migrate"] [dependencies] -core-crypto = { version = "^1.0.0-rc.10", path = "../crypto" } thiserror = "1.0" cfg-if = "1.0" futures-util = "0.3" @@ -33,11 +32,10 @@ async-lock = "2.5" [target.'cfg(not(any(target_arch = "aarch64", target_arch = "x86_64", target_arch = "x86")))'.dependencies] sha2 = { version = "0.10", features = ["force-soft"] } +[target.'cfg(not(target_family = "wasm"))'.dependencies] # UniFFI - Android + iOS bindings - Runtime support -[target.'cfg(not(target_family = "wasm"))'.dependencies.uniffi] -version = "0.24" -git = "https://github.com/wireapp/uniffi-rs.git" -branch = "wire/uniffi-stable" +uniffi = { workspace = true } +core-crypto = { version = "^1.0.0-rc.10", path = "../crypto", features = ["uniffi"] } [target.wasm32-unknown-unknown.dependencies] wasm-bindgen = "0.2" @@ -48,13 +46,12 @@ serde = { version = "1.0", features = ["derive"] } js-sys = "0.3" web-sys = "0.3" strum = "0.25" +core-crypto = { version = "^1.0.0-rc.10", path = "../crypto" } # UniFFI - Android + iOS bindings - Build support [target.'cfg(not(target_family = "wasm"))'.build-dependencies.uniffi] -version = "0.24" -git = "https://github.com/wireapp/uniffi-rs.git" -branch = "wire/uniffi-stable" +workspace = true features = ["build", "bindgen"] [build-dependencies] diff --git a/crypto-ffi/Makefile.toml b/crypto-ffi/Makefile.toml index 625554bbe9..ee863180f5 100644 --- a/crypto-ffi/Makefile.toml +++ b/crypto-ffi/Makefile.toml @@ -133,8 +133,9 @@ args = [ [tasks.ffi-swift] dependencies = ["compile-ffi-swift"] -script_runner = "@duckscript" -script = "mv ./bindings/swift/WireCoreCrypto/WireCoreCrypto/core_crypto_ffi.swift ./bindings/swift/WireCoreCrypto/WireCoreCrypto/CoreCrypto.swift" +script = ''' + mv ./bindings/swift/WireCoreCrypto/WireCoreCrypto/core_crypto_ffi.swift ./bindings/swift/WireCoreCrypto/WireCoreCrypto/CoreCrypto.swift +''' [tasks.compile-ffi-kotlin] @@ -152,8 +153,12 @@ args = [ [tasks.ffi-kotlin] dependencies = ["compile-ffi-kotlin"] -script_runner = "@duckscript" -script = "mv ./bindings/jvm/src/main/kotlin/com/wire/crypto/core_crypto_ffi.kt ./bindings/jvm/src/main/kotlin/com/wire/crypto/CoreCrypto.kt" +script = ''' + mv ./bindings/jvm/src/main/kotlin/com/wire/crypto/core_crypto_ffi.kt ./bindings/jvm/src/main/kotlin/com/wire/crypto/CoreCrypto.kt + sed -i -e 's/\CryptoException\b/CryptoError/g' \ + -e 's/\bE2eIdentityException\b/E2eIdentityError/g' \ + ./bindings/jvm/src/main/kotlin/uniffi/core_crypto/core_crypto.kt +''' [tasks.ffi] dependencies = ["ffi-swift", "ffi-kotlin"] diff --git a/crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto.xcodeproj/project.pbxproj b/crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto.xcodeproj/project.pbxproj index 0f9d0f04b3..6cf2ea692c 100644 --- a/crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto.xcodeproj/project.pbxproj +++ b/crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto.xcodeproj/project.pbxproj @@ -10,6 +10,8 @@ 16CDD1172A2636BB0073FB8E /* WireCoreCrypto.h in Headers */ = {isa = PBXBuildFile; fileRef = 16CDD1162A2636BB0073FB8E /* WireCoreCrypto.h */; settings = {ATTRIBUTES = (Public, ); }; }; 16CDD11F2A26392C0073FB8E /* core_cryptoFFI.h in Headers */ = {isa = PBXBuildFile; fileRef = 16CDD11D2A26392C0073FB8E /* core_cryptoFFI.h */; settings = {ATTRIBUTES = (Public, ); }; }; 16CDD1202A26392C0073FB8E /* CoreCrypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16CDD11E2A26392C0073FB8E /* CoreCrypto.swift */; }; + 692B48242AA0F7860074F00A /* core_crypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 692B48232AA0F7860074F00A /* core_crypto.swift */; }; + 692B48272AA0F9810074F00A /* core_crypto_ffiFFI.h in Headers */ = {isa = PBXBuildFile; fileRef = 692B48262AA0F9810074F00A /* core_crypto_ffiFFI.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -18,6 +20,8 @@ 16CDD11D2A26392C0073FB8E /* core_cryptoFFI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = core_cryptoFFI.h; sourceTree = ""; }; 16CDD11E2A26392C0073FB8E /* CoreCrypto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreCrypto.swift; sourceTree = ""; }; 16CDD1212A29E0760073FB8E /* BuildSettings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = BuildSettings.xcconfig; sourceTree = ""; }; + 692B48232AA0F7860074F00A /* core_crypto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = core_crypto.swift; sourceTree = ""; }; + 692B48262AA0F9810074F00A /* core_crypto_ffiFFI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = core_crypto_ffiFFI.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -54,6 +58,8 @@ 16CDD11D2A26392C0073FB8E /* core_cryptoFFI.h */, 16CDD11E2A26392C0073FB8E /* CoreCrypto.swift */, 16CDD1162A2636BB0073FB8E /* WireCoreCrypto.h */, + 692B48232AA0F7860074F00A /* core_crypto.swift */, + 692B48262AA0F9810074F00A /* core_crypto_ffiFFI.h */, ); path = WireCoreCrypto; sourceTree = ""; @@ -65,6 +71,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 692B48272AA0F9810074F00A /* core_crypto_ffiFFI.h in Headers */, 16CDD11F2A26392C0073FB8E /* core_cryptoFFI.h in Headers */, 16CDD1172A2636BB0073FB8E /* WireCoreCrypto.h in Headers */, ); @@ -98,7 +105,7 @@ isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = 1; - LastUpgradeCheck = 1420; + LastUpgradeCheck = 1430; TargetAttributes = { 16CDD1122A2636BB0073FB8E = { CreatedOnToolsVersion = 14.2; @@ -139,6 +146,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 692B48242AA0F7860074F00A /* core_crypto.swift in Sources */, 16CDD1202A26392C0073FB8E /* CoreCrypto.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -180,6 +188,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -241,6 +250,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -267,10 +277,12 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; + DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -285,6 +297,8 @@ ); MACOSX_DEPLOYMENT_TARGET = 13.1; MARKETING_VERSION = 1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; "OTHER_LDFLAGS[sdk=iphoneos*][arch=arm64]" = "../../../../target/aarch64-apple-ios/release/libcore_crypto_ffi.a"; "OTHER_LDFLAGS[sdk=iphonesimulator*][arch=arm64]" = "../../../../target/aarch64-apple-ios-sim/release/libcore_crypto_ffi.a"; "OTHER_LDFLAGS[sdk=iphonesimulator*][arch=x86_64]" = "../../../../target/x86_64-apple-ios/release/libcore_crypto_ffi.a"; @@ -308,10 +322,12 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; + DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -326,6 +342,8 @@ ); MACOSX_DEPLOYMENT_TARGET = 13.1; MARKETING_VERSION = 1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; "OTHER_LDFLAGS[sdk=iphoneos*][arch=arm64]" = "../../../../target/aarch64-apple-ios/release/libcore_crypto_ffi.a"; "OTHER_LDFLAGS[sdk=iphonesimulator*][arch=arm64]" = "../../../../target/aarch64-apple-ios-sim/release/libcore_crypto_ffi.a"; "OTHER_LDFLAGS[sdk=iphonesimulator*][arch=x86_64]" = "../../../../target/x86_64-apple-ios/release/libcore_crypto_ffi.a"; diff --git a/crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto/WireCoreCrypto.h b/crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto/WireCoreCrypto.h index e5f116f472..490f4845ea 100644 --- a/crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto/WireCoreCrypto.h +++ b/crypto-ffi/bindings/swift/WireCoreCrypto/WireCoreCrypto/WireCoreCrypto.h @@ -24,6 +24,7 @@ FOUNDATION_EXPORT double WireCoreCryptoVersionNumber; //! Project version string for WireCoreCrypto. FOUNDATION_EXPORT const unsigned char WireCoreCryptoVersionString[]; +#import #import diff --git a/crypto-ffi/src/generic.rs b/crypto-ffi/src/generic.rs index b22c6fe65f..17f00532ae 100644 --- a/crypto-ffi/src/generic.rs +++ b/crypto-ffi/src/generic.rs @@ -37,12 +37,17 @@ pub fn version() -> String { } #[derive(Debug, thiserror::Error, uniffi::Error)] -#[uniffi(flat_error)] pub enum CoreCryptoError { #[error(transparent)] - CryptoError(#[from] CryptoError), + CryptoError { + #[from] + error: CryptoError, + }, #[error(transparent)] - E2eIdentityError(#[from] E2eIdentityError), + E2eIdentityError { + #[from] + error: E2eIdentityError, + }, } type CoreCryptoResult = Result; diff --git a/crypto-ffi/src/lib.rs b/crypto-ffi/src/lib.rs index 5c655ba01d..de835734ae 100644 --- a/crypto-ffi/src/lib.rs +++ b/crypto-ffi/src/lib.rs @@ -33,7 +33,7 @@ macro_rules! proteus_impl { result } else { - if let Err(CoreCryptoError::CryptoError(e)) = &result { + if let Err(CoreCryptoError::CryptoError { error: e }) = &result { let errcode = e.proteus_error_code(); if errcode > 0 { $errcode_dest.store(errcode, std::sync::atomic::Ordering::SeqCst); diff --git a/crypto-ffi/uniffi.toml b/crypto-ffi/uniffi.toml index e9fa9123c5..0a6dd206c0 100644 --- a/crypto-ffi/uniffi.toml +++ b/crypto-ffi/uniffi.toml @@ -5,5 +5,5 @@ cdylib_name = "core_crypto_ffi" [bindings.swift] cdylib_name = "core_crypto_ffi" ffi_module_name = "LibCoreCrypto" -ffi_module_filename = "core_cryptoFFI" +ffi_module_filename = "core_crypto_ffiFFI" generate_module_map = false diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml index 1e729637ba..c135e7567f 100644 --- a/crypto/Cargo.toml +++ b/crypto/Cargo.toml @@ -20,6 +20,8 @@ test-all-cipher = ["test-pq-cipher"] test-pq-cipher = [] # execute benches with also real db to better see overhead bench-in-db = [] +uniffi = ["dep:uniffi"] + [dependencies] thiserror = "1.0" @@ -48,6 +50,7 @@ x509-cert = "0.2" pem = "3.0" oid-registry = "0.6" async-recursion = "1" +uniffi = { workspace = true, optional = true } [dependencies.proteus-wasm] version = "2.1" diff --git a/crypto/src/e2e_identity/error.rs b/crypto/src/e2e_identity/error.rs index c61578853e..95a32339c2 100644 --- a/crypto/src/e2e_identity/error.rs +++ b/crypto/src/e2e_identity/error.rs @@ -7,6 +7,8 @@ pub type E2eIdentityResult = Result; /// End to end identity errors #[derive(Debug, thiserror::Error)] +#[cfg_attr(feature = "uniffi", derive(uniffi::Error))] +#[cfg_attr(feature = "uniffi", uniffi(flat_error))] pub enum E2eIdentityError { /// Client misused this library #[error("Incorrect usage of this API")] diff --git a/crypto/src/error.rs b/crypto/src/error.rs index 3165904477..fd50c111e1 100644 --- a/crypto/src/error.rs +++ b/crypto/src/error.rs @@ -18,6 +18,8 @@ use crate::mls::conversation::config::MAX_PAST_EPOCHS; /// CoreCrypto errors #[derive(Debug, thiserror::Error, strum::IntoStaticStr)] +#[cfg_attr(feature = "uniffi", derive(uniffi::Error))] +#[cfg_attr(feature = "uniffi", uniffi(flat_error))] pub enum CryptoError { /// This error is emitted when the requested conversation couldn't be found in our store #[error("Couldn't find conversation")] diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index 80e06bd755..019b7c2a32 100644 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -184,3 +184,6 @@ impl CoreCrypto { self.mls } } + +#[cfg(feature = "uniffi")] +uniffi::setup_scaffolding!("core_crypto");