Skip to content

Commit c3b4bc8

Browse files
committed
Initial commit
1 parent bf0f168 commit c3b4bc8

File tree

3 files changed

+155
-2
lines changed

3 files changed

+155
-2
lines changed

.github/workflows/release.yaml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Release stable rust-std
2+
on:
3+
workflow_call:
4+
inputs:
5+
version:
6+
description: 'The rust version to use e.g. 1.80.0'
7+
required: true
8+
type: string
9+
workflow_dispatch:
10+
inputs:
11+
version:
12+
description: 'The rust version to use e.g. 1.80.0'
13+
required: true
14+
type: string
15+
jobs:
16+
release:
17+
permissions:
18+
contents: write
19+
name: Release stable rust-std
20+
runs-on: macos-latest
21+
env:
22+
VERSION: ${{ inputs.version }}
23+
24+
steps:
25+
- name: Checkout repo for cargo.toml
26+
uses: actions/checkout@v4
27+
28+
- name: Install Rust
29+
run: |
30+
brew install rustup
31+
rustup-init -y --default-toolchain ${VERSION}
32+
cp cargo.toml $HOME/.cargo/config.toml
33+
source $HOME/.cargo/env
34+
35+
- name: Install Android NDK
36+
run: |
37+
ANDROID_NDK_BIN_PATH=$(brew --prefix)/share/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin
38+
brew install --cask android-ndk
39+
# Link all clangs into the binary cargo looks for
40+
ln -s ${ANDROID_NDK_BIN_PATH}/aarch64-linux-android35-clang ${ANDROID_NDK_BIN_PATH}/aarch64-linux-android-clang
41+
ln -s ${ANDROID_NDK_BIN_PATH}/armv7a-linux-androideabi35-clang ${ANDROID_NDK_BIN_PATH}/arm-linux-androideabi-clang
42+
ln -s ${ANDROID_NDK_BIN_PATH}/i686-linux-android35-clang ${ANDROID_NDK_BIN_PATH}/i686-linux-android-clang
43+
ln -s ${ANDROID_NDK_BIN_PATH}/x86_64-linux-android35-clang ${ANDROID_NDK_BIN_PATH}/x86_64-linux-android-clang
44+
45+
echo "ANDROID_NDK_BIN_PATH=${ANDROID_NDK_BIN_PATH}" >> $GITHUB_ENV
46+
47+
- name: Download rust stable source code
48+
run: |
49+
wget -q https://static.rust-lang.org/dist/rustc-${VERSION}-src.tar.xz
50+
wget -q https://static.rust-lang.org/dist/rustc-${VERSION}-src.tar.xz.sha256 -O rust-src.tar.xz.sha256
51+
cat rust-src.tar.xz.sha256 | shasum --check --status
52+
53+
- name: Extract rust src
54+
id: rust-src
55+
run: |
56+
tar xzf rustc-${VERSION}-src.tar.xz
57+
echo "path=$(realpath rustc-${VERSION}-src)" >> $GITHUB_OUTPUT
58+
59+
- name: Download LLVM compiler-rt
60+
id: compiler-rt
61+
env:
62+
GH_TOKEN: ${{ github.token }}
63+
run: |
64+
tag=$(gh release list -R llvm/llvm-project --exclude-pre-releases --exclude-drafts -L 1 --json tagName -q '.[0].tagName')
65+
gh release download ${tag} --pattern "compiler-rt*.tar.xz" -R llvm/llvm-project
66+
mkdir compiler-rt
67+
tar xJf compiler-rt*.tar.xz --strip-components=1 -C compiler-rt
68+
echo "path=$(realpath compiler-rt)" >> $GITHUB_OUTPUT
69+
70+
- name: Build rust std (iOS)
71+
env:
72+
# Allow using unstable cargo features in the standard library.
73+
RUSTC_BOOTSTRAP: 1
74+
# This is required by compiler-builtins
75+
RUST_COMPILER_RT_ROOT: ${{ steps.compiler-rt.outputs.path }}
76+
RUSTC_SRC: ${{ steps.rust-src.outputs.path }}
77+
RUSTFLAGS: "-C panic=abort -C opt-level=z -C llvm-args=--inline-threshold=225 -C codegen-units=1"
78+
run: |
79+
cd ${RUSTC_SRC}/library/std
80+
cargo build \
81+
--release \
82+
--features "panic_immediate_abort,optimize_for_size,compiler-builtins-c" \
83+
--target aarch64-apple-ios \
84+
--target aarch64-apple-ios-sim \
85+
--target x86_64-apple-ios \
86+
87+
- name: Build rust std (Android)
88+
env:
89+
RUSTC_BOOTSTRAP: 1
90+
RUST_COMPILER_RT_ROOT: ${{ steps.compiler-rt.outputs.path }}
91+
RUSTC_SRC: ${{ steps.rust-src.outputs.path }}
92+
RUSTFLAGS: "-C panic=abort -C opt-level=z -C llvm-args=--inline-threshold=225 -C codegen-units=1"
93+
run: |
94+
cd ${RUSTC_SRC}/library/std
95+
# Set the path pointing to the NDK where all the cross-compiling clang binaries exist
96+
export PATH="${ANDROID_NDK_BIN_PATH}:${PATH}"
97+
cargo build \
98+
--release \
99+
--features "panic_immediate_abort,optimize_for_size,compiler-builtins-c" \
100+
--target aarch64-linux-android \
101+
--target armv7-linux-androideabi \
102+
--target i686-linux-android \
103+
--target x86_64-linux-android
104+
105+
- name: Create rust std tarball
106+
id: tarball
107+
env:
108+
RUSTC_SRC: ${{steps.rust-src.outputs.path}}
109+
run: |
110+
ARCHES="aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android"
111+
mkdir -p tarballs
112+
cd tarballs
113+
for ARCH in $ARCHES; do
114+
mkdir -p rust-std-${VERSION}-${ARCH}/rust-std-${ARCH}/lib/rustlib/${ARCH}/lib
115+
rustc -V | sed -e 's/rustc //' > rust-std-${VERSION}-${ARCH}/version
116+
117+
cp ${RUSTC_SRC}/target/${ARCH}/release/deps/*.rlib rust-std-${VERSION}-${ARCH}/rust-std-${ARCH}/lib/rustlib/${ARCH}/lib
118+
tar -czf rust-std-${VERSION}-${ARCH}.tar.gz rust-std-${VERSION}-${ARCH}
119+
shasum -a 256 rust-std-${VERSION}-${ARCH}.tar.gz > rust-std-${VERSION}-${ARCH}.tar.gz.sha256
120+
done
121+
echo "path=$(realpath .)" >> $GITHUB_OUTPUT
122+
123+
- name: Create github release with tarballs
124+
env:
125+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126+
TARBALLS_PATH: ${{ steps.tarball.outputs.path }}
127+
run: |
128+
gh release create "$VERSION" \
129+
--target "$GITHUB_REF_NAME" \
130+
--notes "Rust stable v${VERSION}" \
131+
${TARBALLS_PATH}/*.tar.gz \
132+
${TARBALLS_PATH}/*.tar.gz.sha256

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
# rust-std-mobile
2-
Github actions to compile rust std for iOS and Android
1+
# Rust std for mobile builds
2+
3+
This repository publishes unofficial releases compiled with the minimum needed to use rust on mobile. These builds are based off point rust releases.
4+
5+
## License
6+
7+
Rust is primarily distributed under the terms of both the MIT license and the
8+
Apache License (Version 2.0), with portions covered by various BSD-like
9+
licenses.
10+
11+
See [LICENSE-APACHE](https://github.com/rust-lang/rust/blob/master/LICENSE-APACHE), [LICENSE-MIT](https://github.com/rust-lang/rust/blob/master/LICENSE-MIT), and
12+
[COPYRIGHT](https://github.com/rust-lang/rust/blob/master/COPYRIGHT) for details.

cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[target.aarch64-linux-android]
2+
linker = "aarch64-linux-android35-clang"
3+
4+
[target.armv7-linux-androideabi]
5+
linker = "armv7a-linux-androideabi35-clang"
6+
7+
[target.i686-linux-android]
8+
linker = "i686-linux-android35-clang"
9+
10+
[target.x86_64-linux-android]
11+
linker = "x86_64-linux-android35-clang"

0 commit comments

Comments
 (0)