Skip to content

Commit

Permalink
Merge pull request #12 from getditto/tk/1.46
Browse files Browse the repository at this point in the history
Update from Rust 1.43 to 1.46 and improve packaging in minor ways
  • Loading branch information
thombles authored Oct 13, 2020
2 parents 21ad129 + 6135d82 commit 50b0403
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 47 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ create an issue if you notice any problems.

Visit the [releases page](https://github.com/getditto/rust-bitcode/releases) and
download a zip file. It will have a name of the form
`rust-ios-arm64-20xx-xx-xx.zip` where the date is the Rust nightly that it is
based on.
`rust-ios-arm64-xxx.zip`.

Unzip the file and open a terminal to the extracted directory. Run the
installation script:
Expand All @@ -31,12 +30,7 @@ installation script:
./install.sh
```

This will:
1. Install the toolchain in `~/.rust-ios-arm64/toolchain-YYYY-MM-DD`
2. Configure `rustup` with a custom toolchain under the name `ios-arm64`.

You can also install and add the toolchain yourself if you don't like these
defaults.
This will install the toolchain in `~/.rustup/toolchains/ios-arm64-xxx`.

## Build from source

Expand All @@ -48,15 +42,14 @@ defaults.
repositories under `build/` and compile them. The toolchain will end up
at `build/rust-build/build/x86_64-apple-darwin/stage2`.
5. Run `./install.sh`. This will install the toolchain in
`~/.rust-ios-arm64/toolchain-YYYY-MM-DD` and add it to rustup, the same as
for pre-compiled releases.
`~/.rustup/toolchains/rust-ios-arm64-1.46.0`, making it available in rustup.

## Using the toolchain

Build your library like this:

```
RUSTFLAGS="-Z embed-bitcode" cargo +ios-arm64 build --target aarch64-apple-ios --release --lib
cargo +ios-arm64-1.46.0 build --target aarch64-apple-ios --release --lib
```

## License
Expand Down
5 changes: 2 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cd "$WORKING_DIR/llvm-project"
git reset --hard
git clean -f
git checkout "$LLVM_BRANCH"
git apply ../../patches/llvm-system-libs.patch
cd ..

mkdir -p llvm-build
Expand All @@ -44,11 +45,9 @@ cd rust
git reset --hard
git clean -f
git checkout "$RUST_BRANCH"
git apply ../../patches/rust_embed_cmdline.diff
cd ..
mkdir -p rust-build
cd rust-build
../rust/configure --llvm-config="$WORKING_DIR/llvm-root/bin/llvm-config" --target=aarch64-apple-ios --enable-extended --tools=cargo
export RUSTFLAGS_NOT_BOOTSTRAP=-Zembed-bitcode
../rust/configure --llvm-config="$WORKING_DIR/llvm-root/bin/llvm-config" --target=aarch64-apple-ios --enable-extended --tools=cargo --release-channel=stable
export CFLAGS_aarch64_apple_ios=-fembed-bitcode
python "$WORKING_DIR/rust/x.py" build
13 changes: 5 additions & 8 deletions config.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# 1. Select the best branch, tag or commit hash from https://github.com/apple/llvm-project
# The recommended approach is to use the tagged release that matches the Swift version
# returned by the command below (at this time running Xcode Version 11.3.1 (11C504))
# returned by the command below:
# $ xcrun -sdk iphoneos swiftc --version
# Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
# Target: x86_64-apple-darwin19.3.0

LLVM_BRANCH="tags/swift-5.2.3-RELEASE"
LLVM_BRANCH="tags/swift-5.3-RELEASE"

# 2. Select the best branch, tag or commit hash from https://github.com/rust-lang/rust
# The stable 1.40.0 version of Rust seems to work

RUST_BRANCH="tags/1.43.0"
RUST_BRANCH="tags/1.46.0"

# 3. Select a name for the toolchain you want to install as. The toolchain will be installed
# under $HOME/.rust-ios-arm64/toolchain-$RUST_TOOLCHAIN
# under $HOME/.rustup/toolchains/rust-$RUST_TOOLCHAIN

RUST_TOOLCHAIN="1.43.0"
RUST_TOOLCHAIN="ios-arm64-1.46.0"

26 changes: 18 additions & 8 deletions dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,35 @@
set -euxo
source config.sh

# The built toolchain that we are going to package
WORKING_DIR="$(pwd)/build"
DEST="$(pwd)/dist/rust-ios-arm64-${RUST_TOOLCHAIN}"
TOOLCHAIN_DEST="${DEST}/toolchain-${RUST_TOOLCHAIN}"

rm -rf "$TOOLCHAIN_DEST"
# The directory which will be added to the final zip file
DEST="$(pwd)/dist/rust-${RUST_TOOLCHAIN}"

# The actual toolchain inside that, which will be installed to ~/.rustup/...
TOOLCHAIN_DEST="${DEST}/${RUST_TOOLCHAIN}"

rm -rf "$DEST"
mkdir -p "$TOOLCHAIN_DEST"

# Remove unneeded files from output
rm -rf "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2/lib/rustlib/src"

# Copy in toolchain artifacts
cp -r "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2"/* "$TOOLCHAIN_DEST"
cp -r "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2-tools/x86_64-apple-darwin/release/cargo" "$TOOLCHAIN_DEST/bin"

# Copy in static files that need to be included in the distribution
cp LICENSE* README.md "$DEST"

rm -rf "$DEST/install.sh"
echo "#!/bin/bash" >> "$DEST/install.sh"
echo "DEST_TOOLCHAIN=\"\$HOME/.rust-ios-arm64/toolchain-$RUST_TOOLCHAIN\"" >> "$DEST/install.sh"
echo "DEST_TOOLCHAIN=\"\$HOME/.rustup/toolchains/$RUST_TOOLCHAIN\"" >> "$DEST/install.sh"
echo "mkdir -p \"\$DEST_TOOLCHAIN\"" >> $DEST/install.sh
echo "cp -r \"toolchain-$RUST_TOOLCHAIN\"/* \"\$DEST_TOOLCHAIN\"" >> "$DEST/install.sh"
echo "rustup toolchain link ios-arm64 \"\$DEST_TOOLCHAIN\"" >> "$DEST/install.sh"
echo "cp -r \"$RUST_TOOLCHAIN\"/* \"\$DEST_TOOLCHAIN\"" >> "$DEST/install.sh"
chmod +x "$DEST/install.sh"

cd dist
zip -r "rust-ios-arm64-${RUST_TOOLCHAIN}.zip" "rust-ios-arm64-${RUST_TOOLCHAIN}"
rm -f "rust-${RUST_TOOLCHAIN}.zip"
zip -r "rust-${RUST_TOOLCHAIN}.zip" "rust-${RUST_TOOLCHAIN}"
cd ..
8 changes: 6 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ set -euxo
source config.sh

WORKING_DIR="$(pwd)/build"
DEST_TOOLCHAIN="$HOME/.rust-ios-arm64/toolchain-$RUST_TOOLCHAIN"
DEST_TOOLCHAIN="$HOME/.rustup/toolchains/$RUST_TOOLCHAIN"

# Remove unneeded files from output
rm -rf "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2/lib/rustlib/src"

rm -rf "$DEST_TOOLCHAIN"
mkdir -p "$DEST_TOOLCHAIN"
cp -r "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2"/* "$DEST_TOOLCHAIN"
cp -r "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2-tools/x86_64-apple-darwin/release/cargo" "$DEST_TOOLCHAIN/bin"

rustup toolchain link ios-arm64 "$DEST_TOOLCHAIN"
echo "Installed bitcode-enabled Rust toolchain. Use with: +$RUST_TOOLCHAIN"
40 changes: 40 additions & 0 deletions patches/llvm-system-libs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp
index 6c31df3e173b..69aaaf6ca78e 100644
--- a/llvm/tools/llvm-config/llvm-config.cpp
+++ b/llvm/tools/llvm-config/llvm-config.cpp
@@ -707,7 +707,34 @@ int main(int argc, char **argv) {
// Output system libraries only if linking against a static
// library (since the shared library links to all system libs
// already)
- OS << (LinkMode == LinkModeStatic ? LLVM_SYSTEM_LIBS : "") << '\n';
+
+ // ========== BEGIN HACK ==========
+
+ // There is a bug where "llvm-config --system-libs" will output long absolute paths.
+ // This ends up with rust's cc doing bad things like "-llibz.tbd" or "-llibxml2.dylib".
+ // Some attempts have been made to patch this but none of them have actually landed
+ // in either LLVM 10 (which Apple is currently using) nor in LLVM 11.
+ //
+ // References:
+ // https://discourse.brew.sh/t/llvm-config-10-0-1-advertise-libxml2-tbd-as-system-libs/8593/4
+ // https://reviews.llvm.org/D86134
+ // https://reviews.llvm.org/D87590
+ //
+ // It appears that the right way to fix this involves LLVM's CMakeLists.txt where
+ // these system libraries are calculated. Unfortunately I can't work out how to apply
+ // the proposed fixes to apple's fork of LLVM as the CMake stuff is all a bit different.
+ //
+ // Rather than spend all week understanding LLVM's build system, I'm going to make the
+ // bold assumption that everybody who's building this bitcode toolchain is running on
+ // basically similar Macs, so if I just hardcode the right list of libraries here then
+ // we'll all be okay.
+ //
+ // This can be removed when the appropriate upstream fix reaches Xcode's LLVM.
+
+ //OS << (LinkMode == LinkModeStatic ? LLVM_SYSTEM_LIBS : "") << '\n';
+ OS << (LinkMode == LinkModeStatic ? "-lz -lcurses -lm -lxml2" : "") << '\n';
+
+ // ========== END HACK ==========
}
} else if (!Components.empty()) {
WithColor::error(errs(), "llvm-config")
15 changes: 0 additions & 15 deletions patches/rust_embed_cmdline.diff

This file was deleted.

0 comments on commit 50b0403

Please sign in to comment.