Add BABASHKA_MUSL build variable (#834)
This allows building a Babashka binary using musl C libraries instead, instead of hardcoding this accordingly to the CPU arch.
This commit is contained in:
parent
43ba26e11a
commit
14e053e0a3
6 changed files with 19 additions and 66 deletions
|
|
@ -155,6 +155,7 @@ jobs:
|
|||
BABASHKA_PLATFORM: linux # used in release script
|
||||
BABASHKA_TEST_ENV: native
|
||||
BABASHKA_STATIC: "true"
|
||||
BABASHKA_MUSL: "true"
|
||||
BABASHKA_XMX: "-J-Xmx6500m"
|
||||
resource_class: large
|
||||
steps:
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This script sets up the latest available musl-tools using apt pinning from debian unstable.
|
||||
# The one available in stable and testing are quite outdated and this ensures we get the latest improvements
|
||||
# This explictly installs musl from unstable and keeps the others at a higher priority
|
||||
|
||||
if [ "$BABASHKA_STATIC" != "true" ]
|
||||
then
|
||||
echo "BABASHKA_STATIC wasn't set, skipping musl installation."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$BABASHKA_ARCH" = "aarch64" ]
|
||||
then
|
||||
echo "GraalVM only supports musl on x86_64"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cat >> /etc/apt/sources.list <<eof
|
||||
deb http://ftp.us.debian.org/debian unstable main non-free contrib
|
||||
deb http://non-us.debian.org/debian-non-us unstable/non-us main contrib non-free
|
||||
eof
|
||||
|
||||
cat >> /etc/apt/preferences <<eof
|
||||
Package: *
|
||||
Pin: release a=stable
|
||||
Pin-Priority: 700
|
||||
Package: *
|
||||
Pin: release a=testing
|
||||
Pin-Priority: 650
|
||||
Package: *
|
||||
pin: release a=unstable
|
||||
pin-priority: 600
|
||||
eof
|
||||
|
||||
apt-get update -y && apt-get install musl-tools/unstable -y
|
||||
|
||||
ZLIB_VERSION="1.2.11"
|
||||
|
||||
curl -O -sL "https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz"
|
||||
|
||||
echo "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1 zlib-${ZLIB_VERSION}.tar.gz" |
|
||||
sha256sum --check
|
||||
tar xf "zlib-${ZLIB_VERSION}.tar.gz"
|
||||
|
||||
arch=${BABASHKA_ARCH:-"x86_64"}
|
||||
echo "ARCH: $arch"
|
||||
|
||||
cd "zlib-${ZLIB_VERSION}"
|
||||
CC=musl-gcc ./configure --static --prefix=/usr/lib/$arch-linux-musl/
|
||||
make CC=musl-gcc
|
||||
sudo make install
|
||||
export CC=gcc
|
||||
cd ..
|
||||
|
||||
# depending on GCC version, we will have different directories here.
|
||||
# for example, for GCC 6.3.0 we will have:
|
||||
# - /usr/lib/gcc/x86_64-linux-gnu/6
|
||||
# - /usr/lib/gcc/x86_64-linux-gnu/6.3.0
|
||||
for dest_dir in /usr/lib/gcc/$arch-linux-gnu/*; do
|
||||
sudo cp -f /usr/lib/$arch-linux-musl/lib/libz.a "$dest_dir"
|
||||
done
|
||||
|
|
@ -17,6 +17,7 @@ ENV BABASHKA_XMX=$BABASHKA_XMX
|
|||
# Make it possible to use Docker to build bb with a particular set of features
|
||||
# by setting them at build time via `docker build --build-arg ARG_NAME=true ...`
|
||||
ARG BABASHKA_LEAN=
|
||||
ARG BABASHKA_MUSL=
|
||||
ARG BABASHKA_FEATURE_CORE_ASYNC=
|
||||
ARG BABASHKA_FEATURE_CSV=
|
||||
ARG BABASHKA_FEATURE_JAVA_NIO=
|
||||
|
|
@ -50,6 +51,7 @@ ENV BABASHKA_FEATURE_ORACLEDB=$BABASHKA_FEATURE_ORACLEDB
|
|||
ENV BABASHKA_FEATURE_DATASCRIPT=$BABASHKA_FEATURE_DATASCRIPT
|
||||
ENV BABASHKA_FEATURE_LANTERNA=$BABASHKA_FEATURE_LANTERNA
|
||||
ENV BABASHKA_STATIC=$BABASHKA_STATIC
|
||||
ENV BABASHKA_MUSL=$BABASHKA_MUSL
|
||||
|
||||
COPY . .
|
||||
RUN ./script/uberjar
|
||||
|
|
|
|||
|
|
@ -74,11 +74,11 @@ args=( "-jar" "$BABASHKA_JAR"
|
|||
"$BABASHKA_XMX" )
|
||||
|
||||
BABASHKA_STATIC=${BABASHKA_STATIC:-}
|
||||
BABASHKA_ARCH=${BABASHKA_ARCH:-}
|
||||
BABASHKA_MUSL=${BABASHKA_MUSL:-}
|
||||
|
||||
if [ "$BABASHKA_STATIC" = "true" ]; then
|
||||
args+=("--static")
|
||||
if [ "$BABASHKA_ARCH" != "aarch64" ]; then
|
||||
if [ "$BABASHKA_MUSL" = "true" ]; then
|
||||
args+=("--libc=musl"
|
||||
# see https://github.com/oracle/graal/issues/3398
|
||||
"-H:CCompilerOption=-Wl,-z,stack-size=2097152")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [[ -z "${BABASHKA_STATIC:-}" ]]; then
|
||||
echo "BABASHKA_STATIC wasn't set, skipping musl installation."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -z "${BABASHKA_MUSL:-}" ]]; then
|
||||
echo "BABASHKA_MUSL wasn't set, skipping musl installation."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# This script sets up the latest available musl-tools using apt pinning from debian unstable.
|
||||
# The one available in stable and testing are quite outdated and this ensures we get the latest improvements
|
||||
# This explictly installs musl from unstable and keeps the others at a higher priority
|
||||
|
|
|
|||
|
|
@ -865,9 +865,9 @@ Use bb run --help to show this help output.
|
|||
|
||||
(def musl?
|
||||
"Captured at compile time, to know if we are running inside a
|
||||
statically compiled executable."
|
||||
statically compiled executable with musl."
|
||||
(and (= "true" (System/getenv "BABASHKA_STATIC"))
|
||||
(not= "aarch64" (System/getenv "BABASHKA_ARCH"))))
|
||||
(= "true" (System/getenv "BABASHKA_MUSL"))))
|
||||
|
||||
(defmacro run [args]
|
||||
(if musl?
|
||||
|
|
|
|||
Loading…
Reference in a new issue