1#!/usr/local/bin/bash -e 2 3##################################################################### 4# # 5# Compiles Faust programs to PortAudio and Rust binary # 6# (c) Grame, 2018 # 7# # 8##################################################################### 9 10. faustpath 11. faustoptflags 12. usage.sh 13 14SRC="0" 15ARCHFILE=$FAUSTARCH/minimal-cpal.rs 16 17#PHASE 2 : dispatch command arguments 18while [ $1 ] 19do 20 p=$1 21 22 if [ $p = "-help" ] || [ $p = "-h" ]; then 23 usage faust2cpalrust "[options] [Faust options] <file.dsp>" 24 require CPAL 25 echo "Compiles Faust programs to CPAL and Rust binary" 26 option 27 option -source "only generates the source project." 28 option "Faust options" 29 exit 30 fi 31 32 if [ $p = "-source" ]; then 33 SRC="1" 34 elif [ ${p:0:1} = "-" ]; then 35 OPTIONS="$OPTIONS $p" 36 elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then 37 FILES="$FILES $p" 38 else 39 OPTIONS="$OPTIONS $p" 40 fi 41 42shift 43 44done 45 46#------------------------------------------------------------------- 47# compile the *.dsp files 48# 49 50for p in $FILES; do 51 52 f=$(basename "$p") 53 SRCDIR=$(dirname "$p") 54 55 # creates the dir 56 dspName="${f%.dsp}-cpalrust" 57 rm -rf "$SRCDIR/$dspName" 58 59 # create rust project 60 pushd "$SRCDIR" 61 cargo new $dspName --bin 62 popd 63 64 # compile Faust DSP and put in the cargo folder 65 faust -a $ARCHFILE -lang rust "$SRCDIR/$f" -o "$SRCDIR/$dspName/src/main.rs" 66 67 # add dependencies 68 echo "anyhow = \"*\"" >> "$SRCDIR/$dspName/Cargo.toml" 69 echo "cpal = \"*\"" >> "$SRCDIR/$dspName/Cargo.toml" 70 echo "libm = \"*\"" >> "$SRCDIR/$dspName/Cargo.toml" 71 72 # build the project 73 if [ $SRC = "0" ]; then 74 ( 75 cd "$SRCDIR/$dspName" 76 cargo build --release 77 cargo build 78 ) > /dev/null || exit 79 fi 80 81done 82