Skip to content

Commit

Permalink
Integrate code review comments.
Browse files Browse the repository at this point in the history
1. Provided a fuller explanation of how Xcode integration works, including a pointer to how it can be done without cargo lipo.
2. Run `rustfmt` on the code.
  • Loading branch information
brotskydotcom committed Feb 7, 2022
1 parent 3c8d7e1 commit cfb99e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ crate-type = ["staticlib"]
3. Next, go back to your *"Build Settings"* and add a *"Library Search Path"* of `$(PROJECT_DIR)../myproject/target/universal/$(CONFIGURATION:lower)`. This will provide the right search paths for both debug and release.
4. Finally, add a second *"Run Script"* build phase but leave this one at the bottom (so it runs after the build is complete). Name this one "delete Rust static libraries" and make it run on every build. The content of this phase should be something like:
4. Finally, add a second *"Run Script"* build phase but leave this one at the bottom (so it runs after the build is complete). Name this one "delete Rust static libraries" and make it run on every build. (While it may seem counter-intuitive to delete the library we just built, it's needed to make Xcode's new build system run the build script each time. Back in the days when there were just two target platforms -- x86_64 and arm64 -- the output of cargo lipo would have both and a rebuild wouldn't be necessary. But now that there are actually three target platforms -- x86_64, arm64, and arm64-simulator -- the built library can only have one of the arm64 variants. Every time you change the target platform, the library will need to be rebuilt, but Xcode can't detect that because it's looking at mod dates not at target platforms. So we always delete the built library after it's linked, in order to force it to be rebuilt with the correct target the next time through.) The content of this phase should be something like:
```bash
# Delete the built libraries that were just linked.
# If this isn't done, XCode won't try to rebuild them
Expand All @@ -64,6 +64,8 @@ crate-type = ["staticlib"]
```
5. If you are planning to do `Archive` builds in the XCode application, you also need to go into your *"Build Settings"* and set *Enable Bitcode* to **`No`**. This is because Rust uses a different LLVM than Xcode does, and the in-application XCode `Archive` build process does a bitcode verification which will fail on Rust libraries with an error message such as: `Invalid value (Producer: 'LLVM13.0.0-rust-1.57.0-stable' Reader: 'LLVM APPLE_1_1300.0.29.30_0') for architecture arm64`

A final note about XCode integration: because all XCode builds are "one target at a time", there's really no need to use `cargo lipo` at all when building for iOS. For an example of an Xcode product that invokes cargo directly, look at the apps in the [`rust-on-ios` project](https://github.com/brotskydotcom/rust-on-ios).

## Installation

Install `cargo lipo` with `cargo install cargo-lipo`. `cargo lipo` should always be buildable with the latest stable Rust version. For the minimum supported version check `.travis.yml`.
Expand Down
14 changes: 8 additions & 6 deletions src/xcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn targets_from_env() -> Result<Vec<String>> {
// There's a new "iphonesimulator" platform that requires a special abi suffix
// We just look for "sim" here as a minimal distinguishing check from "iphoneos".
Ok(s) if s.contains("sim") => ("apple-ios", Some("sim")),
_ => ("apple-ios", None)
_ => ("apple-ios", None),
};
Ok(archs
.split(" ")
Expand All @@ -54,11 +54,13 @@ fn map_arch_to_target(arch: &str, platform: &str, abi: Option<&str>) -> Result<S
};
match abi {
// the "sim" abi is only used with aarch64 builds
Some("sim") => if mapped_arch == "aarch64" {
Ok(format!("{}-{}-{}", mapped_arch, platform, "sim"))
} else {
Ok(format!("{}-{}", mapped_arch, platform))
},
Some("sim") => {
if mapped_arch == "aarch64" {
Ok(format!("{}-{}-{}", mapped_arch, platform, "sim"))
} else {
Ok(format!("{}-{}", mapped_arch, platform))
}
}
Some(abi) => Ok(format!("{}-{}-{}", mapped_arch, platform, abi)),
None => Ok(format!("{}-{}", mapped_arch, platform)),
}
Expand Down

0 comments on commit cfb99e0

Please sign in to comment.