forked from Chia-Network/bls-signatures
-
Notifications
You must be signed in to change notification settings - Fork 34
feat: revive Python binds requiring Python >=3.10, rename to dashbls, repair setup.py to work on Windows, update authorship, drop unmaintained parallel impl, shave down README, add build and publish script
#125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
0705266
fix: forcefully replace cmake relic template in Autotools builds
kwvg 5f30f10
doc: shave down README to the bare essentials
kwvg 013c91a
chore: drop unmaintained native Python implementation
kwvg 34b76e9
chore: drop unused and unmaintained workflows
kwvg e866341
refactor: move from `python-bindings` to `binds/python`
kwvg d65ba6b
refactor: avoid clash with upstream, rename to `dashbls`, update author
kwvg 86f4065
chore: partially import `Python.gitignore`
kwvg 02fed5f
build: declare packaging metadata in `pyproject.toml`, add `NOTICE`
kwvg 82f904e
fix: uniformly enforce CMake 3.18 requirement
kwvg ad09335
build: require Python 3.10 or higher
kwvg 211d2e8
build: unify all platforms behind CMake builds
kwvg 74bb315
build: don't make target assumptions based on host, fix Windows flags
kwvg 691c6a9
build: find `pybind11` >=2.13.6 in locally before using `FetchContent`
kwvg 5878b74
build: skip test, bench and honor CPU count for pybind builds
kwvg a6fbf85
build: drop cruft from python bind bundle
kwvg 7373fde
lint: switch to `ruff` for Python enforcement, clean up scripts
kwvg aec88bf
build: add version awareness to python binds
kwvg b3d4252
refactor: switch python binds unit tests to `pytest`
kwvg fabdcf2
refactor: switch python binds benchmarks to `pytest-benchmark`
kwvg 2d429ac
refactor: make samples into distinct files, drop unneeded README
kwvg 4d7934d
fix: bind G1Element/G2Element scalar multiplication against PrivateKey
kwvg fcd4ebb
fix: accept from_message's domain separation tag as bytes
kwvg cb0d8ca
fix: reject oversized from_message domain separation tags
kwvg fee06d9
fix: reject non-contiguous buffers at every parsing entry point
kwvg 60e015a
fix: serialize relic access behind a process-wide lock
kwvg bfdd033
fix: reject oversized from_message messages
kwvg b0cf332
ci: split binds into per-language reusable workflows
kwvg 7e170b7
fix: sidestep `java.lang.UnsupportedClassVersionError` on Ubuntu runners
kwvg e1df3f3
ci: add a reusable workflow for the python binds
kwvg cc949d4
ci: add publish workflow, generate and push PEP 503 index to skip PyPi
kwvg fe6fbf7
build: drop `windows-arm64` from matrix due to relic limitations
kwvg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,104 @@ | ||
| #!/usr/bin/env python3 | ||
| # coding: latin-1 | ||
|
|
||
| # | ||
| # Copyright (c) 2026-present, Microsoft Corporation | ||
| # Copyright (c) 2026-present, The Dash Core developers | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
|
|
||
| """Generate a PEP 503 index for released distributions.""" | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
| import re | ||
| import subprocess | ||
| import sys | ||
| from html import escape | ||
| from pathlib import Path | ||
|
|
||
| # PEP 503: lowercase, runs of -_. collapsed to a single - | ||
| NAME = "dashbls" | ||
| NORMALISED = re.sub(r"[-_.]+", "-", NAME).lower() | ||
|
|
||
| # Must match requires-python in pyproject.toml. | ||
| REQUIRES_PYTHON = ">=3.10" | ||
|
|
||
|
|
||
| def releases(repo: str) -> list[dict]: | ||
| """Every release of `repo`, each with the name, URL and digest of its assets.""" | ||
| out = subprocess.check_output( # noqa: S603 | ||
| [ # noqa: S607 | ||
| "gh", | ||
| "api", | ||
| "--paginate", | ||
| f"repos/{repo}/releases", | ||
| "--jq", | ||
| ".[] | select(.draft | not) | {tag: .tag_name, assets: [.assets[] " | ||
| "| {name, url: .browser_download_url, digest}]}", | ||
| ], | ||
| text=True, | ||
| ) | ||
| return [json.loads(line) for line in out.splitlines() if line.strip()] | ||
|
|
||
|
|
||
| def anchor(name: str, url: str, digest: str | None) -> str: | ||
| """One link, with the hash pip needs to verify what it downloaded. | ||
|
|
||
| The releases API reports a digest as "sha256:<hex>", which is the PEP 503 | ||
| fragment in all but spelling. Without it pip has no integrity check at all | ||
| and --require-hashes has nothing to match against. | ||
| """ | ||
| if digest and digest.startswith("sha256:"): | ||
| url = f"{url}#sha256={digest.removeprefix('sha256:')}" | ||
| return ( | ||
| f' <a href="{escape(url)}" ' | ||
| f'data-requires-python="{escape(REQUIRES_PYTHON)}">{escape(name)}</a><br>' | ||
| ) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--output", required=True, type=Path) | ||
| parser.add_argument( | ||
| "--repo", default=os.environ.get("GITHUB_REPOSITORY", "dashpay/bls-signatures") | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| # Sdists matter as much as wheels here: they are the only thing installable | ||
| # on a platform we do not ship a wheel for, and pip will not find one that | ||
| # the index does not list. | ||
| files = [] | ||
| for release in releases(args.repo): | ||
| for asset in release["assets"]: | ||
| if asset["name"].endswith((".whl", ".tar.gz")): | ||
| files.append((asset["name"], asset["url"], asset.get("digest"))) | ||
|
kwvg marked this conversation as resolved.
|
||
| files.sort() | ||
| if not files: | ||
| sys.exit("no distributions found on any release; refusing to publish an empty index") | ||
|
|
||
| project = args.output / "pep503" / NORMALISED | ||
| project.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| # pypi:repository-version is PEP 629; charset because the filenames are | ||
| # written by whatever runner built them. | ||
| head = '<meta charset="utf-8">\n<meta name="pypi:repository-version" content="1.0">' | ||
| anchors = "\n".join(anchor(*dist) for dist in files) | ||
| (project / "index.html").write_text( | ||
| f"<!DOCTYPE html>\n<html><head>{head}\n<title>Links for {NAME}</title></head>\n" | ||
| f"<body>\n<h1>Links for {NAME}</h1>\n{anchors}\n</body></html>\n", | ||
| encoding="utf-8", | ||
| ) | ||
| (args.output / "pep503" / "index.html").write_text( | ||
| f"<!DOCTYPE html>\n<html><head>{head}\n<title>Simple Index</title></head>\n" | ||
| "<body>\n" | ||
| f' <a href="{NORMALISED}/">{NAME}</a><br>\n' | ||
| "</body></html>\n", | ||
| encoding="utf-8", | ||
| ) | ||
| print(f"indexed {len(files)} distributions for {NAME}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or 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,56 @@ | ||
| name: Binds (Go) | ||
|
|
||
| on: | ||
| workflow_call: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| name: ${{ matrix.os }}, Go ${{ matrix.golang }} | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [macos-latest, ubuntu-24.04-arm] | ||
| golang: [ '1.24' ] | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Install Go | ||
| uses: actions/setup-go@v7 | ||
| with: | ||
| go-version: ^${{ matrix.golang }} | ||
|
|
||
| - name: Prepare build system for Ubuntu | ||
| if: startsWith(matrix.os, 'ubuntu') | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -qq --yes valgrind libgmp-dev cmake | ||
| hash -r | ||
| cmake --version | ||
|
|
||
| - name: Prepare build system for macOS | ||
| if: startsWith(matrix.os, 'macos') | ||
| run: | | ||
| brew install gmp | ||
|
|
||
| - name: Build library using CMake | ||
| run: | | ||
| cores=$(getconf _NPROCESSORS_ONLN) | ||
| jobs=$(( cores > 1 ? cores - 1 : 1 )) | ||
| mkdir -p build && cd build | ||
| cmake .. -DCMAKE_BUILD_TYPE=Debug | ||
| cmake --build . --parallel "$jobs" | ||
|
|
||
| - name: Build bindings | ||
| run: | | ||
| cd go-bindings | ||
| make config | ||
| make |
This file contains hidden or 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,94 @@ | ||
| name: Binds (Javascript) | ||
|
|
||
| on: | ||
| workflow_call: | ||
| secrets: | ||
| NPM_TOKEN: | ||
| description: Token used to publish the package to the npm registry | ||
| required: false | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| name: ${{ matrix.os }}, Javascript | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [macos-latest, ubuntu-24.04-arm] | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up JDK | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: temurin | ||
| java-version: '21' | ||
|
|
||
| - name: Install Emscripten SDK | ||
| uses: mymindstorm/setup-emsdk@v16 | ||
|
|
||
| - name: Build JavaScript bindings | ||
| run: | | ||
| emcc -v | ||
| sh emsdk_build.sh | ||
|
|
||
| - name: Test JavaScript bindings | ||
| run: | | ||
| sh js_test.sh | ||
|
|
||
| publish: | ||
| name: Publish (releases), Javascript | ||
| if: startsWith(github.ref, 'refs/tags/') | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up JDK | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: temurin | ||
| java-version: '21' | ||
|
|
||
| - name: Install Emscripten SDK | ||
| uses: mymindstorm/setup-emsdk@v16 | ||
|
|
||
| - name: Set up Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: '20' | ||
| registry-url: https://registry.npmjs.org | ||
|
|
||
| # emsdk_build.sh copies package.json into js_build/, so the version has to | ||
| # be rewritten in the source tree before the build runs. | ||
| - name: Update version in package.json | ||
| working-directory: js-bindings | ||
| env: | ||
| RELEASE: ${{ github.ref_name }} | ||
| run: | | ||
| jq --arg VER "${RELEASE#v}" '.version=$VER' package.json > temp.json | ||
| mv temp.json package.json | ||
|
|
||
| - name: Build JavaScript bindings | ||
| run: | | ||
| emcc -v | ||
| sh emsdk_build.sh | ||
|
|
||
| - name: Publish to npm | ||
| working-directory: js_build/js-bindings | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| run: npm publish --access public |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.