harbor run -t openthoughts/tasktrove-mix-h2-language-proportional-mix-h2-lang-proportional-3676harbor download openthoughts/tasktrove-mix-h2-language-proportional-mix-h2-lang-proportional-3676You need to implement functionality to precompile specified Extempore library files to improve loading performance. Your implementation should properly handle different operating systems and ensure that the required LLVM directory is set.
Functionality:
.so for Linux and .dylib for macOS).EXT_LLVM_DIR is set; if it is not, output an error message and terminate.Expected Inputs:
EXT_LLVM_DIR should be set to the path of the Extempore LLVM directory.Expected Outputs:
EXT_LLVM_DIR.File Locations and Naming:
/app/.precompile_libraries.sh.xtmprecomp-command-file.xtm as part of the precompilation process, which will be removed after execution.Make sure your script is executable (chmod +x /app/precompile_libraries.sh) and adheres to the described functionality and behavior.
The following test script will be used to verify your solution:
#!/bin/bash
# pre-compile some standard Extempore libraries for faster loading
case $(uname) in
Linux) SHLIB_EXT=so PLATFORM=linux ;;
Darwin) SHLIB_EXT=dylib PLATFORM=osx ;;
*) echo Cannot precompile modules for OS: $(uname) >&2 ; exit 1 ;;
esac
if [ -z "$EXT_LLVM_DIR" ]; then
echo "Need to set EXT_LLVM_DIR to point to your (Extempore) LLVM directory."
exit 2
fi
PRECOMP_LIBS="\
core/math.xtm \
core/audio_dsp.xtm \
core/instruments.xtm \
external/fft.xtm \
external/sndfile.xtm \
external/audio_dsp_ext.xtm \
external/instruments_ext.xtm \
external/rtmidi.xtm \
external/glib.xtm \
external/soil.xtm \
external/opengl.xtm \
external/shaders.xtm \
external/assimp.xtm \
external/openvg.xtm"
PRECOMP_COMMAND_FILENAME="xtmprecomp-command-file.xtm"
PRECOMP_EXTEMPORE_RUN_COMMAND="./extempore --run "
# check all the required shared libs are there
for f in $PRECOMP_LIBS
do
echo "(sys:precomp:compile-xtm-file \"libs/$f\" #t #t)" > $PRECOMP_COMMAND_FILENAME
$PRECOMP_EXTEMPORE_RUN_COMMAND $PRECOMP_COMMAND_FILENAME
rc=$?
if [[ $rc != 0 ]] ; then
echo
echo Error precompiling $f
exit $rc
else
echo
echo Successfully precompiled $f
fi
done
rm $PRECOMP_COMMAND_FILENAME
exit 0