Skip to content

Commit

Permalink
try macos-arm64 github action
Browse files Browse the repository at this point in the history
  • Loading branch information
DBraun committed Apr 4, 2024
1 parent 7778a45 commit 3323a57
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 77 deletions.
147 changes: 90 additions & 57 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
env:
CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM: ${{ secrets.CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM }}
name: Compile
on:
pull_request: {}
Expand All @@ -17,7 +19,7 @@ jobs:
- { name: "win64", os: "windows-2022", python-version: "3.9", python-major: "39"}
- { name: "win64", os: "windows-2022", python-version: "3.11", python-major: "311"}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true

Expand All @@ -27,7 +29,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1
uses: microsoft/setup-msbuild@v2

- name: Get CMake
uses: lukka/get-cmake@latest
Expand Down Expand Up @@ -59,67 +61,98 @@ jobs:
name: TD-Faust-${{ matrix.name }}-Python${{ matrix.python-major }}
path: Plugins

# build-macos:
# strategy:
# matrix:
# include:
# - name: macos-x86_64
# os: macos-latest

# runs-on: macos-latest
# steps:
# - uses: actions/checkout@v3
# with:
# submodules: true

# - name: Setup Python 3.8
# uses: actions/setup-python@v5
# with:
# python-version: '3.8'

# - name: Setup Python 3.9
# run: |
# pip install --upgrade certifi
# cd install_script
# python macos_install_python.py

# - name: Download Libfaust
# shell: cmd
# run: |
# cd thirdparty/libfaust
# python download_libfaust.py

# - name: Build Everything
# run: |
# export PATH=/Library/Frameworks/Python.framework/Versions/3.9:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.9/lib:$PATH
# which python3
# python3 --version
# python build_tdfaust.py --pythonver=3.9

# - name: Build Reverb operator
# shell: cmd
# run: |
# export PATH=$PWD/thirdparty/libfaust/darwin-x64/Release/:$PWD/thirdparty/libfaust/darwin-arm64/Release/:$PATH
# python faust2td.py --dsp reverb.dsp --type "Reverb" --label "Reverb" --icon "Rev" --author "David Braun" --email "github.com/DBraun" --drop-prefix

# - name: Make distribution
# run: |
# rm -rf Plugins/faustlibraries/.git

# - name: Upload artifact
# uses: actions/upload-artifact@v4
# with:
# name: TD-Faust-${{ matrix.name }}-Python${{ matrix.python-major }}
# path: Plugins
build-macos:
strategy:
matrix:
include:
- name: macos-x86_64
arch: x86_64
os: macos-12
python-version: "3.11"
python-major: "311"
libfaust-arch: "x64"
- name: macos-arm64
arch: arm64
os: macos-12
python-version: "3.11"
python-major: "311"
libfaust-arch: "arm64"

runs-on: macos-12
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Setup Python 3.11
run: |
pip install --upgrade certifi
cd install_script
python macos_install_python.py
- name: Brew install requirements (arm64)
if: ${{ endsWith( matrix.name, 'macos-arm64') }}
run: |
brew update
PACKAGES=(flac libogg libtool libvorbis opus mpg123 lame)
DEPS=($(brew deps --union --topological $(echo $PACKAGES) | tr '\n' ' '))
PACKAGES=("${DEPS[@]}" "${PACKAGES[@]}")
export HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_INSTALL_UPGRADE=1
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
for PACKAGE in "${PACKAGES[@]}"
do
echo "Fetching bottle: $PACKAGE"
response=$(brew fetch --bottle-tag=arm64_monterey $PACKAGE 2>&1)
package_path=$(echo $response | sed -n 's/.*\:\ \(.*\.tar\.gz\).*/\1/p')
package_path=$(echo "$package_path" | xargs)
echo "Package Path: $package_path"
brew reinstall --verbose --force-bottle "$package_path" || true
done
brew uninstall --ignore-dependencies curl git || true
- name: Install dependencies macOS
if: ${{ endsWith( matrix.name, 'macos-x86_64') }}
run: |
brew install autoconf autogen automake flac libogg libtool libvorbis opus mpg123 pkg-config
- name: Download Libfaust
shell: cmd
run: |
cd thirdparty/libfaust
python download_libfaust.py
- name: Build Everything
run: |
export PATH=/Library/Frameworks/Python.framework/Versions/3.11:/Library/Frameworks/Python.framework/Versions/3.11/bin:/Library/Frameworks/Python.framework/Versions/3.11/lib:$PATH
which python3
python3 --version
python3 build_tdfaust.py --pythonver=3.11 --arch=${{matrix.arch}}
- name: Build Reverb operator
shell: cmd
run: |
export PATH=$PWD/thirdparty/libfaust/darwin-${{matrix.libfaust-arch}}/Release/bin:$PATH
python3 faust2td.py --dsp reverb.dsp --type "Reverb" --label "Reverb" --icon "Rev" --author "David Braun" --email "github.com/DBraun" --drop-prefix --arch=${{matrix.arch}}
- name: Make distribution
run: |
rm -rf Plugins/faustlibraries/.git
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: TD-Faust-${{ matrix.name }}-Python${{ matrix.python-major }}
path: Plugins

