uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Add support for u128

Open pronebird opened this issue 2 months ago • 3 comments

Hi,

It seems that u128 is not supported out of box. I think we should fix it

pronebird avatar Oct 08 '25 09:10 pronebird

The challenge here is probably bindings - eg, how would Kotlin use it?

mhammond avatar Oct 08 '25 13:10 mhammond

Even Swift has added support for 128-bit integer types recently: https://developer.apple.com/documentation/swift/int128, so it seems the only issue is Kotlin Multiplatform here (Java has BigInteger; see below). It would be great if we could pass u128 directly; it is useful for passing UUIDs.

First-party bindgens

  • Python: int
  • Swift: Int128 and UInt128 in Swift 6 (iOS 18+, macOS 15+)
  • Kotlin/JVM: java.math.BigInteger
  • Ruby: Integer in CRuby 2.4+

Third-party bindgens

  • JavaScript: BigInt
  • Kotlin Multiplatform: :cry:
  • Go: Int in "math/big"
  • C#: System.Int128 and System.UInt128 in .NET 7+, or System.Numerics.BigInteger
  • Dart: BigInt in dart:core
  • Java: java.math.BigInteger

When the FFI-1.0 proposal is completed, I think we can make our own library that implements 128-bit integers.

paxbun avatar Oct 08 '25 14:10 paxbun

Not sure if that's the way out but if Kotlin does not support u128, then we could default to String conversion. This is what I am doing at the moment with protobuf which does not support u128 out of box.

pronebird avatar Oct 09 '25 11:10 pronebird