mozilla / uniffi-rs

a multi-language bindings generator for rust
https://mozilla.github.io/uniffi-rs/
Mozilla Public License 2.0
2.49k stars 211 forks source link

Compiling a Swift module issue #1291

Open Yorik0512 opened 2 years ago

Yorik0512 commented 2 years ago

Hi Uniffi comunity,

I'm trying build swift module from that repo https://github.com/sicpa-dlab/didcomm-rust/tree/stable/uniffi with command swiftc -module-name didcomm -emit-library -o ../wrappers/swift/didcomm/libdidcomm.dylib -emit-module -emit-module-path ../wrappers/swift/didcomm -parse-as-library -L ./target/release/ -ldidcomm_uniffi -Xcc -fmodule-map-file=../wrappers/swift/didcomm/didcommFFI.modulemap ../wrappers/swift/didcomm/didcomm.swift

And after that I catch an error:

error: link command failed with exit code 1 (use -v to see invocation)
Undefined symbols for architecture arm64:
  "_didcomm_2a6d_DIDComm_new", referenced from:
      _$s7didcomm7DidCommC11didResolver06secretE0AcA0bE0_p_AA07SecretsE0_ptcfcSvSpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_pack_encrypted", referenced from:
      _$s7didcomm7DidCommC13packEncrypted3msg2to4from6signBy7options2cbAA9ErrorCodeOAA7MessageV_S2SSgAoA04PackE7OptionsVAA02OnpE6Result_ptFSo10RustBufferVSpySo0T10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_pack_from_prior", referenced from:
      _$s7didcomm7DidCommC13packFromPrior3msg9issuerKid2cbAA9ErrorCodeOAA0eF0V_SSSgAA02OneF10PackResult_ptFSo10RustBufferVSpySo0P10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_pack_plaintext", referenced from:
      _$s7didcomm7DidCommC13packPlaintext3msg2cbAA9ErrorCodeOAA7MessageV_AA06OnPackE6Result_ptFSo10RustBufferVSpySo0N10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_pack_signed", referenced from:
      _$s7didcomm7DidCommC10packSigned3msg6signBy2cbAA9ErrorCodeOAA7MessageV_SSAA06OnPackE6Result_ptFSo10RustBufferVSpySo0P10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_unpack", referenced from:
      _$s7didcomm7DidCommC6unpack3msg7options2cbAA9ErrorCodeOSS_AA13UnpackOptionsVAA02OnJ6Result_ptFSo10RustBufferVSpySo0N10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_unpack_from_prior", referenced from:
      _$s7didcomm7DidCommC15unpackFromPrior04fromF3Jwt2cbAA9ErrorCodeOSS_AA02OneF12UnpackResult_ptFSo10RustBufferVSpySo0O10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_wrap_in_forward", referenced from:
      _$s7didcomm7DidCommC13wrapInForward3msg7headers2to11routingKeys10encAlgAnon2cbAA9ErrorCodeOSS_SDyS2SGSSSaySSGAA0n5CryptM0OAA06OnWrapeF6Result_ptFSo10RustBufferVSpySo0V10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_ExampleDIDResolver_new", referenced from:
      _$s7didcomm18ExampleDidResolverC9knownDidsACSayAA0C3DocVG_tcfcSvSpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_ExampleDIDResolver_resolve", referenced from:
      _$s7didcomm18ExampleDidResolverC7resolve3did2cbAA9ErrorCodeOSS_AA02OncD6ResultCtFSo10RustBufferVSpySo0L10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_ExampleSecretsResolver_find_secrets", referenced from:
      _$s7didcomm22ExampleSecretsResolverC04findC09secretIds2cbAA9ErrorCodeOSaySSG_AA06OnFindC6ResultCtFSo10RustBufferVSpySo0N10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_ExampleSecretsResolver_get_secret", referenced from:
      _$s7didcomm22ExampleSecretsResolverC9getSecret8secretId2cbAA9ErrorCodeOSS_AA05OnGetF6ResultCtFSo10RustBufferVSpySo0O10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_ExampleSecretsResolver_new", referenced from:
      _$s7didcomm22ExampleSecretsResolverC05knownC0ACSayAA6SecretVG_tcfcSvSpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnDIDResolverResult_error", referenced from:
      _$s7didcomm19OnDidResolverResultC5error3err3msgyAA9ErrorKindO_SStKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnDIDResolverResult_success", referenced from:
      _$s7didcomm19OnDidResolverResultC7success6resultyAA0C3DocVSg_tKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnFindSecretsResult_error", referenced from:
      _$s7didcomm19OnFindSecretsResultC5error3err3msgyAA9ErrorKindO_SStKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnFindSecretsResult_success", referenced from:
      _$s7didcomm19OnFindSecretsResultC7success6resultySaySSG_tKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnGetSecretResult_error", referenced from:
      _$s7didcomm17OnGetSecretResultC5error3err3msgyAA9ErrorKindO_SStKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnGetSecretResult_success", referenced from:
      _$s7didcomm17OnGetSecretResultC7success6resultyAA0D0VSg_tKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_DIDComm_object_free", referenced from:
      _$s7didcomm7DidCommCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_DIDResolver_init_callback", referenced from:
      _$s7didcomm40FfiConverterCallbackInterfaceDidResolver33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_ExampleDIDResolver_object_free", referenced from:
      _$s7didcomm18ExampleDidResolverCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_ExampleSecretsResolver_object_free", referenced from:
      _$s7didcomm22ExampleSecretsResolverCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnDIDResolverResult_object_free", referenced from:
      _$s7didcomm19OnDidResolverResultCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnFindSecretsResult_object_free", referenced from:
      _$s7didcomm19OnFindSecretsResultCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnFromPriorPackResult_init_callback", referenced from:
      _$s7didcomm50FfiConverterCallbackInterfaceOnFromPriorPackResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnFromPriorUnpackResult_init_callback", referenced from:
      _$s7didcomm52FfiConverterCallbackInterfaceOnFromPriorUnpackResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnGetSecretResult_object_free", referenced from:
      _$s7didcomm17OnGetSecretResultCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnPackEncryptedResult_init_callback", referenced from:
      _$s7didcomm50FfiConverterCallbackInterfaceOnPackEncryptedResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnPackPlaintextResult_init_callback", referenced from:
      _$s7didcomm50FfiConverterCallbackInterfaceOnPackPlaintextResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnPackSignedResult_init_callback", referenced from:
      _$s7didcomm47FfiConverterCallbackInterfaceOnPackSignedResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnUnpackResult_init_callback", referenced from:
      _$s7didcomm43FfiConverterCallbackInterfaceOnUnpackResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnWrapInForwardResult_init_callback", referenced from:
      _$s7didcomm50FfiConverterCallbackInterfaceOnWrapInForwardResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_SecretsResolver_init_callback", referenced from:
      _$s7didcomm44FfiConverterCallbackInterfaceSecretsResolver33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_rustbuffer_free", referenced from:
      _$sSo10RustBufferV7didcommE10deallocate33_70915CE519991AA7D20AEA431BE4069FLLyyFySpySo0A10CallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_rustbuffer_from_bytes", referenced from:
      _$sSo10RustBufferV7didcommE4from33_70915CE519991AA7D20AEA431BE4069FLLyABSRys5UInt8VGFZABSpySo0A10CallStatusVGXEfU_ in didcomm-1.o
