-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #391 from AltGr/gh-act-static-bin
Add github action rules for static binaries generation (Linux, Macos)
- Loading branch information
Showing
9 changed files
with
220 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Generate static binaries | ||
on: | ||
push: | ||
branches: | ||
- master | ||
tags: | ||
- '*' | ||
pull_request: | ||
branches: | ||
- '**' | ||
jobs: | ||
static-bin-linux: | ||
name: Builds static Linux binaries | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v2 | ||
- name: Build the binaries | ||
run: | | ||
./scripts/static-build.sh | ||
- name: Test the binaries | ||
run: | | ||
bin=(./learn-ocaml-client ./learn-ocaml-server ./learn-ocaml) | ||
file "${bin[@]}" | ||
ldd "${bin[@]}" | ||
for b in "${bin[@]}"; do ( set -x; "$b" --version ); done | ||
- name: Archive static binaries | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: static-binaries-linux | ||
path: | | ||
learn-ocaml | ||
learn-ocaml-server | ||
learn-ocaml-client | ||
static-bin-macos: | ||
name: Builds static Macos binaries | ||
runs-on: macos-latest | ||
env: | ||
OPAMYES: 1 | ||
OPAMDEPEXTYES: 1 | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v2 | ||
- name: Show OS version | ||
run: | | ||
sw_vers | ||
system_profiler SPSoftwareDataType | ||
uname -a | ||
# Need unreleased 2.1.0~rc | ||
# - name: Retrieve opam | ||
# run: | | ||
# mkdir "$HOME/bin" | ||
# wget https://github.com/ocaml/opam/releases/download/2.1.0-beta2/opam-2.1.0-beta2-x86_64-macos -O $HOME/bin/opam | ||
# chmod a+x $HOME/bin/opam | ||
# echo "$HOME/bin" >> $GITHUB_PATH | ||
- name: Install latest opam | ||
run: | | ||
brew install opam --HEAD | ||
- name: Prepare build environment | ||
run: | | ||
opam init -a --bare | ||
opam switch create . ocaml-base-compiler 'dune<2' --deps-only | ||
- name: Build the binaries | ||
run: | | ||
opam exec -- make LINKING_MODE=static | ||
- name: Test the binaries | ||
run: | | ||
bin=(./learn-ocaml-client ./learn-ocaml-server ./learn-ocaml) | ||
dir="_build/install/default/bin" | ||
file "$dir"/* | ||
otool -L "$dir"/* | ||
for b in "${bin[@]}"; do ( set -x; "$dir/$b" --version ); done | ||
- name: Archive static binaries | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: static-binaries-macos | ||
path: _build/install/default/bin/* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ translations/*.pot | |
**/.merlin | ||
|
||
tests/corpuses/* | ||
|
||
detect-libs.* |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
set -ue | ||
|
||
LC_ALL=C | ||
|
||
cd $(dirname "$0")/.. | ||
|
||
## Run build in container | ||
|
||
set -o pipefail | ||
git ls-files -z | xargs -0 tar c | \ | ||
docker run --rm -i \ | ||
ocamlpro/ocaml:4.05 \ | ||
sh -uexc \ | ||
'tar x >&2 && | ||
sudo apk add openssl-libs-static >&2 && | ||
opam switch create . ocaml-system "dune<2" --deps-only >&2 && | ||
opam exec make LINKING_MODE=static >&2 && | ||
tar c -hC _build/install/default/bin .' | \ | ||
tar vx |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/sh | ||
set -ue | ||
|
||
# This script is called by dune to generate the linking flags for static builds | ||
# (on the limited set of supported platforms). It only returns an empty set of | ||
# flags for the default dynamic linking mode. | ||
|
||
LC_ALL=C | ||
|
||
help_exit() { | ||
echo "Usage: $0 dynamic|static linux|macosx [extra-libs]" >&2 | ||
exit 2 | ||
} | ||
|
||
[ $# -lt 2 ] && help_exit | ||
|
||
echo ";; generated by $0" | ||
|
||
case "$1" in | ||
dynamic) echo "()"; exit 0;; | ||
static) ;; | ||
*) echo "Invalid linking mode '$1'."; help_exit | ||
esac | ||
|
||
shift | ||
case "$1" in | ||
macosx) shift; EXTRA_LIBS="curses $*";; | ||
linux) shift; EXTRA_LIBS="$*";; | ||
--) shift; EXTRA_LIBS="$*";; | ||
*) echo "Not supported %{ocamlc-config:system} '$1'."; help_exit | ||
esac | ||
|
||
## Static linking configuration ## | ||
|
||
# The linked C libraries list may need updating on changes to the dependencies. | ||
# | ||
# To get the correct list for manual linking, the simplest way is to set the | ||
# flags to `-verbose`, while on the normal `autolink` mode, then extract them | ||
# from the gcc command-line. | ||
# The Makefile contains a target to automate this: `make detect-libs`. | ||
|
||
case $(uname -s) in | ||
Linux) | ||
case $(. /etc/os-release && echo $ID) in | ||
alpine) | ||
COMMON_LIBS="camlstr base_stubs ssl_threads_stubs ssl crypto cstruct_stubs lwt_unix_stubs bigarray unix c" | ||
# `m` and `pthread` are built-in musl | ||
echo '(-noautolink' | ||
echo ' -cclib -Wl,-Bstatic' | ||
echo ' -cclib -static-libgcc' | ||
for l in $EXTRA_LIBS $COMMON_LIBS; do | ||
echo " -cclib -l$l" | ||
done | ||
echo ' -cclib -static)' | ||
;; | ||
*) | ||
echo "Error: static linking is only supported in Alpine, to avoids glibc constraints" >&2 | ||
exit 3 | ||
esac | ||
;; | ||
Darwin) | ||
COMMON_LIBS="camlstr base_stubs ssl_threads_stubs /usr/local/opt/openssl/lib/libssl.a /usr/local/opt/openssl/lib/libcrypto.a cstruct_stubs lwt_unix_stubs bigarray unix" | ||
# `m` and `pthread` are built-in in libSystem | ||
echo '(-noautolink' | ||
for l in $EXTRA_LIBS $COMMON_LIBS; do | ||
if [ "${l%.a}" != "${l}" ]; then echo " -cclib $l" | ||
else echo " -cclib -l$l" | ||
fi | ||
done | ||
echo ')' | ||
;; | ||
*) | ||
echo "Static linking is not supported for your platform. See $0 to contribute." >&2 | ||
exit 3 | ||
esac |