Skip to content

Commit 50b0403

Browse files
authored
Merge pull request #12 from getditto/tk/1.46
Update from Rust 1.43 to 1.46 and improve packaging in minor ways
2 parents 21ad129 + 6135d82 commit 50b0403

File tree

7 files changed

+75
-47
lines changed

7 files changed

+75
-47
lines changed

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ create an issue if you notice any problems.
2121

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

2726
Unzip the file and open a terminal to the extracted directory. Run the
2827
installation script:
@@ -31,12 +30,7 @@ installation script:
3130
./install.sh
3231
```
3332

34-
This will:
35-
1. Install the toolchain in `~/.rust-ios-arm64/toolchain-YYYY-MM-DD`
36-
2. Configure `rustup` with a custom toolchain under the name `ios-arm64`.
37-
38-
You can also install and add the toolchain yourself if you don't like these
39-
defaults.
33+
This will install the toolchain in `~/.rustup/toolchains/ios-arm64-xxx`.
4034

4135
## Build from source
4236

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

5447
## Using the toolchain
5548

5649
Build your library like this:
5750

5851
```
59-
RUSTFLAGS="-Z embed-bitcode" cargo +ios-arm64 build --target aarch64-apple-ios --release --lib
52+
cargo +ios-arm64-1.46.0 build --target aarch64-apple-ios --release --lib
6053
```
6154

6255
## License

build.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cd "$WORKING_DIR/llvm-project"
2828
git reset --hard
2929
git clean -f
3030
git checkout "$LLVM_BRANCH"
31+
git apply ../../patches/llvm-system-libs.patch
3132
cd ..
3233

3334
mkdir -p llvm-build
@@ -44,11 +45,9 @@ cd rust
4445
git reset --hard
4546
git clean -f
4647
git checkout "$RUST_BRANCH"
47-
git apply ../../patches/rust_embed_cmdline.diff
4848
cd ..
4949
mkdir -p rust-build
5050
cd rust-build
51-
../rust/configure --llvm-config="$WORKING_DIR/llvm-root/bin/llvm-config" --target=aarch64-apple-ios --enable-extended --tools=cargo
52-
export RUSTFLAGS_NOT_BOOTSTRAP=-Zembed-bitcode
51+
../rust/configure --llvm-config="$WORKING_DIR/llvm-root/bin/llvm-config" --target=aarch64-apple-ios --enable-extended --tools=cargo --release-channel=stable
5352
export CFLAGS_aarch64_apple_ios=-fembed-bitcode
5453
python "$WORKING_DIR/rust/x.py" build

config.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
# 1. Select the best branch, tag or commit hash from https://github.com/apple/llvm-project
22
# The recommended approach is to use the tagged release that matches the Swift version
3-
# returned by the command below (at this time running Xcode Version 11.3.1 (11C504))
3+
# returned by the command below:
44
# $ xcrun -sdk iphoneos swiftc --version
5-
# Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
6-
# Target: x86_64-apple-darwin19.3.0
75

8-
LLVM_BRANCH="tags/swift-5.2.3-RELEASE"
6+
LLVM_BRANCH="tags/swift-5.3-RELEASE"
97

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

13-
RUST_BRANCH="tags/1.43.0"
10+
RUST_BRANCH="tags/1.46.0"
1411

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

18-
RUST_TOOLCHAIN="1.43.0"
15+
RUST_TOOLCHAIN="ios-arm64-1.46.0"
1916

dist.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,35 @@
22
set -euxo
33
source config.sh
44

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

9-
rm -rf "$TOOLCHAIN_DEST"
8+
# The directory which will be added to the final zip file
9+
DEST="$(pwd)/dist/rust-${RUST_TOOLCHAIN}"
10+
11+
# The actual toolchain inside that, which will be installed to ~/.rustup/...
12+
TOOLCHAIN_DEST="${DEST}/${RUST_TOOLCHAIN}"
13+
14+
rm -rf "$DEST"
1015
mkdir -p "$TOOLCHAIN_DEST"
16+
17+
# Remove unneeded files from output
18+
rm -rf "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2/lib/rustlib/src"
19+
20+
# Copy in toolchain artifacts
1121
cp -r "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2"/* "$TOOLCHAIN_DEST"
1222
cp -r "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2-tools/x86_64-apple-darwin/release/cargo" "$TOOLCHAIN_DEST/bin"
1323

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

16-
rm -rf "$DEST/install.sh"
1727
echo "#!/bin/bash" >> "$DEST/install.sh"
18-
echo "DEST_TOOLCHAIN=\"\$HOME/.rust-ios-arm64/toolchain-$RUST_TOOLCHAIN\"" >> "$DEST/install.sh"
28+
echo "DEST_TOOLCHAIN=\"\$HOME/.rustup/toolchains/$RUST_TOOLCHAIN\"" >> "$DEST/install.sh"
1929
echo "mkdir -p \"\$DEST_TOOLCHAIN\"" >> $DEST/install.sh
20-
echo "cp -r \"toolchain-$RUST_TOOLCHAIN\"/* \"\$DEST_TOOLCHAIN\"" >> "$DEST/install.sh"
21-
echo "rustup toolchain link ios-arm64 \"\$DEST_TOOLCHAIN\"" >> "$DEST/install.sh"
30+
echo "cp -r \"$RUST_TOOLCHAIN\"/* \"\$DEST_TOOLCHAIN\"" >> "$DEST/install.sh"
2231
chmod +x "$DEST/install.sh"
2332

2433
cd dist
25-
zip -r "rust-ios-arm64-${RUST_TOOLCHAIN}.zip" "rust-ios-arm64-${RUST_TOOLCHAIN}"
34+
rm -f "rust-${RUST_TOOLCHAIN}.zip"
35+
zip -r "rust-${RUST_TOOLCHAIN}.zip" "rust-${RUST_TOOLCHAIN}"
2636
cd ..

install.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ set -euxo
33
source config.sh
44

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

8+
# Remove unneeded files from output
9+
rm -rf "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2/lib/rustlib/src"
10+
11+
rm -rf "$DEST_TOOLCHAIN"
812
mkdir -p "$DEST_TOOLCHAIN"
913
cp -r "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2"/* "$DEST_TOOLCHAIN"
1014
cp -r "$WORKING_DIR/rust-build/build/x86_64-apple-darwin/stage2-tools/x86_64-apple-darwin/release/cargo" "$DEST_TOOLCHAIN/bin"
1115

12-
rustup toolchain link ios-arm64 "$DEST_TOOLCHAIN"
16+
echo "Installed bitcode-enabled Rust toolchain. Use with: +$RUST_TOOLCHAIN"

patches/llvm-system-libs.patch

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

patches/rust_embed_cmdline.diff

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)