2023-07-13 13:02:38 +03:00
#!/bin/bash
2023-10-05 00:06:23 +08:00
set -e
function readlink( ) {
echo " $( cd " $( dirname " $1 " ) " ; pwd -P) "
}
2023-07-13 13:02:38 +03:00
OS = linux
ARCH = ${ 1 :- ` uname -a | rev | cut -d' ' -f2 | rev` }
2024-04-19 21:17:22 +01:00
GHC_VERSION = 9.6.3
2023-07-13 13:02:38 +03:00
2023-10-05 00:06:23 +08:00
if [ " $ARCH " = = "aarch64" ] ; then
COMPOSE_ARCH = arm64
else
COMPOSE_ARCH = x64
fi
root_dir = " $( dirname " $( dirname " $( readlink " $0 " ) " ) " ) "
cd $root_dir
2023-07-13 13:02:38 +03:00
BUILD_DIR = dist-newstyle/build/$ARCH -$OS /ghc-${ GHC_VERSION } /simplex-chat-*
2024-01-31 21:47:10 +07:00
exports = ( $( sed 's/foreign export ccall "chat_migrate_init_key"//' src/Simplex/Chat/Mobile.hs | sed 's/foreign export ccall "chat_reopen_store"//' | grep "foreign export ccall" | cut -d '"' -f2) )
for elem in " ${ exports [@] } " ; do count = $( grep -R " $elem $" libsimplex.dll.def | wc -l) ; if [ $count -ne 1 ] ; then echo Wrong exports in libsimplex.dll.def. Add \" $elem \" to that file; exit 1; fi ; done
for elem in " ${ exports [@] } " ; do count = $( grep -R " \" $elem \" " flake.nix | wc -l) ; if [ $count -ne 2 ] ; then echo Wrong exports in flake.nix. Add \" $elem \" in two places of the file; exit 1; fi ; done
2023-07-13 13:02:38 +03:00
rm -rf $BUILD_DIR
2023-08-25 04:56:37 +08:00
cabal build lib:simplex-chat --ghc-options= '-optl-Wl,-rpath,$ORIGIN -flink-rts -threaded'
2023-07-13 13:02:38 +03:00
cd $BUILD_DIR /build
#patchelf --add-needed libHSrts_thr-ghc${GHC_VERSION}.so libHSsimplex-chat-*-inplace-ghc${GHC_VERSION}.so
#patchelf --add-rpath '$ORIGIN' libHSsimplex-chat-*-inplace-ghc${GHC_VERSION}.so
2023-10-05 00:06:23 +08:00
mkdir deps 2> /dev/null || true
2023-07-13 13:02:38 +03:00
ldd libHSsimplex-chat-*-inplace-ghc${ GHC_VERSION } .so | grep "ghc" | cut -d' ' -f 3 | xargs -I { } cp { } ./deps/
cd -
rm -rf apps/multiplatform/common/src/commonMain/cpp/desktop/libs/$OS -$ARCH /
rm -rf apps/multiplatform/desktop/build/cmake
mkdir -p apps/multiplatform/common/src/commonMain/cpp/desktop/libs/$OS -$ARCH /
2023-10-05 00:06:23 +08:00
cp -r $BUILD_DIR /build/deps/* apps/multiplatform/common/src/commonMain/cpp/desktop/libs/$OS -$ARCH /
2023-07-13 13:02:38 +03:00
cp $BUILD_DIR /build/libHSsimplex-chat-*-inplace-ghc${ GHC_VERSION } .so apps/multiplatform/common/src/commonMain/cpp/desktop/libs/$OS -$ARCH /
2023-09-22 01:03:47 +08:00
scripts/desktop/prepare-vlc-linux.sh
2023-10-05 00:06:23 +08:00
links_dir = apps/multiplatform/build/links
mkdir -p $links_dir
cd $links_dir
ln -sfT ../../common/src/commonMain/cpp/desktop/libs/$OS -$ARCH / $OS -$COMPOSE_ARCH