Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 141 additions & 6 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ on:
- pyproject.toml
# And when we change this workflow itself...
- .github/workflows/build-binaries.yml
- .github/ty-ecosystem.toml
- scripts/build_ty_pgo.sh

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -122,6 +124,20 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: arm64
- name: Install the latest version of uv
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
with:
enable-cache: true
version: "0.11.19"
- name: Install llvm-profdata
run: rustup component add llvm-tools-preview
- name: Check native target
run: |
test "$(rustc -vV | sed -n 's/^host: //p' | tr -d '\r')" = "aarch64-apple-darwin"
- name: Train PGO ty
run: scripts/build_ty_pgo.sh
env:
PGO_TRAIN_ONLY: 1
- name: "Prep README.md"
run: python scripts/transform_readme.py
- name: "Build wheels - aarch64"
Expand All @@ -130,6 +146,8 @@ jobs:
maturin-version: v1.13.3
target: aarch64
args: --release --locked --out dist --compatibility pypi
env:
RUSTFLAGS: -Cprofile-use=${{ github.workspace }}/ruff/target/ty-pgo/ty.profdata -Cllvm-args=-pgo-warn-missing-function
- name: "Test wheel - aarch64"
run: |
pip install dist/"${PACKAGE_NAME}"-*.whl --force-reinstall
Expand Down Expand Up @@ -179,6 +197,37 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: ${{ matrix.platform.arch }}
- name: Install the latest version of uv
if: ${{ startsWith(matrix.platform.target, 'x86_64') }}
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
with:
enable-cache: true
version: "0.11.19"
- name: Install llvm-profdata
if: ${{ startsWith(matrix.platform.target, 'x86_64') }}
run: rustup component add llvm-tools-preview
- name: Check native target
if: ${{ startsWith(matrix.platform.target, 'x86_64') }}
shell: bash
run: |
test "$(rustc -vV | sed -n 's/^host: //p' | tr -d '\r')" = "x86_64-pc-windows-msvc"
- name: Configure Git for ecosystem corpus
if: ${{ startsWith(matrix.platform.target, 'x86_64') }}
shell: bash
run: git config --system core.longpaths true
- name: Train PGO ty
if: ${{ startsWith(matrix.platform.target, 'x86_64') }}
shell: bash
run: |
temp_dir="$(cygpath -u "${RUNNER_TEMP}")/ty-pgo-tmp"
mkdir -p "${temp_dir}"
TMP="$(cygpath -w "${temp_dir}")" \
TEMP="$(cygpath -w "${temp_dir}")" \
PGO_TARGET_DIR="$(cygpath -u "${RUNNER_TEMP}")/ty-pgo" \
scripts/build_ty_pgo.sh
env:
ECOSYSTEM_ANALYZER_SOURCE: git+https://github.com/MichaReiser/ecosystem-analyzer@b82a3e8098d0535175d15f9024c9d5bd720bad8d
PGO_TRAIN_ONLY: 1
- name: "Prep README.md"
run: python scripts/transform_readme.py
- name: "Build wheels"
Expand All @@ -190,6 +239,7 @@ jobs:
env:
# aarch64 build fails, see https://github.com/PyO3/maturin/issues/2110
XWIN_VERSION: 16
RUSTFLAGS: ${{ startsWith(matrix.platform.target, 'x86_64') && format('-Cprofile-use={0}/ty-pgo/ty.profdata -Cllvm-args=-pgo-warn-missing-function', runner.temp) || '' }}
- name: "Test wheel"
if: ${{ !startsWith(matrix.platform.target, 'aarch64') }}
shell: bash
Expand Down Expand Up @@ -234,6 +284,24 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
- name: Install the latest version of uv
if: ${{ startsWith(matrix.target, 'x86_64') }}
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
with:
enable-cache: true
version: "0.11.19"
- name: Install llvm-profdata
if: ${{ startsWith(matrix.target, 'x86_64') }}
run: rustup component add llvm-tools-preview
- name: Check native target
if: ${{ startsWith(matrix.target, 'x86_64') }}
run: |
test "$(rustc -vV | sed -n 's/^host: //p' | tr -d '\r')" = "x86_64-unknown-linux-gnu"
- name: Train PGO ty
if: ${{ startsWith(matrix.target, 'x86_64') }}
run: scripts/build_ty_pgo.sh
env:
PGO_TRAIN_ONLY: 1
- name: "Prep README.md"
run: python scripts/transform_readme.py
- name: "Build wheels"
Expand All @@ -242,7 +310,10 @@ jobs:
maturin-version: v1.13.3
target: ${{ matrix.target }}
manylinux: 2_17
docker-options: ${{ startsWith(matrix.target, 'x86_64') && '-e RUSTFLAGS' || '' }}
args: --release --locked --out dist --compatibility pypi
env:
RUSTFLAGS: ${{ startsWith(matrix.target, 'x86_64') && format('-Cprofile-use={0}/ruff/target/ty-pgo/ty.profdata -Cllvm-args=-pgo-warn-missing-function', github.workspace) || '' }}
- name: "Test wheel"
if: ${{ startsWith(matrix.target, 'x86_64') }}
run: |
Expand Down Expand Up @@ -276,18 +347,82 @@ jobs:
*.tar.gz
*.sha256

