From ca8aeaaf6c7ee0ab3634c0b3ec968588611a1a63 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 3 Aug 2024 16:55:43 +0300 Subject: [PATCH] update pgo workfows to use explicit LLVM and rust version --- .github/workflows/release.yml | 54 +++++++++++++---------------------- build_pgo.sh | 49 +++++++++++++++---------------- 2 files changed, 43 insertions(+), 60 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3657439f..12fa5057 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,9 +61,7 @@ jobs: needs: ["create-release"] runs-on: ${{ matrix.os }} env: - # When CARGO is set to CROSS, TARGET_DIR includes matrix.target. TARGET_DIR: ./target - # Emit backtraces on panics. RUST_BACKTRACE: 1 MACOSX_DEPLOYMENT_TARGET: 10.9 @@ -81,13 +79,13 @@ jobs: os: ubuntu-20.04 target: x86_64-unknown-linux-musl - build: macos-aarch64 - os: macos-14 # macOS 14 is M1 runner + os: macos-14 target: aarch64-apple-darwin - build: macos-x86 os: macos-13 target: x86_64-apple-darwin - build: windows - os: "windows-2019" + os: windows-2019 target: x86_64-pc-windows-msvc steps: @@ -101,34 +99,31 @@ jobs: shell: bash run: | echo "MANUAL=1" >> $GITHUB_ENV - - - name: Install Rust (Non-windows) - if: matrix.build != 'windows' - uses: dtolnay/rust-toolchain@stable + + - name: Install Rust + uses: dtolnay/rust-toolchain@master with: + toolchain: 1.80.0 targets: ${{ matrix.target }} components: llvm-tools - - name: Install Rust (Windows) - if: matrix.build == 'windows' - uses: dtolnay/rust-toolchain@stable - with: - targets: ${{ matrix.target }} - - - name: Install Xcode - if: matrix.build == 'macos-x86' || matrix.build == 'macos-aarch64' - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: latest-stable - - - name: Export Rust Environment Variables - if: matrix.build != 'windows' + - name: Setup Rust environment run: | echo "RUSTUP_HOME=$HOME/.rustup" >> $GITHUB_ENV echo "CARGO_HOME=$HOME/.cargo" >> $GITHUB_ENV LLVM_TOOLS_PATH=$(rustc --print sysroot)/lib/rustlib/${{ matrix.target }}/bin echo "PATH=$LLVM_TOOLS_PATH:$HOME/.cargo/bin:$PATH" >> $GITHUB_ENV + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v1 + with: + version: "18.0" + + - name: Set up LLVM environment + run: | + echo "LLVM_PATH=${{ env.LLVM_PATH }}" >> $GITHUB_ENV + echo "${{ env.LLVM_PATH }}/bin" >> $GITHUB_PATH + - name: Install Cross toolchain (zig) if: matrix.build == 'macos-aarch64' || matrix.build == 'linux-aarch64' uses: goto-bus-stop/setup-zig@v2 @@ -157,28 +152,19 @@ jobs: if: matrix.build == 'linux' shell: bash run: | - export TOOLCHAIN=stable-x86_64-unknown-linux-gnu - export TARGET=x86_64-unknown-linux-gnu + export TARGET=${{ matrix.target }} ./build_pgo.sh env: HOME: ${{ github.workspace }} - name: Build PGO Binary (macOS) - if: matrix.build == 'macos-x86' + if: matrix.build == 'macos-x86' || matrix.build == 'macos-aarch64' run: | - export TOOLCHAIN=stable-x86_64-apple-darwin - export TARGET=x86_64-apple-darwin + export TARGET=${{ matrix.target }} ./build_pgo.sh env: HOME: ${{ github.workspace }} - - name: Build PGO binary (macOS AARCH64) - if: matrix.build == 'macos-aarch64' - run: | - export TOOLCHAIN=stable-aarch64-apple-darwin - export TARGET=aarch64-apple-darwin - ./build_pgo.sh - - name: Build release binary (linux MUSL) if: matrix.build == 'linux-static' run: cargo build --target ${{ matrix.target }} --release diff --git a/build_pgo.sh b/build_pgo.sh index 7608490b..390d9379 100755 --- a/build_pgo.sh +++ b/build_pgo.sh @@ -1,29 +1,30 @@ -echo "Building binary for instrumented run" +#!/bin/bash +set -e -# define toolchain variable -if [ -n "$TOOLCHAIN" ]; then - TOOLCHAIN=$TOOLCHAIN -elif [ "$(uname)" == "Darwin" ]; then - TOOLCHAIN="stable-aarch64-apple-darwin" -else - TOOLCHAIN="stable-x86_64-unknown-linux-gnu" -fi +# Function to determine the default target +get_default_target() { + case "$(uname -sm)" in + "Darwin x86_64") echo "x86_64-apple-darwin" ;; + "Darwin arm64") echo "aarch64-apple-darwin" ;; + "Linux x86_64") echo "x86_64-unknown-linux-gnu" ;; + "Linux aarch64") echo "aarch64-unknown-linux-gnu" ;; + *) echo "unknown" ;; + esac +} + +# Use the provided TARGET or default to the current machine's target +TARGET=${TARGET:-$(get_default_target)} -if [ -n "$TARGET" ]; then - TARGET=$TARGET -elif [ "$(uname)" == "Darwin" ]; then - TARGET="aarch64-apple-darwin" -else - TARGET="x86_64-unknown-linux-gnu" +if [ "$TARGET" = "unknown" ]; then + echo "Error: Unable to determine default target. Please specify TARGET explicitly." + exit 1 fi -echo "Cleaning up old build artifacts" -cargo clean -rm -rf /tmp/pgo-data +echo "Using target: $TARGET" -PATH=$HOME/.rustup/toolchains/$TOOLCHAIN/lib/rustlib/$TARGET/bin:$PATH +echo "Building binary for instrumented run" RUSTFLAGS="-Cprofile-generate=/tmp/pgo-data" \ - cargo +stable build --release --target $TARGET --features fast-alloc + cargo build --release --target $TARGET --features fast-alloc echo "Running instrumented binary" for i in $(find samples -name "*.evtx"); do @@ -34,12 +35,8 @@ for i in $(find samples -name "*.evtx"); do done echo "Merging profile data" -if [[ "$OSTYPE" == "darwin"* ]]; then - /usr/bin/xcrun llvm-profdata merge -o /tmp/pgo-data/merged.profdata /tmp/pgo-data -else - llvm-profdata merge -o /tmp/pgo-data/merged.profdata /tmp/pgo-data -fi +llvm-profdata merge -o /tmp/pgo-data/merged.profdata /tmp/pgo-data echo "Building binary with profile data" RUSTFLAGS="-Cprofile-use=/tmp/pgo-data/merged.profdata" \ - cargo +stable build --release --target $TARGET --features fast-alloc + cargo build --release --target $TARGET --features fast-alloc \ No newline at end of file