fix: refactored some code to simplify #70
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
name: Rust | |
on: | |
push: | |
branches: [ "main" ] | |
paths: | |
- src/** | |
- Cargo.* | |
- .github/workflows/rust.yml | |
pull_request: | |
branches: [ "main" ] | |
env: | |
CARGO_TERM_COLOR: always | |
BUILD_TYPE: release | |
SHARED_LIBRARY_NAME: dragon_toml | |
jobs: | |
build: | |
runs-on: ${{ matrix.runs-on }} | |
container: ${{ matrix.container }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
# - target: x86_64-unknown-linux-musl | |
- target: x86_64-unknown-linux-gnu | |
runs-on: ubuntu-latest | |
container: quay.io/pypa/manylinux2014_x86_64 | |
shared-lib-extension: so | |
bitness: 64 | |
- target: x86_64-pc-windows-msvc | |
runs-on: windows-latest | |
container: '' | |
shared-lib-extension: dll | |
bitness: 64 | |
- target: i686-pc-windows-msvc | |
runs-on: windows-latest | |
shared-lib-extension: dll | |
bitness: 32 | |
container: '' | |
- target: x86_64-apple-darwin | |
arch: x86_64 | |
runs-on: macos-latest | |
container: '' | |
shared-lib-extension: dylib | |
bitness: 64 | |
- target: aarch64-apple-darwin | |
arch: aarch64 | |
runs-on: macos-latest | |
container: '' | |
shared-lib-extension: dylib | |
bitness: 64 | |
steps: | |
- name: Install Rust Toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
target: ${{ matrix.target }} | |
- uses: actions/checkout@v3 | |
- name: Build | |
run: | | |
rustup target add ${{ matrix.target }} | |
cargo build --target=${{ matrix.target }} --verbose --${{ env.BUILD_TYPE }} | |
pushd target/${{ matrix.target }}/${{ env.BUILD_TYPE }} | |
mv *.${{ matrix.shared-lib-extension }} ${{ env.SHARED_LIBRARY_NAME }}_${{ matrix.bitness }}.${{ matrix.shared-lib-extension }} | |
- name: Bundle MacOS Framework | |
if: ${{ matrix.runs-on == 'macos-latest' }} | |
run: | | |
BUILD_TYPE=${{ env.BUILD_TYPE }} | |
SHARED_LIBARY_NAME=${{ env.SHARED_LIBRARY_NAME }}_${{ matrix.bitness }}.${{ matrix.shared-lib-extension }} | |
BUILD_OUTPUT_DIR=target/${{ matrix.target }}/${{ env.BUILD_TYPE }} | |
FRAMEWORK_NAME=${{ env.SHARED_LIBRARY_NAME }}_${{ matrix.bitness }} | |
pushd $BUILD_OUTPUT_DIR | |
rm -rf $FRAMEWORK_NAME.framework | |
mkdir -p $FRAMEWORK_NAME.framework/Versions/A | |
cp $SHARED_LIBARY_NAME $FRAMEWORK_NAME.framework/Versions/A/$FRAMEWORK_NAME | |
chmod ugo+rx $FRAMEWORK_NAME.framework/Versions/A/$FRAMEWORK_NAME | |
ln -s ./A ./$FRAMEWORK_NAME.framework/Versions/Current | |
ln -s ./Versions/A/$FRAMEWORK_NAME ./$FRAMEWORK_NAME.framework | |
rm -rf $FRAMEWORK_NAME.framework.zip | |
zip -r $FRAMEWORK_NAME.framework.zip $FRAMEWORK_NAME.framework | |
popd | |
- name: Run tests | |
run: cargo test --verbose | |
- name: Upload artifact | |
if: ${{ matrix.runs-on != 'macos-latest' }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: shared-library-${{ matrix.target }} | |
if-no-files-found: error | |
path: | | |
target/${{ matrix.target }}/${{ env.BUILD_TYPE }}/*.${{ matrix.shared-lib-extension }} | |
- name: Upload MacOS Framework artifact | |
if: ${{ matrix.runs-on == 'macos-latest' }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: shared-library-${{ matrix.target }} | |
if-no-files-found: error | |
path: | | |
target/${{ matrix.target }}/${{ env.BUILD_TYPE }}/*.framework.zip |