Skip to content

Commit

Permalink
Merge pull request #437 from codacy/use-sbt-native-image
Browse files Browse the repository at this point in the history
feature: Migrate to sbt-native-image
  • Loading branch information
rubencodacy authored Feb 23, 2023
2 parents 1132856 + ba9583b commit d3a4da6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 51 deletions.
23 changes: 6 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,32 +249,21 @@ workflows:
- codacy/sbt:
name: create_artifacts
cmd: |
(cd graalvm; docker build -t graavlm:latest .)
sbt "assembly;graalvm-native-image:packageBin"
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/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:
- compile_and_test
- 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:
Expand Down
18 changes: 10 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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 := "22.3.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",
Expand All @@ -73,11 +78,8 @@ graalVMNativeImageOptions := 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",
"--static",
"--libc=musl"
)
"--report-unsupported-elements-at-runtime"
) ++ osSpecificOptions

dependsOn(coverageParser)

Expand Down
11 changes: 0 additions & 11 deletions graalvm/Dockerfile

This file was deleted.

24 changes: 10 additions & 14 deletions graalvm/build-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
mkdir -p $HOME/.musl
cd $HOME/.musl

(
cd $musl
./configure --disable-shared --prefix=$dest
make -j "$(nproc)"
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
TOOLCHAIN_DIR=$HOME/.musl/x86_64-linux-musl-native
export CC=$TOOLCHAIN_DIR/bin/gcc

zlib='zlib-1.2.13'
zlibtargz=$zlib.tar.gz
Expand All @@ -22,8 +17,9 @@ tar -xf $zlibtargz

(
cd $zlib
export CC=musl-gcc
./configure --static --prefix=$dest
./configure --prefix=$TOOLCHAIN_DIR --static
make -j "$(nproc)"
make install
sudo make install
)

echo "$TOOLCHAIN_DIR/bin"
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d3a4da6

Please sign in to comment.