Skip to content

Commit

Permalink
Merge pull request #7 from andrewwhitehead/build-update
Browse files Browse the repository at this point in the history
GHA support and build updates
  • Loading branch information
andrewwhitehead authored Feb 18, 2021
2 parents 8b683e0 + edb0cd1 commit dea3d95
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 47 deletions.
176 changes: 176 additions & 0 deletions .github/workflows/build.yml
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/*
59 changes: 41 additions & 18 deletions .github/workflows/rusttest.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: "Unit Tests"
name: "Run Tests"

on:
push:
branches:
- main
branches: [main]
pull_request:
branches:
- main
branches: [main]

jobs:
lints:
name: Lints

runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand All @@ -21,23 +21,31 @@ jobs:
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt

- name: Run cargo fmt
- name: Cache cargo resources
uses: Swatinem/rust-cache@v1

- name: Cargo check
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
command: check

- name: Run cargo check
- name: Cargo fmt
uses: actions-rs/cargo@v1
with:
command: check
command: fmt
args: --all -- --check

test:
name: Test Suite
runs-on: ubuntu-latest
needs: [lints]

strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand All @@ -47,21 +55,36 @@ jobs:
with:
profile: minimal
toolchain: stable
override: true

- name: Test default features
- name: Cache cargo resources
uses: Swatinem/rust-cache@v1

- name: Debug build
uses: actions-rs/cargo@v1
with:
command: build
args: --manifest-path indy-credx/Cargo.toml --features vendored

- name: Test indy-utils
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path indy-utils/Cargo.toml

- name: Test CL
- name: Test indy-data-types (CL)
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path indy-data-types/Cargo.toml --features cl

- name: Test CL-native
- name: Test indy-data-types (CL-native)
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path indy-data-types/Cargo.toml --features cl_native,vendored

- name: Test indy-credx (vendored)
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path indy-data-types/Cargo.toml --features cl_native
args: --manifest-path indy-credx/Cargo.toml --features vendored
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode
target
Cargo.lock
96 changes: 96 additions & 0 deletions build.sh
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
1 change: 1 addition & 0 deletions indy-credx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ crate-type = ["staticlib", "rlib", "cdylib"]
default = ["ffi"]
ffi = ["ffi-support", "logger", "zeroize"]
logger = ["env_logger"]
vendored = ["indy-data-types/vendored"]

[dependencies]
env_logger = { version = "0.7.1", optional = true }
Expand Down
Loading

0 comments on commit dea3d95

Please sign in to comment.