fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
6080e498
patching
1--- 2name : Release 3on : 4workflow_dispatch : 5push : 6branches : 7- main 8paths : 9- version.bzl 10 11defaults : 12run : 13shell : bash 14 15env : 16BAZEL_STARTUP_FLAGS : --bazelrc=${{ github.workspace }}/.github/github.bazelrc 17 18jobs : 19validation : 20runs-on : ubuntu-20.04 21steps : 22- uses : actions/checkout@v3 23# TODO: Unfortunately it's not obvious how to restrict `workflow_dispatch` to a particular branch 24# so this step ensures releases are always done off of `main`. 25- name : Ensure branch is 'main' 26run : | 27git fetch origin &> /dev/null 28branch="$(git rev-parse --abbrev-ref HEAD)" 29if [[ "${branch}" != "main" ]]; then 30echo "The release branch must be main. Got '${branch}'' instead." >&2 31exit 1 32else 33echo "Branch is '${branch}'" 34fi 35- name : Ensure release does not already exist 36run : | 37git fetch origin &> /dev/null 38version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')" 39if [[ -n "$(git tag -l ${version})" ]]; then 40echo "A release '${version}' already exists." >&2 41exit 1 42else 43echo "Tag '${version}' will be created" 44fi 45builds : 46needs : validation 47runs-on : ${{ matrix.os }} 48strategy : 49fail-fast : false 50matrix : 51# Create a job for each target triple 52include : 53- os : macos-12 54env : 55TARGET : "aarch64-apple-darwin" 56- os : ubuntu-20.04 57env : 58TARGET : "aarch64-unknown-linux-gnu" 59- os : windows-2022 60env : 61TARGET : "aarch64-pc-windows-msvc" 62- os : macos-12 63env : 64TARGET : "x86_64-apple-darwin" 65- os : ubuntu-20.04 66env : 67TARGET : "x86_64-pc-windows-gnu" 68- os : windows-2022 69env : 70TARGET : "x86_64-pc-windows-msvc" 71- os : ubuntu-20.04 72env : 73TARGET : "x86_64-unknown-linux-gnu" 74- os : ubuntu-20.04 75env : 76TARGET : "x86_64-unknown-linux-musl" 77steps : 78- uses : actions/checkout@v3 79- name : Install rust toolchains for host 80run : | 81# Detect the current version of rust 82version="$(grep 'DEFAULT_RUST_VERSION =' ./rust/private/common.bzl | grep -o '[[:digit:].]\+')" 83rustup override set "${version}" 84rustup target add ${TARGET} 85rustup update stable --no-self-update --force-non-host 86rustup default stable 87env : 88TARGET : "${{ matrix.env.TARGET }}" 89- name : Setup macos build tooling 90run : | 91sudo xcode-select -s /Applications/Xcode_13.1.app/Contents/Developer/ 92# Set SDK environment variables 93echo "SDKROOT=$(xcrun -sdk macosx12.0 --show-sdk-path)" >> $GITHUB_ENV 94echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx12.0 --show-sdk-platform-version)" >> $GITHUB_ENV 95if : startswith(matrix.os, 'macos') 96- name : Setup Windows Bazelrc 97run : | 98echo "startup --output_user_root=C:/tmp" > ./user.bazelrc 99if : startswith(matrix.os, 'Windows') 100- name : Build cargo-bazel binaries 101run : | 102# Build binaries 103if [[ "${RUNNER_OS}" == "Windows" ]]; then 104OUTPUT_PATH="$(cygpath "${{ github.workspace }}/crate_universe/target/artifacts" -m)" 105else 106OUTPUT_PATH="${{ github.workspace }}/crate_universe/target/artifacts" 107fi 108bazel ${BAZEL_STARTUP_FLAGS[@]} run //crate_universe/tools/cross_installer -- --target=${TARGET} --output="${OUTPUT_PATH}" 109env : 110TARGET : "${{ matrix.env.TARGET }}" 111- uses : actions/upload-artifact@v3 112with : 113name : "${{ matrix.env.TARGET }}" 114path : ${{ github.workspace }}/crate_universe/target/artifacts/${{ matrix.env.TARGET }} 115if-no-files-found : error 116release : 117needs : builds 118runs-on : ubuntu-20.04 119steps : 120- uses : actions/checkout@v3 121- uses : actions/download-artifact@v3 122with : 123path : ${{ github.workspace }}/crate_universe/target/artifacts 124- name : Detect the current version 125run : | 126version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | grep -o '[[:digit:].]\+')" 127echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV 128- name : Create the rules archive 129run : | 130# Update urls and sha256 values 131bazel ${BAZEL_STARTUP_FLAGS[@]} run //crate_universe/tools/urls_generator -- --artifacts-dir="${ARTIFACTS_DIR}" --url-prefix="${URL_PREFIX}" 132bazel clean 133# Build an archive of the repo contents. 134# `examples/bzlmod` is included for the BCR presubmit; it must appear before --exclude="examples" 135tar -czf ${{ github.workspace }}/.github/rules_rust.tar.gz -C ${{ github.workspace }} --exclude=".git" --exclude=".github" --exclude="crate_universe/target" examples/bzlmod --exclude="examples" . 136# Save the sha256 checksum of the distro archive to the environment 137sha256_base64="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_rust.tar.gz | awk '{ print $1 }' | xxd -r -p | base64)" 138echo "ARCHIVE_SHA256_BASE64=${sha256_base64}" >> $GITHUB_ENV 139env : 140CARGO_BAZEL_GENERATOR_URL : file://${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel 141ARTIFACTS_DIR : ${{ github.workspace }}/crate_universe/target/artifacts 142URL_PREFIX : https://github.com/${{ github.repository_owner }}/rules_rust/releases/download/${{ env.RELEASE_VERSION }} 143# Upload the artifact in case creating a release fails so all artifacts can then be manually recovered. 144- uses : actions/upload-artifact@v3 145with : 146name : "rules_rust.tar.gz" 147path : ${{ github.workspace }}/.github/rules_rust.tar.gz 148if-no-files-found : error 149- name : Generate release notes 150run : | 151# Generate the release notes 152sed 's#{version}#${{ env.RELEASE_VERSION }}#g' ${{ github.workspace }}/.github/release_notes.template \ 153| sed 's#{sha256_base64}#${{ env.ARCHIVE_SHA256_BASE64 }}#g' \ 154> ${{ github.workspace }}/.github/release_notes.txt 155- name : Create release 156uses : softprops/action-gh-release@v1 157id : rules_rust_release 158env : 159GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 160with : 161generate_release_notes : true 162tag_name : ${{ env.RELEASE_VERSION }} 163body_path : ${{ github.workspace }}/.github/release_notes.txt 164target_commitish : ${{ github.base_ref }} 165 166- name : "Upload the rules archive" 167uses : actions/upload-release-asset@v1 168env : 169GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 170with : 171upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 172asset_name : rules_rust-v${{ env.RELEASE_VERSION }}.tar.gz 173asset_path : ${{ github.workspace }}/.github/rules_rust.tar.gz 174asset_content_type : application/gzip 175 176# There must be a upload action for each platform triple we create 177- name : "Upload aarch64-apple-darwin" 178uses : actions/upload-release-asset@v1 179env : 180GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 181with : 182upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 183asset_name : cargo-bazel-aarch64-apple-darwin 184asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-apple-darwin/cargo-bazel 185asset_content_type : application/octet-stream 186- name : "Upload aarch64-pc-windows-msvc" 187uses : actions/upload-release-asset@v1 188env : 189GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 190with : 191upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 192asset_name : cargo-bazel-aarch64-pc-windows-msvc.exe 193asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-pc-windows-msvc/cargo-bazel.exe 194asset_content_type : application/octet-stream 195- name : "Upload aarch64-unknown-linux-gnu" 196uses : actions/upload-release-asset@v1 197env : 198GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 199with : 200upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 201asset_name : cargo-bazel-aarch64-unknown-linux-gnu 202asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/aarch64-unknown-linux-gnu/cargo-bazel 203asset_content_type : application/octet-stream 204- name : "Upload x86_64-apple-darwin" 205uses : actions/upload-release-asset@v1 206env : 207GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 208with : 209upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 210asset_name : cargo-bazel-x86_64-apple-darwin 211asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-apple-darwin/cargo-bazel 212asset_content_type : application/octet-stream 213- name : "Upload x86_64-pc-windows-gnu" 214uses : actions/upload-release-asset@v1 215env : 216GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 217with : 218upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 219asset_name : cargo-bazel-x86_64-pc-windows-gnu.exe 220asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-gnu/cargo-bazel.exe 221asset_content_type : application/octet-stream 222- name : "Upload x86_64-pc-windows-msvc" 223uses : actions/upload-release-asset@v1 224env : 225GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 226with : 227upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 228asset_name : cargo-bazel-x86_64-pc-windows-msvc.exe 229asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-pc-windows-msvc/cargo-bazel.exe 230asset_content_type : application/octet-stream 231- name : "Upload x86_64-unknown-linux-gnu" 232uses : actions/upload-release-asset@v1 233env : 234GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 235with : 236upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 237asset_name : cargo-bazel-x86_64-unknown-linux-gnu 238asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-gnu/cargo-bazel 239asset_content_type : application/octet-stream 240- name : "Upload x86_64-unknown-linux-musl" 241uses : actions/upload-release-asset@v1 242env : 243GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 244with : 245upload_url : ${{ steps.rules_rust_release.outputs.upload_url }} 246asset_name : cargo-bazel-x86_64-unknown-linux-musl 247asset_path : ${{ github.workspace }}/crate_universe/target/artifacts/x86_64-unknown-linux-musl/cargo-bazel 248asset_content_type : application/octet-stream