Skip to content

Build C-API

Build C-API #44

Workflow file for this run

name: Build C-API
on:
workflow_dispatch:
schedule:
- cron: '0 18 * * 6'
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ${{ matrix.os }}
env:
# For some builds, we use cross to test on 32-bit and big-endian
# systems.
CARGO: cargo
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
TARGET_FLAGS: ""
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
TARGET_DIR: ./target
# Emit backtraces on panics.
RUST_BACKTRACE: 1
strategy:
fail-fast: false
matrix:
build: [linux-x86, linux-arm-v7, linux-arm-aarch64, macos-x86, macos-aarch64, win-msvc]
include:
- build: linux-x86
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
libname: libdeep_filter_ladspa
libext: so
- build: linux-arm-v7
os: ubuntu-22.04
target: armv7-unknown-linux-gnueabihf
cc: arm-linux-gnueabihf-gcc
cargoc-feat: '--features=vendored-openssl'
libname: libdeep_filter_ladspa
libext: so
- build: linux-arm-aarch64
os: ubuntu-22.04
target: aarch64-unknown-linux-gnu
cc: aarch64-linux-gnu-gcc
cargoc-feat: '--features=vendored-openssl'
libname: libdeep_filter_ladspa
libext: so
- build: macos-x86
os: macos-12
target: x86_64-apple-darwin
libname: libdeep_filter_ladspa
libext: dylib
- build: macos-aarch64
os: macos-12
target: aarch64-apple-darwin
libname: libdeep_filter_ladspa
libext: dylib
- build: win-msvc
os: windows-2022
target: x86_64-pc-windows-msvc
cargoc-feat: '--features=vendored-openssl'
cinstall-args: '--crt-static'
libname: deep_filter_ladspa
libext: dll
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
target: ${{ matrix.target }}
- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.toml') }}
cache-on-failure: true
- name: Install gcc-arm-linux-gnueabihf
if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
run: |
mkdir .cargo
sudo apt-get update
sudo apt-get install --no-install-recommends gcc-arm-linux-gnueabihf crossbuild-essential-armhf
echo -e "[target.${{ matrix.target }}]\nlinker=\"${{ matrix.cc }}\"\n" > .cargo/config
- name: Install gcc-aarch64-linux-gnu
if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }}
run: |
mkdir .cargo
sudo apt-get update
sudo apt-get install --no-install-recommends gcc-aarch64-linux-gnu crossbuild-essential-arm64
echo -e "[target.${{ matrix.target }}]\nlinker=\"${{ matrix.cc }}\"\n" > .cargo/config
- name: Setup target
run: |
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- name: Install Perl on Windows
if: ${{ runner.os == 'windows' }}
uses: shogo82148/actions-setup-perl@v1
with:
perl-version: '5.34'
- name: Install cargo-c
run: |
cargo install cargo-c ${{ matrix.cargoc-feat }}
- name: Show command used for Cargo
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Build release binary
shell: bash
run: |
${{ env.CARGO }} cinstall --profile=release-lto -p deep_filter \
--destdir=${{ env.TARGET_DIR }} \
${{ matrix.cinstall-args }} \
${{ env.TARGET_FLAGS }}
- name: Rebuild header using the settings in cbindgen.toml
shell: bash
run: |
cbindgen --config cbindgen.toml --crate deep_filter --output ${{ env.TARGET_DIR }}/usr/local/include/deep_filter/deep_filter.h
- name: Copy to staging
shell: bash
run: |
mkdir staging
mv ${{ env.TARGET_DIR }}/usr staging
- name: List built files
if: ${{ runner.os != 'macos' }}
run: tree staging
- name: List built files
if: ${{ runner.os == 'macos' }}
run: find ./staging
- uses: actions/upload-artifact@v3
with:
name: clib-${{ matrix.target }}
path: ./staging
retention-days: 7