Skip to content

Commit

Permalink
Add a workflow to build cross platform libs
Browse files Browse the repository at this point in the history
Removed the manually compiles shared objects
Updated src.cmake to suit
  • Loading branch information
omeryusufyagci committed Oct 27, 2024
1 parent 6009fc2 commit 6571a82
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/build_cross-platform_libs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build Cross-Platform Libraries

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
target: aarch64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: windows-latest
target: x86_64-pc-windows-gnu

steps:
- uses: actions/checkout@v2

- name: Download DeepFilterNet
run: git clone --depth 1 https://github.com/Rikorose/DeepFilterNet.git DeepFilterNet

- name: Install Rust Targets
run: rustup target add ${{ matrix.target }}

- name: Install Dependencies (macOS)
if: matrix.os == 'macos-latest'
run: brew install zig

- name: Build libdf for macOS (Universal Binary)
if: matrix.os == 'macos-latest'
env:
RUSTFLAGS: "-C linker=zig cc -C link-arg=-target -C link-arg=aarch64-apple-darwin"
run: |
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export MACOSX_DEPLOYMENT_TARGET=11.0
cargo build --manifest-path=DeepFilterNet/Cargo.toml --release --features capi --target aarch64-apple-darwin -Z build-std
cargo build --manifest-path=DeepFilterNet/Cargo.toml --release --features capi --target x86_64-apple-darwin
mkdir -p MediaProcessor/lib
lipo -create -output MediaProcessor/lib/libdf.dylib \
target/aarch64-apple-darwin/release/libdf.dylib \
target/x86_64-apple-darwin/release/libdf.dylib
- name: Build libdf for Linux
if: matrix.os == 'ubuntu-latest'
run: |
cargo build --manifest-path=DeepFilterNet/Cargo.toml --release --features capi --target x86_64-unknown-linux-gnu
mkdir -p MediaProcessor/lib
mv target/x86_64-unknown-linux-gnu/release/libdf.so MediaProcessor/lib/libdf.so
- name: Build libdf for Windows
if: matrix.os == 'windows-latest'
run: |
cargo build --manifest-path=DeepFilterNet/Cargo.toml --release --features capi --target x86_64-pc-windows-gnu
mkdir -p MediaProcessor/lib
mv target/x86_64-pc-windows-gnu/release/libdf.dll MediaProcessor/lib/libdf.dll
mv target/x86_64-pc-windows-gnu/release/libdf.dll.a MediaProcessor/lib/libdf.dll.a
10 changes: 3 additions & 7 deletions MediaProcessor/cmake/src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ target_link_libraries(MediaProcessor PRIVATE Threads::Threads)
target_link_libraries(MediaProcessor PRIVATE ${SNDFILE_LIBRARIES})

if(APPLE)
if(CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
set(DF_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libdf.dylib)
else()
message(FATAL_ERROR "x86_64 MacOS is currently not supported (should come very soon!).")
# set(DF_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libdf.dylib)
endif()
set(DF_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libdf.dylib)
elseif(WIN32)
set(DF_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libdf.dll.a) # link with .dll.a, use .dll at runtime
set(DF_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libdf.dll.a)
elseif(UNIX)
set(DF_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libdf.so)
else()
message(FATAL_ERROR "Unsupported platform")
endif()

set_target_properties(MediaProcessor PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
Binary file removed MediaProcessor/lib/df.dll
Binary file not shown.
Binary file removed MediaProcessor/lib/libdf.dll.a
Binary file not shown.
Binary file removed MediaProcessor/lib/libdf.dylib
Binary file not shown.
Binary file removed MediaProcessor/lib/libdf.so
Binary file not shown.

0 comments on commit 6571a82

Please sign in to comment.