Skip to content

Commit

Permalink
Update from Rust 1.43 to 1.46 and improve packaging in minor ways.
Browse files Browse the repository at this point in the history
In particular, toolchains are now installed against their specific
version number, so they can coexist. This is particularly useful in CI
environments where different branches may be on different versions.
  • Loading branch information
thombles committed Oct 13, 2020
1 parent 21ad129 commit 94414ae
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 32 deletions.
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
7 changes: 3 additions & 4 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
# 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

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 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 94414ae

Please sign in to comment.