livebook/.github/scripts/app/bootstrap_mac.sh

147 lines
3.2 KiB
Bash
Raw Normal View History

2022-01-18 00:34:38 +08:00
#!/bin/bash
2022-06-22 14:04:59 +08:00
set -e pipefail
2022-01-18 00:34:38 +08:00
main() {
export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN)
2022-06-22 14:04:59 +08:00
wxwidgets_repo="wxWidgets/wxWidgets"
wxwidgets_ref="v3.1.7"
otp_repo="erlang/otp"
otp_ref="OTP-25.0.2"
2022-05-20 20:17:40 +08:00
elixir_vsn="1.13.4"
2022-01-18 00:34:38 +08:00
target=$(target)
mkdir -p tmp
2022-06-22 14:04:59 +08:00
wxwidgets_dir="$PWD/tmp/wxwidgets-${wxwidgets_ref}-$target"
if [ ! -d $wxwidgets_dir ]; then
build_wxwidgets $wxwidgets_repo $wxwidgets_ref $target $wxwidgets_dir
2022-01-18 00:34:38 +08:00
fi
2022-06-22 14:04:59 +08:00
export PATH="${wxwidgets_dir}/bin:$PATH"
echo "checking wx"
2022-01-18 00:34:38 +08:00
file `which wxrc`
wx-config --version
echo
openssl_dir=$(brew --prefix openssl@1.1)
2022-06-22 14:04:59 +08:00
otp_dir="$PWD/tmp/otp-${otp_ref}-$target"
if [ ! -d $otp_dir ]; then
build_otp $otp_repo $otp_ref $target $openssl_dir $otp_dir
2022-01-18 00:34:38 +08:00
fi
2022-06-22 14:04:59 +08:00
export PATH="${otp_dir}/bin:$PATH"
echo "checking otp"
2022-01-18 00:34:38 +08:00
file `which erlc`
erl +V
erl -noshell -eval 'ok = crypto:start(), io:format("crypto ok~n"), halt().'
erl -noshell -eval '{wx_ref,_,_,_} = wx:new(), io:format("wx ok~n"), halt().'
echo
2022-06-22 14:04:59 +08:00
elixir_dir="$PWD/tmp/elixir-${elixir_vsn}"
if [ ! -d "${elixir_dir}" ]; then
2022-01-18 00:34:38 +08:00
build_elixir $elixir_vsn
fi
2022-06-22 14:04:59 +08:00
export PATH="${elixir_dir}/bin:$PATH"
echo "checking elixir"
2022-01-18 00:34:38 +08:00
elixir --version
cat << EOF > tmp/bootstrap_env.sh
2022-06-22 14:04:59 +08:00
export PATH="${otp_dir}/bin:\$PATH"
export PATH="${elixir_dir}/bin:\$PATH"
2022-01-18 00:34:38 +08:00
EOF
}
build_wxwidgets() {
2022-06-22 14:04:59 +08:00
repo=$1
ref=$2
target=$3
dest_dir=$4
src_dir=tmp/wxwidgets-$ref-src
if [ ! -d $src_dir ]; then
echo cloning $repo $ref
git clone --branch $ref --depth 1 --recursive https://github.com/$repo $src_dir
2022-01-18 00:34:38 +08:00
fi
2022-06-22 14:04:59 +08:00
cd $src_dir
2022-01-18 00:34:38 +08:00
./configure \
--disable-shared \
2022-06-22 14:04:59 +08:00
--prefix=$dest_dir \
2022-01-18 00:34:38 +08:00
--with-cocoa \
--with-macosx-version-min=10.15 \
--with-libjpeg=builtin \
--with-libtiff=builtin \
--with-libpng=builtin \
--with-liblzma=builtin \
--with-zlib=builtin \
--with-expat=builtin
make
make install
2022-06-22 14:04:59 +08:00
cd -
2022-01-18 00:34:38 +08:00
}
build_otp() {
2022-06-22 14:04:59 +08:00
repo=$1
ref=$2
target=$3
openssl_dir=$4
dest_dir=$5
src_dir=tmp/otp-$ref-src
if [ ! -d $src_dir ]; then
echo cloning $repo $ref
git clone --branch $ref --depth 1 --recursive https://github.com/$repo $src_dir
fi
2022-01-18 00:34:38 +08:00
2022-06-22 14:04:59 +08:00
export RELEASE_ROOT=$dest_dir
2022-01-18 00:34:38 +08:00
2022-06-22 14:04:59 +08:00
cd $src_dir
2022-01-18 00:34:38 +08:00
export ERL_TOP=`pwd`
./otp_build configure \
--disable-dynamic-ssl-lib \
--with-ssl=$openssl_dir
./otp_build boot -a
./otp_build release -a $RELEASE_ROOT
make release_docs DOC_TARGETS=chunks
2022-06-22 14:04:59 +08:00
cd -
2022-01-18 00:34:38 +08:00
cd $RELEASE_ROOT
./Install -sasl $PWD
./bin/erl -noshell -eval 'io:format("~s", [erlang:system_info(system_version)]), halt().'
./bin/erl -noshell -eval 'ok = crypto:start(), halt().'
./bin/erl -noshell -eval '{wx_ref,_,_,_} = wx:new(), halt().'
2022-06-22 14:04:59 +08:00
cd -
2022-01-18 00:34:38 +08:00
}
build_elixir() {
vsn=$1
otp_release=$(erl -noshell -eval 'io:format("~s", [erlang:system_info(otp_release)]), halt().')
cd tmp
# TODO: On Elixir 1.14, use https://github.com/elixir-lang/elixir/releases/download/v${vsn}/elixir-${vsn}-otp-${otp_release}.zip
url=https://repo.hex.pm/builds/elixir/v${vsn}-otp-${otp_release}.zip
curl --fail -LO $url
mkdir elixir-$vsn
unzip v${vsn}-otp-${otp_release}.zip -d elixir-$vsn
2022-06-22 14:04:59 +08:00
cd -
2022-01-18 00:34:38 +08:00
}
target() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case $arch in
"arm64") arch="aarch64";;
*) ;;
esac
echo "$arch-$os"
}
main