Skip to content

Commit

Permalink
Static build (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
lthms committed Jan 4, 2024
1 parent 6d9d485 commit 8c99db0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(env
(static
(flags
(:standard -cclib -static))))
43 changes: 43 additions & 0 deletions scripts/build-static-scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/bash

set -e

version="$(git rev-parse --short HEAD)"
release_name="zbg-${version}"
archive_suffix="-linux-$(uname -m).tar.gz"

echo "Building artifacts for ${release_name}"

worktree=$(git rev-parse --show-toplevel)
tmp_workspace="$(mktemp -d)"

if [ -f "_artifacts/${release_name}${archive_suffix}" ]; then
echo "_artifacts/${release_name}${archive_suffix} already exists. You need to delete it to run this script."
exit 2
fi

# Building a static distribution

pushd "${tmp_workspace}"
git clone -q "${worktree}" .
# add ocaml-option-no-compression to support ocaml.5.1.*
opam switch create . --no-install --deps-only --packages "ocaml-option-static,ocaml.5.0.0" -y
eval $(opam env)
opam pin . --no-action -y
opam install . --deps-only -y
dune build --profile=static -p zbg
mkdir -p artifacts/bin/
cp _build/default/bin/main.exe artifacts/bin/zbg
opam switch remove . -y
popd
mkdir -p _artifacts
mv "${tmp_workspace}/artifacts" "_artifacts/${release_name}"

# Creating the archive

rm -rf "${tmp_workspace}"
pushd _artifacts
tar czvf "${release_name}${archive_suffix}" "${release_name}"
rm -rf ${release_name}

popd

0 comments on commit 8c99db0

Please sign in to comment.