Skip to content

Commit dea3d95

Browse files
Merge pull request #7 from andrewwhitehead/build-update
GHA support and build updates
2 parents 8b683e0 + edb0cd1 commit dea3d95

File tree

7 files changed

+352
-47
lines changed

7 files changed

+352
-47
lines changed

.github/workflows/build.yml

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
name: "Build Packages"
2+
3+
"on":
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
inputs:
8+
publish:
9+
description: "Publish packages"
10+
required: true
11+
default: "false"
12+
13+
jobs:
14+
build-manylinux:
15+
name: Build Library (Manylinux)
16+
17+
strategy:
18+
matrix:
19+
include:
20+
- os: ubuntu-latest
21+
lib: libindy_credx.so
22+
container: andrewwhitehead/manylinux2014-base
23+
24+
container: ${{ matrix.container }}
25+
runs-on: ${{ matrix.os }}
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
- name: Install Rust toolchain
32+
uses: actions-rs/toolchain@v1
33+
with:
34+
profile: minimal
35+
toolchain: stable
36+
37+
- name: Cache cargo resources
38+
uses: Swatinem/rust-cache@v1
39+
40+
- name: Build library
41+
env:
42+
BUILD_FEATURES: vendored
43+
BUILD_TARGET: ${{ matrix.target }}
44+
run: sh ./build.sh
45+
46+
- name: Upload library artifacts
47+
uses: actions/upload-artifact@v2
48+
with:
49+
name: library-${{ runner.os }}
50+
path: target/release/${{ matrix.lib }}
51+
52+
build-other:
53+
name: Build Library (MacOS/Win)
54+
55+
strategy:
56+
matrix:
57+
include:
58+
- os: macos-latest # macos-11.0 for universal
59+
lib: libindy_credx.dylib
60+
# target: apple-darwin
61+
toolchain: stable # beta for universal
62+
- os: windows-latest
63+
lib: indy_credx.dll
64+
toolchain: stable
65+
66+
runs-on: ${{ matrix.os }}
67+
68+
steps:
69+
- name: Checkout
70+
uses: actions/checkout@v2
71+
72+
- name: Install Rust toolchain
73+
uses: actions-rs/toolchain@v1
74+
with:
75+
profile: minimal
76+
toolchain: ${{ matrix.toolchain }}
77+
78+
- name: Cache cargo resources
79+
uses: Swatinem/rust-cache@v1
80+
81+
# pre-build so that openssl dependency is cached, otherwise it will complain:
82+
# "This perl implementation doesn't produce Windows like paths"
83+
- if: "runner.os == 'Windows'"
84+
name: Pre-build (Windows)
85+
uses: actions-rs/cargo@v1
86+
env:
87+
OPENSSL_STATIC: 1
88+
with:
89+
command: build
90+
args: --release --manifest-path indy-credx/Cargo.toml --features vendored
91+
92+
- name: Build library
93+
env:
94+
BUILD_FEATURES: vendored
95+
BUILD_TARGET: ${{ matrix.target }}
96+
BUILD_TOOLCHAIN: ${{ matrix.toolchain }}
97+
OPENSSL_STATIC: 1
98+
run: sh ./build.sh
99+
100+
- name: Upload library artifacts
101+
uses: actions/upload-artifact@v2
102+
with:
103+
name: library-${{ runner.os }}
104+
path: target/release/${{ matrix.lib }}
105+
106+
build-py:
107+
name: Build Python
108+
needs: [build-manylinux, build-other]
109+
110+
strategy:
111+
matrix:
112+
os: [ubuntu-latest, macos-latest, windows-latest]
113+
python-version: [3.6]
114+
include:
115+
- os: ubuntu-latest
116+
plat-name: manylinux2014_x86_64
117+
- os: macos-latest
118+
plat-name: macosx_10_9_x86_64 # macosx_10_9_universal2
119+
- os: windows-latest
120+
plat-name: win_amd64
121+
122+
runs-on: ${{ matrix.os }}
123+
124+
steps:
125+
- name: Checkout
126+
uses: actions/checkout@v2
127+
128+
- name: Set up Python ${{ matrix.python-version }}
129+
uses: actions/setup-python@v2
130+
with:
131+
python-version: ${{ matrix.python-version }}
132+
133+
- name: Install dependencies
134+
run: |
135+
python -m pip install --upgrade pip
136+
pip install setuptools wheel twine auditwheel
137+
138+
- name: Fetch library artifacts
139+
uses: actions/download-artifact@v2
140+
with:
141+
name: library-${{ runner.os }}
142+
path: wrappers/python/indy_credx/
143+
144+
- name: Build python package
145+
run: |
146+
python setup.py bdist_wheel --python-tag=py3 --plat-name=${{ matrix.plat-name }}
147+
working-directory: wrappers/python
148+
149+
- name: Test python package
150+
shell: sh
151+
run: |
152+
cd wrappers/python
153+
pip install --upgrade pip
154+
pip install dist/*
155+
python -m demo.test
156+
157+
- if: "runner.os == 'Linux'"
158+
name: Auditwheel
159+
run: auditwheel show wrappers/python/dist/*
160+
161+
- name: Upload python package
162+
uses: actions/upload-artifact@v2
163+
with:
164+
name: python-${{ runner.os }}
165+
path: wrappers/python/dist/*
166+
167+
- if: |
168+
(github.event_name == 'release' ||
169+
(github.event_name == 'workflow_dispatch' &&
170+
github.event.inputs.publish == 'true'))
171+
name: Publish python package
172+
env:
173+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
174+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
175+
run: |
176+
twine upload --skip-existing wrappers/python/dist/*

.github/workflows/rusttest.yml

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
name: "Unit Tests"
1+
name: "Run Tests"
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [main]
76
pull_request:
8-
branches:
9-
- main
7+
branches: [main]
108

119
jobs:
1210
lints:
1311
name: Lints
12+
1413
runs-on: ubuntu-latest
14+
1515
steps:
1616
- name: Checkout sources
1717
uses: actions/checkout@v2
@@ -21,23 +21,31 @@ jobs:
2121
with:
2222
profile: minimal
2323
toolchain: stable
24-
override: true
25-
components: rustfmt
2624

27-
- name: Run cargo fmt
25+
- name: Cache cargo resources
26+
uses: Swatinem/rust-cache@v1
27+
28+
- name: Cargo check
2829
uses: actions-rs/cargo@v1
2930
with:
30-
command: fmt
31-
args: --all -- --check
31+
command: check
3232

33-
- name: Run cargo check
33+
- name: Cargo fmt
3434
uses: actions-rs/cargo@v1
3535
with:
36-
command: check
36+
command: fmt
37+
args: --all -- --check
3738

3839
test:
3940
name: Test Suite
40-
runs-on: ubuntu-latest
41+
needs: [lints]
42+
43+
strategy:
44+
matrix:
45+
os: [macos-latest, windows-latest, ubuntu-latest]
46+
47+
runs-on: ${{ matrix.os }}
48+
4149
steps:
4250
- name: Checkout sources
4351
uses: actions/checkout@v2
@@ -47,21 +55,36 @@ jobs:
4755
with:
4856
profile: minimal
4957
toolchain: stable
50-
override: true
5158

52-
- name: Test default features
59+
- name: Cache cargo resources
60+
uses: Swatinem/rust-cache@v1
61+
62+
- name: Debug build
63+
uses: actions-rs/cargo@v1
64+
with:
65+
command: build
66+
args: --manifest-path indy-credx/Cargo.toml --features vendored
67+
68+
- name: Test indy-utils
5369
uses: actions-rs/cargo@v1
5470
with:
5571
command: test
72+
args: --manifest-path indy-utils/Cargo.toml
5673

57-
- name: Test CL
74+
- name: Test indy-data-types (CL)
5875
uses: actions-rs/cargo@v1
5976
with:
6077
command: test
6178
args: --manifest-path indy-data-types/Cargo.toml --features cl
6279

63-
- name: Test CL-native
80+
- name: Test indy-data-types (CL-native)
81+
uses: actions-rs/cargo@v1
82+
with:
83+
command: test
84+
args: --manifest-path indy-data-types/Cargo.toml --features cl_native,vendored
85+
86+
- name: Test indy-credx (vendored)
6487
uses: actions-rs/cargo@v1
6588
with:
6689
command: test
67-
args: --manifest-path indy-data-types/Cargo.toml --features cl_native
90+
args: --manifest-path indy-credx/Cargo.toml --features vendored

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.vscode
12
target
23
Cargo.lock

build.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/sh
2+
3+
# NOTE:
4+
# MacOS universal build currently requires MacOS 11 (Big Sur) for the appropriate SDK,
5+
# and `sudo xcode-select --install` must be run to install the command line utilities.
6+
# Rust's `beta` channel must be installed because aarch64 is still a tier-2 target:
7+
# `rustup toolchain install beta`.
8+
# The build command becomes `BUILD_TARGET=apple-darwin BUILD_TOOLCHAIN=beta ./build.sh`
9+
10+
RUSTUP=${RUSTUP:-`command -v rustup`}
11+
PROJECT=indy-credx
12+
LIB_NAME=indy_credx
13+
FEATURES="${BUILD_FEATURES:-default}"
14+
15+
if [ ! -x "$RUSTUP" ]; then
16+
echo "rustup command not found: it can be obtained from https://rustup.rs/"
17+
exit 1
18+
fi
19+
20+
TOOLCHAIN=`$RUSTUP default`
21+
TARGET="${BUILD_TARGET-}"
22+
23+
if [ -z "$BUILD_TOOLCHAIN" ]; then
24+
BUILD_TOOLCHAIN=${TOOLCHAIN%%-*}
25+
if [ -z "$BUILD_TOOLCHAIN" ]; then
26+
echo "Error: Could not determine default Rust toolchain"
27+
exit 1
28+
fi
29+
fi
30+
31+
MACOS_UNIVERSAL_TARGETS="aarch64-apple-darwin x86_64-apple-darwin"
32+
33+
# Fail on any execution errors
34+
set -e
35+
36+
if [ "$TARGET" = "apple-darwin" ]; then
37+
# MacOS universal build
38+
INSTALLED_TARGETS=`$RUSTUP +$BUILD_TOOLCHAIN target list --installed`
39+
# Install target(s) as needed
40+
echo "Checking install targets for MacOS universal build .."
41+
for target in $MACOS_UNIVERSAL_TARGETS; do
42+
if ! `echo "$INSTALLED_TARGETS" | grep -q $target`; then
43+
$RUSTUP +$BUILD_TOOLCHAIN target add $target
44+
fi
45+
done
46+
elif [ -z "$TARGET" ]; then
47+
case "$TOOLCHAIN" in
48+
*apple-darwin*)
49+
# Check if the required targets for a universal build are installed
50+
INSTALLED_TARGETS=`$RUSTUP +$BUILD_TOOLCHAIN target list --installed`
51+
TARGET="apple-darwin"
52+
for target in $MACOS_UNIVERSAL_TARGETS; do
53+
if ! `echo "$INSTALLED_TARGETS" | grep -q $target`; then
54+
TARGET=
55+
break
56+
fi
57+
done
58+
if [ "$TARGET" = "apple-darwin" ]; then
59+
echo "Automatically enabled MacOS universal build"
60+
else
61+
echo "Universal MacOS build not enabled"
62+
fi
63+
esac
64+
fi
65+
66+
if [ "$TARGET" = "apple-darwin" ]; then
67+
MAJOR_VER=`sw_vers | grep ProductVersion | cut -f 2 | cut -f 1 -d .`
68+
if [ "$MAJOR_VER" -lt 11 ]; then
69+
echo "MacOS universal build requires OS 11 (Big Sur) or newer"
70+
TARGET=
71+
fi
72+
fi
73+
74+
if [ "$TARGET" = "apple-darwin" ]; then
75+
# Build both targets and combine them into a universal library with `lipo`
76+
TARGET_LIBS=
77+
for target in $MACOS_UNIVERSAL_TARGETS; do
78+
echo "Building $PROJECT for toolchain '$BUILD_TOOLCHAIN', target '$target'.."
79+
$RUSTUP run $BUILD_TOOLCHAIN cargo build --manifest-path indy-credx/Cargo.toml --release --features $FEATURES --target $target
80+
TARGET_LIBS="./target/$target/release/lib${LIB_NAME}.dylib $TARGET_LIBS"
81+
done
82+
83+
mkdir -p ./target/release
84+
OUTPUT="./target/release/lib${LIB_NAME}.dylib"
85+
echo "Combining targets into universal library"
86+
lipo -create -output $OUTPUT $TARGET_LIBS
87+
else
88+
# Build normal target
89+
echo "Building $PROJECT for toolchain '$BUILD_TOOLCHAIN'.."
90+
CMD="$RUSTUP run $BUILD_TOOLCHAIN cargo build --manifest-path indy-credx/Cargo.toml --release --features $FEATURES"
91+
if [ -n "$TARGET" ]; then
92+
$CMD --target "$TARGET"
93+
else
94+
$CMD
95+
fi
96+
fi

indy-credx/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ crate-type = ["staticlib", "rlib", "cdylib"]
1919
default = ["ffi"]
2020
ffi = ["ffi-support", "logger", "zeroize"]
2121
logger = ["env_logger"]
22+
vendored = ["indy-data-types/vendored"]
2223

2324
[dependencies]
2425
env_logger = { version = "0.7.1", optional = true }

0 commit comments

Comments
 (0)