Skip to content

Commit

Permalink
Refactor build.yaml workflow: Update Python setup and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Oct 19, 2024
1 parent 1fa81d7 commit 3850944
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 92 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_call:

jobs:
build:
Expand Down Expand Up @@ -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
Expand Down
95 changes: 7 additions & 88 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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):
Expand Down

0 comments on commit 3850944

Please sign in to comment.