linux-aarch64:
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-build') }}
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
submodules: recursive
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: arm64
- name: Install the latest version of uv
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
with:
enable-cache: true
version: "0.11.19"
- name: Install llvm-profdata
run: rustup component add llvm-tools-preview
- name: Check native target
run: |
test "$(rustc -vV | sed -n 's/^host: //p' | tr -d '\r')" = "aarch64-unknown-linux-gnu"
- name: Train PGO ty
run: scripts/build_ty_pgo.sh
env:
PGO_TRAIN_ONLY: 1
- name: "Prep README.md"
run: python scripts/transform_readme.py
- name: "Build wheels"
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
maturin-version: v1.13.3
target: aarch64-unknown-linux-gnu
manylinux: 2_17
docker-options: -e JEMALLOC_SYS_WITH_LG_PAGE=16 -e RUSTFLAGS
args: --release --locked --out dist --compatibility pypi
env:
RUSTFLAGS: -Cprofile-use=${{ github.workspace }}/ruff/target/ty-pgo/ty.profdata -Cllvm-args=-pgo-warn-missing-function
- name: "Test wheel"
run: |
pip install dist/"${PACKAGE_NAME}"-*.whl --force-reinstall
"${MODULE_NAME}" version
"${MODULE_NAME}" --help
python -m "${MODULE_NAME}" --help
- name: "Upload wheels"
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: wheels-aarch64-unknown-linux-gnu
path: dist
- name: "Archive binary"
shell: bash
run: |
set -euo pipefail

TARGET=aarch64-unknown-linux-gnu
ARCHIVE_NAME=ty-$TARGET
ARCHIVE_FILE=$ARCHIVE_NAME.tar.gz

mkdir -p $ARCHIVE_NAME
cp ruff/target/$TARGET/release/ty $ARCHIVE_NAME/ty
tar czvf $ARCHIVE_FILE $ARCHIVE_NAME
shasum -a 256 $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
- name: "Upload binary"
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: artifacts-aarch64-unknown-linux-gnu
path: |
*.tar.gz
*.sha256

linux-cross:
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-build') }}
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- target: aarch64-unknown-linux-gnu
arch: aarch64
manylinux: 2_17
# see https://github.com/astral-sh/ruff/issues/3791
# and https://github.com/gnzlbg/jemallocator/issues/170#issuecomment-1503228963
maturin_docker_options: -e JEMALLOC_SYS_WITH_LG_PAGE=16
- target: armv7-unknown-linux-gnueabihf
arch: armv7
manylinux: 2_17
Expand Down
66 changes: 66 additions & 0 deletions scripts/benchmark_ty_pgo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
set -euo pipefail