create-release:
if: startsWith(github.ref, 'refs/tags/v')
# needs: [build-windows, build-macos]
needs: [build-windows]
needs: [build-windows, build-macos]
runs-on: ubuntu-latest
name: "Create Release on GitHub"
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
path: "dist"

Expand Down
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ cmake_minimum_required(VERSION 3.13.0 FATAL_ERROR)
set(VERSION 0.4.2)
project(TD-Faust VERSION ${VERSION})

# 10-digit alphanumeric developer ID
set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "$ENV{CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM}")

set(SndFile_DIR ${SndFile_DIR})

message(STATUS "TD-Faust external")
Expand Down Expand Up @@ -114,3 +117,13 @@ if(MSVC)
${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:TD-Faust>" ${CMAKE_SOURCE_DIR}/Plugins
)
endif()

# Ensure that we only attempt to sign on macOS.
if(APPLE)
if(NOT "${CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM}" STREQUAL "")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Developer ID Application")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Manual")
else()
message(WARNING "CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM is not set. The plugin will not be signed.")
endif()
endif()
22 changes: 13 additions & 9 deletions build_tdfaust.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,35 @@ def build_windows(pythonver: str):
run_command(["cmake", "--build", "build", "--config", "Release"])
os.system(f'cp "thirdparty/libsndfile-1.2.0-win64/bin/sndfile.dll" "Plugins/sndfile.dll"')

def build_macos(pythonver: str, touchdesigner_app: str):
def build_macos(pythonver: str, touchdesigner_app: str, arch: str=None):
os.system('rm -r Plugins/TD-Faust.plugin')

cmake_osx_deployment_target = "11.0"
if platform.machine() == 'arm64':
cmake_osx_deployment_target = f"-DCMAKE_OSX_DEPLOYMENT_TARGET=12.0"
if arch == 'arm64':
libfaust_dir = f"{os.getcwd()}/thirdparty/libfaust/darwin-arm64/Release"
elif platform.machine() == 'x86_64':
cmake_build_arch = f"-DCMAKE_OSX_ARCHITECTURES=arm64"
elif arch == 'x86_64':
libfaust_dir = f"{os.getcwd()}/thirdparty/libfaust/darwin-x64/Release"
cmake_build_arch = f"-DCMAKE_OSX_ARCHITECTURES=x86_64"
else:
raise RuntimeError(f"Unknown CPU architecture: {platform.machine()}.")
raise RuntimeError(f"Unknown CPU architecture: {arch}.")

# Build libsndfile
print("Building libsndfile.")
os.chdir("thirdparty/libsndfile")
run_command(["cmake", "-Bbuild", "-DCMAKE_VERBOSE_MAKEFILE=ON", "-DCMAKE_INSTALL_PREFIX=./install"])
run_command(["cmake", "-Bbuild", "-DCMAKE_VERBOSE_MAKEFILE=ON", "-DCMAKE_INSTALL_PREFIX=./install", cmake_osx_deployment_target, cmake_build_arch])
run_command(["cmake", "--build", "build", "--config", "Release"])
run_command(["cmake", "--build", "build", "--target", "install"])
os.chdir("../..")

# Build with CMake
cmake_command = [
"cmake", "-Bbuild", "-G", "Xcode",
f"-DCMAKE_OSX_DEPLOYMENT_TARGET={cmake_osx_deployment_target}",
f"-DLIBFAUST_DIR={libfaust_dir}",
f"-DPYTHONVER={pythonver}",
f"-DPython_ROOT_DIR={touchdesigner_app}/Contents/Frameworks/Python.framework/Versions/{pythonver}"
f"-DPython_ROOT_DIR={touchdesigner_app}/Contents/Frameworks/Python.framework/Versions/{pythonver}",
cmake_osx_deployment_target,
cmake_build_arch
]
run_command(cmake_command)
run_command(["cmake", "--build", "build", "--config", "Release"])
Expand All @@ -67,11 +70,12 @@ def build_macos(pythonver: str, touchdesigner_app: str):
parser = argparse.ArgumentParser(description="Build TD-Faust plugin for Windows or macOS.")
parser.add_argument("--pythonver", default="3.11", help="Specify the Python version.")
parser.add_argument("--touchdesigner_app", default="/Applications/TouchDesigner.app", help="Path to TouchDesigner app (macOS only).")
parser.add_argument("--arch", default=platform.machine(), help="CPU Architecture for which to build.")
args = parser.parse_args()

if platform.system() == "Windows":
build_windows(args.pythonver)
elif platform.system() == "Darwin":
build_macos(args.pythonver, args.touchdesigner_app)
build_macos(args.pythonver, args.touchdesigner_app, args.arch)
else:
raise RuntimeError(f"Unsupported operating system: {platform.system()}.")
24 changes: 20 additions & 4 deletions faust2td.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def add_toggle(item) -> str:
parser.add_argument('--email', required=False, default='', help="The author's email")
parser.add_argument('--drop-prefix', required=False, action='store_true', default=False,
help="Automatically drop the first group name to make the CHOP's parameter names shorter.")
parser.add_argument("--arch", default=platform.machine(), help="CPU Architecture for which to build.")

