From cc84dbd549e36e76337ff71957187b4dd2b50f32 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 28 Nov 2022 18:47:10 +0100 Subject: [PATCH 1/6] feature: Migrate to sbt-native-image --- .circleci/config.yml | 22 +++++----------------- build.sbt | 17 ++++++++++------- graalvm/Dockerfile | 11 ----------- project/plugins.sbt | 2 +- 4 files changed, 16 insertions(+), 36 deletions(-) delete mode 100644 graalvm/Dockerfile diff --git a/.circleci/config.yml b/.circleci/config.yml index 23389da5..37c15049 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -229,10 +229,10 @@ workflows: - codacy/sbt: name: create_artifacts cmd: | - (cd graalvm; docker build -t graavlm:latest .) - sbt "assembly;graalvm-native-image:packageBin" + graalvm/build-deps.sh + sbt "assembly;nativeImage" mkdir -p ~/workdir/tmp-artifacts - mv target/graalvm-native-image/codacy-coverage-reporter ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux + mv target/native-image/codacy-coverage-reporter ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux mv target/codacy-coverage-reporter-assembly-$(cat .version).jar ~/workdir/tmp-artifacts/codacy-coverage-reporter-assembly.jar persist_to_workspace: true requires: @@ -240,21 +240,9 @@ workflows: - codacy/sbt_osx: name: create_artifacts_for_osx cmd: | - # TODO GraalVM version should be in a single place - export GRAAL_VERSION=21.0.0 - export TARGET_GRAAL="./target/graalvm-$GRAAL_VERSION.tar.gz" - mkdir -p target - if [[ ! -e $TARGET_GRAAL ]]; then - curl -L "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-$GRAAL_VERSION/graalvm-ce-java8-darwin-amd64-$GRAAL_VERSION.tar.gz" -o "$TARGET_GRAAL" - fi - sudo tar -xf $TARGET_GRAAL -C /Library/Java/JavaVirtualMachines - /usr/libexec/java_home -V - export JAVA_HOME=/Library/Java/JavaVirtualMachines/graalvm-ce-java8-$GRAAL_VERSION/Contents/Home - export PATH="$PATH:$JAVA_HOME/bin" - sudo gu install native-image - sbt "set GraalVMNativeImage / containerBuildImage := None; set graalVMNativeImageOptions --= Seq(\"--static\", \"--libc=musl\"); graalvm-native-image:packageBin" + sbt nativeImage mkdir -p ~/workdir/tmp-artifacts - mv $HOME/workdir/target/graalvm-native-image/codacy-coverage-reporter $HOME/workdir/tmp-artifacts/codacy-coverage-reporter-darwin + mv $HOME/workdir/target/native-image/codacy-coverage-reporter $HOME/workdir/tmp-artifacts/codacy-coverage-reporter-darwin persist_to_workspace: true persist_to_workspace_path: "tmp-artifacts/codacy-coverage-reporter-darwin" requires: diff --git a/build.sbt b/build.sbt index c3cbb527..baabd02e 100644 --- a/build.sbt +++ b/build.sbt @@ -59,10 +59,15 @@ Global / cancelable := true javacOptions ++= Seq("-source", "11", "-target", "11") -enablePlugins(GraalVMNativeImagePlugin) -GraalVMNativeImage / containerBuildImage := Some("graavlm:latest") +enablePlugins(NativeImagePlugin) -graalVMNativeImageOptions := Seq( +nativeImageVersion := "21.0.0" + +val osSpecificOptions = + if (sys.props("os.name") == "Mac OS X") Seq.empty[String] + else Seq("--static", "--libc=musl") + +nativeImageOptions := Seq( "--verbose", "--no-server", "--enable-http", @@ -74,10 +79,8 @@ graalVMNativeImageOptions := Seq( "-H:+ReportExceptionStackTraces", "--no-fallback", "--initialize-at-build-time", - "--report-unsupported-elements-at-runtime", - "--static", - "--libc=musl" -) + "--report-unsupported-elements-at-runtime" +) ++ osSpecificOptions dependsOn(coverageParser) diff --git a/graalvm/Dockerfile b/graalvm/Dockerfile deleted file mode 100644 index df09ccbe..00000000 --- a/graalvm/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM ghcr.io/graalvm/graalvm-ce:21.0.0 - -RUN gu install native-image - -WORKDIR /opt/graalvm - -COPY build-deps.sh . - -RUN ./build-deps.sh - -ENTRYPOINT [ "native-image" ] diff --git a/project/plugins.sbt b/project/plugins.sbt index dd2359ee..756b7aff 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ -addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9") +addSbtPlugin("org.scalameta" % "sbt-native-image" % "0.3.1") addSbtPlugin("com.codacy" % "codacy-sbt-plugin" % "22.0.1") // Publish From eff883e1904485b3d377dccfbf010757e4cfe0c4 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 28 Nov 2022 18:55:04 +0100 Subject: [PATCH 2/6] Use sudo for make install --- graalvm/build-deps.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graalvm/build-deps.sh b/graalvm/build-deps.sh index 3fe7bde9..4b9e874b 100755 --- a/graalvm/build-deps.sh +++ b/graalvm/build-deps.sh @@ -12,7 +12,7 @@ dest=/usr/local cd $musl ./configure --disable-shared --prefix=$dest make -j "$(nproc)" - make install + sudo make install ) zlib='zlib-1.2.13' @@ -25,5 +25,5 @@ tar -xf $zlibtargz export CC=musl-gcc ./configure --static --prefix=$dest make -j "$(nproc)" - make install + sudo make install ) From 2844370bb53886f0c4b3f8a028da64f66ba61fc4 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 28 Nov 2022 19:21:36 +0100 Subject: [PATCH 3/6] Update installation of musl --- build.sbt | 2 +- graalvm/build-deps.sh | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/build.sbt b/build.sbt index baabd02e..5b039620 100644 --- a/build.sbt +++ b/build.sbt @@ -61,7 +61,7 @@ javacOptions ++= Seq("-source", "11", "-target", "11") enablePlugins(NativeImagePlugin) -nativeImageVersion := "21.0.0" +nativeImageVersion := "22.3.0" val osSpecificOptions = if (sys.props("os.name") == "Mac OS X") Seq.empty[String] diff --git a/graalvm/build-deps.sh b/graalvm/build-deps.sh index 4b9e874b..81aa6184 100755 --- a/graalvm/build-deps.sh +++ b/graalvm/build-deps.sh @@ -2,18 +2,13 @@ set -e +o pipefail -musl='musl-1.2.2' -musltargz=$musl.tar.gz -curl https://musl.libc.org/releases/$musltargz --output $musltargz -tar -xf $musltargz -dest=/usr/local +export TOOLCHAIN_DIR=$HOME/.musl +mkdir -p $TOOLCHAIN_DIR +cd $TOOLCHAIN_DIR -( - cd $musl - ./configure --disable-shared --prefix=$dest - make -j "$(nproc)" - sudo make install -) +curl http://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz --output musl.tgz +tar -xf musl.tgz +export CC=$TOOLCHAIN_DIR/bin/gcc zlib='zlib-1.2.13' zlibtargz=$zlib.tar.gz @@ -22,8 +17,7 @@ tar -xf $zlibtargz ( cd $zlib - export CC=musl-gcc - ./configure --static --prefix=$dest + ./configure --prefix=$TOOLCHAIN_DIR --static make -j "$(nproc)" sudo make install ) From 0894e9508e8d902c35ac4291418b944fda1adc26 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 28 Nov 2022 19:28:50 +0100 Subject: [PATCH 4/6] Fix build-deps.sh --- .circleci/config.yml | 2 +- graalvm/build-deps.sh | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 37c15049..0b7789c4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -229,7 +229,7 @@ workflows: - codacy/sbt: name: create_artifacts cmd: | - graalvm/build-deps.sh + export PATH=$(graalvm/build-deps.sh):$PATH sbt "assembly;nativeImage" mkdir -p ~/workdir/tmp-artifacts mv target/native-image/codacy-coverage-reporter ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux diff --git a/graalvm/build-deps.sh b/graalvm/build-deps.sh index 81aa6184..2fbedf5c 100755 --- a/graalvm/build-deps.sh +++ b/graalvm/build-deps.sh @@ -2,12 +2,12 @@ set -e +o pipefail -export TOOLCHAIN_DIR=$HOME/.musl -mkdir -p $TOOLCHAIN_DIR -cd $TOOLCHAIN_DIR +mkdir -p $HOME/.musl +cd $HOME/.musl curl http://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz --output musl.tgz tar -xf musl.tgz +TOOLCHAIN_DIR=$HOME/.musl/x86_64-linux-musl-native export CC=$TOOLCHAIN_DIR/bin/gcc zlib='zlib-1.2.13' @@ -21,3 +21,5 @@ tar -xf $zlibtargz make -j "$(nproc)" sudo make install ) + +echo "$TOOLCHAIN_DIR/bin" From 98159608c503366d3e06049daad12f2bace480e4 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 28 Nov 2022 19:53:27 +0100 Subject: [PATCH 5/6] Remove --initialize-at-build-time --- build.sbt | 1 - 1 file changed, 1 deletion(-) diff --git a/build.sbt b/build.sbt index 5b039620..d07111b0 100644 --- a/build.sbt +++ b/build.sbt @@ -78,7 +78,6 @@ nativeImageOptions := Seq( "-H:IncludeResourceBundles=com.sun.org.apache.xerces.internal.impl.msg.XMLMessages", "-H:+ReportExceptionStackTraces", "--no-fallback", - "--initialize-at-build-time", "--report-unsupported-elements-at-runtime" ) ++ osSpecificOptions From ba9583bf441b9e0ed22164f51b6f1749e22ee8f1 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 28 Nov 2022 19:54:23 +0100 Subject: [PATCH 6/6] fix PATH --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0b7789c4..5c2d2ff7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -229,7 +229,8 @@ workflows: - codacy/sbt: name: create_artifacts cmd: | - export PATH=$(graalvm/build-deps.sh):$PATH + graalvm/build-deps.sh + export PATH=$HOME/.musl/x86_64-linux-musl-native/bin:$PATH sbt "assembly;nativeImage" mkdir -p ~/workdir/tmp-artifacts mv target/native-image/codacy-coverage-reporter ~/workdir/tmp-artifacts/codacy-coverage-reporter-linux