Skip to content

Commit

Permalink
simplify build procedure (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
DBraun authored Jan 30, 2024
1 parent 2a53f3f commit ffdc771
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 119 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ jobs:
shell: cmd
run: |
cd thirdparty/libfaust
call download_libfaust.bat
python download_libfaust.py
- name: Build TD-Faust
shell: cmd
run: |
call build_windows.bat
env:
PYTHONVER: ${{ matrix.python-version}}
python build_tdfaust.py --pythonver=${{ matrix.python-version}}
- name: Build Reverb operator
shell: cmd
Expand Down Expand Up @@ -85,12 +83,18 @@ jobs:
# 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
# sh -v build_macos.sh
# python build_tdfaust.py --pythonver=3.9

# - name: Build Reverb operator
# shell: cmd
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Backup/*
Release/
Debug/
build*
!build_tdfaust.py
TD-Faust.[0-9]*.toe
SketchSynth.[0-9]*.toe
*dsp.json
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ The previous overview was about using a multi-purpose CHOP to dynamically compil

These are the requirements:

* Download libfaust by going to `thirdparty/libfaust` and running either `call download_libfaust.bat` on Windows or `sh download_libfaust.sh` on macOS.
* Download libfaust by going to `thirdparty/libfaust` and running `python download_libfaust.py`.
* Pick a Faust DSP file such as `reverb.dsp` that defines a `process = ...;`.
* Python should be installed.
* CMake should be installed.

If on Windows, you should open an x64 Native Tools for Visual Studio command prompt. On macOS, you can use Terminal. Then run a variation of the following script:
If on Windows, you should open an "x64 Native Tools for Visual Studio" command prompt. On macOS, you can use Terminal. Then run a variation of the following script:

```bash
python faust2td.py --dsp reverb.dsp --type "Reverb" --label "Reverb" --icon "Rev" --author "David Braun" --email "github.com/DBraun" --drop-prefix
Expand Down Expand Up @@ -62,7 +62,7 @@ Limitations and Gotchas:

Visit TD-Faust's [Releases](https://github.com/DBraun/TD-Faust/releases) page. Download and unzip the latest Windows version. Copy `TD-Faust.dll` and the `faustlibraries` folder to this repository's `Plugins` folder. Open `TD-Faust.toe` and compile a few examples.

If you need to compile `TD-Faust.dll` yourself, you should first install [Python 3.11](https://www.python.org/downloads/release/python-3117/) to `C:/Python311/` and confirm it's in your system PATH. You'll also need Visual Studio 2022 and CMake. Then open a cmd window to `thirdparty/libsndfile` and run `call download_libfaust.bat`. Then you can open a cmd window to this repo's root directory and run `call build_windows.bat`.
If you need to compile `TD-Faust.dll` yourself, you should first install [Python 3.11](https://www.python.org/downloads/release/python-3117/) to `C:/Python311/` and confirm it's in your system PATH. You'll also need Visual Studio 2022 and CMake. Then open a "x64 Native Tools for Visual Studio" command prompt with Administrator privileges to `thirdparty/libsndfile` and run `python download_libfaust.py`. Then `cd` to this repo's root directory and run `python build_tdfaust.py`.

### macOS

Expand All @@ -76,12 +76,10 @@ TD-Faust is designed for macOS version 11.0 and later. Also, macOS users need to
2. Install Xcode.
3. [Install CMake](https://cmake.org/download/) and confirm that it's installed by running `cmake --version` in Terminal. You may need to run `export PATH="/Applications/CMake.app/Contents/bin":"$PATH"`
4. Install requirements with [brew](http://brew.sh/): `brew install autoconf autogen automake flac libogg libtool libvorbis opus mpg123 pkg-config`
5. In a Terminal window, navigate to `thirdparty/libfaust` and run `sh download_libfaust.sh`.
5. In a Terminal window, navigate to `thirdparty/libfaust` and run `python download_libfaust.py`.
6. In a Terminal Window, export a variable to the TouchDesigner.app to which you'd like to support. For example: `export TOUCHDESIGNER_APP=/Applications/TouchDesigner.app`, assuming this version is a 2022.22650 build or higher.
7. Optional: depending on the Python version associated with the TouchDesigner you intend to use, run `export PYTHONVER=3.11` or `export PYTHONVER=3.9`.
8. In the same Terminal window, navigate to the root of this repository and run `sh build_macos.sh`
9. In a Terminal window, navigate to the root of this repository and run `sh build_macos.sh`.
10. Open `TD-Faust.toe`
7. In the same Terminal window, navigate to the root of this repository and run `python build_tdfaust.py --pythonver=3.11`
8. Open `TD-Faust.toe`

## Tutorial

Expand Down
41 changes: 0 additions & 41 deletions build_macos.sh

This file was deleted.

77 changes: 77 additions & 0 deletions build_tdfaust.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import argparse
import os
import platform
import subprocess


def run_command(command, shell=False):
subprocess.run(command, shell=shell, check=True)

def build_windows(pythonver):
os.system('rm build/CMakeCache.txt')

# Download libsndfile
libsndfile_dir = "thirdparty/libsndfile-1.2.0-win64/"
if not os.path.exists(libsndfile_dir):
print("Downloading libsndfile...")
os.chdir('thirdparty')
run_command(["curl", "-OL", "https://github.com/libsndfile/libsndfile/releases/download/1.2.0/libsndfile-1.2.0-win64.zip"])
run_command(["7z", "x", "libsndfile-1.2.0-win64.zip", "-y"])
os.remove("libsndfile-1.2.0-win64.zip")
print("Downloaded libsndfile.")
os.chdir("..")

# Build with CMake
cmake_command = [
"cmake", "-Bbuild", "-DCMAKE_BUILD_TYPE=Release",
"-DLIBFAUST_DIR=thirdparty/libfaust/win64/Release",
"-DSndFile_DIR=thirdparty/libsndfile/build",
f"-DPYTHONVER={pythonver}"
]
run_command(cmake_command)
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, touchdesigner_app):
os.system('rm -r Plugins/TD-Faust.plugin')

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

# Build libsndfile
print("Building libsndfile.")
os.chdir("thirdparty/libsndfile")
run_command(["cmake", "-Bbuild", "-DCMAKE_VERBOSE_MAKEFILE=ON", "-DCMAKE_INSTALL_PREFIX=./install"])
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}"
]
run_command(cmake_command)
run_command(["xcodebuild", "-configuration", "Release", "-project", "build/TD-Faust.xcodeproj"], shell=True)
os.system('mv build/Release/TD-Faust.plugin Plugins')

if __name__ == "__main__":
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).")
args = parser.parse_args()

if platform.system() == "Windows":
build_windows(args.pythonver)
elif platform.system() == "Darwin":
build_macos(args.pythonver, args.touchdesigner_app)
else:
raise RuntimeError(f"Unsupported operating system: {platform.system()}.")
33 changes: 0 additions & 33 deletions build_windows.bat

This file was deleted.

3 changes: 0 additions & 3 deletions thirdparty/libfaust/download_libfaust.bat

This file was deleted.

55 changes: 55 additions & 0 deletions thirdparty/libfaust/download_libfaust.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import argparse
import os
import platform
import subprocess
from pathlib import Path


def download_file(url: str, output: str) -> None:
if os.path.exists(output) and not args.force:
print(f"File already exists: {output}")
else:
subprocess.run(["curl", "-L", url, "-o", output], check=True)

def install_windows(version: str) -> None:
exe_file = f"Faust-{version}-win64.exe"
download_file(f"https://github.com/grame-cncm/faust/releases/download/{version}/{exe_file}", exe_file)
cwd = str(Path(__file__).parent)
subprocess.run([exe_file, "/S", f"/D={cwd}\\win64\\Release"], check=True)

def install_macos(version: str) -> None:
for arch in ["arm64", "x64"]:
dmg_file = f"Faust-{version}-{arch}.dmg"
download_file(f"https://github.com/grame-cncm/faust/releases/download/{version}/{dmg_file}", dmg_file)
subprocess.run(["hdiutil", "attach", dmg_file], check=True)
dir_path = f"darwin-{arch}/Release"
os.makedirs(dir_path, exist_ok=True)
subprocess.run(["cp", "-R", f"/Volumes/Faust-{version}/Faust-{version}/*", dir_path], check=True)
subprocess.run(["hdiutil", "detach", f"/Volumes/Faust-{version}/"], check=True)

def install_linux(version: str) -> None:
zip_file = f"libfaust-ubuntu-x86_64.zip"
download_file(f"https://github.com/grame-cncm/faust/releases/download/{version}/{zip_file}", zip_file)
dir_path = "ubuntu-x86_64/Release"
os.makedirs(dir_path, exist_ok=True)
subprocess.run(["unzip", zip_file, "-d", dir_path], check=True)

def main(version: str) -> None:
system = platform.system()
if system == "Windows":
install_windows(version)
elif system == "Darwin":
install_macos(version)
elif system == "Linux":
install_linux(version)
else:
raise RuntimeError(f"Unknown operating system: {system}.")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Download and install Libfaust.")
parser.add_argument("-v", "--version", default="2.69.3", help="Specify the version of Faust to download.")
parser.add_argument("--force", action="store_true", help="Force download even if files already exist.")
args = parser.parse_args()

main(args.version)
29 changes: 0 additions & 29 deletions thirdparty/libfaust/download_libfaust.sh

This file was deleted.

0 comments on commit ffdc771

Please sign in to comment.