generated from aarnphm/bazix
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
145 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: wheels | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
pull_request: | ||
types: [labeled, opened, synchronized, reopened] | ||
|
||
concurrency: | ||
group: wheels-${{ github.event.pull_request.number || github.sha }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
LINES: 200 | ||
COLUMNS: 200 | ||
|
||
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun | ||
defaults: | ||
run: | ||
shell: bash --noprofile --norc -exo pipefail {0} | ||
|
||
jobs: | ||
build: | ||
# Similar to numpy/numpy wheels actions setup. | ||
name: Build wheels for python${{ matrix.python }} (${{ matrix.os }}) | ||
runs-on: ${{ matrix.os }} | ||
timeout-minutes: 20 | ||
if: "!github.event.repository.fork" # Don't run on fork repository | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python: ["3.8", "3.9", "3.10", "3.11"] | ||
os: ["ubuntu-latest", "macos-latest"] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # fetch all tags and branches | ||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- name: Set up QEMU | ||
if: runner.os == 'Linux' | ||
uses: docker/setup-qemu-action@v2 | ||
with: | ||
platforms: all | ||
- name: Set up Clang [Linux] | ||
if: runner.os == 'Linux' | ||
uses: egor-tensin/setup-clang@v1 | ||
- name: Set up Clang [MacOS] | ||
if: ${{ startsWith(matrix.os, 'macos') }} | ||
run: brew install llvm | ||
- name: Build wheels | ||
run: | | ||
./tools/bazel build //:whispercpp_wheel | ||
- name: Get output wheel path | ||
id: bazel-bin | ||
run: | | ||
echo "path=$(./tools/bazel info bazel-bin)" >> "$GITHUB_OUTPUT" | ||
ls -rthla $(./tools/bazel info bazel-bin) | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: cp-python${{ matrix.python }}-${{ matrix.os }} | ||
path: ${{ steps.bazel-bin.outputs.path }}/*.whl | ||
|
||
publish: | ||
needs: [build] | ||
name: Publish wheels to PyPI | ||
runs-on: ubuntu-latest | ||
if: github.repository_owner == 'aarnphm' | ||
steps: | ||
- uses: actions/download-artifact@v3 | ||
- name: Display structure of downloaded files | ||
run: | | ||
apt-get install -y tree | ||
tree | ||
- name: Publish built wheels | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | ||
with: | ||
password: ${{ secrets.PYPI_API_TOKEN }} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library") | |
load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
load("@rules_python//python:packaging.bzl", "py_wheel") | ||
load("@com_github_bentoml_plugins//rules/py:packaging.bzl", "py_package") | ||
load("@python_abi//:abi.bzl", "python_abi") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
|
@@ -90,6 +91,7 @@ py_package( | |
|
||
py_wheel( | ||
name = "whispercpp_wheel", | ||
abi = python_abi(), | ||
author = "Aaron Pham", | ||
author_email = "[email protected]", | ||
classifiers = [ | ||
|
@@ -120,7 +122,7 @@ py_wheel( | |
"//:x86_64-pc-windows-msvc": "win_amd64", | ||
"//:x86_64-unknown-linux-gnu": "manylinux2014_x86_64", | ||
}), | ||
python_tag = "py3", | ||
python_tag = python_abi(), | ||
strip_path_prefixes = ["src"], | ||
version = "0.0.1", | ||
visibility = ["//:__subpackages__"], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
abi_bzl_template = """\ | ||
def python_abi(): | ||
return "{python_abi}" | ||
""" | ||
|
||
def _get_python_bin(ctx): | ||
python_version = ctx.attr.python_version | ||
if python_version != "2" and python_version != "3": | ||
fail("python_version must be one of: '2', '3'") | ||
|
||
# we reuse the PYTHON_BIN_PATH environment variable from pybind11 so that the | ||
# ABI tag we detect is always compatible with the version of python that was | ||
# used for the build. | ||
python_bin = ctx.os.environ.get("PYTHON_BIN_PATH") | ||
if python_bin != None: | ||
return python_bin | ||
|
||
python_bin = ctx.which("python" + python_version) | ||
if python_bin != None: | ||
return python_bin | ||
|
||
fail("Failed to find python binary.") | ||
|
||
def _get_python_abi(ctx, python_bin): | ||
result = ctx.execute([ | ||
python_bin, | ||
"-c", | ||
"import platform;" + | ||
"assert platform.python_implementation() == 'CPython';" + | ||
"version = platform.python_version_tuple();" + | ||
"print(f'cp{version[0]}{version[1]}')", | ||
]) | ||
return result.stdout.splitlines()[0] | ||
|
||
def _declare_python_abi_impl(ctx): | ||
python_bin = _get_python_bin(ctx) | ||
python_abi = _get_python_abi(ctx, python_bin) | ||
ctx.file("BUILD") | ||
ctx.file("abi.bzl", abi_bzl_template.format(python_abi = python_abi)) | ||
|
||
declare_python_abi = repository_rule( | ||
implementation = _declare_python_abi_impl, | ||
attrs = { | ||
"python_version": attr.string(mandatory = True), | ||
}, | ||
local = True, | ||
) |