From 3850944a23bb32908994386b2a951612e00af232 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Sat, 19 Oct 2024 19:10:08 -0400 Subject: [PATCH] Refactor build.yaml workflow: Update Python setup and dependencies --- .github/workflows/build.yaml | 18 ++++++- .github/workflows/release.yaml | 95 +++------------------------------- setup.py | 7 +-- 3 files changed, 28 insertions(+), 92 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 373be10..30d9a9c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -5,6 +5,7 @@ on: branches: [ main ] pull_request: branches: [ main ] + workflow_call: jobs: build: @@ -44,11 +45,26 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python + - name: Set up Python Non-Mac + if: ${{ matrix.os != 'macos-latest' }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - name: Set up Python Mac arm64 + if: ${{ matrix.os == 'macos-latest' && matrix.platform == 'arm64' }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + architecture: 'arm64' + + - name: Set up Python Mac arm64 + if: ${{ matrix.os == 'macos-latest' && matrix.platform == 'x86_64' }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + architecture: 'x86_64' + - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b8a880f..9d8e771 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,96 +6,15 @@ on: - '[0-9]+.[0-9]+.[0-9]+' jobs: - build: - strategy: - fail-fast: false - matrix: - os: ['windows-latest', 'macos-latest', 'ubuntu-latest'] - python-version: ['3.10', '3.11', '3.12'] - platform: ['x86_64', 'arm64', 'win64'] - acceleration: ['cpu', 'cuda', 'hipblas', 'vulkan'] - exclude: - - os: windows-latest - platform: arm64 - - os: windows-latest - platform: x86_64 - - os: macos-latest - acceleration: cuda - - os: macos-latest - acceleration: hipblas - - os: macos-latest - acceleration: vulkan - - os: macos-latest - platform: win64 - - os: ubuntu-latest - platform: win64 - - os: ubuntu-latest - platform: arm64 - - os: ubuntu-latest - acceleration: cuda - - os: ubuntu-latest - acceleration: hipblas - - os: ubuntu-latest - acceleration: vulkan - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install numpy cmake wheel setuptools build - - - name: Build wheel - env: - SIMPLER_WHISPER_ACCELERATION: ${{ matrix.acceleration }} - SIMPLER_WHISPER_PLATFORM: ${{ matrix.platform }} - run: | - python setup.py build_ext --inplace - python -m build --wheel - - - name: Rename wheel file - shell: python - run: | - import os - import glob - - wheel_file = glob.glob('dist/*.whl')[0] - base_name = os.path.basename(wheel_file) - name_parts = base_name.split('-') - - # Insert acceleration and platform before the last part (which is like 'any.whl') - new_name_parts = name_parts[:-1] + ['${{ matrix.acceleration }}', '${{ matrix.platform }}'] + [name_parts[-1]] - new_name = '-'.join(new_name_parts) - - new_path = os.path.join('dist', new_name) - os.rename(wheel_file, new_path) - print(f"Renamed {base_name} to {new_name}") - - - name: Set wheel name - shell: pwsh - run: | - $wheelName = "wheel-${{ matrix.os }}-${{ matrix.platform }}-py${{ matrix.python-version }}" - if ("${{ matrix.acceleration }}" -ne "") { - $wheelName += "-${{ matrix.acceleration }}" - } - echo "WHEEL_NAME=$wheelName" >> $env:GITHUB_ENV - - - name: Upload wheel artifact - uses: actions/upload-artifact@v4 - with: - name: ${{ env.WHEEL_NAME }} - path: dist/*.whl + build-project: + name: Build Project 🧱 + uses: ./.github/workflows/build.yaml + secrets: inherit + permissions: + contents: read create_release: - needs: build + needs: build-project runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/setup.py b/setup.py index 623c79a..67c07d6 100644 --- a/setup.py +++ b/setup.py @@ -34,11 +34,13 @@ def build_extension(self, ext): f'-DACCELERATION={acceleration}', ] + env = os.environ.copy() + # Add platform-specific arguments if platform.system() == "Darwin": # macOS - cmake_args.append(f'-DCMAKE_OSX_ARCHITECTURES={target_platform}') + cmake_args += [f'-DCMAKE_OSX_ARCHITECTURES={target_platform}'] # add MACOS_ARCH env variable to specify the target platform - os.environ["MACOS_ARCH"] = target_platform + env["MACOS_ARCH"] = target_platform cfg = 'Debug' if self.debug else 'Release' build_args = ['--config', cfg] @@ -52,7 +54,6 @@ def build_extension(self, ext): cmake_args += [f'-DCMAKE_BUILD_TYPE={cfg}'] build_args += ['--', '-j2'] - env = os.environ.copy() env['CXXFLAGS'] = f'{env.get("CXXFLAGS", "")} -DVERSION_INFO=\\"{self.distribution.get_version()}\\"' if not os.path.exists(self.build_temp):