ECOSYSTEM_ANALYZER_COMMIT="${ECOSYSTEM_ANALYZER_COMMIT:-7e3a45ca84ad4a30ba90cb27af0b568f37608e84}"
RUFF_DIR="${RUFF_DIR:-ruff}"
EXCLUDE_NEWER="${EXCLUDE_NEWER:-$(git -C "${RUFF_DIR}" show --no-ext-diff --format=%cI --no-patch HEAD)}"
TY_MAX_PARALLELISM="${TY_MAX_PARALLELISM:-8}"
BENCHMARK_DIR="${BENCHMARK_DIR:-${RUFF_DIR}/target/ty-pgo-benchmark}"
case "${RUFF_DIR}" in
/*) ruff_dir="${RUFF_DIR}" ;;
*) ruff_dir="$(pwd)/${RUFF_DIR}" ;;
esac
case "${BENCHMARK_DIR}" in
/*) benchmark_dir="${BENCHMARK_DIR}" ;;
*) benchmark_dir="$(pwd)/${BENCHMARK_DIR}" ;;
esac
RELEASE_TARGET_DIR="${benchmark_dir}/release"
PGO_TARGET_DIR="${benchmark_dir}/pgo"
RELEASE_TY="${RELEASE_TARGET_DIR}/release/ty"
PGO_TY="${PGO_TARGET_DIR}/release/ty"
ECOSYSTEM_DIR="${benchmark_dir}/ecosystem"
ECOSYSTEM_CONFIG_DIR="${ECOSYSTEM_DIR}/config"
ECOSYSTEM_CACHE_DIR="${ECOSYSTEM_DIR}/cache"

echo "Building release ty"
(
cd "${ruff_dir}"
CARGO_TARGET_DIR="${RELEASE_TARGET_DIR}" cargo build --locked --package ty --release
)

RUFF_DIR="${ruff_dir}" \
PGO_TARGET_DIR="${PGO_TARGET_DIR}" \
PGO_OUTPUT="${PGO_TY}" \
EXCLUDE_NEWER="${EXCLUDE_NEWER}" \
ECOSYSTEM_ANALYZER_COMMIT="${ECOSYSTEM_ANALYZER_COMMIT}" \
scripts/build_ty_pgo.sh

echo "Comparing release and PGO release on the ecosystem analyzer corpus"
mkdir -p "${ECOSYSTEM_CONFIG_DIR}/ty"
cp "${ruff_dir}/.github/ty-ecosystem.toml" "${ECOSYSTEM_CONFIG_DIR}/ty/ty.toml"
(
cd "${ruff_dir}"
TY_MAX_PARALLELISM="${TY_MAX_PARALLELISM}" UV_EXCLUDE_NEWER="${EXCLUDE_NEWER}" XDG_CACHE_HOME="${ECOSYSTEM_CACHE_DIR}" XDG_CONFIG_HOME="${ECOSYSTEM_CONFIG_DIR}" uvx \
--from "git+https://github.com/astral-sh/ecosystem-analyzer@${ECOSYSTEM_ANALYZER_COMMIT}" \
ecosystem-analyzer \
--flaky-runs 1 \
diff \
--old HEAD \
--new HEAD \
--ty-binary-old "${RELEASE_TY}" \
--ty-binary-new "${PGO_TY}" \
--output-old "${ECOSYSTEM_DIR}/release.json" \
--output-new "${ECOSYSTEM_DIR}/pgo.json"
)

uvx \
--from "git+https://github.com/astral-sh/ecosystem-analyzer@${ECOSYSTEM_ANALYZER_COMMIT}" \
ecosystem-analyzer \
generate-timing-diff \
"${ECOSYSTEM_DIR}/release.json" \
"${ECOSYSTEM_DIR}/pgo.json" \
--old-name release \
--new-name pgo-release \
--output-html "${ECOSYSTEM_DIR}/timing.html"

echo "Ecosystem timing report: ${ECOSYSTEM_DIR}/timing.html"
21 changes: 21 additions & 0 deletions scripts/benchmark_ty_pgo_instructions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail

ECOSYSTEM_ANALYZER_COMMIT="${ECOSYSTEM_ANALYZER_COMMIT:-7e3a45ca84ad4a30ba90cb27af0b568f37608e84}"
BENCHMARK_DIR="${BENCHMARK_DIR:-ruff/target/ty-pgo-benchmark}"
RELEASE_TY="${BENCHMARK_DIR}/release/release/ty"
PGO_TY="${BENCHMARK_DIR}/pgo/release/ty"

if [[ ! -x "${RELEASE_TY}" || ! -x "${PGO_TY}" ]]; then
echo "Build release ty and run scripts/build_ty_pgo.sh before comparing instructions." >&2
exit 1
fi

env -u UV_EXCLUDE_NEWER UV_NO_CONFIG=1 uv run \
--no-project \
--python 3.14 \
--with "git+https://github.com/astral-sh/ecosystem-analyzer@${ECOSYSTEM_ANALYZER_COMMIT}" \
python scripts/compare_ty_pgo_instructions.py \
--release-ty "${RELEASE_TY}" \
--pgo-ty "${PGO_TY}" \
"$@"
Loading
Loading