ld: symbol(s) not found for architecture arm64

If someone catch the same issue please share your experience how to resolve that error. Thanks in advance.

┆Issue is synchronized with this Jira Task ┆friendlyId: UNIFFI-178

skhamis commented 2 years ago

Hi @Yorik0512,

Do you happen to be using an M1 Mac?

Yorik0512 commented 2 years ago

Hi @skhamis

Yes, I'm using M1 Mac

skhamis commented 2 years ago

This usually indicates there is some mismatch in how the binaries are being built. The usual suspects are:

This doesn't seem like an Uniffi issue as we use Uniffi successfully to build both arm64 and x86-64 successfully in application services: https://github.com/mozilla/application-services/blob/main/megazords/ios-rust/build-xcframework.sh

Yorik0512 commented 2 years ago

Hi @skhamis

Thank you for your answer. I did previous command on Intel Mac and I catch the same error but for x86_64:

Undefined symbols for architecture x86_64:
  "_didcomm_2a6d_DIDComm_new", referenced from:
      _$s7didcomm7DidCommC11didResolver06secretE0AcA0bE0_p_AA07SecretsE0_ptcfcSvSpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_pack_encrypted", referenced from:
      _$s7didcomm7DidCommC13packEncrypted3msg2to4from6signBy7options2cbAA9ErrorCodeOAA7MessageV_S2SSgAoA04PackE7OptionsVAA02OnpE6Result_ptFSo10RustBufferVSpySo0T10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_pack_from_prior", referenced from:
      _$s7didcomm7DidCommC13packFromPrior3msg9issuerKid2cbAA9ErrorCodeOAA0eF0V_SSSgAA02OneF10PackResult_ptFSo10RustBufferVSpySo0P10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_pack_plaintext", referenced from:
      _$s7didcomm7DidCommC13packPlaintext3msg2cbAA9ErrorCodeOAA7MessageV_AA06OnPackE6Result_ptFSo10RustBufferVSpySo0N10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_pack_signed", referenced from:
      _$s7didcomm7DidCommC10packSigned3msg6signBy2cbAA9ErrorCodeOAA7MessageV_SSAA06OnPackE6Result_ptFSo10RustBufferVSpySo0P10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_unpack", referenced from:
      _$s7didcomm7DidCommC6unpack3msg7options2cbAA9ErrorCodeOSS_AA13UnpackOptionsVAA02OnJ6Result_ptFSo10RustBufferVSpySo0N10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_unpack_from_prior", referenced from:
      _$s7didcomm7DidCommC15unpackFromPrior04fromF3Jwt2cbAA9ErrorCodeOSS_AA02OneF12UnpackResult_ptFSo10RustBufferVSpySo0O10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_DIDComm_wrap_in_forward", referenced from:
      _$s7didcomm7DidCommC13wrapInForward3msg7headers2to11routingKeys10encAlgAnon2cbAA9ErrorCodeOSS_SDyS2SGSSSaySSGAA0n5CryptM0OAA06OnWrapeF6Result_ptFSo10RustBufferVSpySo0V10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_ExampleDIDResolver_new", referenced from:
      _$s7didcomm18ExampleDidResolverC9knownDidsACSayAA0C3DocVG_tcfcSvSpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_ExampleDIDResolver_resolve", referenced from:
      _$s7didcomm18ExampleDidResolverC7resolve3did2cbAA9ErrorCodeOSS_AA02OncD6ResultCtFSo10RustBufferVSpySo0L10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_ExampleSecretsResolver_find_secrets", referenced from:
      _$s7didcomm22ExampleSecretsResolverC04findC09secretIds2cbAA9ErrorCodeOSaySSG_AA06OnFindC6ResultCtFSo10RustBufferVSpySo0N10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_ExampleSecretsResolver_get_secret", referenced from:
      _$s7didcomm22ExampleSecretsResolverC9getSecret8secretId2cbAA9ErrorCodeOSS_AA05OnGetF6ResultCtFSo10RustBufferVSpySo0O10CallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_ExampleSecretsResolver_new", referenced from:
      _$s7didcomm22ExampleSecretsResolverC05knownC0ACSayAA6SecretVG_tcfcSvSpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnDIDResolverResult_error", referenced from:
      _$s7didcomm19OnDidResolverResultC5error3err3msgyAA9ErrorKindO_SStKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnDIDResolverResult_success", referenced from:
      _$s7didcomm19OnDidResolverResultC7success6resultyAA0C3DocVSg_tKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnFindSecretsResult_error", referenced from:
      _$s7didcomm19OnFindSecretsResultC5error3err3msgyAA9ErrorKindO_SStKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnFindSecretsResult_success", referenced from:
      _$s7didcomm19OnFindSecretsResultC7success6resultySaySSG_tKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnGetSecretResult_error", referenced from:
      _$s7didcomm17OnGetSecretResultC5error3err3msgyAA9ErrorKindO_SStKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_didcomm_2a6d_OnGetSecretResult_success", referenced from:
      _$s7didcomm17OnGetSecretResultC7success6resultyAA0D0VSg_tKFySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_DIDComm_object_free", referenced from:
      _$s7didcomm7DidCommCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_DIDResolver_init_callback", referenced from:
      _$s7didcomm40FfiConverterCallbackInterfaceDidResolver33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_ExampleDIDResolver_object_free", referenced from:
      _$s7didcomm18ExampleDidResolverCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_ExampleSecretsResolver_object_free", referenced from:
      _$s7didcomm22ExampleSecretsResolverCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnDIDResolverResult_object_free", referenced from:
      _$s7didcomm19OnDidResolverResultCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnFindSecretsResult_object_free", referenced from:
      _$s7didcomm19OnFindSecretsResultCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnFromPriorPackResult_init_callback", referenced from:
      _$s7didcomm50FfiConverterCallbackInterfaceOnFromPriorPackResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnFromPriorUnpackResult_init_callback", referenced from:
      _$s7didcomm52FfiConverterCallbackInterfaceOnFromPriorUnpackResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnGetSecretResult_object_free", referenced from:
      _$s7didcomm17OnGetSecretResultCfdySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnPackEncryptedResult_init_callback", referenced from:
      _$s7didcomm50FfiConverterCallbackInterfaceOnPackEncryptedResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnPackPlaintextResult_init_callback", referenced from:
      _$s7didcomm50FfiConverterCallbackInterfaceOnPackPlaintextResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnPackSignedResult_init_callback", referenced from:
      _$s7didcomm47FfiConverterCallbackInterfaceOnPackSignedResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnUnpackResult_init_callback", referenced from:
      _$s7didcomm43FfiConverterCallbackInterfaceOnUnpackResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_OnWrapInForwardResult_init_callback", referenced from:
      _$s7didcomm50FfiConverterCallbackInterfaceOnWrapInForwardResult33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_SecretsResolver_init_callback", referenced from:
      _$s7didcomm44FfiConverterCallbackInterfaceSecretsResolver33_70915CE519991AA7D20AEA431BE4069FLLO04initD0yyFZySpySo14RustCallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_rustbuffer_free", referenced from:
      _$sSo10RustBufferV7didcommE10deallocate33_70915CE519991AA7D20AEA431BE4069FLLyyFySpySo0A10CallStatusVGXEfU_ in didcomm-1.o
  "_ffi_didcomm_2a6d_rustbuffer_from_bytes", referenced from:
      _$sSo10RustBufferV7didcommE4from33_70915CE519991AA7D20AEA431BE4069FLLyABSRys5UInt8VGFZABSpySo0A10CallStatusVGXEfU_ in didcomm-1.o
ld: symbol(s) not found for architecture x86_64

macbook pro 2017 year with macOS Monterey (Version 12.4) swift-driver version: 1.45.2 Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12) Target: x86_64-apple-macosx12.0

Yorik0512 commented 2 years ago

Hi @skhamis

Fixed issue, just updated Cargo.toml dependencies on last. But when I'm trying build dylib file in xcode catch the error:

ld: building for iOS Simulator, but linking in dylib built for macOS, file 'AwesomeProject/ios/libdidcomm.dylib' for architecture x86_64
panicfrog commented 1 year ago

Hi @skhamis

Fixed issue, just updated Cargo.toml dependencies on last. But when I'm trying build dylib file in xcode catch the error:

ld: building for iOS Simulator, but linking in dylib built for macOS, file 'AwesomeProject/ios/libdidcomm.dylib' for architecture x86_64

please check your xcode setting, Build Settings -> Architectures