# Cross Platform: Rust to LLVM IR and is LLVM IR is portable?

**URL:** <https://users.rust-lang.org/t/cross-platform-rust-to-llvm-ir-and-is-llvm-ir-is-portable/7767>\
**Category:** help\
**Created:** [October 25, 2016, 2:30pm UTC](https://users.rust-lang.org/t/cross-platform-rust-to-llvm-ir-and-is-llvm-ir-is-portable/7767 "2016-10-25T14:30:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bijjubhattaram](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@bijjubhattaram](https://users.rust-lang.org/u/bijjubhattaram)\
**Post date:** [October 25, 2016, 2:30pm UTC](https://users.rust-lang.org/t/cross-platform-rust-to-llvm-ir-and-is-llvm-ir-is-portable/7767/1 "2016-10-25T14:30:48Z")

</div>

Hi

As Rust Compiler is based on LLVM (correct me if i am wrong), and i can convert a library/binary project into LLVM IR using "rustc .... --emit=llvm-ir"

(Cross Platform): Is this LLVM IR portable to any platform that is supported by rust link (windows/Linux/Mac) and compile final executable ?

if not What is MIR, is this MIR cross platform ?

Thanks in advance  
B

---

<div class="post-metadata">

**Author:** ![17cupsofcoffee](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/17cupsofcoffee/32/8665_2.png) [@17cupsofcoffee](https://users.rust-lang.org/u/17cupsofcoffee)\
**Post date:** [October 25, 2016, 3:32pm UTC](https://users.rust-lang.org/t/cross-platform-rust-to-llvm-ir-and-is-llvm-ir-is-portable/7767/2 "2016-10-25T15:32:21Z")

</div>

Yes, LLVM's intermediate language is cross platform. That's one of the main reasons for it existing! Rust doesn't have to handle the specifics of compiling your code down to the target architecture/OS; it just has to turn it into IR, and then LLVM can take it from there.

That said, you definitely don't have to have Rust emit IR and then manually compile it - cross compilation is really easy, especially if you use [rustup](https://blog.rust-lang.org/2016/05/13/rustup.html) to manage the different toolchains.

For an explanation of what exactly MIR is, I'd recommend [this blog post](https://blog.rust-lang.org/2016/04/19/MIR.html) - Niko Matsakis has a golden gift for making complicated topics easy to understand, and I can guarantee I wouldn't do a better job trying to explain it here 😛

---

<div class="post-metadata">

**Author:** ![steveklabnik](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steveklabnik/32/120_2.png) [@steveklabnik](https://users.rust-lang.org/u/steveklabnik)\
**Post date:** [October 25, 2016, 3:37pm UTC](https://users.rust-lang.org/t/cross-platform-rust-to-llvm-ir-and-is-llvm-ir-is-portable/7767/3 "2016-10-25T15:37:25Z")

</div>

> [@17cupsofcoffee](#):
>
> LLVM's intermediate language is cross platform.

This is not my understanding. See [Frequently Asked Questions (FAQ) — LLVM 18.0.0git documentation](http://llvm.org/docs/FAQ.html#can-i-compile-c-or-c-code-to-platform-independent-llvm-bitcode) for example, or [c++ - LLVM bitcode cross-platform - Stack Overflow](http://stackoverflow.com/questions/14258194/llvm-bitcode-cross-platform)

---

<div class="post-metadata">

**Author:** ![17cupsofcoffee](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/17cupsofcoffee/32/8665_2.png) [@17cupsofcoffee](https://users.rust-lang.org/u/17cupsofcoffee)\
**Post date:** [October 25, 2016, 3:51pm UTC](https://users.rust-lang.org/t/cross-platform-rust-to-llvm-ir-and-is-llvm-ir-is-portable/7767/4 "2016-10-25T15:51:59Z")

</div>

Whoops, sorry, apparently my understanding of it was a bit oversimplified. Thanks for the clarification!

---

<div class="post-metadata">

**Author:** ![cuviper](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/cuviper/32/3156_2.png) [@cuviper](https://users.rust-lang.org/u/cuviper)\
**Post date:** [October 25, 2016, 4:40pm UTC](https://users.rust-lang.org/t/cross-platform-rust-to-llvm-ir-and-is-llvm-ir-is-portable/7767/5 "2016-10-25T16:40:11Z")

</div>

The way I understand it is that the IR itself is platform independent, but the represented code will almost certainly have a lot of platform assumptions baked in.

---

<div class="post-metadata">

**Author:** ![skade](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/skade/32/1127_2.png) [@skade](https://users.rust-lang.org/u/skade)\
**Post date:** [October 25, 2016, 5:01pm UTC](https://users.rust-lang.org/t/cross-platform-rust-to-llvm-ir-and-is-llvm-ir-is-portable/7767/6 "2016-10-25T17:01:26Z")

</div>

To add problems, LLVM IR an implementation detail of LLVM and not stable. Different versions of LLVM might or might not understand IR generated by another version.

This is an issue as Apple now supports sending them code as bitcode: [https://github.com/rust-lang/rust/issues/35968](https://github.com/rust-lang/rust/issues/35968)

It needs you to use the correct version of LLVM.

To my understanding, there's other platforms where that approach is used.

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steffahn/32/47569_2.png) [@steffahn](https://users.rust-lang.org/u/steffahn)\
**Post date:** [January 12, 2023, 8:41am UTC](https://users.rust-lang.org/t/cross-platform-rust-to-llvm-ir-and-is-llvm-ir-is-portable/7767/7 "2023-01-12T08:41:37Z")

</div>

Closed on January 12, 2023, 8:41am UTC


