Skip to content

Add build script for macOS & fix some cli/readme issues #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ build*/
/__pycache__
*.pyc
*.csv
*.a
venv
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
EMSDK_ENV_PATH?=/home/sevagh/repos/emsdk/emsdk_env.sh

default: cli

cli:
Expand All @@ -11,7 +9,11 @@ cli-debug:
cmake --build build/build-cli -- -j16

wasm:
@/bin/bash -c 'source $(EMSDK_ENV_PATH) && \
@if [ -z "$$EMSDK" ]; then \
echo "Error: EMSDK environment variable is not set. Please install and activate emsdk first."; \
exit 1; \
fi
@/bin/bash -c 'source "$$EMSDK/emsdk_env.sh" && \
emcmake cmake -S src_wasm -B build/build-wasm -DCMAKE_BUILD_TYPE=Release \
&& cmake --build build/build-wasm -- -j16'

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ Clone the repo with submodules:
$ git clone --recurse-submodules https://github.com/sevagh/demucs.cpp
```

Create a Python venv (or conda env) and install the requirements:
Create and activate a Python venv (or conda env) and install the requirements:
```
$ python -m venv my-env
$ source my-env/bin/activate
$ pip install -r ./scripts/requirements.txt
```

Activate your venv and run the ONNXRuntime builder scripts:
Run the ONNXRuntime builder scripts:
```
$ activate my-env
$ ./scripts/build-ort-linux.sh
$ ./scripts/build-ort-wasm.sh
```
Expand Down
61 changes: 61 additions & 0 deletions scripts/build-ort-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
set -euf -o pipefail

ONNX_CONFIG="${1:-./ort-model/model.required_operators_and_types.config}"
CMAKE_BUILD_TYPE=MinSizeRel

build_arch() {
ONNX_CONFIG="$1"
ARCH="$2"
BUILD_DIR=./build/build-ort-mac/$ARCH

python ./vendor/onnxruntime/tools/ci_build/build.py \
--build_dir "${BUILD_DIR}" \
--config=${CMAKE_BUILD_TYPE} \
--parallel \
--minimal_build \
--apple_deploy_target="10.15" \
--disable_ml_ops --disable_rtti \
--include_ops_by_config "$ONNX_CONFIG" \
--enable_reduced_operator_type_support \
--cmake_extra_defines CMAKE_OSX_ARCHITECTURES="${ARCH}" \
--cmake_extra_defines "EIGEN_NO_AUTOMATIC_RESIZING=1;EIGEN_MPL2_ONLY=1" \
--skip_tests

libtool -static -o "onnxruntime-macOS_${ARCH}-static-combined.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnx.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnxruntime_graph.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnx_proto.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnxruntime_mlas.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnx_test_data_proto.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnxruntime_optimizer.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnx_test_runner_common.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnxruntime_common.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnxruntime_providers.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnxruntime_session.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnxruntime_flatbuffers.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnxruntime_test_utils.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnxruntime_framework.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/libonnxruntime_util.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/_deps/re2-build/libre2.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/_deps/google_nsync-build/libnsync_cpp.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/_deps/protobuf-build/libprotobuf-lite.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/_deps/abseil_cpp-build/absl/hash/libabsl_hash.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/_deps/abseil_cpp-build/absl/hash/libabsl_city.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/_deps/abseil_cpp-build/absl/hash/libabsl_low_level_hash.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/_deps/abseil_cpp-build/absl/base/libabsl_throw_delegate.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/_deps/abseil_cpp-build/absl/container/libabsl_raw_hash_set.a" \
"${BUILD_DIR}/${CMAKE_BUILD_TYPE}/_deps/abseil_cpp-build/absl/base/libabsl_raw_logging_internal.a"
}

build_arch "$ONNX_CONFIG" x86_64
build_arch "$ONNX_CONFIG" arm64

OUTPUT_DIR=./build/build-ort-mac/universal/${CMAKE_BUILD_TYPE}

mkdir -p ${OUTPUT_DIR}
lipo -create onnxruntime-macos_x86_64-static-combined.a \
onnxruntime-macos_arm64-static-combined.a \
-output "${OUTPUT_DIR}/libonnxruntime.a"
rm onnxruntime-macos_x86_64-static-combined.a
rm onnxruntime-macos_arm64-static-combined.a
1 change: 1 addition & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ onnx
#onnxruntime==1.16.3
#onnx==1.13.1
bin2c
flatbuffers
27 changes: 23 additions & 4 deletions src_cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,48 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -ffast-math -flto -fno-signed-zeros -fassociative-math -freciprocal-math -fno-math-errno -fno-rounding-math -funsafe-math-optimizations -fno-trapping-math -fno-rtti -DNDEBUG")

if(APPLE)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math -flto -fno-signed-zeros -fassociative-math -freciprocal-math -fno-math-errno -fno-rounding-math -funsafe-math-optimizations -fno-trapping-math -fno-rtti -DNDEBUG")
else()
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -ffast-math -flto -fno-signed-zeros -fassociative-math -freciprocal-math -fno-math-errno -fno-rounding-math -funsafe-math-optimizations -fno-trapping-math -fno-rtti -DNDEBUG")
endif()

# Set some libremidi flags for wasm and header-only
add_definitions(-DLIBREMIDI_HEADER_ONLY=1)
#add_definitions(-DORT_NO_EXCEPTIONS=1)

# Define the path to the compiled ONNX Runtime static library
set(ONNX_RUNTIME_LIB ${CMAKE_SOURCE_DIR}/../build/build-ort-linux/MinSizeRel/libonnxruntime.so)
if(APPLE)
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
set(ONNX_RUNTIME_LIB ${CMAKE_SOURCE_DIR}/../build/build-ort-mac/universal/MinSizeRel/libonnxruntime.a)
# Add Foundation framework
find_library(FOUNDATION_FRAMEWORK Foundation)
else()
set(ONNX_RUNTIME_LIB ${CMAKE_SOURCE_DIR}/../build/build-ort-linux/MinSizeRel/libonnxruntime.so)
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/onnxruntime/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../ort-model/model)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/eigen)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/oboe-resampler)

# Dont build libnyquist examples
set(LIBNYQUIST_BUILD_EXAMPLE OFF CACHE BOOL "Build libnyquist examples" FORCE)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/libnyquist ${CMAKE_BINARY_DIR}/libnyquist)

file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../src/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../src_cli/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../ort-model/model/model.ort.c" "${CMAKE_CURRENT_SOURCE_DIR}/../vendor/oboe-resampler/*.cpp")
add_executable(basicpitch ${SOURCES})

# we only need header mode for libremidi
# use target_include_directories to treat it like a system library to ignore warnings
target_include_directories(basicpitch SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/libremidi/include)

target_link_libraries(basicpitch ${ONNX_RUNTIME_LIB} libnyquist)
target_link_libraries(basicpitch ${ONNX_RUNTIME_LIB} libnyquist::libnyquist)
if(APPLE)
target_link_libraries(basicpitch ${FOUNDATION_FRAMEWORK})
endif()
target_compile_definitions(basicpitch PRIVATE LIBREMIDI_HEADER_ONLY=1)

file(GLOB SOURCES_TO_LINT "${CMAKE_CURRENT_SOURCE_DIR}/../src/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../src/*.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/../src_wasm/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../src_cli/*.cpp")
Expand Down
2 changes: 1 addition & 1 deletion vendor/onnxruntime
Submodule onnxruntime updated 4661 files