From 70b90b85001e81ef944e4c24fbd30eae8ee2efe4 Mon Sep 17 00:00:00 2001 From: jsonch Date: Fri, 17 May 2024 10:48:31 -0400 Subject: [PATCH] release building scripts and simple unified scripts to run and unpack --- Makefile | 12 ++++- release/dpt.sh | 46 +++++++++++++++++++ release/unpack.sh | 18 ++++++++ .../build_linux_release.sh | 30 ++++++++---- .../build_macos_release.sh | 29 ++++++++---- 5 files changed, 117 insertions(+), 18 deletions(-) create mode 100755 release/dpt.sh create mode 100755 release/unpack.sh rename release/build_linux.sh => scripts/build_linux_release.sh (66%) rename release/build_macos.sh => scripts/build_macos_release.sh (52%) diff --git a/Makefile b/Makefile index 96997979..b6f2a934 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ DEV_DEPENDENCIES = \ merlin \ ocamlformat -.PHONY: test promote test-promote test-cc clean +.PHONY: test promote test-promote test-cc clean release-macos release-linux default: dune build src/bin/main.exe @@ -35,6 +35,16 @@ default: dune build src/bin/lucidcc.exe cp -f _build/default/src/bin/lucidcc.exe lucidcc +macos-release: + dune build src/bin/main.exe + cp -f _build/default/src/bin/main.exe dpt + ./scripts/build_macos_release.sh + +linux-release: + dune build src/bin/main.exe + cp -f _build/default/src/bin/main.exe dpt + ./scripts/build_linux_release.sh + all: dune build src/bin/main.exe cp -f _build/default/src/bin/main.exe dpt diff --git a/release/dpt.sh b/release/dpt.sh new file mode 100755 index 00000000..3dd85bda --- /dev/null +++ b/release/dpt.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +script_dir=$(dirname $0) + +macos_dir="$script_dir/macos/lucid" +linux_dir="$script_dir/linux/lucid" + +# set bin_dir to the correct directory based on the OS +if [[ "$OSTYPE" == "darwin"* ]]; then + bin_dir=$macos_dir + if [ ! -f "$bin_dir/dpt" ]; then + echo "MacOS binary not found in $macos_dir" + echo "You may need to run the 'unpack.sh' script in the release directory" + exit 1 + fi +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + if [ ! -f "$linux_dir/dpt" ]; then + echo "Linux binary not found in $linux_dir" + echo "You may need to run the 'unpack.sh' script in the release directory" + exit 1 + fi + bin_dir=$linux_dir +else + echo "Unsupported OS -- you should build the project from source" + exit 1 +fi + +# run dpt in the appropriate directory +$bin_dir/dpt $@ + + + +# case "$1" in +# compile) +# shift # Remove the first argument and pass the rest to the compiler +# exec "$APPDIR/usr/bin/dptc" "$@" +# ;; +# interpret) +# shift # Remove the first argument and pass the rest to the interpreter +# exec "$APPDIR/usr/bin/dpt" "$@" +# ;; +# *) +# echo "Usage: $0 {compile|interpret} args" +# exit 1 +# ;; +# esac \ No newline at end of file diff --git a/release/unpack.sh b/release/unpack.sh new file mode 100755 index 00000000..4f8363b1 --- /dev/null +++ b/release/unpack.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# unpack the release tarballs in this script's directory + +my_dir="$(dirname "$0")" + +# check if each tarball exists and unpack it +if [ ! -f $my_dir/macos.tar.gz ]; then + echo "macos.tar.gz not found -- skipping" +else + tar -xvf $my_dir/macos.tar.gz +fi + +if [ ! -f $my_dir/linux.tar.gz ]; then + echo "linux.tar.gz not found -- skipping" +else + tar -xvf $my_dir/linux.tar.gz +fi \ No newline at end of file diff --git a/release/build_linux.sh b/scripts/build_linux_release.sh similarity index 66% rename from release/build_linux.sh rename to scripts/build_linux_release.sh index c341c682..58b58172 100755 --- a/release/build_linux.sh +++ b/scripts/build_linux_release.sh @@ -12,18 +12,25 @@ else exit 1 fi -release_dir=./linux/lucid -lib_dir=$release_dir/lib +# make sure this is run from the repo root +if [ ! -d ".git" ] +then + echo "This script must be run from the root of the repository." + exit 1 +fi +release_base=./release +os_base=linux +release_dir=$release_base/$os_base/lucid +lib_dir=$release_dir/libs +rm -rf $release_dir mkdir -p $lib_dir # 1. build the binary locally (in the parent directory) -cd .. -make -cd - +# make # copy binary -cp ../dpt "$release_dir"/dpt +cp dpt "$release_dir"/dpt # Run ldd on the binary and parse output deps=$(ldd "$release_dir"/dpt | awk '/=>/ {print $3} !/=>/ {if ($1 ~ /^\//) print $1}') @@ -44,8 +51,13 @@ for lib in $deps; do fi done +echo "patching binary dynamic lib paths" patchelf --set-rpath '$ORIGIN/lib' "$release_dir"/dpt -echo "======================" -echo "Linux binary package built in $release_dir. Please distribute this entire folder and run dpt inside of it." -echo "======================" \ No newline at end of file +# package os release in a tarball inside of the release dir +echo "Packaging release" +cd $release_base +tar -zcvf "$os_base".tar.gz $os_base +rm -rf $os_base + +echo "done building linux release" diff --git a/release/build_macos.sh b/scripts/build_macos_release.sh similarity index 52% rename from release/build_macos.sh rename to scripts/build_macos_release.sh index 07e082e6..2191d892 100755 --- a/release/build_macos.sh +++ b/scripts/build_macos_release.sh @@ -12,21 +12,34 @@ then exit fi -release_dir=./macos/lucid +# make sure this is run from the repo root +if [ ! -d ".git" ] +then + echo "This script must be run from the root of the repository." + exit 1 +fi + +release_base=./release +os_base=macos +release_dir=$release_base/$os_base/lucid lib_dir=$release_dir/libs rm -rf $release_dir mkdir -p $lib_dir -cd .. make -cd - -cp ../dpt $release_dir/ +cp dpt $release_dir/ # run dylibbundler to bundle the dynamic libraries (mainly z3) +echo "patching binary dynamic lib paths" dylibbundler -od -b -x $release_dir/dpt -d $lib_dir -p @executable_path/libs/ -# print release information -echo "======================" -echo "MacOS binary package built in $release_dir. Please distribute this entire folder and run dpt inside of it." -echo "======================" + +# package os release in a tarball inside of the release dir +echo "Packaging release" +cd $release_base +tar -zcvf "$os_base".tar.gz $os_base +# remove the release directory +rm -rf $os_base + +echo "done building macos release"