args = parser.parse_args()

Expand All @@ -175,6 +176,8 @@ def add_toggle(item) -> str:

# Turn the Faust code into C++ code:
faust_script = f'faust -i "{dsp_file}" -lang cpp -cn FaustDSP -json -a faust2touchdesigner/template_faustaudio.h -o faust2touchdesigner/{op_type}.h'

print(f'Executing faust script:\n{faust_script}')

subprocess.call(shlex.split(faust_script))

Expand Down Expand Up @@ -270,13 +273,22 @@ def add_toggle(item) -> str:
with open(f'faust2touchdesigner/Faust_{op_type}_CHOP.cpp', 'w') as f:
f.write(template)

cmake_osx_deployment_target = f"-DCMAKE_OSX_DEPLOYMENT_TARGET=12.0"

cmake_build_arch = f"-DCMAKE_OSX_ARCHITECTURES=x86_64"

if platform.system() == 'Windows':
libfaust_dir = 'thirdparty/libfaust/win64/Release'
else:
if 'arm' in platform.processor():
arch = args.arch
if arch == 'arm64':
libfaust_dir = 'thirdparty/libfaust/darwin-arm64/Release'
else:
cmake_build_arch = f"-DCMAKE_OSX_ARCHITECTURES=arm64"
elif arch == 'x86_64':
libfaust_dir = 'thirdparty/libfaust/darwin-x64/Release'
cmake_build_arch = f"-DCMAKE_OSX_ARCHITECTURES=x86_64"
else:
raise RuntimeError(f"Unknown CPU architecture: {arch}.")

libfaust_dir = str(abspath(libfaust_dir))

Expand All @@ -286,7 +298,11 @@ def add_toggle(item) -> str:
assert isdir(libfaust_dir), "Have you run `sh download_libfaust.sh`?"

# execute CMake and build
subprocess.call(shlex.split(f'cmake faust2touchdesigner -Bbuild_faust2touchdesigner -DOP_TYPE={op_type} -DAUTHOR_NAME="{author_name}" -DLIBFAUST_DIR="{libfaust_dir}" -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0'))
subprocess.call(shlex.split(f'cmake --build build_faust2touchdesigner --config Release'))
build_dir = 'build_faust2touchdesigner'
subprocess.call(shlex.split(f'cmake faust2touchdesigner -{build_dir} -DOP_TYPE={op_type} -DAUTHOR_NAME="{author_name}" -DLIBFAUST_DIR="{libfaust_dir}" {cmake_osx_deployment_target} {cmake_build_arch}'))
subprocess.call(shlex.split(f'cmake --build {build_dir} --config Release'))

if platform.system() == 'Darwin':
subprocess.call(shlex.split(f'cp -r {build_dir}/{op_type}.plugin Plugins'))

print('All done!')
15 changes: 14 additions & 1 deletion faust2touchdesigner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ cmake_minimum_required(VERSION 3.13.0 FATAL_ERROR)
set(VERSION 0.0.1)
project(${OP_TYPE} VERSION ${VERSION})

# 10-digit alphanumeric developer ID
set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "$ENV{CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM}")

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${OP_TYPE})

set(TOUCHDESIGNER_INC ${PROJECT_SOURCE_DIR}/../thirdparty/TouchDesigner/)
Expand Down Expand Up @@ -45,7 +48,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_BUNDLE_VERSION "${VERSION}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${VERSION}"
MACOSX_BUNDLE_COPYRIGHT "${AUTHOR_NAME}"
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Faust2TouchDesigner/Info.plist
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
XCODE_ATTRIBUTE_FRAMEWORK_SEARCH_PATHS "/System/Library/PrivateFrameworks /Library/Frameworks"
)

Expand Down Expand Up @@ -76,3 +79,13 @@ if(MSVC)
${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:${PROJECT_NAME}>" ${CMAKE_SOURCE_DIR}/../Plugins
)
endif()

# Ensure that we only attempt to sign on macOS.
if(APPLE)
if(NOT "${CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM}" STREQUAL "")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Developer ID Application")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Manual")
else()
message(WARNING "CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM is not set. The plugin will not be signed.")
endif()
endif()
24 changes: 24 additions & 0 deletions faust2touchdesigner/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
4 changes: 0 additions & 4 deletions faust2touchdesigner/template_faustaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ struct Meta;
#include <faust/gui/LayoutUI.h>
#include <faust/gui/ValueConverter.h>
#include <faust/misc.h>

<<includeIntrinsic>>

<<includeclass>>
4 changes: 2 additions & 2 deletions install_script/macos_install_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def install_cpython(tmp: Path, version: str, url: str) -> Path:
def main():

tmp = Path("/tmp/cibw_tmp")
version = "3.9"
url = "https://www.python.org/ftp/python/3.9.9/python-3.9.9-macos11.pkg"
version = "3.11"
url = "https://www.python.org/ftp/python/3.11.9/python-3.11.9-macos11.pkg"

base_python = install_cpython(tmp, version, url)
assert base_python.exists()
Expand Down

0 comments on commit 3323a57

Please sign in to comment.