Last active
August 27, 2022 16:54
-
-
Save Syzygies/15cbaebd5d7a31630650b7a8436a8f1f to your computer and use it in GitHub Desktop.
Build script for Idris 2 on Apple silicon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# script to install Idris2, once chez scheme already installed | |
# abort on any error | |
set -e | |
# we assume this script is in project/bin, and cd to project | |
cd "$(dirname "$0")/.." | |
echo | |
bootstrap="make bootstrap SCHEME=scheme" | |
install="make install" | |
dylib='support/c/libidris2_support.dylib' | |
message () { | |
text=${1:?} | |
divider=$( echo "--${text}--" | sed 's/./-/g' ) | |
printf "\n${divider}\n ${text}\n${divider}\n\n" | |
} | |
dycopy () { | |
dest=${1:?} | |
cp "${dylib}" "${dest}" | |
file "${dest}/libidris2_support.dylib" | |
} | |
# we assume the .tgz file is somewhere in project | |
# abort if not a tested .tgz archive | |
archives=$( find . -name 'idris2*.tgz' | sort --reverse ) | |
tgz= | |
for name in $archives | |
do | |
sha=$( shasum -a 256 "${name}" ) | |
sha=${sha%% *} | |
while read known | |
do | |
known=${known%% *} | |
if [ "${sha}" = "${known}" ] | |
then | |
tgz=${name} | |
break 2 | |
fi | |
done <<EOS | |
a8cf6f60756b93fd97f9d4e9c48473e6e41179a6312ae10d93005591eec48859 idris2-0.5.1.tgz | |
EOS | |
done | |
if [ -z $tgz ] | |
then | |
echo 'known .tgz archive not found; aborting' | |
exit | |
else | |
echo "${tgz}" | |
fi | |
# build directory unpacked from .tgz file | |
dir=$( basename "${tgz}" ) | |
dir=${dir%.tgz} | |
dir=${dir/idris/Idris} | |
# scorched earth testing | |
# rm -rf ~/.idris2 | |
# rm -rf "${dir}" | |
# unpack build directory if missing, apply patches | |
if [ ! -d "${dir}" ] | |
then | |
tar zxf "${tgz}" | |
patch "${dir}/bootstrap/idris2_app/idris2.ss" <<EOS | |
21c21 | |
< [(i3osx ti3osx a6osx ta6osx) "darwin"] | |
--- | |
> [(i3osx ti3osx a6osx ta6osx tarm64osx) "darwin"] | |
EOS | |
patch "${dir}/support/chez/support.ss" <<EOS | |
7c7 | |
< [(i3osx ti3osx a6osx ta6osx) "darwin"] | |
--- | |
> [(i3osx ti3osx a6osx ta6osx tarm64osx) "darwin"] | |
EOS | |
fi | |
cd "${dir}" | |
pwd | |
export CPATH="$(brew --prefix)/include" | |
message "${bootstrap}" | |
if ! $bootstrap | |
then | |
message "FAILED: ${bootstrap} (trying again)" | |
file "${dylib}" | |
# we stubbornly avoid /usr/local/lib | |
# permission issues, and brew doesn't like sharing a lane | |
dycopy . | |
for lib in libs/* | |
do | |
dycopy "${lib}" | |
done | |
echo | |
$bootstrap | |
fi | |
message $install | |
$install | |
# don't ask | |
patch "$(which idris2)" <<'EOS' | |
14c14,15 | |
< "$DIR/idris2_app/idris2.so" "$@" | |
--- | |
> cd "$DIR/idris2_app" | |
> ./idris2.so "$@" | |
EOS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment