aleo.codegen: build-time ABI→Python emitter (#47) #63
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
| name: SDK Wheels | |
| on: | |
| push: | |
| paths: | |
| - 'sdk/**' | |
| - 'sdk-abi/**' | |
| - '.github/workflows/sdk-wheels.yml' | |
| - '.github/workflows/sdk.yml' | |
| branches: | |
| - main | |
| - master | |
| tags: | |
| - '*' | |
| pull_request: | |
| paths: | |
| - 'sdk/**' | |
| - 'sdk-abi/**' | |
| - '.github/workflows/sdk-wheels.yml' | |
| - '.github/workflows/sdk.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| # The crate is abi3-py37, so each platform needs exactly one wheel that works | |
| # on every CPython >= 3.7. 32-bit targets (i686/x86) are deliberately dropped: | |
| # snarkvm 4.x and its aws-lc-sys dependency do not support them. | |
| jobs: | |
| tests: | |
| uses: ./.github/workflows/sdk.yml | |
| build: | |
| name: build (${{ matrix.platform.name }}) | |
| needs: [tests] | |
| runs-on: ${{ matrix.platform.runner }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: | |
| - name: linux-x86_64 | |
| runner: ubuntu-latest | |
| target: x86_64 | |
| - name: linux-aarch64 | |
| # native arm runner — avoids cross-compiling aws-lc-sys C code | |
| runner: ubuntu-24.04-arm | |
| target: aarch64 | |
| - name: macos-x86_64 | |
| runner: macos-13 | |
| target: x86_64 | |
| - name: macos-aarch64 | |
| runner: macos-latest | |
| target: aarch64 | |
| - name: windows-x64 | |
| runner: windows-latest | |
| target: x64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| # Build the mainnet extension module wheel. | |
| - name: Build mainnet wheel | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| # Run from sdk/ so cargo picks up sdk/.cargo/config.toml (macOS | |
| # needs its dynamic_lookup link flags; cargo resolves config from | |
| # the working directory, not the manifest path). | |
| working-directory: ./sdk | |
| target: ${{ matrix.platform.target }} | |
| args: --release --out dist --features mainnet | |
| sccache: 'true' | |
| manylinux: ${{ startsWith(matrix.platform.name, 'linux') && '2_28' || 'auto' }} | |
| # The manylinux container needs git (snarkvm is a git dependency) | |
| # and cmake + a C toolchain (aws-lc-sys builds C sources). | |
| before-script-linux: | | |
| if command -v dnf &> /dev/null; then | |
| dnf install -y git cmake clang | |
| elif command -v yum &> /dev/null; then | |
| yum install -y git cmake3 clang && ln -sf "$(command -v cmake3)" /usr/local/bin/cmake | |
| fi | |
| # maturin emits one cdylib per invocation (named by pyproject | |
| # module-name). Build a second wheel for the testnet extension module with | |
| # module-name overridden to aleo._aleolib_testnet. | |
| - name: Override module-name for testnet build | |
| shell: bash | |
| run: | | |
| cp sdk/pyproject.toml sdk/pyproject.toml.mainnet.bak | |
| sed -i.bak 's/module-name = "aleo._aleolib_mainnet"/module-name = "aleo._aleolib_testnet"/' sdk/pyproject.toml | |
| - name: Build testnet wheel | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| working-directory: ./sdk | |
| target: ${{ matrix.platform.target }} | |
| args: --release --out dist-testnet --no-default-features --features testnet | |
| sccache: 'true' | |
| manylinux: ${{ startsWith(matrix.platform.name, 'linux') && '2_28' || 'auto' }} | |
| before-script-linux: | | |
| if command -v dnf &> /dev/null; then | |
| dnf install -y git cmake clang | |
| elif command -v yum &> /dev/null; then | |
| yum install -y git cmake3 clang && ln -sf "$(command -v cmake3)" /usr/local/bin/cmake | |
| fi | |
| # Splice the testnet .so into the mainnet wheel -> one two-network wheel. | |
| - name: Merge testnet module into wheel | |
| shell: bash | |
| run: | | |
| mv sdk/pyproject.toml.mainnet.bak sdk/pyproject.toml | |
| # The manylinux build runs in a Docker container that writes sdk/dist | |
| # and sdk/dist-testnet as root; this step runs on the host as the | |
| # runner user, so reclaim ownership before repacking the wheel | |
| # (Linux only — native macOS/Windows builds are already runner-owned). | |
| if [ "$RUNNER_OS" = "Linux" ]; then | |
| sudo chown -R "$(id -u):$(id -g)" sdk/dist sdk/dist-testnet | |
| fi | |
| python .github/scripts/merge_testnet_so.py sdk/dist sdk/dist-testnet | |
| # Every runner here matches its wheel's platform, so install and smoke | |
| # test the actual artifact — importing BOTH networks — before it ships. | |
| - name: Smoke test wheel | |
| shell: bash | |
| run: | | |
| pip install --find-links sdk/dist aleo | |
| python -c " | |
| from aleo.mainnet import PrivateKey as MainnetPrivateKey | |
| from aleo.testnet import PrivateKey as TestnetPrivateKey | |
| import aleo.mainnet as mainnet | |
| import aleo.testnet as testnet | |
| mpk = MainnetPrivateKey.random() | |
| tpk = TestnetPrivateKey.random() | |
| assert str(mpk).startswith('APrivateKey1') | |
| assert str(mpk.address).startswith('aleo1') | |
| assert str(tpk.address).startswith('aleo1') | |
| assert mainnet.Network.id() == 0 | |
| assert testnet.Network.id() == 1 | |
| print('two-network wheel ok:', mpk.address, tpk.address) | |
| " | |
| - name: Upload wheel | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.platform.name }} | |
| path: sdk/dist | |
| build-abi: | |
| name: abi-build (${{ matrix.platform.name }}) | |
| needs: [tests] | |
| runs-on: ${{ matrix.platform.runner }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: | |
| - name: linux-x86_64 | |
| runner: ubuntu-latest | |
| target: x86_64 | |
| - name: linux-aarch64 | |
| runner: ubuntu-24.04-arm | |
| target: aarch64 | |
| - name: macos-x86_64 | |
| runner: macos-13 | |
| target: x86_64 | |
| - name: macos-aarch64 | |
| runner: macos-latest | |
| target: aarch64 | |
| - name: windows-x64 | |
| runner: windows-latest | |
| target: x64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Build wheel | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| working-directory: ./sdk-abi | |
| target: ${{ matrix.platform.target }} | |
| args: --release --out dist | |
| sccache: 'true' | |
| manylinux: ${{ startsWith(matrix.platform.name, 'linux') && '2_28' || 'auto' }} | |
| before-script-linux: | | |
| if command -v dnf &> /dev/null; then | |
| dnf install -y git cmake clang | |
| elif command -v yum &> /dev/null; then | |
| yum install -y git cmake3 clang && ln -sf "$(command -v cmake3)" /usr/local/bin/cmake | |
| fi | |
| - name: Smoke test wheel | |
| shell: bash | |
| run: | | |
| pip install --find-links sdk-abi/dist aleo-abi | |
| python -c "import aleo_abi; print(aleo_abi.generate_abi.__name__)" | |
| - name: Upload wheel | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: abi-wheels-${{ matrix.platform.name }} | |
| path: sdk-abi/dist | |
| sdist: | |
| needs: [tests] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build sdist | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| working-directory: ./sdk | |
| command: sdist | |
| args: --out dist | |
| - name: Upload sdist | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-sdist | |
| path: sdk/dist | |
| sdist-abi: | |
| needs: [tests] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build sdist | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| working-directory: ./sdk-abi | |
| command: sdist | |
| args: --out dist | |
| - name: Upload sdist | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: abi-wheels-sdist | |
| path: sdk-abi/dist | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| if: "startsWith(github.ref, 'refs/tags/')" | |
| needs: [build, sdist, build-abi, sdist-abi] | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: '*wheels-*' | |
| merge-multiple: true | |
| path: dist | |
| - name: Publish to PyPI | |
| uses: PyO3/maturin-action@v1 | |
| env: | |
| MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
| with: | |
| command: upload | |
| args: --non-interactive --skip-existing dist/* |