[#831] Workaround for musl stack size issues

This commit is contained in:
Michiel Borkent 2021-05-10 18:29:26 +02:00 committed by GitHub
parent 73d454be46
commit 6edc26c834
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 4 deletions

View file

@ -3,7 +3,6 @@
rm -rf /tmp/release
mkdir -p /tmp/release
cp bb /tmp/release
# cp src-bash/bbk /tmp/release
VERSION=$(cat resources/BABASHKA_VERSION)

View file

@ -76,7 +76,9 @@ args=( "-jar" "$BABASHKA_JAR"
BABASHKA_STATIC=${BABASHKA_STATIC:-}
if [ "$BABASHKA_STATIC" = "true" ]; then
args+=("--static" "--libc=musl")
args+=("--static" "--libc=musl"
# see https://github.com/oracle/graal/issues/3398
"-H:CCompilerOption=-Wl,-z,stack-size=2097152")
# needs to be in a separate script as we need sudo and >> redirects in it wont work.
sudo bash script/setup-musl

View file

@ -863,6 +863,25 @@ Use bb run --help to show this help output.
(let [opts (parse-opts args)]
(exec opts)))
(def static?
"Captured at compile time, to know if we are running inside a
statically compiled executable."
(System/getenv "BABASHKA_STATIC"))
(defmacro run [args]
(if static?
;; When running in musl-compiled static executable we lift execution of bb
;; inside a thread, so we have a larger than default stack size, set by an
;; argument to the linker. See https://github.com/oracle/graal/issues/3398
`(let [v# (volatile! nil)
f# (fn []
(vreset! v# (apply main ~args)))]
(doto (Thread. nil f# "main")
(.start)
(.join))
@v#)
`(apply main ~args)))
(defn -main
[& args]
(handle-pipe!)
@ -874,10 +893,10 @@ Use bb run --help to show this help output.
(dotimes [i n]
(if (< i last-iteration)
(with-out-str (apply main args))
(do (apply main args)
(do (run args)
(binding [*out* *err*]
(println "ran" n "times"))))))
(let [exit-code (apply main args)]
(let [exit-code (run args)]
(System/exit exit-code))))
;;;; Scratch