
Show HN: Rust Toolchain for iOS Bitcode - bigfish24
https://github.com/getditto/rust-bitcode
======
tbojanin
Can someone ELIF what's a toolchain for iOS bitcode?

~~~
bluejekyll
Apple requires bitcode submissions for tvOS and watchOS, this has effectively
meant that you needed Apple’s toolchain to build and distribute binaries for
those platforms.

Bitcode is an intermediate format produced by LLVM, which allows for
optimization passes to be applied to it across different languages. For
example, C, C++, Swift, ObjC, and Rust can all benefit from some of the same
bitcode optimization passes.

In theory Apple wanted this so they could improve the performance of
applications when distributed on some of their platforms, though the benefits
and potential of this has been a bit dubious. It did mean that Rust (until
this) couldn’t easily target those Apple products.

~~~
anonova
I was under the impression that it wasn't for performance but for
distribution, i.e., to optimize for app size. Instead of having a fat binary
crosscompiled for different architectures, Apple uses the bitcode to compile
and distribute per architecture. It's part of the "app thinning" process.

~~~
MaxGabriel
To expand on this, it also lets them target new CPU architectures without
having developers recompile code for that architecture. This lets them make
incremental improvements (eg armv7), but would also let them use their own CPU
architecture should they move away from Intel/ARM.

As an example here’s Chris Lattner tweeting about that use case:

[https://twitter.com/clattner_llvm/status/1091186386634326017...](https://twitter.com/clattner_llvm/status/1091186386634326017?s=21)

~~~
saagarjha
> but would also let them use their own CPU architecture should they move away
> from Intel/ARM

Only if their new architecture looked a lot like Intel/ARM. Bitcode can’t
paper over all architectural differences.

~~~
pjmlp
Regular bitcode cannot do it. However Apple has naturally customized it for
their own purposes.

Not everything that Apple does lands on upstream.

------
dknecht
Is the main advantage you can run on WatchOS and AppleTV? Do you notice any
performance improvements?

~~~
rhodysurf
Yes. There are no performance improvements, its just required by Apple.

------
dep_b
Great work! Is it easy to interact between Swift and Rust or UIKit libraries?

~~~
pornel
Unfortunately, you have to use C or ObjC (or at least the ObjC runtime) as the
middleman.

Now that there is a stable Swift ABI, at least it's theoretically possible to
add a first-class Swift interoperability support to Rust, but it's a quite a
chunk of work that nobody has attempted yet.

Currently the practical approach is to write the UI in Swift and Rust on the
back-end, e.g. gif.ski app does it this way:
[https://github.com/sindresorhus/Gifski](https://github.com/sindresorhus/Gifski)

------
rhodysurf
Awesome. I tried tinkering with this a hwile back and failed.

------
steeve
This is very cool!

------
woodrowbarlow
does apple still require that you submit source code as objective C with your
app? i recall google creating a transpiler from java to objective C some years
ago so they could use their existing java codebases and still meet apple's
requirement for submitting objective C source code.

~~~
vardump
I wasn't aware Apple ever required source code submission? Not at least in iOS
projects I was involved with or know about.

