-
Notifications
You must be signed in to change notification settings - Fork 67
Add github action rules for static binaries generation (Linux, Macos) #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
867ea50
PoC: static linking of learnocaml_server
AltGr 9aa56d3
Don't require dune 2
AltGr aee8d7e
Add a script to build statically-linked binaries using Docker and musl
AltGr d20ac0b
Limit maximum version of dune
AltGr a59798b
Github actions to generate the static binaries (Linux, Macos)
AltGr 1150bfa
Static builds: use an environment variable rather than files laying a…
AltGr a556f76
More robust static-build.sh
AltGr d1a25f6
test: Run more tests
erikmd 91cef45
chore(Makefile): Add `make detect-libs`
erikmd a25955c
test(.ci-macosx.sh): Run `make detect-libs`
erikmd e41d8a1
fix: details
erikmd 7276fab
fix: small issue with `make detect-libs` on macOS
erikmd 74cb300
chore: Skip -lpthread as libpthread is builtin in libSystem.dylib
erikmd 18e1d50
fix(client,main): Add -lcurses if (= %{ocaml-config:system} macosx)
erikmd a1265b2
chore(GHA): Split cmd => (Build the binaries, Test the binaries)
erikmd 68a302f
chore(GHA): Print OS version for macosx
erikmd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,61 @@ | ||
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: Generate the binaries | ||
run: | | ||
./scripts/static-build.sh | ||
ldd learn-ocaml learn-ocaml-server learn-ocaml-client | ||
- 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 | ||
# 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 | ||
otool -L _build/install/default/bin/* | ||
- name: Archive static binaries | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: static-binaries-macos | ||
path: _build/install/default/bin/* |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,19 @@ | ||||||
#!/usr/bin/env bash | ||||||
set -ue | ||||||
|
||||||
LC_ALL=C | ||||||
|
||||||
cd $(dirname "$0")/.. | ||||||
|
||||||
## Run build in container | ||||||
|
||||||
tar c $(git ls-files) | \ | ||||||
docker run --rm -i \ | ||||||
AltGr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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 && | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick (if you don't disagree):
Suggested change
|
||||||
tar c -hC _build/install/default/bin .' | \ | ||||||
tar vx |
This file contains hidden or 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 hidden or 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,61 @@ | ||
#!/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 | ||
|
||
echo ";; generated by $0" | ||
|
||
case "$1" in | ||
dynamic) echo "()"; exit 0;; | ||
static) ;; | ||
*) echo "Invalid linking mode '$1'. Usage: $0 dynamic|static [extra-libs]" >&2; exit 2 | ||
esac | ||
|
||
shift | ||
EXTRA_LIBS="$*" | ||
|
||
## 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. | ||
erikmd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 `pthreads` 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 pthread" | ||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment somewhere recalling the feature (or PR) that is needed here, and not available in opam 2.0.x?