Skip to content

Commit

Permalink
update pgo workfows to use explicit LLVM and rust version
Browse files Browse the repository at this point in the history
  • Loading branch information
omerbenamram committed Aug 3, 2024
1 parent 51fb694 commit ca8aeaa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 60 deletions.
54 changes: 20 additions & 34 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
49 changes: 23 additions & 26 deletions build_pgo.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit ca8aeaa

Please sign in to comment.