Comment by viktorcode

1 day ago

> We previously explored Swift, but the C++ interop never quite got there

But Rust doesn't have C++ interop at all?

You can do it via the C ABI, and use opaque pointers to represent higher-level Rust/C++ concepts if you want to.

Firefox is a mixed C++ / Rust codebase with a relatively close coupling between Rust and C++ components in places (layout/dom/script are in C++ while style is in Rust, and a mix of WebRender (Rust) and Skia (C++) are used for rendering with C++ glue code)

  • > You can do it via the C ABI, and use opaque pointers to represent higher-level Rust/C++ concepts

    Yeah but, you can do the same in Swift

    • My understanding from a brief read of the Swift issue is that they kept running into bugs in the Swift compiler which, in practice, prevented them from doing the things that they ought to be do in theory. This went on for long enough, that they got fed up and abandoned Swift.

      The Rust compiler is incredibly solid (across all target platforms), and while it's C/C++ interop is relatively simplistic, what does exist is extensively battle tested in production codebases.

>But Rust doesn't have C++ interop at all?

It also doesn't have the disadvantages of Swift. Once the promise of Swift/C++ interop is gone there isn't enough left to recommend it.

  • I’m curious what issues people were running into with Swift’s built in C++ interop? I haven’t had the chance to use it myself, but it seemed reasonable to me at a surface level.

There is also cxx.rs, which is quite nice, albeit you have to struggle sending `std` types back and forth a bit

  • > albeit you have to struggle sending `std` types back and forth a bit

    Firefox solves this partly by not using `std` types.

    For example, https://github.com/mozilla/thin-vec exists in large part because it's compatible with Firefox's existing C++ Vec/Array implementation (with the bonus that it's only 8 bytes on the stack compared to 24 for the std Vec).

Rust has cxx which I would argue is "good enough" for most use cases. At least all C++ use cases I have. Not perfect, but pretty damn reasonable.