|
| 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 |
0 commit comments