Hi all! I’m trying to introduce a rust library to ...
# kotlin-native
s
Hi all! I’m trying to introduce a rust library to KMP, but I don’t know how to configure ios cinterops, I’ve tried to build an xcode project to verify that the
.h
.a
is working, but currently in KMP it prompts:
Copy code
Undefined symbols for architecture x86_64:
  "_CTFontGetXHeight", referenced from:
      SkScalerContext_Mac::generateFontMetrics(SkFontMetrics*) in libskia.a(fontmgr_mac_ct.SkScalerContext_mac_ct.o)
  "_CTFontGetUnderlineThickness", referenced from:
      SkScalerContext_Mac::generateFontMetrics(SkFontMetrics*) in libskia.a(fontmgr_mac_ct.SkScalerContext_mac_ct.o)
  "_CTFontGetUnderlinePosition", referenced from:
      SkScalerContext_Mac::generateFontMetrics(SkFontMetrics*) in libskia.a(fontmgr_mac_ct.SkScalerContext_mac_ct.o)
  "_CTFontGetAdvancesForGlyphs", referenced from:
      SkScalerContext_Mac::generateMetrics(SkGlyph*, SkArenaAlloc*) in libskia.a(fontmgr_mac_ct.SkScalerContext_mac_ct.o)
  "_CTFontCreatePathForGlyph", referenced from:
      SkScalerContext_Mac::generateMetrics(SkGlyph*, SkArenaAlloc*) in libskia.a(fontmgr_mac_ct.SkScalerContext_mac_ct.o)
      SkScalerContext_Mac::generatePath(SkGlyph const&, SkPath*) in libskia.a(fontmgr_mac_ct.SkScalerContext_mac_ct.o)
  "_CTFontDrawGlyphs", referenced from:
      SkCTFontGetSmoothBehavior() in libskia.a(libskia.SkCTFont.o)
      SkScalerContext_Mac::Offscreen::getCG(SkScalerContext_Mac const&, SkGlyph const&, unsigned short, unsigned long*, bool) in libskia.a(fontmgr_mac_ct.SkScalerContext_mac_ct.o)
  "_kCTFontVariationAxisMinimumValueKey", referenced from:
      SkCTVariationFromSkFontArguments(__CTFont const*, SkFontArguments const&) in libskia.a(fontmgr_mac_ct.SkTypeface_mac_ct.o)
      SkTypeface_Mac::onGetVariationDesignParameters(SkFontParameters::Variation::Axis*, int) const in libskia.a(fontmgr_mac_ct.SkTypeface_mac_ct.o)
  "_CTFontGetSize", referenced from:
      ...
  "_CTFontGetSymbolicTraits", referenced from:
      create_from_name(char const*, SkFontStyle const&) in libskia.a(fontmgr_mac_ct.SkFontMgr_mac_ct.o)
      SkTypeface_Mac::Make(std::__1::unique_ptr<__CTFont const, SkFunctionWrapper<void (void const*), &(CFRelease)> >, OpszVariation, std::__1::unique_ptr<SkStreamAsset, std::__1::default_delete<SkStreamAsset> >)::$_0::operator()() const in libskia.a(fontmgr_mac_ct.SkTypeface_mac_ct.o)
      SkTypeface_Mac::onGetAdvancedMetrics() const in libskia.a(fontmgr_mac_ct.SkTypeface_mac_ct.o)
  "_kCTFontFamilyNameKey", referenced from:
      SkTypeface_Mac::onCreateFamilyNameIterator() const in libskia.a(fontmgr_mac_ct.SkTypeface_mac_ct.o)
  "_CTFontCollectionCreateMatchingFontDescriptors", referenced from:
      (anonymous namespace)::SkCopyAvailableFontFamilyNames(__CTFontCollection const*) in libskia.a(fontmgr_mac_ct.SkFontMgr_mac_ct.o)
  "_CTFontCopyAttribute", referenced from:
      SkCTFontCreateExactCopy(__CTFont const*, double, OpszVariation) in libskia.a(fontmgr_mac_ct.SkTypeface_mac_ct.o)
      SkTypeface_Mac::onOpenStream(int*) const in libskia.a(fontmgr_mac_ct.SkTypeface_mac_ct.o)
  "_CTFontCreateForString", referenced from:
      SkFontMgr_Mac::onMatchFamilyStyleCharacter(char const*, SkFontStyle const&, char const**, int, int) const in libskia.a(fontmgr_mac_ct.SkFontMgr_mac_ct.o)
ld: symbol(s) not found for architecture x86_64
demo: https://github.com/qdsfdhvh/compose-hellorust
n
Do note that Kotlin Native doesn't provide any Rust interop. Interoperability with Rust isn't supported.
k
It would if rust exposes C interop, yes?
n
If rust generates a C compliant API then that would work with Kotlin Native via its C interop. This doesn't automatically mean that Rust interop is supported since that would require direct communication between Kotlin and Rust, without an intermediate API getting in the way.
k
Well, I mean, I would assume anybody trying to interop with Rust would expose a C interface. AFAIK, that’s the only (reasonable) way to interop with Rust.
That is me making assumptions. Definitely no direct interop.
Looking at the errors, that does look like what the OP is trying to do.
n
Not surprising since C in some ways acts as a common language for many native/platforms APIs like JS does for web APIs.
I'm not familiar with how Rust generates C APIs. Does Rust only generate header files, or does it generate header and library files (aka traditional C library)?
Looks like the OP hasn't setup the configuration properly for generating the C library from Rust. Some libraries (like LVGL for example - https://docs.lvgl.io/8/porting/project.html#configuration-file ) use configuration to determine which symbols to include in library files (to keep the file size down as much as possible - common in Embedded environments).