Example of an automated script that does most of this: https://github.com/surpher/PactSwiftMockServer/blob/fb8148866bb05f49a0b1dcaae66c67bad1e7eca7/Support/build_rust_dependencies
curl https://sh.rustup.rs -sSf | sh
rustup target list
rustup target add aarch64-apple-ios aarch64-apple-darwin x86_64-apple-ios x86_64-apple-darwin
# While arm64-apple-ios-sim is still in Tier 3:
rustup component add rust-src --toolchain nightly-x86_64-apple-darwin
rustup toolchain install nightly
more: https://doc.rust-lang.org/edition-guide/rust-2018/rustup-for-managing-rust-versions.html
cargo-lipo
- a tool for building universal iOS binaries,
cbindgen
- a tool for generating C headers from rust
cargo install cargo-lipo
cargo install cbindgen
cd pact-reference/rust/pact_mock_server_ffi
cbindgen src/lib.rs -l c > pact_mock_server.h
cp pact_mock_server.h ../PactSwift/Sources/Headers/pact_mock_server.h
cd pact-reference/rust/pact_mock_server_ffi
nano Cargo.toml
Set the following:
[lib]
name = "pact_mock_server"
crate-type = ["staticlib", "cdylib"]
https://github.com/japaric/rust-cross
cargo lipo --release
cp ../target/universal/release/libpact_mock_server.a /path/to/PactSwift/Resources/iOS/lipact_mock_server.a
cargo build --target=x86_64-apple-ios --release
cp ../target/x86_64-apple-ios/release/libpact_mock_server.a /path/to/PactSwift/Resources/iOS/lipact_mock_server.a
cargo +nightly build -Z build-std --target aarch64-apple-ios-sim --release
cp ../target/arm64-apple-ios-sim/release/libpact_mock_server.a /path/to/PactSwift/Resources/arm64iOSsim/libpact_mock_server.a
cargo build --targget=x86_64-apple-darwin --release
cp ../target/x86_64-apple-darwin/release/libpact_mock_server.a /path/to/PactSwift/Resources/macOS-x86_64/lipact_mock_server.a
cargo build --target=aarch64-apple-darwin --release
cp ../target/arm64-apple-darwin/release/libpact_mock_server.a /path/to/PactSwift/Resources/macOS-arm64/lipact_mock_server.a
https://nadim.computer/posts/2022-02-11-maccatalyst.html
lipo -info libpact_mock_server.a
lipo libfoo.a -thin arm64 -output libfoo-arm64.a
Use -thin
and not -extract
the latter, still outputs a fat file, one which happens to only contain a single architecture.
lipo -create foo-arm64.a foo-x86_64.a -output foo.a
For a fat lib, start by having cargo
build the Rust code separately for each architecture. use lipo
to combine the outputs into a fat binary.
cargo +nightly build -Z build-std --target aarch64-apple-ios-sim
curll --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
apt-get install protobuf-compiler
https://blog.mozilla.org/data/2021/04/16/this-week-in-glean-rustc-ios-and-an-m1/
- https://nachbaur.com/2019/03/22/working-with-multiple-architectures/
- https://doc.rust-lang.org/edition-guide/rust-2018/rustup-for-managing-rust-versions.html
- https://github.com/guedou/cargo-strip
- https://github.com/johnthagen/min-sized-rust (Minimize size of rust lib)
- https://users.rust-lang.org/t/unable-to-build-a-dynamic-library-dylib-for-ios/24918/4 (building and using dynamic libs for development purposes - would be it enough for PactSwift? It shouldn't be embedded in the release app anyway!)
- https://visly.app/blog/rust-on-ios
- https://medium.com/flutter-community/using-ffi-on-flutter-plugins-to-run-native-rust-code-d64c0f14f9c2
- https://www.reddit.com/r/rust/comments/aae6x8/rust_ios_and_linking_against_fat_native_libraries/