Skip to content

Commit

Permalink
fix!: UniFFI Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
OtaK committed Aug 31, 2023
1 parent d5ad750 commit 568bdf3
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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

<details>
<summary>git-conventional changelog</summary>
{{git-cliff tag="v1.0.0-rc.11" unreleased=true}}
</details>

* 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

<details>
<summary>git-conventional changelog</summary>
{{git-cliff tag="v1.0.0-rc.10" unreleased=true}}
{{git-cliff tag="v1.0.0-rc.10"}}
</details>

* fix: Fix Kotin & Swift wrappers by producing correct symbols
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 5 additions & 8 deletions crypto-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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]
Expand Down
13 changes: 9 additions & 4 deletions crypto-ffi/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -18,6 +20,8 @@
16CDD11D2A26392C0073FB8E /* core_cryptoFFI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = core_cryptoFFI.h; sourceTree = "<group>"; };
16CDD11E2A26392C0073FB8E /* CoreCrypto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreCrypto.swift; sourceTree = "<group>"; };
16CDD1212A29E0760073FB8E /* BuildSettings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = BuildSettings.xcconfig; sourceTree = "<group>"; };
692B48232AA0F7860074F00A /* core_crypto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = core_crypto.swift; sourceTree = "<group>"; };
692B48262AA0F9810074F00A /* core_crypto_ffiFFI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = core_crypto_ffiFFI.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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 = "<group>";
Expand All @@ -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 */,
);
Expand Down Expand Up @@ -98,7 +105,7 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastUpgradeCheck = 1420;
LastUpgradeCheck = 1430;
TargetAttributes = {
16CDD1122A2636BB0073FB8E = {
CreatedOnToolsVersion = 14.2;
Expand Down Expand Up @@ -139,6 +146,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
692B48242AA0F7860074F00A /* core_crypto.swift in Sources */,
16CDD1202A26392C0073FB8E /* CoreCrypto.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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";
Expand All @@ -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";
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ FOUNDATION_EXPORT double WireCoreCryptoVersionNumber;
//! Project version string for WireCoreCrypto.
FOUNDATION_EXPORT const unsigned char WireCoreCryptoVersionString[];

#import <WireCoreCrypto/core_crypto_ffiFFI.h>
#import <WireCoreCrypto/core_cryptoFFI.h>


11 changes: 8 additions & 3 deletions crypto-ffi/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = Result<T, CoreCryptoError>;
Expand Down
2 changes: 1 addition & 1 deletion crypto-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crypto-ffi/uniffi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions crypto/src/e2e_identity/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub type E2eIdentityResult<T> = Result<T, E2eIdentityError>;

/// 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")]
Expand Down
2 changes: 2 additions & 0 deletions crypto/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
3 changes: 3 additions & 0 deletions crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,6 @@ impl CoreCrypto {
self.mls
}
}

#[cfg(feature = "uniffi")]
uniffi::setup_scaffolding!("core_crypto");

0 comments on commit 568bdf3

Please sign in to comment.