diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index babeeec..c6b2ea4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - run: scala-cli compile . build-linux: - if: github.event_name == 'push' + if: github.event_name == 'push' || github.event_name == 'pull_request' needs: compile strategy: matrix: @@ -30,16 +30,7 @@ jobs: - name: Build in Alpine container run: | - docker run --rm -v "$PWD":/work -w /work alpine:latest sh -c ' - apk add --no-cache bash curl clang lld musl-dev openjdk17-jre-headless && - curl -fLo /usr/local/bin/coursier https://github.com/coursier/launchers/raw/master/coursier.jar && - chmod +x /usr/local/bin/coursier && - coursier launch scala-cli -- --power package . -o comport -f \ - --native-mode release-fast \ - --native-lto thin \ - --native-gc commix \ - --native-linking "-static" - ' + ./build-with-container.sh - name: Upload artifact uses: actions/upload-artifact@v4 @@ -48,7 +39,7 @@ jobs: path: comport build-macos: - if: github.event_name == 'push' + if: github.event_name == 'push' || github.event_name == 'pull_request' needs: compile strategy: matrix: @@ -64,10 +55,7 @@ jobs: - name: Build native binary run: | - scala-cli --power package . -o comport -f \ - --native-mode release-fast \ - --native-lto full \ - --native-gc commix + ./build.sh - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0456b4d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM alpine:latest + +# libc++-dev is for exception handling +RUN apk add --no-cache bash curl clang libc++-dev alpine-sdk lld musl-dev openjdk17-jre-headless +RUN curl -fLo /usr/local/bin/coursier https://github.com/coursier/launchers/raw/master/coursier.jar && chmod +x /usr/local/bin/coursier +RUN coursier launch scala-cli +ENV PATH="$PATH:/root/.local/share/coursier/bin" +WORKDIR /work diff --git a/build-with-container.sh b/build-with-container.sh new file mode 100755 index 0000000..42924f8 --- /dev/null +++ b/build-with-container.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -eux +set pipefail + +docker build -t comport-builder . +docker run --rm -v "$PWD":/work --rm -e SCALA_CLI_LAUNCH='coursier launch scala-cli --' -e LINKFLAGS=-static comport-builder:latest sh /work/build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..8627f65 --- /dev/null +++ b/build.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Build script using scala-cli. Overwrites `./comport` if exists. + +set -eux +set pipefail + +LINKFLAGS=${LINKFLAGS:-} +COURSIER=${COURSIER:-cs} +SCALA_CLI_LAUNCH=${SCALA_CLI_LAUNCH:-scala-cli} + +${SCALA_CLI_LAUNCH} --power package . -o comport -f \ + --native-mode release-fast \ + --native-lto full \ + --native-gc commix \ + --native-linking "${LINKFLAGS}" diff --git a/comport.scala b/comport.scala index d6e0f60..c0a8724 100644 --- a/comport.scala +++ b/comport.scala @@ -1,5 +1,5 @@ //> using platform native -//> using scala 3.3 +//> using scala 3.8.2 //> using options -no-indent -rewrite //> using dep com.lihaoyi::mainargs::0.7.8 //> using dep com.lihaoyi::os-lib::0.11.8