-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from andrewwhitehead/build-update
GHA support and build updates
- Loading branch information
Showing
7 changed files
with
352 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
name: "Build Packages" | ||
|
||
"on": | ||
release: | ||
types: [created] | ||
workflow_dispatch: | ||
inputs: | ||
publish: | ||
description: "Publish packages" | ||
required: true | ||
default: "false" | ||
|
||
jobs: | ||
build-manylinux: | ||
name: Build Library (Manylinux) | ||
|
||
strategy: | ||
matrix: | ||
include: | ||
- os: ubuntu-latest | ||
lib: libindy_credx.so | ||
container: andrewwhitehead/manylinux2014-base | ||
|
||
container: ${{ matrix.container }} | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
|
||
- name: Cache cargo resources | ||
uses: Swatinem/rust-cache@v1 | ||
|
||
- name: Build library | ||
env: | ||
BUILD_FEATURES: vendored | ||
BUILD_TARGET: ${{ matrix.target }} | ||
run: sh ./build.sh | ||
|
||
- name: Upload library artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: library-${{ runner.os }} | ||
path: target/release/${{ matrix.lib }} | ||
|
||
build-other: | ||
name: Build Library (MacOS/Win) | ||
|
||
strategy: | ||
matrix: | ||
include: | ||
- os: macos-latest # macos-11.0 for universal | ||
lib: libindy_credx.dylib | ||
# target: apple-darwin | ||
toolchain: stable # beta for universal | ||
- os: windows-latest | ||
lib: indy_credx.dll | ||
toolchain: stable | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: ${{ matrix.toolchain }} | ||
|
||
- name: Cache cargo resources | ||
uses: Swatinem/rust-cache@v1 | ||
|
||
# pre-build so that openssl dependency is cached, otherwise it will complain: | ||
# "This perl implementation doesn't produce Windows like paths" | ||
- if: "runner.os == 'Windows'" | ||
name: Pre-build (Windows) | ||
uses: actions-rs/cargo@v1 | ||
env: | ||
OPENSSL_STATIC: 1 | ||
with: | ||
command: build | ||
args: --release --manifest-path indy-credx/Cargo.toml --features vendored | ||
|
||
- name: Build library | ||
env: | ||
BUILD_FEATURES: vendored | ||
BUILD_TARGET: ${{ matrix.target }} | ||
BUILD_TOOLCHAIN: ${{ matrix.toolchain }} | ||
OPENSSL_STATIC: 1 | ||
run: sh ./build.sh | ||
|
||
- name: Upload library artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: library-${{ runner.os }} | ||
path: target/release/${{ matrix.lib }} | ||
|
||
build-py: | ||
name: Build Python | ||
needs: [build-manylinux, build-other] | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
python-version: [3.6] | ||
include: | ||
- os: ubuntu-latest | ||
plat-name: manylinux2014_x86_64 | ||
- os: macos-latest | ||
plat-name: macosx_10_9_x86_64 # macosx_10_9_universal2 | ||
- os: windows-latest | ||
plat-name: win_amd64 | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine auditwheel | ||
- name: Fetch library artifacts | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: library-${{ runner.os }} | ||
path: wrappers/python/indy_credx/ | ||
|
||
- name: Build python package | ||
run: | | ||
python setup.py bdist_wheel --python-tag=py3 --plat-name=${{ matrix.plat-name }} | ||
working-directory: wrappers/python | ||
|
||
- name: Test python package | ||
shell: sh | ||
run: | | ||
cd wrappers/python | ||
pip install --upgrade pip | ||
pip install dist/* | ||
python -m demo.test | ||
- if: "runner.os == 'Linux'" | ||
name: Auditwheel | ||
run: auditwheel show wrappers/python/dist/* | ||
|
||
- name: Upload python package | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: python-${{ runner.os }} | ||
path: wrappers/python/dist/* | ||
|
||
- if: | | ||
(github.event_name == 'release' || | ||
(github.event_name == 'workflow_dispatch' && | ||
github.event.inputs.publish == 'true')) | ||
name: Publish python package | ||
env: | ||
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | ||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | ||
run: | | ||
twine upload --skip-existing wrappers/python/dist/* |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.vscode | ||
target | ||
Cargo.lock |
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,96 @@ | ||
#!/bin/sh | ||
|
||
# NOTE: | ||
# MacOS universal build currently requires MacOS 11 (Big Sur) for the appropriate SDK, | ||
# and `sudo xcode-select --install` must be run to install the command line utilities. | ||
# Rust's `beta` channel must be installed because aarch64 is still a tier-2 target: | ||
# `rustup toolchain install beta`. | ||
# The build command becomes `BUILD_TARGET=apple-darwin BUILD_TOOLCHAIN=beta ./build.sh` | ||
|
||
RUSTUP=${RUSTUP:-`command -v rustup`} | ||
PROJECT=indy-credx | ||
LIB_NAME=indy_credx | ||
FEATURES="${BUILD_FEATURES:-default}" | ||
|
||
if [ ! -x "$RUSTUP" ]; then | ||
echo "rustup command not found: it can be obtained from https://rustup.rs/" | ||
exit 1 | ||
fi | ||
|
||
TOOLCHAIN=`$RUSTUP default` | ||
TARGET="${BUILD_TARGET-}" | ||
|
||
if [ -z "$BUILD_TOOLCHAIN" ]; then | ||
BUILD_TOOLCHAIN=${TOOLCHAIN%%-*} | ||
if [ -z "$BUILD_TOOLCHAIN" ]; then | ||
echo "Error: Could not determine default Rust toolchain" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
MACOS_UNIVERSAL_TARGETS="aarch64-apple-darwin x86_64-apple-darwin" | ||
|
||
# Fail on any execution errors | ||
set -e | ||
|
||
if [ "$TARGET" = "apple-darwin" ]; then | ||
# MacOS universal build | ||
INSTALLED_TARGETS=`$RUSTUP +$BUILD_TOOLCHAIN target list --installed` | ||
# Install target(s) as needed | ||
echo "Checking install targets for MacOS universal build .." | ||
for target in $MACOS_UNIVERSAL_TARGETS; do | ||
if ! `echo "$INSTALLED_TARGETS" | grep -q $target`; then | ||
$RUSTUP +$BUILD_TOOLCHAIN target add $target | ||
fi | ||
done | ||
elif [ -z "$TARGET" ]; then | ||
case "$TOOLCHAIN" in | ||
*apple-darwin*) | ||
# Check if the required targets for a universal build are installed | ||
INSTALLED_TARGETS=`$RUSTUP +$BUILD_TOOLCHAIN target list --installed` | ||
TARGET="apple-darwin" | ||
for target in $MACOS_UNIVERSAL_TARGETS; do | ||
if ! `echo "$INSTALLED_TARGETS" | grep -q $target`; then | ||
TARGET= | ||
break | ||
fi | ||
done | ||
if [ "$TARGET" = "apple-darwin" ]; then | ||
echo "Automatically enabled MacOS universal build" | ||
else | ||
echo "Universal MacOS build not enabled" | ||
fi | ||
esac | ||
fi | ||
|
||
if [ "$TARGET" = "apple-darwin" ]; then | ||
MAJOR_VER=`sw_vers | grep ProductVersion | cut -f 2 | cut -f 1 -d .` | ||
if [ "$MAJOR_VER" -lt 11 ]; then | ||
echo "MacOS universal build requires OS 11 (Big Sur) or newer" | ||
TARGET= | ||
fi | ||
fi | ||
|
||
if [ "$TARGET" = "apple-darwin" ]; then | ||
# Build both targets and combine them into a universal library with `lipo` | ||
TARGET_LIBS= | ||
for target in $MACOS_UNIVERSAL_TARGETS; do | ||
echo "Building $PROJECT for toolchain '$BUILD_TOOLCHAIN', target '$target'.." | ||
$RUSTUP run $BUILD_TOOLCHAIN cargo build --manifest-path indy-credx/Cargo.toml --release --features $FEATURES --target $target | ||
TARGET_LIBS="./target/$target/release/lib${LIB_NAME}.dylib $TARGET_LIBS" | ||
done | ||
|
||
mkdir -p ./target/release | ||
OUTPUT="./target/release/lib${LIB_NAME}.dylib" | ||
echo "Combining targets into universal library" | ||
lipo -create -output $OUTPUT $TARGET_LIBS | ||
else | ||
# Build normal target | ||
echo "Building $PROJECT for toolchain '$BUILD_TOOLCHAIN'.." | ||
CMD="$RUSTUP run $BUILD_TOOLCHAIN cargo build --manifest-path indy-credx/Cargo.toml --release --features $FEATURES" | ||
if [ -n "$TARGET" ]; then | ||
$CMD --target "$TARGET" | ||
else | ||
$CMD | ||
fi | ||
fi |
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
Oops, something went wrong.