2 Commitit 5336c23c68 ... e1f297214c

Tekijä SHA1 Viesti Päivämäärä
  Andy Dill e1f297214c Document the madness 5 vuotta sitten
  Andy Dill f7f33d7d06 It works! 5 vuotta sitten
5 muutettua tiedostoa jossa 27 lisäystä ja 1 poistoa
  1. 22 0
      README.md
  2. 2 0
      librusty/.cargo/config
  3. 1 1
      librusty/rust-toolchain
  4. 2 0
      librusty/src/lib.rs
  5. BIN
      unity/Assets/Plugins/iOS/librusty.a

+ 22 - 0
README.md

@@ -0,0 +1,22 @@
1
+# rust-on-ios
2
+
3
+This is a quick proof-of-concept for a bitcode-enabled library built from Rust intended for consumption in an iOS app built in Unity (2018.4.11f1)
4
+
5
+Unity defaults to embedding bitcode meaning all static dependencies must do likewise. Rust, by default, does not embed bitcode for static library targets. We can use `-C lto -Z embed-bitcode` to ask Rust to embed bitcode (afaict `-C lto` is required because the shipped iOS rust-std libs also need to embed bitcode.)
6
+
7
+Naturally both Rust and Apple have forked LLVM and they are not always in-sync which is the current major problem [outlined here](https://github.com/rust-lang/rust/issues/35968). For Xcode 11.1 the latest Rust version we can use is `nightly-2019-07-17`.
8
+
9
+## Building
10
+
11
+- cd librusty
12
+- cargo install cargo-lipo
13
+- rustup target add aarch64-apple-ios
14
+- cargo lipo --targets aarch64-apple-ios --release
15
+- cp target/universal/release/librusty.a ../unity/Assets/Plugins/iOS/librusty.a
16
+
17
+## So, what?
18
+
19
+Until Rust officially decides to support bitcode we have to jump through hoops in order to do so:
20
+- We must use a specific (nightly) compiler version
21
+- Xcode betas/updates **may** break linkability of our static library
22
+- Downstream developers **may not** all be on the same (latest) version of Xcode

+ 2 - 0
librusty/.cargo/config

@@ -0,0 +1,2 @@
1
+[build]
2
+rustflags = ["-C", "lto", "-Z", "embed-bitcode"]

+ 1 - 1
librusty/rust-toolchain

@@ -1 +1 @@
1
-nightly-2019-09-13
1
+nightly-2019-07-17

+ 2 - 0
librusty/src/lib.rs

@@ -2,6 +2,7 @@ use std::ffi::CStr;
2 2
 use std::ffi::CString;
3 3
 use std::os::raw::c_char;
4 4
 
5
+#[no_mangle]
5 6
 #[allow(non_snake_case)]
6 7
 pub extern "C" fn DoSomeInterestingWork(count: i32, content: *const c_char) -> *const c_char {
7 8
     let content_string = unsafe { CStr::from_ptr(content) }
@@ -22,6 +23,7 @@ pub extern "C" fn DoSomeInterestingWork(count: i32, content: *const c_char) -> *
22 23
         .into_raw()
23 24
 }
24 25
 
26
+#[no_mangle]
25 27
 #[allow(non_snake_case)]
26 28
 pub extern "C" fn FreeString(content: *mut c_char) {
27 29
     unsafe {

BIN
unity/Assets/Plugins/iOS/librusty.a