diff --git a/.circleci/config.pkl b/.circleci/config.pkl index fa2c14b52..d1b3aa765 100644 --- a/.circleci/config.pkl +++ b/.circleci/config.pkl @@ -21,7 +21,7 @@ import "jobs/GradleCheckJob.pkl" import "jobs/DeployJob.pkl" import "jobs/SimpleGradleJob.pkl" -local prbJobs: Listing = gradleCheckJobs.keys.toListing() +local prbJobs: Listing = (gradleCheckJobs.keys + buildNativeJobs.keys.filter((it) -> it.startsWith("libpkl") && it.endsWith("snapshot"))).toListing() local buildAndTestJobs = (prbJobs) { "bench" @@ -81,7 +81,7 @@ triggerPackageDocsBuild = "release" local buildNativeJobs: Mapping = new { for (_dist in List("release", "snapshot")) { - for (_project in List("pkl-cli", "pkl-doc")) { + for (_project in List("pkl-cli", "pkl-doc", "libpkl")) { for (_arch in List("amd64", "aarch64")) { for (_os in List("macOS", "linux")) { ["\(_project)-\(_os)-\(_arch)-\(_dist)"] { @@ -89,6 +89,7 @@ local buildNativeJobs: Mapping = new { os = _os isRelease = _dist == "release" project = _project + buildDir = if (_project == "libpkl") "libpkl/build/native-libs/" else "\(_project)/build/executable/" } } } @@ -98,12 +99,14 @@ local buildNativeJobs: Mapping = new { musl = true isRelease = _dist == "release" project = _project + buildDir = if (_project == "libpkl") "libpkl/build/native-libs/" else "\(_project)/build/executable/" } ["\(_project)-windows-amd64-\(_dist)"] { arch = "amd64" os = "windows" isRelease = _dist == "release" project = _project + buildDir = if (_project == "libpkl") "libpkl/build/native-libs/" else "\(_project)/build/executable/" } } } diff --git a/.circleci/config.yml b/.circleci/config.yml index ab1f9abdc..628a0eb67 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,6 +23,7 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true -Dpkl.targetArch=amd64 pkl-cli:buildNative name: gradle buildNative - persist_to_workspace: @@ -100,6 +101,7 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-cli:buildNative name: gradle buildNative - persist_to_workspace: @@ -131,6 +133,7 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-cli:buildNative name: gradle buildNative - persist_to_workspace: @@ -192,6 +195,7 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-cli:buildNative name: gradle buildNative - persist_to_workspace: @@ -269,6 +273,7 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true -Dpkl.musl=true pkl-cli:buildNative name: gradle buildNative - persist_to_workspace: @@ -298,16 +303,664 @@ jobs: && cp -r . /jdk name: Set up environment shell: bash.exe + - run: + command: choco install mingw + name: Installing mingw + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-cli:buildNative + name: gradle buildNative + shell: bash.exe + - persist_to_workspace: + root: '.' + paths: + - pkl-cli/build/executable/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /jdk + resource_class: windows.large + machine: + image: windows-server-2022-gui:current + pkl-doc-macOS-amd64-release: + steps: + - checkout + - run: + command: /usr/sbin/softwareupdate --install-rosetta --agree-to-license + name: Installing Rosetta 2 + - run: + command: |- + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_x64_mac_hotspot_21.0.5_11.tar.gz -o /tmp/jdk.tar.gz + + mkdir $HOME/jdk \ + && cd $HOME/jdk \ + && cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC . + name: Set up environment + shell: '#!/bin/bash -exo pipefail' + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true -Dpkl.targetArch=amd64 pkl-doc:buildNative + name: gradle buildNative + - persist_to_workspace: + root: '.' + paths: + - pkl-doc/build/executable/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /Users/distiller/jdk/Contents/Home + resource_class: m2pro.large + macos: + xcode: 15.3.0 + pkl-doc-linux-amd64-release: + steps: + - checkout + - restore_cache: + key: staticdeps-amd64 + name: Restore static deps from cache + - run: + command: |- + sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \ + && microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \ + && microdnf clean all \ + && rm -rf /var/cache/dnf + + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_x64_linux_hotspot_21.0.5_11.tar.gz -o /tmp/jdk.tar.gz + + mkdir /jdk \ + && cd /jdk \ + && cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC . + + mkdir -p ~/staticdeps/bin + + cp /usr/lib/gcc/x86_64-redhat-linux/8/libstdc++.a ~/staticdeps + + # install zlib + if [[ ! -f ~/staticdeps/include/zlib.h ]]; then + curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz + + mkdir -p /tmp/dep_zlib-1.2.13 \ + && cd /tmp/dep_zlib-1.2.13 \ + && cat /tmp/zlib.tar.gz | tar --strip-components=1 -xzC . \ + && echo "zlib-1.2.13: configure..." && ./configure --static --prefix="$HOME"/staticdeps > /dev/null \ + && echo "zlib-1.2.13: make..." && make -s -j4 \ + && echo "zlib-1.2.13: make install..." && make -s install \ + && rm -rf /tmp/dep_zlib-1.2.13 + fi + + # install musl + if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then + curl -Lf https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz + + mkdir -p /tmp/dep_musl-1.2.2 \ + && cd /tmp/dep_musl-1.2.2 \ + && cat /tmp/musl.tar.gz | tar --strip-components=1 -xzC . \ + && echo "musl-1.2.2: configure..." && ./configure --disable-shared --prefix="$HOME"/staticdeps > /dev/null \ + && echo "musl-1.2.2: make..." && make -s -j4 \ + && echo "musl-1.2.2: make install..." && make -s install \ + && rm -rf /tmp/dep_musl-1.2.2 + + # native-image expects to find an executable at this path. + ln -s ~/staticdeps/bin/musl-gcc ~/staticdeps/bin/x86_64-linux-musl-gcc + fi + name: Set up environment + shell: '#!/bin/bash -exo pipefail' + - save_cache: + paths: + - ~/staticdeps + key: staticdeps-amd64 + name: Save statics deps to cache + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-doc:buildNative + name: gradle buildNative + - persist_to_workspace: + root: '.' + paths: + - pkl-doc/build/executable/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /jdk + resource_class: xlarge + docker: + - image: oraclelinux:8-slim + pkl-doc-macOS-aarch64-release: + steps: + - checkout + - run: + command: |- + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_aarch64_mac_hotspot_21.0.5_11.tar.gz -o /tmp/jdk.tar.gz + + mkdir $HOME/jdk \ + && cd $HOME/jdk \ + && cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC . + name: Set up environment + shell: '#!/bin/bash -exo pipefail' + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-doc:buildNative + name: gradle buildNative + - persist_to_workspace: + root: '.' + paths: + - pkl-doc/build/executable/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /Users/distiller/jdk/Contents/Home + resource_class: m2pro.large + macos: + xcode: 15.3.0 + pkl-doc-linux-aarch64-release: + steps: + - checkout + - restore_cache: + key: staticdeps-aarch64 + name: Restore static deps from cache + - run: + command: |- + sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \ + && microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \ + && microdnf clean all \ + && rm -rf /var/cache/dnf + + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_aarch64_linux_hotspot_21.0.5_11.tar.gz -o /tmp/jdk.tar.gz + + mkdir /jdk \ + && cd /jdk \ + && cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC . + + mkdir -p ~/staticdeps/bin + + cp /usr/lib/gcc/aarch64-redhat-linux/8/libstdc++.a ~/staticdeps + + # install zlib + if [[ ! -f ~/staticdeps/include/zlib.h ]]; then + curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz + + mkdir -p /tmp/dep_zlib-1.2.13 \ + && cd /tmp/dep_zlib-1.2.13 \ + && cat /tmp/zlib.tar.gz | tar --strip-components=1 -xzC . \ + && echo "zlib-1.2.13: configure..." && ./configure --static --prefix="$HOME"/staticdeps > /dev/null \ + && echo "zlib-1.2.13: make..." && make -s -j4 \ + && echo "zlib-1.2.13: make install..." && make -s install \ + && rm -rf /tmp/dep_zlib-1.2.13 + fi + name: Set up environment + shell: '#!/bin/bash -exo pipefail' + - save_cache: + paths: + - ~/staticdeps + key: staticdeps-aarch64 + name: Save statics deps to cache + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-doc:buildNative + name: gradle buildNative + - persist_to_workspace: + root: '.' + paths: + - pkl-doc/build/executable/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /jdk + resource_class: arm.xlarge + docker: + - image: arm64v8/oraclelinux:8-slim + pkl-doc-linux-alpine-amd64-release: + steps: + - checkout + - restore_cache: + key: staticdeps-amd64 + name: Restore static deps from cache + - run: + command: |- + sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \ + && microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \ + && microdnf clean all \ + && rm -rf /var/cache/dnf + + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_x64_linux_hotspot_21.0.5_11.tar.gz -o /tmp/jdk.tar.gz + + mkdir /jdk \ + && cd /jdk \ + && cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC . + + mkdir -p ~/staticdeps/bin + + cp /usr/lib/gcc/x86_64-redhat-linux/8/libstdc++.a ~/staticdeps + + # install zlib + if [[ ! -f ~/staticdeps/include/zlib.h ]]; then + curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz + + mkdir -p /tmp/dep_zlib-1.2.13 \ + && cd /tmp/dep_zlib-1.2.13 \ + && cat /tmp/zlib.tar.gz | tar --strip-components=1 -xzC . \ + && echo "zlib-1.2.13: configure..." && ./configure --static --prefix="$HOME"/staticdeps > /dev/null \ + && echo "zlib-1.2.13: make..." && make -s -j4 \ + && echo "zlib-1.2.13: make install..." && make -s install \ + && rm -rf /tmp/dep_zlib-1.2.13 + fi + + # install musl + if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then + curl -Lf https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz + + mkdir -p /tmp/dep_musl-1.2.2 \ + && cd /tmp/dep_musl-1.2.2 \ + && cat /tmp/musl.tar.gz | tar --strip-components=1 -xzC . \ + && echo "musl-1.2.2: configure..." && ./configure --disable-shared --prefix="$HOME"/staticdeps > /dev/null \ + && echo "musl-1.2.2: make..." && make -s -j4 \ + && echo "musl-1.2.2: make install..." && make -s install \ + && rm -rf /tmp/dep_musl-1.2.2 + + # native-image expects to find an executable at this path. + ln -s ~/staticdeps/bin/musl-gcc ~/staticdeps/bin/x86_64-linux-musl-gcc + fi + name: Set up environment + shell: '#!/bin/bash -exo pipefail' + - save_cache: + paths: + - ~/staticdeps + key: staticdeps-amd64 + name: Save statics deps to cache + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true -Dpkl.musl=true pkl-doc:buildNative + name: gradle buildNative + - persist_to_workspace: + root: '.' + paths: + - pkl-doc/build/executable/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /jdk + resource_class: xlarge + docker: + - image: oraclelinux:8-slim + pkl-doc-windows-amd64-release: + steps: + - checkout + - run: + command: |- + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_x64_windows_hotspot_21.0.5_11.zip -o /tmp/jdk.zip + + unzip /tmp/jdk.zip -d /tmp/jdk \ + && cd /tmp/jdk/jdk-* \ + && mkdir /jdk \ + && cp -r . /jdk + name: Set up environment + shell: bash.exe + - run: + command: choco install mingw + name: Installing mingw + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-doc:buildNative + name: gradle buildNative + shell: bash.exe + - persist_to_workspace: + root: '.' + paths: + - pkl-doc/build/executable/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /jdk + resource_class: windows.large + machine: + image: windows-server-2022-gui:current + libpkl-macOS-amd64-release: + steps: + - checkout + - run: + command: /usr/sbin/softwareupdate --install-rosetta --agree-to-license + name: Installing Rosetta 2 + - run: + command: |- + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_x64_mac_hotspot_21.0.5_11.tar.gz -o /tmp/jdk.tar.gz + + mkdir $HOME/jdk \ + && cd $HOME/jdk \ + && cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC . + name: Set up environment + shell: '#!/bin/bash -exo pipefail' + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true -Dpkl.targetArch=amd64 libpkl:buildNative + name: gradle buildNative + - persist_to_workspace: + root: '.' + paths: + - libpkl/build/native-libs/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /Users/distiller/jdk/Contents/Home + resource_class: m2pro.large + macos: + xcode: 15.3.0 + libpkl-linux-amd64-release: + steps: + - checkout + - restore_cache: + key: staticdeps-amd64 + name: Restore static deps from cache + - run: + command: |- + sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \ + && microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \ + && microdnf clean all \ + && rm -rf /var/cache/dnf + + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_x64_linux_hotspot_21.0.5_11.tar.gz -o /tmp/jdk.tar.gz + + mkdir /jdk \ + && cd /jdk \ + && cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC . + + mkdir -p ~/staticdeps/bin + + cp /usr/lib/gcc/x86_64-redhat-linux/8/libstdc++.a ~/staticdeps + + # install zlib + if [[ ! -f ~/staticdeps/include/zlib.h ]]; then + curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz + + mkdir -p /tmp/dep_zlib-1.2.13 \ + && cd /tmp/dep_zlib-1.2.13 \ + && cat /tmp/zlib.tar.gz | tar --strip-components=1 -xzC . \ + && echo "zlib-1.2.13: configure..." && ./configure --static --prefix="$HOME"/staticdeps > /dev/null \ + && echo "zlib-1.2.13: make..." && make -s -j4 \ + && echo "zlib-1.2.13: make install..." && make -s install \ + && rm -rf /tmp/dep_zlib-1.2.13 + fi + + # install musl + if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then + curl -Lf https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz + + mkdir -p /tmp/dep_musl-1.2.2 \ + && cd /tmp/dep_musl-1.2.2 \ + && cat /tmp/musl.tar.gz | tar --strip-components=1 -xzC . \ + && echo "musl-1.2.2: configure..." && ./configure --disable-shared --prefix="$HOME"/staticdeps > /dev/null \ + && echo "musl-1.2.2: make..." && make -s -j4 \ + && echo "musl-1.2.2: make install..." && make -s install \ + && rm -rf /tmp/dep_musl-1.2.2 + + # native-image expects to find an executable at this path. + ln -s ~/staticdeps/bin/musl-gcc ~/staticdeps/bin/x86_64-linux-musl-gcc + fi + name: Set up environment + shell: '#!/bin/bash -exo pipefail' + - save_cache: + paths: + - ~/staticdeps + key: staticdeps-amd64 + name: Save statics deps to cache + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true libpkl:buildNative + name: gradle buildNative + - persist_to_workspace: + root: '.' + paths: + - libpkl/build/native-libs/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /jdk + resource_class: xlarge + docker: + - image: oraclelinux:8-slim + libpkl-macOS-aarch64-release: + steps: + - checkout + - run: + command: |- + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_aarch64_mac_hotspot_21.0.5_11.tar.gz -o /tmp/jdk.tar.gz + + mkdir $HOME/jdk \ + && cd $HOME/jdk \ + && cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC . + name: Set up environment + shell: '#!/bin/bash -exo pipefail' + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true libpkl:buildNative + name: gradle buildNative + - persist_to_workspace: + root: '.' + paths: + - libpkl/build/native-libs/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /Users/distiller/jdk/Contents/Home + resource_class: m2pro.large + macos: + xcode: 15.3.0 + libpkl-linux-aarch64-release: + steps: + - checkout + - restore_cache: + key: staticdeps-aarch64 + name: Restore static deps from cache + - run: + command: |- + sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \ + && microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \ + && microdnf clean all \ + && rm -rf /var/cache/dnf + + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_aarch64_linux_hotspot_21.0.5_11.tar.gz -o /tmp/jdk.tar.gz + + mkdir /jdk \ + && cd /jdk \ + && cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC . + + mkdir -p ~/staticdeps/bin + + cp /usr/lib/gcc/aarch64-redhat-linux/8/libstdc++.a ~/staticdeps + + # install zlib + if [[ ! -f ~/staticdeps/include/zlib.h ]]; then + curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz + + mkdir -p /tmp/dep_zlib-1.2.13 \ + && cd /tmp/dep_zlib-1.2.13 \ + && cat /tmp/zlib.tar.gz | tar --strip-components=1 -xzC . \ + && echo "zlib-1.2.13: configure..." && ./configure --static --prefix="$HOME"/staticdeps > /dev/null \ + && echo "zlib-1.2.13: make..." && make -s -j4 \ + && echo "zlib-1.2.13: make install..." && make -s install \ + && rm -rf /tmp/dep_zlib-1.2.13 + fi + name: Set up environment + shell: '#!/bin/bash -exo pipefail' + - save_cache: + paths: + - ~/staticdeps + key: staticdeps-aarch64 + name: Save statics deps to cache + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true libpkl:buildNative + name: gradle buildNative + - persist_to_workspace: + root: '.' + paths: + - libpkl/build/native-libs/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /jdk + resource_class: arm.xlarge + docker: + - image: arm64v8/oraclelinux:8-slim + libpkl-linux-alpine-amd64-release: + steps: + - checkout + - restore_cache: + key: staticdeps-amd64 + name: Restore static deps from cache + - run: + command: |- + sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \ + && microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \ + && microdnf clean all \ + && rm -rf /var/cache/dnf + + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_x64_linux_hotspot_21.0.5_11.tar.gz -o /tmp/jdk.tar.gz + + mkdir /jdk \ + && cd /jdk \ + && cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC . + + mkdir -p ~/staticdeps/bin + + cp /usr/lib/gcc/x86_64-redhat-linux/8/libstdc++.a ~/staticdeps + + # install zlib + if [[ ! -f ~/staticdeps/include/zlib.h ]]; then + curl -Lf https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz -o /tmp/zlib.tar.gz + + mkdir -p /tmp/dep_zlib-1.2.13 \ + && cd /tmp/dep_zlib-1.2.13 \ + && cat /tmp/zlib.tar.gz | tar --strip-components=1 -xzC . \ + && echo "zlib-1.2.13: configure..." && ./configure --static --prefix="$HOME"/staticdeps > /dev/null \ + && echo "zlib-1.2.13: make..." && make -s -j4 \ + && echo "zlib-1.2.13: make install..." && make -s install \ + && rm -rf /tmp/dep_zlib-1.2.13 + fi + + # install musl + if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then + curl -Lf https://musl.libc.org/releases/musl-1.2.2.tar.gz -o /tmp/musl.tar.gz + + mkdir -p /tmp/dep_musl-1.2.2 \ + && cd /tmp/dep_musl-1.2.2 \ + && cat /tmp/musl.tar.gz | tar --strip-components=1 -xzC . \ + && echo "musl-1.2.2: configure..." && ./configure --disable-shared --prefix="$HOME"/staticdeps > /dev/null \ + && echo "musl-1.2.2: make..." && make -s -j4 \ + && echo "musl-1.2.2: make install..." && make -s install \ + && rm -rf /tmp/dep_musl-1.2.2 + + # native-image expects to find an executable at this path. + ln -s ~/staticdeps/bin/musl-gcc ~/staticdeps/bin/x86_64-linux-musl-gcc + fi + name: Set up environment + shell: '#!/bin/bash -exo pipefail' + - save_cache: + paths: + - ~/staticdeps + key: staticdeps-amd64 + name: Save statics deps to cache - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-cli:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true -Dpkl.musl=true libpkl:buildNative + name: gradle buildNative + - persist_to_workspace: + root: '.' + paths: + - libpkl/build/native-libs/ + - store_test_results: + path: ~/test-results + environment: + LANG: en_US.UTF-8 + JAVA_HOME: /jdk + resource_class: xlarge + docker: + - image: oraclelinux:8-slim + libpkl-windows-amd64-release: + steps: + - checkout + - run: + command: |- + # install jdk + curl -Lf \ + https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_x64_windows_hotspot_21.0.5_11.zip -o /tmp/jdk.zip + + unzip /tmp/jdk.zip -d /tmp/jdk \ + && cd /tmp/jdk/jdk-* \ + && mkdir /jdk \ + && cp -r . /jdk + name: Set up environment + shell: bash.exe + - run: + command: choco install mingw + name: Installing mingw + - run: + command: |- + export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true libpkl:buildNative name: gradle buildNative shell: bash.exe - persist_to_workspace: root: '.' paths: - - pkl-cli/build/executable/ + - libpkl/build/native-libs/ - store_test_results: path: ~/test-results environment: @@ -316,7 +969,7 @@ jobs: resource_class: windows.large machine: image: windows-server-2022-gui:current - pkl-doc-macOS-amd64-release: + pkl-cli-macOS-amd64-snapshot: steps: - checkout - run: @@ -336,21 +989,22 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true -Dpkl.targetArch=amd64 pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -Dpkl.targetArch=amd64 pkl-cli:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - pkl-cli/build/executable/ - store_test_results: path: ~/test-results environment: LANG: en_US.UTF-8 JAVA_HOME: /Users/distiller/jdk/Contents/Home - resource_class: macos.m1.large.gen1 + resource_class: m2pro.large macos: xcode: 15.3.0 - pkl-doc-linux-amd64-release: + pkl-cli-linux-amd64-snapshot: steps: - checkout - restore_cache: @@ -413,12 +1067,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-cli:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - pkl-cli/build/executable/ - store_test_results: path: ~/test-results environment: @@ -427,7 +1082,7 @@ jobs: resource_class: xlarge docker: - image: oraclelinux:8-slim - pkl-doc-macOS-aarch64-release: + pkl-cli-macOS-aarch64-snapshot: steps: - checkout - run: @@ -444,21 +1099,22 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-cli:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - pkl-cli/build/executable/ - store_test_results: path: ~/test-results environment: LANG: en_US.UTF-8 JAVA_HOME: /Users/distiller/jdk/Contents/Home - resource_class: macos.m1.large.gen1 + resource_class: m2pro.large macos: xcode: 15.3.0 - pkl-doc-linux-aarch64-release: + pkl-cli-linux-aarch64-snapshot: steps: - checkout - restore_cache: @@ -505,12 +1161,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-cli:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - pkl-cli/build/executable/ - store_test_results: path: ~/test-results environment: @@ -519,7 +1176,7 @@ jobs: resource_class: arm.xlarge docker: - image: arm64v8/oraclelinux:8-slim - pkl-doc-linux-alpine-amd64-release: + pkl-cli-linux-alpine-amd64-snapshot: steps: - checkout - restore_cache: @@ -582,12 +1239,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true -Dpkl.musl=true pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -Dpkl.musl=true pkl-cli:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - pkl-cli/build/executable/ - store_test_results: path: ~/test-results environment: @@ -596,7 +1254,7 @@ jobs: resource_class: xlarge docker: - image: oraclelinux:8-slim - pkl-doc-windows-amd64-release: + pkl-cli-windows-amd64-snapshot: steps: - checkout - run: @@ -611,16 +1269,20 @@ jobs: && cp -r . /jdk name: Set up environment shell: bash.exe + - run: + command: choco install mingw + name: Installing mingw - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -DreleaseBuild=true pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-cli:buildNative name: gradle buildNative shell: bash.exe - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - pkl-cli/build/executable/ - store_test_results: path: ~/test-results environment: @@ -629,7 +1291,7 @@ jobs: resource_class: windows.large machine: image: windows-server-2022-gui:current - pkl-cli-macOS-amd64-snapshot: + pkl-doc-macOS-amd64-snapshot: steps: - checkout - run: @@ -649,12 +1311,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -Dpkl.targetArch=amd64 pkl-cli:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -Dpkl.targetArch=amd64 pkl-doc:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-cli/build/executable/ + - pkl-doc/build/executable/ - store_test_results: path: ~/test-results environment: @@ -663,7 +1326,7 @@ jobs: resource_class: m2pro.large macos: xcode: 15.3.0 - pkl-cli-linux-amd64-snapshot: + pkl-doc-linux-amd64-snapshot: steps: - checkout - restore_cache: @@ -726,12 +1389,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-cli:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-doc:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-cli/build/executable/ + - pkl-doc/build/executable/ - store_test_results: path: ~/test-results environment: @@ -740,7 +1404,7 @@ jobs: resource_class: xlarge docker: - image: oraclelinux:8-slim - pkl-cli-macOS-aarch64-snapshot: + pkl-doc-macOS-aarch64-snapshot: steps: - checkout - run: @@ -757,12 +1421,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-cli:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-doc:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-cli/build/executable/ + - pkl-doc/build/executable/ - store_test_results: path: ~/test-results environment: @@ -771,7 +1436,7 @@ jobs: resource_class: m2pro.large macos: xcode: 15.3.0 - pkl-cli-linux-aarch64-snapshot: + pkl-doc-linux-aarch64-snapshot: steps: - checkout - restore_cache: @@ -818,12 +1483,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-cli:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-doc:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-cli/build/executable/ + - pkl-doc/build/executable/ - store_test_results: path: ~/test-results environment: @@ -832,7 +1498,7 @@ jobs: resource_class: arm.xlarge docker: - image: arm64v8/oraclelinux:8-slim - pkl-cli-linux-alpine-amd64-snapshot: + pkl-doc-linux-alpine-amd64-snapshot: steps: - checkout - restore_cache: @@ -895,12 +1561,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -Dpkl.musl=true pkl-cli:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -Dpkl.musl=true pkl-doc:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-cli/build/executable/ + - pkl-doc/build/executable/ - store_test_results: path: ~/test-results environment: @@ -909,7 +1576,7 @@ jobs: resource_class: xlarge docker: - image: oraclelinux:8-slim - pkl-cli-windows-amd64-snapshot: + pkl-doc-windows-amd64-snapshot: steps: - checkout - run: @@ -924,16 +1591,20 @@ jobs: && cp -r . /jdk name: Set up environment shell: bash.exe + - run: + command: choco install mingw + name: Installing mingw - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-cli:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-doc:buildNative name: gradle buildNative shell: bash.exe - persist_to_workspace: root: '.' paths: - - pkl-cli/build/executable/ + - pkl-doc/build/executable/ - store_test_results: path: ~/test-results environment: @@ -942,7 +1613,7 @@ jobs: resource_class: windows.large machine: image: windows-server-2022-gui:current - pkl-doc-macOS-amd64-snapshot: + libpkl-macOS-amd64-snapshot: steps: - checkout - run: @@ -962,21 +1633,22 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -Dpkl.targetArch=amd64 pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -Dpkl.targetArch=amd64 libpkl:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - libpkl/build/native-libs/ - store_test_results: path: ~/test-results environment: LANG: en_US.UTF-8 JAVA_HOME: /Users/distiller/jdk/Contents/Home - resource_class: macos.m1.large.gen1 + resource_class: m2pro.large macos: xcode: 15.3.0 - pkl-doc-linux-amd64-snapshot: + libpkl-linux-amd64-snapshot: steps: - checkout - restore_cache: @@ -1039,12 +1711,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true libpkl:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - libpkl/build/native-libs/ - store_test_results: path: ~/test-results environment: @@ -1053,7 +1726,7 @@ jobs: resource_class: xlarge docker: - image: oraclelinux:8-slim - pkl-doc-macOS-aarch64-snapshot: + libpkl-macOS-aarch64-snapshot: steps: - checkout - run: @@ -1070,21 +1743,22 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true libpkl:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - libpkl/build/native-libs/ - store_test_results: path: ~/test-results environment: LANG: en_US.UTF-8 JAVA_HOME: /Users/distiller/jdk/Contents/Home - resource_class: macos.m1.large.gen1 + resource_class: m2pro.large macos: xcode: 15.3.0 - pkl-doc-linux-aarch64-snapshot: + libpkl-linux-aarch64-snapshot: steps: - checkout - restore_cache: @@ -1131,12 +1805,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true libpkl:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - libpkl/build/native-libs/ - store_test_results: path: ~/test-results environment: @@ -1145,7 +1820,7 @@ jobs: resource_class: arm.xlarge docker: - image: arm64v8/oraclelinux:8-slim - pkl-doc-linux-alpine-amd64-snapshot: + libpkl-linux-alpine-amd64-snapshot: steps: - checkout - restore_cache: @@ -1208,12 +1883,13 @@ jobs: - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -Dpkl.musl=true pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true -Dpkl.musl=true libpkl:buildNative name: gradle buildNative - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - libpkl/build/native-libs/ - store_test_results: path: ~/test-results environment: @@ -1222,7 +1898,7 @@ jobs: resource_class: xlarge docker: - image: oraclelinux:8-slim - pkl-doc-windows-amd64-snapshot: + libpkl-windows-amd64-snapshot: steps: - checkout - run: @@ -1237,16 +1913,20 @@ jobs: && cp -r . /jdk name: Set up environment shell: bash.exe + - run: + command: choco install mingw + name: Installing mingw - run: command: |- export PATH=~/staticdeps/bin:$PATH - ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true pkl-doc:buildNative + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH + ./gradlew --info --stacktrace -DtestReportsDir=${HOME}/test-results -DpklMultiJdkTesting=true libpkl:buildNative name: gradle buildNative shell: bash.exe - persist_to_workspace: root: '.' paths: - - pkl-doc/build/executable/ + - libpkl/build/native-libs/ - store_test_results: path: ~/test-results environment: @@ -1417,6 +2097,24 @@ workflows: - gradle-check-windows: requires: - hold + - libpkl-macOS-amd64-snapshot: + requires: + - hold + - libpkl-linux-amd64-snapshot: + requires: + - hold + - libpkl-macOS-aarch64-snapshot: + requires: + - hold + - libpkl-linux-aarch64-snapshot: + requires: + - hold + - libpkl-linux-alpine-amd64-snapshot: + requires: + - hold + - libpkl-windows-amd64-snapshot: + requires: + - hold when: matches: value: << pipeline.git.branch >> @@ -1425,6 +2123,12 @@ workflows: jobs: - gradle-check - gradle-check-windows + - libpkl-macOS-amd64-snapshot + - libpkl-linux-amd64-snapshot + - libpkl-macOS-aarch64-snapshot + - libpkl-linux-aarch64-snapshot + - libpkl-linux-alpine-amd64-snapshot + - libpkl-windows-amd64-snapshot - bench - gradle-compatibility - pkl-cli-macOS-amd64-snapshot @@ -1439,10 +2143,22 @@ workflows: - pkl-doc-linux-aarch64-snapshot - pkl-doc-linux-alpine-amd64-snapshot - pkl-doc-windows-amd64-snapshot + - libpkl-macOS-amd64-snapshot + - libpkl-linux-amd64-snapshot + - libpkl-macOS-aarch64-snapshot + - libpkl-linux-aarch64-snapshot + - libpkl-linux-alpine-amd64-snapshot + - libpkl-windows-amd64-snapshot - deploy-snapshot: requires: - gradle-check - gradle-check-windows + - libpkl-macOS-amd64-snapshot + - libpkl-linux-amd64-snapshot + - libpkl-macOS-aarch64-snapshot + - libpkl-linux-aarch64-snapshot + - libpkl-linux-alpine-amd64-snapshot + - libpkl-windows-amd64-snapshot - bench - gradle-compatibility - pkl-cli-macOS-amd64-snapshot @@ -1457,6 +2173,12 @@ workflows: - pkl-doc-linux-aarch64-snapshot - pkl-doc-linux-alpine-amd64-snapshot - pkl-doc-windows-amd64-snapshot + - libpkl-macOS-amd64-snapshot + - libpkl-linux-amd64-snapshot + - libpkl-macOS-aarch64-snapshot + - libpkl-linux-aarch64-snapshot + - libpkl-linux-alpine-amd64-snapshot + - libpkl-windows-amd64-snapshot context: pkl-maven-release - trigger-docsite-build: requires: @@ -1481,6 +2203,42 @@ workflows: ignore: /.*/ tags: only: /^v?\d+\.\d+\.\d+$/ + - libpkl-macOS-amd64-snapshot: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ + - libpkl-linux-amd64-snapshot: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ + - libpkl-macOS-aarch64-snapshot: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ + - libpkl-linux-aarch64-snapshot: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ + - libpkl-linux-alpine-amd64-snapshot: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ + - libpkl-windows-amd64-snapshot: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ - bench: filters: branches: @@ -1565,10 +2323,52 @@ workflows: ignore: /.*/ tags: only: /^v?\d+\.\d+\.\d+$/ + - libpkl-macOS-amd64-release: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ + - libpkl-linux-amd64-release: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ + - libpkl-macOS-aarch64-release: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ + - libpkl-linux-aarch64-release: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ + - libpkl-linux-alpine-amd64-release: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ + - libpkl-windows-amd64-release: + filters: + branches: + ignore: /.*/ + tags: + only: /^v?\d+\.\d+\.\d+$/ - github-release: requires: - gradle-check - gradle-check-windows + - libpkl-macOS-amd64-snapshot + - libpkl-linux-amd64-snapshot + - libpkl-macOS-aarch64-snapshot + - libpkl-linux-aarch64-snapshot + - libpkl-linux-alpine-amd64-snapshot + - libpkl-windows-amd64-snapshot - bench - gradle-compatibility - pkl-cli-macOS-amd64-release @@ -1583,6 +2383,12 @@ workflows: - pkl-doc-linux-aarch64-release - pkl-doc-linux-alpine-amd64-release - pkl-doc-windows-amd64-release + - libpkl-macOS-amd64-release + - libpkl-linux-amd64-release + - libpkl-macOS-aarch64-release + - libpkl-linux-aarch64-release + - libpkl-linux-alpine-amd64-release + - libpkl-windows-amd64-release context: pkl-github-release filters: branches: @@ -1612,6 +2418,12 @@ workflows: jobs: - gradle-check - gradle-check-windows + - libpkl-macOS-amd64-snapshot + - libpkl-linux-amd64-snapshot + - libpkl-macOS-aarch64-snapshot + - libpkl-linux-aarch64-snapshot + - libpkl-linux-alpine-amd64-snapshot + - libpkl-windows-amd64-snapshot - bench - gradle-compatibility - pkl-cli-macOS-amd64-release @@ -1626,6 +2438,12 @@ workflows: - pkl-doc-linux-aarch64-release - pkl-doc-linux-alpine-amd64-release - pkl-doc-windows-amd64-release + - libpkl-macOS-amd64-release + - libpkl-linux-amd64-release + - libpkl-macOS-aarch64-release + - libpkl-linux-aarch64-release + - libpkl-linux-alpine-amd64-release + - libpkl-windows-amd64-release when: matches: value: << pipeline.git.branch >> diff --git a/.circleci/jobs/BuildNativeJob.pkl b/.circleci/jobs/BuildNativeJob.pkl index ccef55700..dae8674c1 100644 --- a/.circleci/jobs/BuildNativeJob.pkl +++ b/.circleci/jobs/BuildNativeJob.pkl @@ -29,6 +29,9 @@ project: String javaVersion = "21.0" +/// The build directory that artifacts are written to +buildDir: String + extraGradleArgs { when (os == "macOS" && arch == "amd64") { "-Dpkl.targetArch=\(arch)" @@ -141,6 +144,14 @@ steps { } setupMacEnvironment } + when (os == "windows") { + new Config.RunStep { + name = "Installing mingw" + command = """ + choco install mingw + """ + } + } new Config.RunStep { name = "gradle buildNative" when (module.os == "windows") { @@ -148,13 +159,14 @@ steps { } command = #""" export PATH=~/staticdeps/bin:$PATH + export PATH=/c/ProgramData/mingw64/mingw64/bin:$PATH ./gradlew \#(module.gradleArgs) \#(project):buildNative """# } new Config.PersistToWorkspaceStep { root = "." paths { - "\(project)/build/executable/" + buildDir } } } diff --git a/buildSrc/src/main/kotlin/BuildInfo.kt b/buildSrc/src/main/kotlin/BuildInfo.kt index 8c0755a58..27aa72117 100644 --- a/buildSrc/src/main/kotlin/BuildInfo.kt +++ b/buildSrc/src/main/kotlin/BuildInfo.kt @@ -15,7 +15,10 @@ */ @file:Suppress("MemberVisibilityCanBePrivate") +import Target.Arch +import Target.OS import java.io.File +import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.artifacts.VersionCatalog import org.gradle.api.artifacts.VersionCatalogsExtension @@ -79,11 +82,10 @@ open class BuildInfo(private val project: Project) { val graalVmJdkVersion: String by lazy { libs.findVersion("graalVmJdkVersion").get().toString() } val osName: String by lazy { - when { - os.isMacOsX -> "macos" - os.isLinux -> "linux" - os.isWindows -> "windows" - else -> throw RuntimeException("${os.familyName} is not supported.") + when (os) { + OS.MacOS -> "macos" + OS.Linux -> "linux" + OS.Windows -> "windows" } } @@ -103,29 +105,31 @@ open class BuildInfo(private val project: Project) { val installDir: File by lazy { File(homeDir, baseName) } val baseDir: String by lazy { - if (os.isMacOsX) "$installDir/Contents/Home" else installDir.toString() + if (os.isMacOS) "$installDir/Contents/Home" else installDir.toString() } } + /** The target machine to build, defaulting to the host system machine. */ + val targetMachine: Target by lazy { Target.from(os = os, arch = targetArch, musl = musl) } + /** The target architecture to build, defaulting to the system architecture. */ - val targetArch by lazy { System.getProperty("pkl.targetArch") ?: arch } + val targetArch: Arch by lazy { System.getProperty("pkl.targetArch")?.let(Arch::fromName) ?: arch } /** Tells if this is a cross-arch build (e.g. targeting amd64 when on an aarch64 machine). */ val isCrossArch by lazy { arch != targetArch } /** Tells if cross-arch builds are supported on this machine. */ - val isCrossArchSupported by lazy { os.isMacOsX } + val isCrossArchSupported by lazy { os.isMacOS } /** Whether to build native executables using the musl toolchain or not. */ val musl: Boolean by lazy { java.lang.Boolean.getBoolean("pkl.musl") } - /** Same logic as [org.gradle.internal.os.OperatingSystem#arch], which is protected. */ - val arch: String by lazy { + val arch: Arch by lazy { when (val arch = System.getProperty("os.arch")) { - "x86" -> "i386" - "x86_64" -> "amd64" - "powerpc" -> "ppc" - else -> arch + "x86_64", + "amd64" -> Arch.AMD64 + "aarch64" -> Arch.AARCH64 + else -> throw GradleException("Cannot build Pkl on arch: $arch") } } @@ -356,8 +360,14 @@ open class BuildInfo(private val project: Project) { File(System.getProperty("user.home"), "staticdeps/bin/x86_64-linux-musl-gcc").exists() } - val os: org.gradle.internal.os.OperatingSystem by lazy { - org.gradle.internal.os.OperatingSystem.current() + val os: OS by lazy { + val currentOs = org.gradle.internal.os.OperatingSystem.current() + when { + currentOs.isMacOsX -> OS.MacOS + currentOs.isLinux -> OS.Linux + currentOs.isWindows -> OS.Windows + else -> throw GradleException("Cannot build on ${currentOs.name}") + } } // could be `commitId: Provider = project.provider { ... }` diff --git a/buildSrc/src/main/kotlin/NativeImageBuild.kt b/buildSrc/src/main/kotlin/NativeImageBuild.kt index 727640ffa..819f1b54d 100644 --- a/buildSrc/src/main/kotlin/NativeImageBuild.kt +++ b/buildSrc/src/main/kotlin/NativeImageBuild.kt @@ -17,6 +17,8 @@ import javax.inject.Inject import org.gradle.api.DefaultTask import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.FileCollection +import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property import org.gradle.api.provider.Provider @@ -25,43 +27,47 @@ import org.gradle.api.services.BuildServiceParameters import org.gradle.api.tasks.ClasspathNormalizer import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.OutputFiles import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction import org.gradle.kotlin.dsl.registerIfAbsent import org.gradle.kotlin.dsl.withNormalizer import org.gradle.process.ExecOperations -enum class Architecture { - AMD64, - AARCH64, -} - abstract class NativeImageBuildService : BuildService abstract class NativeImageBuild : DefaultTask() { - @get:Input abstract val imageName: Property + @get:Input abstract val outputName: Property @get:Input abstract val extraNativeImageArgs: ListProperty - @get:Input abstract val arch: Property + @get:Input abstract val arch: Property + + /** + * The main class entrypoint for the executable. + * + * This option is not necessary if [sharedLibrary] is true. + */ + @get:Optional @get:Input abstract val mainClass: Property - @get:Input abstract val mainClass: Property + /** Create a shared library, instead of an executable. */ + @get:Input abstract val sharedLibrary: Property @get:InputFiles abstract val classpath: ConfigurableFileCollection @get:OutputDirectory abstract val outputDir: DirectoryProperty - @get:OutputFile val outputFile = outputDir.flatMap { it.file(imageName) } - @get:Inject protected abstract val execOperations: ExecOperations + @get:Inject protected abstract val objectFactory: ObjectFactory + private val graalVm: Provider = arch.map { a -> when (a) { - Architecture.AMD64 -> buildInfo.graalVmAmd64 - Architecture.AARCH64 -> buildInfo.graalVmAarch64 + Target.Arch.AMD64 -> buildInfo.graalVmAmd64 + Target.Arch.AARCH64 -> buildInfo.graalVmAarch64 } } @@ -91,6 +97,8 @@ abstract class NativeImageBuild : DefaultTask() { // CPU resources). usesService(buildService) + sharedLibrary.convention(false) + outputDir.convention(project.layout.buildDirectory.dir("executable")) group = "build" @@ -105,6 +113,33 @@ abstract class NativeImageBuild : DefaultTask() { .withPathSensitivity(PathSensitivity.ABSOLUTE) } + @Suppress("unused") + @OutputFiles + fun getEffectiveOutputFiles(): FileCollection { + return objectFactory + .fileCollection() + .from( + sharedLibrary.map { isLibrary -> + val dir = outputDir.get() + val libraryName = outputName.get() + // if building a library, native-image outputs five files (four headers, and dynamic lib) + // otherwise, it outputs just the one file + if (isLibrary) { + val sharedLibrarySuffix = buildInfo.os.sharedLibrarySuffix + dir.files( + "$libraryName.$sharedLibrarySuffix", + "$libraryName.h", + "${libraryName}_dynamic.h", + "graal_isolate.h", + "graal_isolate_dynamic.h", + ) + } else { + dir.file(libraryName) + } + } + ) + } + @TaskAction protected fun run() { execOperations.exec { @@ -128,9 +163,14 @@ abstract class NativeImageBuild : DefaultTask() { add("-H:IncludeResourceBundles=org.pkl.core.errorMessages") add("-H:IncludeResourceBundles=org.pkl.parser.errorMessages") add("-H:IncludeResources=org/pkl/commons/cli/PklCARoots.pem") - add("-H:Class=${mainClass.get()}") + if (mainClass.isPresent) { + add("-H:Class=${mainClass.get()}") + } + if (sharedLibrary.get()) { + add("--shared") + } add("-o") - add(imageName.get()) + add(outputName.get()) // the actual limit (currently) used by native-image is this number + 1400 (idea is to // compensate for Truffle's own nodes) add("-H:MaxRuntimeCompileMethods=1800") @@ -160,7 +200,7 @@ abstract class NativeImageBuild : DefaultTask() { // make sure dev machine stays responsive (15% slowdown on my laptop) val processors = Runtime.getRuntime().availableProcessors() / - if (buildInfo.os.isMacOsX && !buildInfo.isCiBuild) 4 else 1 + if (buildInfo.os.isMacOS && !buildInfo.isCiBuild) 4 else 1 add("-J-XX:ActiveProcessorCount=${processors}") // Pass through all `HOMEBREW_` prefixed environment variables to allow build with shimmed // tools. diff --git a/buildSrc/src/main/kotlin/Target.kt b/buildSrc/src/main/kotlin/Target.kt new file mode 100644 index 000000000..51dcc3c08 --- /dev/null +++ b/buildSrc/src/main/kotlin/Target.kt @@ -0,0 +1,82 @@ +/* + * Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@file:Suppress("MemberVisibilityCanBePrivate") + +/** + * A build target when building native libraries or executables. + * + * Pkl only builds for the following listed targets. + */ +enum class Target(val os: OS, val arch: Arch, val musl: Boolean) { + MacosAarch64(os = OS.MacOS, arch = Arch.AARCH64, musl = false), + MacosAmd64(os = OS.MacOS, arch = Arch.AMD64, musl = false), + LinuxAarch64(os = OS.Linux, arch = Arch.AARCH64, musl = false), + LinuxAmd64(os = OS.Linux, arch = Arch.AMD64, musl = false), + AlpineLinuxAmd64(os = OS.Linux, arch = Arch.AMD64, musl = true), + WindowsAmd64(os = OS.Windows, arch = Arch.AMD64, musl = false); + + companion object { + fun from(os: OS, arch: Arch, musl: Boolean): Target { + for (target in values()) { + if (target.os == os && target.arch == arch && target.musl == musl) { + return target + } + } + throw IllegalArgumentException("Cannot build for $os-$arch with musl: $musl") + } + } + + val targetName: String + get() { + return if (musl) { + assert(os == OS.Linux) + "alpine-linux-$arch" + } else "$os-$arch" + } + + enum class Arch(private val simpleName: String) { + AARCH64("aarch64"), + AMD64("amd64"); + + override fun toString() = simpleName + + companion object { + fun fromName(name: String): Arch = + when (name) { + "aarch64" -> AARCH64 + "amd64" -> AMD64 + else -> throw IllegalArgumentException("Unknown arch: $name") + } + } + } + + enum class OS(val simpleName: String, val sharedLibrarySuffix: String, val displayName: String) { + MacOS("macos", "dylib", "macOS"), + Linux("linux", "so", "Linux"), + Windows("windows", "dll", "Windows"); + + override fun toString(): String = simpleName + + val isWindows: Boolean + get() = this == Windows + + val isMacOS: Boolean + get() = this == MacOS + + val isLinux: Boolean + get() = this == Linux + } +} diff --git a/buildSrc/src/main/kotlin/pklNativeExecutable.gradle.kts b/buildSrc/src/main/kotlin/pklNativeExecutable.gradle.kts index b55c5c0e8..84ddc5448 100644 --- a/buildSrc/src/main/kotlin/pklNativeExecutable.gradle.kts +++ b/buildSrc/src/main/kotlin/pklNativeExecutable.gradle.kts @@ -36,31 +36,37 @@ val stagedAlpineLinuxAmd64Executable: Configuration by configurations.creating val stagedWindowsAmd64Executable: Configuration by configurations.creating dependencies { - fun executableFile(suffix: String) = + fun executableFile(target: Target) = files( layout.buildDirectory.dir("executable").map { dir -> - dir.file(executableSpec.name.map { "$it-$suffix" }) + dir.file( + executableSpec.name.map { name -> + if (target.os.isWindows) "$name-${target.targetName}.exe" + else "$name-${target.targetName}" + } + ) } ) - stagedMacAarch64Executable(executableFile("macos-aarch64")) - stagedMacAmd64Executable(executableFile("macos-amd64")) - stagedLinuxAmd64Executable(executableFile("linux-amd64")) - stagedLinuxAarch64Executable(executableFile("linux-aarch64")) - stagedAlpineLinuxAmd64Executable(executableFile("alpine-linux-amd64")) - stagedWindowsAmd64Executable(executableFile("windows-amd64.exe")) + stagedMacAarch64Executable(executableFile(Target.MacosAarch64)) + stagedMacAmd64Executable(executableFile(Target.MacosAmd64)) + stagedLinuxAarch64Executable(executableFile(Target.LinuxAarch64)) + stagedLinuxAmd64Executable(executableFile(Target.LinuxAmd64)) + stagedAlpineLinuxAmd64Executable(executableFile(Target.AlpineLinuxAmd64)) + stagedWindowsAmd64Executable(executableFile(Target.WindowsAmd64)) } -private fun NativeImageBuild.amd64() { - arch = Architecture.AMD64 - dependsOn(":installGraalVmAmd64") -} +private fun NativeImageBuild.configure(target: Target) { + arch = target.arch -private fun NativeImageBuild.aarch64() { - arch = Architecture.AARCH64 - dependsOn(":installGraalVmAarch64") -} + outputName = executableSpec.name.map { "$it-${target.targetName}" } + mainClass = executableSpec.mainClass + + if (target.arch == Target.Arch.AARCH64) { + dependsOn(":installGraalVmAarch64") + } else { + dependsOn(":installGraalVmAmd64") + } -private fun NativeImageBuild.setClasspath() { classpath.from(sourceSets.main.map { it.output }) classpath.from( project(":pkl-commons-cli").extensions.getByType(SourceSetContainer::class)["svm"].output @@ -69,35 +75,17 @@ private fun NativeImageBuild.setClasspath() { } val macExecutableAmd64 by - tasks.registering(NativeImageBuild::class) { - imageName = executableSpec.name.map { "$it-macos-amd64" } - mainClass = executableSpec.mainClass - amd64() - setClasspath() - } + tasks.registering(NativeImageBuild::class) { configure(Target.MacosAmd64) } val macExecutableAarch64 by - tasks.registering(NativeImageBuild::class) { - imageName = executableSpec.name.map { "$it-macos-aarch64" } - mainClass = executableSpec.mainClass - aarch64() - setClasspath() - } + tasks.registering(NativeImageBuild::class) { configure(Target.MacosAarch64) } val linuxExecutableAmd64 by - tasks.registering(NativeImageBuild::class) { - imageName = executableSpec.name.map { "$it-linux-amd64" } - mainClass = executableSpec.mainClass - amd64() - setClasspath() - } + tasks.registering(NativeImageBuild::class) { configure(Target.LinuxAmd64) } val linuxExecutableAarch64 by tasks.registering(NativeImageBuild::class) { - imageName = executableSpec.name.map { "$it-linux-aarch64" } - mainClass = executableSpec.mainClass - aarch64() - setClasspath() + configure(Target.LinuxAarch64) // Ensure compatibility for kernels with page size set to 4k, 16k and 64k // (e.g. Raspberry Pi 5, Asahi Linux) extraNativeImageArgs.add("-H:PageSize=65536") @@ -105,19 +93,13 @@ val linuxExecutableAarch64 by val alpineExecutableAmd64 by tasks.registering(NativeImageBuild::class) { - imageName = executableSpec.name.map { "$it-alpine-linux-amd64" } - mainClass = executableSpec.mainClass - amd64() - setClasspath() + configure(Target.AlpineLinuxAmd64) extraNativeImageArgs.addAll(listOf("--static", "--libc=musl")) } val windowsExecutableAmd64 by tasks.registering(NativeImageBuild::class) { - imageName = executableSpec.name.map { "$it-windows-amd64" } - mainClass = executableSpec.mainClass - amd64() - setClasspath() + configure(Target.WindowsAmd64) extraNativeImageArgs.add("-Dfile.encoding=UTF-8") } @@ -134,6 +116,7 @@ val testStartNativeExecutable by val execOutput = providers.exec { commandLine(assembleNative.get().outputs.files.singleFile, "--version") } + @Suppress("DuplicatedCode") doLast { val outputText = execOutput.standardOutput.asText.get() if (!outputText.contains(buildInfo.pklVersionNonUnique)) { @@ -144,7 +127,7 @@ val testStartNativeExecutable by outputFile.get().asFile.toPath().apply { try { parent.createDirectories() - } catch (ignored: java.nio.file.FileAlreadyExistsException) {} + } catch (_: java.nio.file.FileAlreadyExistsException) {} writeText("OK") } } @@ -156,124 +139,72 @@ private fun Task.wraps(other: TaskProvider) { outputs.files(other) } -val testNative by tasks.existing { dependsOn(testStartNativeExecutable) } +@Suppress("unused") val testNative by tasks.existing { dependsOn(testStartNativeExecutable) } -val assembleNativeMacOsAarch64 by tasks.existing { wraps(macExecutableAarch64) } +@Suppress("unused") val assembleNativeMacOsAarch64 by tasks.existing { wraps(macExecutableAarch64) } -val assembleNativeMacOsAmd64 by tasks.existing { wraps(macExecutableAmd64) } +@Suppress("unused") val assembleNativeMacOsAmd64 by tasks.existing { wraps(macExecutableAmd64) } +@Suppress("unused") val assembleNativeLinuxAarch64 by tasks.existing { wraps(linuxExecutableAarch64) } -val assembleNativeLinuxAmd64 by tasks.existing { wraps(linuxExecutableAmd64) } +@Suppress("unused") val assembleNativeLinuxAmd64 by tasks.existing { wraps(linuxExecutableAmd64) } +@Suppress("unused") val assembleNativeAlpineLinuxAmd64 by tasks.existing { wraps(alpineExecutableAmd64) } +@Suppress("unused") val assembleNativeWindowsAmd64 by tasks.existing { wraps(windowsExecutableAmd64) } +private fun MavenPublication.configurePublication(target: Target, configuration: Configuration) { + artifactId = "${executableSpec.publicationName.get()}-${target.targetName}" + pom { + name = "${executableSpec.publicationName.get()}-${target.targetName}" + url = executableSpec.website + artifact(configuration.singleFile) { + classifier = null + extension = if (target.os.isWindows) "exe" else "bin" + builtBy(configuration) + } + description = + executableSpec.documentationName.map { name -> + buildString { + append("Native $name executable for ${target.os.displayName}/${target.arch}") + if (target.musl) { + append(" and statically linked to musl") + } + append(".") + } + } + } +} + publishing { publications { // need to put in `afterEvaluate` because `artifactId` cannot be set lazily. project.afterEvaluate { create("macExecutableAmd64") { - artifactId = "${executableSpec.publicationName.get()}-macos-amd64" - artifact(stagedMacAmd64Executable.singleFile) { - classifier = null - extension = "bin" - builtBy(stagedMacAmd64Executable) - } - pom { - name = "${executableSpec.publicationName.get()}-macos-amd64" - url = executableSpec.website - description = - executableSpec.documentationName.map { name -> - "Native $name executable for macOS/amd64." - } - } + configurePublication(Target.MacosAmd64, stagedMacAmd64Executable) } create("macExecutableAarch64") { - artifactId = "${executableSpec.publicationName.get()}-macos-aarch64" - artifact(stagedMacAarch64Executable.singleFile) { - classifier = null - extension = "bin" - builtBy(stagedMacAarch64Executable) - } - pom { - name = "${executableSpec.publicationName.get()}-macos-aarch64" - url = executableSpec.website - description = - executableSpec.documentationName.map { name -> - "Native $name executable for macOS/aarch64." - } - } + configurePublication(Target.MacosAarch64, stagedMacAarch64Executable) } create("linuxExecutableAmd64") { - artifactId = "${executableSpec.publicationName.get()}-linux-amd64" - artifact(stagedLinuxAmd64Executable.singleFile) { - classifier = null - extension = "bin" - builtBy(stagedLinuxAmd64Executable) - } - pom { - name = "${executableSpec.publicationName.get()}-linux-amd64" - url = executableSpec.website - description = - executableSpec.documentationName.map { name -> - "Native $name executable for linux/amd64." - } - } + configurePublication(Target.LinuxAmd64, stagedLinuxAmd64Executable) } create("linuxExecutableAarch64") { - artifactId = "${executableSpec.publicationName.get()}-linux-aarch64" - artifact(stagedLinuxAarch64Executable.singleFile) { - classifier = null - extension = "bin" - builtBy(stagedLinuxAarch64Executable) - } - pom { - name = "${executableSpec.publicationName.get()}-linux-aarch64" - url = executableSpec.website - description = - executableSpec.documentationName.map { name -> - "Native $name executable for linux/aarch64." - } - } + configurePublication(Target.LinuxAarch64, stagedLinuxAarch64Executable) } create("alpineLinuxExecutableAmd64") { - artifactId = "${executableSpec.publicationName.get()}-alpine-linux-amd64" - artifact(stagedAlpineLinuxAmd64Executable.singleFile) { - classifier = null - extension = "bin" - builtBy(stagedAlpineLinuxAmd64Executable) - } - pom { - name = "${executableSpec.publicationName.get()}-alpine-linux-amd64" - url = executableSpec.website - description = - executableSpec.documentationName.map { name -> - "Native $name executable for linux/amd64 and statically linked to musl." - } - } + configurePublication(Target.AlpineLinuxAmd64, stagedAlpineLinuxAmd64Executable) } create("windowsExecutableAmd64") { - artifactId = "${executableSpec.publicationName.get()}-windows-amd64" - artifact(stagedWindowsAmd64Executable.singleFile) { - classifier = null - extension = "exe" - builtBy(stagedWindowsAmd64Executable) - } - pom { - name = "${executableSpec.publicationName.get()}-windows-amd64" - url = executableSpec.website - description = - executableSpec.documentationName.map { name -> - "Native $name executable for windows/amd64." - } - } + configurePublication(Target.WindowsAmd64, stagedWindowsAmd64Executable) } } } diff --git a/buildSrc/src/main/kotlin/pklNativeLifecycle.gradle.kts b/buildSrc/src/main/kotlin/pklNativeLifecycle.gradle.kts index b6cc60136..60d7c047a 100644 --- a/buildSrc/src/main/kotlin/pklNativeLifecycle.gradle.kts +++ b/buildSrc/src/main/kotlin/pklNativeLifecycle.gradle.kts @@ -52,68 +52,37 @@ val assembleNative by throw GradleException("Cross-arch builds are not supported on ${buildInfo.os.name}") } - when { - buildInfo.os.isMacOsX && buildInfo.targetArch == "aarch64" -> { - wraps(assembleNativeMacOsAarch64) + val underlyingTask = + when (buildInfo.targetMachine) { + Target.MacosAarch64 -> assembleNativeMacOsAarch64 + Target.MacosAmd64 -> assembleNativeMacOsAmd64 + Target.LinuxAarch64 -> assembleNativeLinuxAarch64 + Target.LinuxAmd64 -> assembleNativeLinuxAmd64 + Target.AlpineLinuxAmd64 -> assembleNativeAlpineLinuxAmd64 + Target.WindowsAmd64 -> assembleNativeWindowsAmd64 } - buildInfo.os.isMacOsX && buildInfo.targetArch == "amd64" -> { - wraps(assembleNativeMacOsAmd64) - } - buildInfo.os.isLinux && buildInfo.targetArch == "aarch64" -> { - wraps(assembleNativeLinuxAarch64) - } - buildInfo.os.isLinux && buildInfo.targetArch == "amd64" -> { - if (buildInfo.musl) wraps(assembleNativeAlpineLinuxAmd64) - else wraps(assembleNativeLinuxAmd64) - } - buildInfo.os.isWindows && buildInfo.targetArch == "amd64" -> { - wraps(assembleNativeWindowsAmd64) - } - buildInfo.musl -> { - throw GradleException("Building musl on ${buildInfo.os} is not supported") - } - else -> { - throw GradleException( - "Unsupported os/arch pair: ${buildInfo.os.name}/${buildInfo.targetArch}" - ) - } - } + wraps(underlyingTask) } val testNative by tasks.registering { group = "verification" + @Suppress("DuplicatedCode") if (!buildInfo.isCrossArchSupported && buildInfo.isCrossArch) { throw GradleException("Cross-arch builds are not supported on ${buildInfo.os.name}") } - when { - buildInfo.os.isMacOsX && buildInfo.targetArch == "aarch64" -> { - dependsOn(testNativeMacOsAarch64) + val underlyingTask = + when (buildInfo.targetMachine) { + Target.MacosAarch64 -> testNativeMacOsAarch64 + Target.MacosAmd64 -> testNativeMacOsAmd64 + Target.LinuxAarch64 -> testNativeLinuxAarch64 + Target.LinuxAmd64 -> testNativeLinuxAmd64 + Target.AlpineLinuxAmd64 -> testNativeAlpineLinuxAmd64 + Target.WindowsAmd64 -> testNativeWindowsAmd64 } - buildInfo.os.isMacOsX && buildInfo.targetArch == "amd64" -> { - dependsOn(testNativeMacOsAmd64) - } - buildInfo.os.isLinux && buildInfo.targetArch == "aarch64" -> { - dependsOn(testNativeLinuxAarch64) - } - buildInfo.os.isLinux && buildInfo.targetArch == "amd64" -> { - if (buildInfo.musl) dependsOn(testNativeAlpineLinuxAmd64) - else dependsOn(testNativeLinuxAmd64) - } - buildInfo.os.isWindows && buildInfo.targetArch == "amd64" -> { - dependsOn(testNativeWindowsAmd64) - } - buildInfo.musl -> { - throw GradleException("Building musl on ${buildInfo.os} is not supported") - } - else -> { - throw GradleException( - "Unsupported os/arch pair: ${buildInfo.os.name}/${buildInfo.targetArch}" - ) - } - } + wraps(underlyingTask) } val checkNative by diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 750ba6e8a..7a3d7a58b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -28,6 +28,7 @@ jimfs = "1.+" jline = "3.23.0" jmh = "1.+" jmhPlugin = "0.7.2" +jna = "5.+" jsr305 = "3.+" junit = "5.+" kotlin = "2.0.21" @@ -69,6 +70,8 @@ jimfs = { group = "com.google.jimfs", name = "jimfs", version.ref = "jimfs" } jlineReader = { group = "org.jline", name = "jline-reader", version.ref = "jline" } jlineTerminal = { group = "org.jline", name = "jline-terminal", version.ref = "jline" } jlineTerminalJansi = { group = "org.jline", name = "jline-terminal-jansi", version.ref = "jline" } +jna = { group = "net.java.dev.jna", name = "jna", version.ref = "jna" } +jnaPlatform = { group = "net.java.dev.jna", name = "jna-platform", version.ref = "jna" } jsr305 = { group = "com.google.code.findbugs", name = "jsr305", version.ref = "jsr305" } junitApi = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" } junitEngine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" } diff --git a/libpkl/gradle.lockfile b/libpkl/gradle.lockfile index 90ef20152..0bf3ac50d 100644 --- a/libpkl/gradle.lockfile +++ b/libpkl/gradle.lockfile @@ -1,41 +1,41 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. -com.github.ajalt.clikt:clikt-core-jvm:5.0.3=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.github.ajalt.clikt:clikt-core:5.0.3=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -com.github.ajalt.clikt:clikt-jvm:5.0.3=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.github.ajalt.clikt:clikt-markdown-jvm:5.0.3=runtimeClasspath,testRuntimeClasspath -com.github.ajalt.clikt:clikt-markdown:5.0.3=runtimeClasspath,testRuntimeClasspath -com.github.ajalt.clikt:clikt:5.0.3=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -com.github.ajalt.colormath:colormath-jvm:3.6.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.github.ajalt.colormath:colormath:3.6.0=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -com.github.ajalt.mordant:mordant-core-jvm:3.0.1=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.github.ajalt.mordant:mordant-core:3.0.1=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -com.github.ajalt.mordant:mordant-jvm-ffm-jvm:3.0.1=runtimeClasspath,testRuntimeClasspath -com.github.ajalt.mordant:mordant-jvm-ffm:3.0.1=runtimeClasspath,testRuntimeClasspath -com.github.ajalt.mordant:mordant-jvm-graal-ffi-jvm:3.0.1=runtimeClasspath,testRuntimeClasspath -com.github.ajalt.mordant:mordant-jvm-graal-ffi:3.0.1=runtimeClasspath,testRuntimeClasspath -com.github.ajalt.mordant:mordant-jvm-jna-jvm:3.0.1=runtimeClasspath,testRuntimeClasspath -com.github.ajalt.mordant:mordant-jvm-jna:3.0.1=runtimeClasspath,testRuntimeClasspath -com.github.ajalt.mordant:mordant-jvm:3.0.1=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.github.ajalt.mordant:mordant-markdown-jvm:3.0.1=runtimeClasspath,testRuntimeClasspath -com.github.ajalt.mordant:mordant-markdown:3.0.1=runtimeClasspath,testRuntimeClasspath -com.github.ajalt.mordant:mordant:3.0.1=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -net.java.dev.jna:jna-platform:5.17.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -net.java.dev.jna:jna:5.14.0=runtimeClasspath -net.java.dev.jna:jna:5.17.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata -org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.graalvm.polyglot:polyglot:24.1.2=compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.graalvm.sdk:collections:24.1.2=compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.graalvm.sdk:graal-sdk:24.1.2=compileClasspath,compileOnlyDependenciesMetadata,runtimeClasspath,testRuntimeClasspath -org.graalvm.sdk:jniutils:24.1.2=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.graalvm.sdk:nativeimage:24.1.2=compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.graalvm.sdk:word:24.1.2=compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.graalvm.truffle:truffle-api:24.1.2=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.graalvm.truffle:truffle-compiler:24.1.2=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.graalvm.truffle:truffle-runtime:24.1.2=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +com.github.ajalt.clikt:clikt-core-jvm:5.0.3=compileClasspath,nativeTestCompileClasspath,nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +com.github.ajalt.clikt:clikt-core:5.0.3=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +com.github.ajalt.clikt:clikt-jvm:5.0.3=compileClasspath,nativeTestCompileClasspath,nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +com.github.ajalt.clikt:clikt-markdown-jvm:5.0.3=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +com.github.ajalt.clikt:clikt-markdown:5.0.3=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +com.github.ajalt.clikt:clikt:5.0.3=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +com.github.ajalt.colormath:colormath-jvm:3.6.0=compileClasspath,nativeTestCompileClasspath,nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +com.github.ajalt.colormath:colormath:3.6.0=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +com.github.ajalt.mordant:mordant-core-jvm:3.0.1=compileClasspath,nativeTestCompileClasspath,nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +com.github.ajalt.mordant:mordant-core:3.0.1=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +com.github.ajalt.mordant:mordant-jvm-ffm-jvm:3.0.1=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +com.github.ajalt.mordant:mordant-jvm-ffm:3.0.1=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +com.github.ajalt.mordant:mordant-jvm-graal-ffi-jvm:3.0.1=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +com.github.ajalt.mordant:mordant-jvm-graal-ffi:3.0.1=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +com.github.ajalt.mordant:mordant-jvm-jna-jvm:3.0.1=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +com.github.ajalt.mordant:mordant-jvm-jna:3.0.1=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +com.github.ajalt.mordant:mordant-jvm:3.0.1=compileClasspath,nativeTestCompileClasspath,nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +com.github.ajalt.mordant:mordant-markdown-jvm:3.0.1=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +com.github.ajalt.mordant:mordant-markdown:3.0.1=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +com.github.ajalt.mordant:mordant:3.0.1=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +net.bytebuddy:byte-buddy:1.15.11=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +net.java.dev.jna:jna-platform:5.17.0=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath +net.java.dev.jna:jna:5.14.0=runtimeClasspath,testRuntimeClasspath +net.java.dev.jna:jna:5.17.0=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath +org.apiguardian:apiguardian-api:1.1.2=nativeTestCompileClasspath,nativeTestImplementationDependenciesMetadata,testCompileClasspath,testImplementationDependenciesMetadata,testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata +org.assertj:assertj-core:3.27.3=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.graalvm.polyglot:polyglot:24.1.2=compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.graalvm.sdk:collections:24.1.2=compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.graalvm.sdk:graal-sdk:24.1.2=compileClasspath,compileOnlyDependenciesMetadata,nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +org.graalvm.sdk:jniutils:24.1.2=compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.graalvm.sdk:nativeimage:24.1.2=compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.graalvm.sdk:word:24.1.2=compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.graalvm.truffle:truffle-api:24.1.2=compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.graalvm.truffle:truffle-compiler:24.1.2=compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.graalvm.truffle:truffle-runtime:24.1.2=compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath org.jetbrains.kotlin:kotlin-build-common:2.0.21=kotlinBuildToolsApiClasspath org.jetbrains.kotlin:kotlin-build-tools-api:2.0.21=kotlinBuildToolsApiClasspath @@ -47,35 +47,36 @@ org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21=kotlinBuildToolsApiClasspat org.jetbrains.kotlin:kotlin-klib-commonizer-embeddable:2.0.21=kotlinKlibCommonizerClasspath org.jetbrains.kotlin:kotlin-native-prebuilt:2.0.21=kotlinNativeBundleConfiguration org.jetbrains.kotlin:kotlin-reflect:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath -org.jetbrains.kotlin:kotlin-script-runtime:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17,kotlinKlibCommonizerClasspath -org.jetbrains.kotlin:kotlin-scripting-common:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17 -org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17 -org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17 -org.jetbrains.kotlin:kotlin-scripting-jvm:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17 -org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.jetbrains.kotlin:kotlin-stdlib:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.jetbrains.kotlin:kotlin-script-runtime:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathNativeTest,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17,kotlinKlibCommonizerClasspath +org.jetbrains.kotlin:kotlin-scripting-common:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathNativeTest,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17 +org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathNativeTest,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17 +org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathNativeTest,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17 +org.jetbrains.kotlin:kotlin-scripting-jvm:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathNativeTest,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17 +org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathNativeTest,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17,kotlinKlibCommonizerClasspath,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath -org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.jetbrains:markdown-jvm:0.7.3=runtimeClasspath,testRuntimeClasspath -org.jetbrains:markdown:0.7.3=runtimeClasspath,testRuntimeClasspath -org.junit.jupiter:junit-jupiter-api:5.11.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathNativeTest,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17,kotlinKlibCommonizerClasspath,nativeTestCompileClasspath,nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.jetbrains:markdown-jvm:0.7.3=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +org.jetbrains:markdown:0.7.3=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +org.junit.jupiter:junit-jupiter-api:5.12.2=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath org.junit.jupiter:junit-jupiter-api:5.8.2=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath -org.junit.jupiter:junit-jupiter-engine:5.11.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.junit.jupiter:junit-jupiter-engine:5.12.2=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,testRuntimeClasspath org.junit.jupiter:junit-jupiter-engine:5.8.2=testJdk17RuntimeClasspath -org.junit.jupiter:junit-jupiter-params:5.11.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.junit.jupiter:junit-jupiter-params:5.12.2=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath org.junit.jupiter:junit-jupiter-params:5.8.2=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath org.junit.jupiter:junit-jupiter:5.8.2=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath -org.junit.platform:junit-platform-commons:1.12.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.junit.platform:junit-platform-commons:1.12.2=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath org.junit.platform:junit-platform-commons:1.8.2=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath -org.junit.platform:junit-platform-engine:1.12.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.junit.platform:junit-platform-engine:1.12.2=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,testRuntimeClasspath org.junit.platform:junit-platform-engine:1.8.2=testJdk17RuntimeClasspath +org.junit.platform:junit-platform-launcher:1.12.2=nativeTestRuntimeClasspath org.junit.platform:junit-platform-launcher:1.8.2=testJdk17RuntimeClasspath -org.junit:junit-bom:5.11.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.junit:junit-bom:5.12.2=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath org.junit:junit-bom:5.8.2=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath -org.msgpack:msgpack-core:0.9.8=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.msgpack:msgpack-core:0.9.8=compileClasspath,implementationDependenciesMetadata,nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath org.opentest4j:opentest4j:1.2.0=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath -org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath -org.organicdesign:Paguro:3.10.3=runtimeClasspath,testRuntimeClasspath -org.snakeyaml:snakeyaml-engine:2.9=runtimeClasspath,testRuntimeClasspath -empty=annotationProcessor,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDefExtensions,shadow,signatures,sourcesJar,stagedAlpineLinuxAmd64NativeLibrary,stagedLinuxAarch64NativeLibrary,stagedLinuxAmd64NativeLibrary,stagedMacAarch64NativeLibrary,stagedMacAmd64NativeLibrary,stagedWindowsAmd64NativeLibrary,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testJdk17AnnotationProcessor,testJdk17ApiDependenciesMetadata,testJdk17CompileOnlyDependenciesMetadata,testJdk17IntransitiveDependenciesMetadata,testJdk17KotlinScriptDefExtensions,testKotlinScriptDefExtensions +org.opentest4j:opentest4j:1.3.0=nativeTestCompileClasspath,nativeTestImplementation,nativeTestImplementationDependenciesMetadata,nativeTestRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath +org.organicdesign:Paguro:3.10.3=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +org.snakeyaml:snakeyaml-engine:2.9=nativeTestImplementation,nativeTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath +empty=annotationProcessor,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDefExtensions,nativeTestAnnotationProcessor,nativeTestApiDependenciesMetadata,nativeTestCompileOnlyDependenciesMetadata,nativeTestIntransitiveDependenciesMetadata,nativeTestKotlinScriptDefExtensions,sourcesJar,stagedAlpineLinuxAmd64NativeLibrary,stagedLinuxAarch64NativeLibrary,stagedLinuxAmd64NativeLibrary,stagedMacAarch64NativeLibrary,stagedMacAmd64NativeLibrary,stagedWindowsAmd64NativeLibrary,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testJdk17AnnotationProcessor,testJdk17ApiDependenciesMetadata,testJdk17CompileOnlyDependenciesMetadata,testJdk17IntransitiveDependenciesMetadata,testJdk17KotlinScriptDefExtensions,testKotlinScriptDefExtensions diff --git a/libpkl/libpkl.gradle.kts b/libpkl/libpkl.gradle.kts index df1a8eebb..388fd4002 100644 --- a/libpkl/libpkl.gradle.kts +++ b/libpkl/libpkl.gradle.kts @@ -1,18 +1,18 @@ /* -* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* https://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ @file:Suppress("unused") plugins { @@ -29,6 +29,14 @@ val stagedLinuxAarch64NativeLibrary: Configuration by configurations.creating val stagedAlpineLinuxAmd64NativeLibrary: Configuration by configurations.creating val stagedWindowsAmd64NativeLibrary: Configuration by configurations.creating +val nativeTestSourceSet = sourceSets.create("nativeTest") + +val nativeTestImplementation: Configuration by + configurations.getting { extendsFrom(configurations.testImplementation.get()) } + +val nativeTestRuntimeOnly: Configuration by + configurations.getting { extendsFrom(configurations.testRuntimeOnly.get()) } + dependencies { compileOnly(libs.graalSdk) @@ -41,268 +49,202 @@ dependencies { implementation(libs.truffleApi) implementation(libs.truffleRuntime) - testImplementation(projects.pklCommonsTest) - testImplementation("net.java.dev.jna:jna:5.17.0") - testImplementation("net.java.dev.jna:jna-platform:5.17.0") - - fun sharedLibrary(osAndArch: String) = files(nativeLibraryOutputFiles(osAndArch)) - - stagedMacAarch64NativeLibrary(sharedLibrary("macos-aarch64")) - stagedMacAmd64NativeLibrary(sharedLibrary("macos-amd64")) - stagedLinuxAmd64NativeLibrary(sharedLibrary("linux-amd64")) - stagedLinuxAarch64NativeLibrary(sharedLibrary("linux-aarch64")) - stagedAlpineLinuxAmd64NativeLibrary(sharedLibrary("alpine-linux-amd64")) - stagedWindowsAmd64NativeLibrary(sharedLibrary("windows-amd64.exe")) + nativeTestImplementation(projects.pklCommonsTest) + nativeTestImplementation(libs.jna) + nativeTestImplementation(libs.jnaPlatform) + nativeTestRuntimeOnly("org.junit.platform:junit-platform-launcher") } -private fun extension(osAndArch: String) = - when (osAndArch.split("-").dropWhile { it == "alpine" }.first()) { - "linux" -> "so" - "macos" -> "dylib" - "unix" -> "so" - "windows" -> "dll" - else -> { - throw StopExecutionException( - "Don't know how to construct library extension for OS: ${osAndArch.split("-").first()}" - ) - } - } +private fun NativeImageBuild.configure(target: Target) { + arch = target.arch -private fun nativeLibraryOutputFiles(osAndArch: String) = - project.layout.buildDirectory.dir("libs/$osAndArch").map { outputDir -> - // TODO(kushal): dashes/underscores for library files? C convention assumes underscores. - val libraryName = "libpkl_internal" - val libraryOutputFiles = - listOf( - "lib${libraryName}.${extension(osAndArch)}", - "${libraryName}_dynamic.h", - "${libraryName}.h", - - // GraalVM shared headers. - "graal_isolate.h", - "graal_isolate_dynamic.h", - ) - - libraryOutputFiles.map { filename -> outputDir.file(filename) } + if (target.arch == Target.Arch.AARCH64) { + dependsOn(":installGraalVmAarch64") + } else { + dependsOn(":installGraalVmAmd64") } -private fun NativeImageBuild.setOutputFiles(osAndArch: String) { - outputs.files(nativeLibraryOutputFiles(osAndArch)) -} - -private fun NativeImageBuild.amd64() { - arch = Architecture.AMD64 - dependsOn(":installGraalVmAmd64") -} - -private fun NativeImageBuild.aarch64() { - arch = Architecture.AARCH64 - dependsOn(":installGraalVmAarch64") -} + outputDir = target.outputDir + outputName = "libpkl_internal" -private fun NativeImageBuild.setClasspath() { classpath.from(sourceSets.main.map { it.output }) classpath.from( project(":pkl-commons-cli").extensions.getByType(SourceSetContainer::class)["svm"].output ) classpath.from(configurations.runtimeClasspath) + + sharedLibrary = true } -val macNativeLibraryAmd64 by - tasks.registering(NativeImageBuild::class) { - outputDir = project.layout.buildDirectory.dir("libs/macos-amd64") - imageName = "libpkl_internal" - mainClass = "org.pkl.libpkl.LibPkl" - amd64() - setClasspath() - extraNativeImageArgs = listOf("--shared") - - setOutputFiles("macos-amd64") - } +val macNativeImageAmd64 by + tasks.registering(NativeImageBuild::class) { configure(Target.MacosAmd64) } -val macNativeLibraryAarch64 by - tasks.registering(NativeImageBuild::class) { - outputDir = project.layout.buildDirectory.dir("libs/macos-aarch64") - imageName = "libpkl_internal" - mainClass = "org.pkl.libpkl.LibPkl" - aarch64() - setClasspath() - extraNativeImageArgs = listOf("--shared") - - setOutputFiles("macos-aarch64") - } +val macNativeImageAarch64 by + tasks.registering(NativeImageBuild::class) { configure(Target.MacosAarch64) } -val linuxNativeLibraryAmd64 by - tasks.registering(NativeImageBuild::class) { - outputDir = project.layout.buildDirectory.dir("libs/linux-amd64") - imageName = "libpkl_internal" - mainClass = "org.pkl.libpkl.LibPkl" - amd64() - setClasspath() - extraNativeImageArgs = listOf("--shared") - - setOutputFiles("linux-amd64") - } +val linuxNativeImageAmd64 by + tasks.registering(NativeImageBuild::class) { configure(Target.LinuxAmd64) } -val linuxNativeLibraryAarch64 by +val linuxNativeImageAarch64 by tasks.registering(NativeImageBuild::class) { - outputDir = project.layout.buildDirectory.dir("libs/linux-aarch64") - imageName = "libpkl_internal" - mainClass = "org.pkl.libpkl.LibPkl" - aarch64() - setClasspath() - + configure(Target.LinuxAarch64) extraNativeImageArgs = listOf( - "--shared", // Ensure compatibility for kernels with page size set to 4k, 16k and 64k // (e.g. Raspberry Pi 5, Asahi Linux) - "-H:PageSize=65536", + "-H:PageSize=65536" ) - - setOutputFiles("linux-aarch64") } -val alpineNativeLibraryAmd64 by +val alpineNativeImageAmd64 by tasks.registering(NativeImageBuild::class) { - outputDir = project.layout.buildDirectory.dir("libs/alpine-linux-amd64") - imageName = "libpkl_internal" - mainClass = "org.pkl.libpkl.LibPkl" - amd64() - setClasspath() - + configure(Target.AlpineLinuxAmd64) extraNativeImageArgs = listOf( - "--shared", // TODO(kushal): https://github.com/oracle/graal/issues/3053 - "--libc=musl", + "--libc=musl" ) - - setOutputFiles("alpine-linux-amd64") } -val windowsNativeLibraryAmd64 by +val windowsNativeImageAmd64 by tasks.registering(NativeImageBuild::class) { - outputDir = project.layout.buildDirectory.dir("libs/windows-amd64") - imageName = "libpkl_internal" - mainClass = "org.pkl.libpkl.LibPkl" - amd64() - setClasspath() - extraNativeImageArgs = listOf("--shared", "-Dfile.encoding=UTF-8") - - setOutputFiles("windows-amd64") + configure(Target.WindowsAmd64) + extraNativeImageArgs = listOf("-Dfile.encoding=UTF-8") } -val assembleNative by - tasks.existing { - // TODO(kushal): Remove this later. Only exists to debug output files are in the graph. - finalizedBy(validateNativeLibraryFilestasks) - } +val Target.outputDir + get() = layout.buildDirectory.dir("native-libs/$targetName") -// TODO(kushal): Remove this later. Only exists to debug output files are in the graph. -val validateNativeLibraryFilestasks by - tasks.registering { - val assembleTasks = mutableSetOf>() +fun Exec.configureCompile(target: Target) { + val projectDir = project.layout.projectDirectory.asFile.path - when { - buildInfo.os.isMacOsX -> { - assembleTasks.add(macNativeLibraryAmd64) - if (buildInfo.arch == "aarch64") { - assembleTasks.add(macNativeLibraryAarch64) - } - } + workingDir = target.outputDir.get().asFile - buildInfo.os.isWindows -> { - assembleTasks.add(windowsNativeLibraryAmd64) - } + enabled = buildInfo.targetMachine == target - buildInfo.os.isLinux && buildInfo.arch == "aarch64" -> { - assembleTasks.add(linuxNativeLibraryAarch64) - } + val outputFile = "libpkl.${buildInfo.os.sharedLibrarySuffix}" - buildInfo.os.isLinux && buildInfo.arch == "amd64" -> { - assembleTasks.add(linuxNativeLibraryAmd64) - if (buildInfo.hasMuslToolchain) { - assembleTasks.add(alpineNativeLibraryAmd64) + executable = + when { + target.musl -> "musl-gcc" + else -> "gcc" + } + + argumentProviders.add( + CommandLineArgumentProvider { + buildList { + add("-shared") + add("-o") + add(outputFile) + if (buildInfo.isReleaseBuild) { + add("-O2") + } + add("-g") + add("-Wall") + add("$projectDir/src/main/c/pkl.c") + add("-I$projectDir/src/main/c") + add("-I${target.outputDir.get()}") + add("-L${target.outputDir.get()}") + add("-fPIC") + add("-lpkl_internal") + if (target.os.isMacOS) { + val archStr = + when (target.arch) { + Target.Arch.AMD64 -> "x86_64" + Target.Arch.AARCH64 -> "arm64" + } + add("-target") + add("$archStr-apple-darwin") } } } + ) - dependsOn(assembleTasks) - - doLast { - for (taskProvider in assembleTasks) { - val task = taskProvider.get() - val outputFiles = task.outputs.files.files + outputs.files(target.outputDir.map { it.files(outputFile, "pkl.h") }) - println("==== Validating Native Library Files Exist ====") - println("${task.name} outputs:") - outputFiles.forEach { file -> println("- ${file.absolutePath} (exists: ${file.exists()})") } - } + doLast { + copy { + from(file("src/c/pkl.h")) + into(target.outputDir) } } - -// Expose underlying task's outputs -private fun Task.wraps(other: TaskProvider) { - dependsOn(other) - outputs.files(other) } -val assembleNativeMacOsAarch64 by tasks.existing { wraps(macNativeLibraryAarch64) } - -val assembleNativeMacOsAmd64 by tasks.existing { wraps(macNativeLibraryAmd64) } - -val assembleNativeLinuxAarch64 by tasks.existing { wraps(linuxNativeLibraryAarch64) } +val macCCompileAarch64 by + tasks.registering(Exec::class) { + dependsOn(macNativeImageAarch64) + configureCompile(Target.MacosAarch64) + } -val assembleNativeLinuxAmd64 by tasks.existing { wraps(linuxNativeLibraryAmd64) } +val macCCompileAmd64 by + tasks.registering(Exec::class) { + dependsOn(macNativeImageAmd64) + configureCompile(Target.MacosAmd64) + } -val assembleNativeAlpineLinuxAmd64 by tasks.existing { wraps(alpineNativeLibraryAmd64) } +val linuxCCompileAmd64 by + tasks.registering(Exec::class) { + dependsOn(linuxNativeImageAmd64) + configureCompile(Target.LinuxAmd64) + } -val assembleNativeWindowsAmd64 by tasks.existing { wraps(windowsNativeLibraryAmd64) } +val linuxCCompileAarch64 by + tasks.registering(Exec::class) { + dependsOn(linuxNativeImageAarch64) + configureCompile(Target.LinuxAarch64) + } -val macNativeFullLibraryAarch64 by +val alpineLinuxCCompileAmd64 by tasks.registering(Exec::class) { - dependsOn(macNativeLibraryAarch64) - - val libraryOutputDir = project.layout.buildDirectory.dir("libs/macos-aarch64").get() - val projectDir = project.layout.projectDirectory.asFile.path - - workingDir = libraryOutputDir.asFile - - // TODO: Make this portable. - commandLine( - "/usr/bin/cc", - "-shared", - "-o", - "libpkl.dylib", - "$projectDir/src/main/c/pkl.c", - "-I$projectDir/src/main/c", - "-I$libraryOutputDir", - "-L$libraryOutputDir", - "-lpkl_internal", - ) + dependsOn(alpineNativeImageAmd64) + configureCompile(Target.AlpineLinuxAmd64) } -val macNativeFullLibraryAarch64Copy by +val windowsCCompileAmd64 by tasks.registering(Exec::class) { - dependsOn(macNativeFullLibraryAarch64) + dependsOn(windowsNativeImageAmd64) + configureCompile(Target.WindowsAmd64) + } - val libraryOutputDir = project.layout.buildDirectory.dir("libs/macos-aarch64").get() - val projectDir = project.layout.projectDirectory.asFile.path +tasks.assembleNativeMacOsAarch64 { dependsOn(macCCompileAarch64) } - workingDir = libraryOutputDir.asFile +tasks.assembleNativeMacOsAmd64 { dependsOn(macCCompileAmd64) } - commandLine("cp", "$projectDir/src/main/c/pkl.h", libraryOutputDir) - } +tasks.assembleNativeLinuxAmd64 { dependsOn(linuxCCompileAmd64) } -tasks.withType { - dependsOn(macNativeFullLibraryAarch64Copy) +tasks.assembleNativeLinuxAarch64 { dependsOn(linuxCCompileAarch64) } - val nativeLibsDir = project.layout.buildDirectory.dir("libs/macos-aarch64").get().asFile - jvmArgs("-Djna.library.path=${nativeLibsDir.absolutePath}") +tasks.assembleNativeAlpineLinuxAmd64 { dependsOn(alpineLinuxCCompileAmd64) } - useJUnitPlatform() -} +tasks.assembleNativeWindowsAmd64 { dependsOn(windowsCCompileAmd64) } + +val nativeTest by + tasks.registering(Test::class) { + dependsOn(tasks.assembleNative) + + description = "Test native libraries" + group = "verification" + + testClassesDirs = nativeTestSourceSet.output.classesDirs + classpath = nativeTestSourceSet.runtimeClasspath + + // It's not good enough to just provide `jna.library.path` on Linux; need to also provide + // `LD_LIBRARY_PATH` or `java.library.path` so that transitive libraries can be loaded. + jvmArgumentProviders.add( + CommandLineArgumentProvider { + listOf( + "-Djna.library.path=" + buildInfo.targetMachine.outputDir.get().asFile.absolutePath, + "-Djava.library.path=" + buildInfo.targetMachine.outputDir.get().asFile.absolutePath, + ) + } + ) + + environment("LD_LIBRARY_PATH", buildInfo.targetMachine.outputDir.get().asFile.absolutePath) + + useJUnitPlatform() + } + +tasks.testNative { dependsOn(nativeTest) } private val licenseHeaderFile by lazy { rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt") diff --git a/libpkl/src/main/java/org/pkl/libpkl/LibPkl.java b/libpkl/src/main/java/org/pkl/libpkl/LibPkl.java index 409afce75..1857d0111 100644 --- a/libpkl/src/main/java/org/pkl/libpkl/LibPkl.java +++ b/libpkl/src/main/java/org/pkl/libpkl/LibPkl.java @@ -79,18 +79,4 @@ public static void handleSendMessageToNative(byte[] bytes) { cb.invoke(bytes.length, pin.addressOfArrayElement(0), LibPkl.userData); } } - - /** - * Needed otherwise we see the following error: - * - *

Error: Method 'org.pkl.libpkl.LibPkl.main' is declared as the main entry point but it can - * not be found. Make sure that class 'org.pkl.libpkl.LibPkl' is on the classpath and that method - * 'main(String[])' exists in that class. - * - *

TODO: Clean this up once merged onto a feature-branch - * - *

This is because we are passing a main class to native-image using the -H:Class= arg. That - * argument is optional and not required when building a shared library. - */ - public static void main(String[] argv) {} } diff --git a/libpkl/src/test/kotlin/org/pkl/libpkl/JNATestClient.kt b/libpkl/src/nativeTest/kotlin/org/pkl/libpkl/JNATestClient.kt similarity index 100% rename from libpkl/src/test/kotlin/org/pkl/libpkl/JNATestClient.kt rename to libpkl/src/nativeTest/kotlin/org/pkl/libpkl/JNATestClient.kt diff --git a/libpkl/src/test/kotlin/org/pkl/libpkl/LibPklLibrary.kt b/libpkl/src/nativeTest/kotlin/org/pkl/libpkl/LibPklLibrary.kt similarity index 97% rename from libpkl/src/test/kotlin/org/pkl/libpkl/LibPklLibrary.kt rename to libpkl/src/nativeTest/kotlin/org/pkl/libpkl/LibPklLibrary.kt index 2c54ac666..5a29c2ce3 100644 --- a/libpkl/src/test/kotlin/org/pkl/libpkl/LibPklLibrary.kt +++ b/libpkl/src/nativeTest/kotlin/org/pkl/libpkl/LibPklLibrary.kt @@ -20,6 +20,7 @@ import com.sun.jna.Library import com.sun.jna.Native import com.sun.jna.Pointer +@Suppress("FunctionName") interface LibPklLibrary : Library { companion object { val INSTANCE: LibPklLibrary = Native.load("pkl", LibPklLibrary::class.java) diff --git a/libpkl/src/test/kotlin/org/pkl/libpkl/MessagePackDebugRenderer.kt b/libpkl/src/nativeTest/kotlin/org/pkl/libpkl/MessagePackDebugRenderer.kt similarity index 100% rename from libpkl/src/test/kotlin/org/pkl/libpkl/MessagePackDebugRenderer.kt rename to libpkl/src/nativeTest/kotlin/org/pkl/libpkl/MessagePackDebugRenderer.kt diff --git a/libpkl/src/test/kotlin/org/pkl/libpkl/NativeTest.kt b/libpkl/src/nativeTest/kotlin/org/pkl/libpkl/NativeTest.kt similarity index 100% rename from libpkl/src/test/kotlin/org/pkl/libpkl/NativeTest.kt rename to libpkl/src/nativeTest/kotlin/org/pkl/libpkl/NativeTest.kt