diff --git a/.github/workflows/build-and-publish-bindings.yml b/.github/workflows/build-and-publish-bindings.yml index f9bc73e..d43fe31 100644 --- a/.github/workflows/build-and-publish-bindings.yml +++ b/.github/workflows/build-and-publish-bindings.yml @@ -17,16 +17,60 @@ on: required: true jobs: build: - runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + include: + - os: ubuntu-latest + jextract_url: https://download.java.net/java/early_access/jextract/25/2/openjdk-25-jextract+2-4_linux-x64_bin.tar.gz + jextract_archive: jdk.tar.gz + os_name: linux + gradle_cmd: ./gradlew + - os: windows-latest + jextract_url: https://download.java.net/java/early_access/jextract/25/2/openjdk-25-jextract+2-4_windows-x64_bin.tar.gz + jextract_archive: jdk.tar.gz + os_name: windows + gradle_cmd: .\gradlew.bat + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - - run: wget -O $RUNNER_TEMP/jdk.tar.gz https://download.java.net/java/early_access/jextract/22/5/openjdk-22-jextract+5-33_linux-x64_bin.tar.gz - - run: tar -xf $RUNNER_TEMP/jdk.tar.gz - - run: echo "JEXTRACT_HOME=$(pwd)/jextract-22" >> $GITHUB_ENV + + - name: Download jextract (Linux) + if: matrix.os == 'ubuntu-latest' + run: wget -O $RUNNER_TEMP/${{ matrix.jextract_archive }} ${{ matrix.jextract_url }} + + - name: Download jextract (Windows) + if: matrix.os == 'windows-latest' + run: | + Invoke-WebRequest -Uri "${{ matrix.jextract_url }}" -OutFile "$env:RUNNER_TEMP\${{ matrix.jextract_archive }}" + shell: pwsh + + - name: Extract jextract (Linux) + if: matrix.os == 'ubuntu-latest' + run: tar -xf $RUNNER_TEMP/${{ matrix.jextract_archive }} + + - name: Extract jextract (Windows) + if: matrix.os == 'windows-latest' + run: tar -xf $env:RUNNER_TEMP\${{ matrix.jextract_archive }} + shell: pwsh + + - name: Set JEXTRACT_HOME (Linux) + if: matrix.os == 'ubuntu-latest' + run: echo "JEXTRACT_HOME=$(pwd)/jextract-25" >> $GITHUB_ENV + + - name: Set JEXTRACT_HOME (Windows) + if: matrix.os == 'windows-latest' + run: echo "JEXTRACT_HOME=$((Get-Location).Path)\jextract-25" >> $env:GITHUB_ENV + shell: pwsh + - uses: actions/setup-java@v4 id: install-jdk with: - java-version: 21 + java-version: 25 distribution: temurin - name: Setup Gradle @@ -35,25 +79,27 @@ jobs: gradle-version: wrapper - name: Download natives - run: ./gradlew -PwgpuVersion=${{ inputs.wgpuVersion }} :natives:download + run: ${{ matrix.gradle_cmd }} "-PwgpuVersion=${{ inputs.wgpuVersion }}" "-Pos=${{ matrix.os_name }}" :natives:download - name: Extract natives - run: ./gradlew -PwgpuVersion=${{ inputs.wgpuVersion }} :natives:unzip + run: ${{ matrix.gradle_cmd }} "-PwgpuVersion=${{ inputs.wgpuVersion }}" "-Pos=${{ matrix.os_name }}" :natives:unzip - name: Copy headers - run: ./gradlew -PwgpuVersion=${{ inputs.wgpuVersion }} ':natives:copyWgpuHeaders' + run: ${{ matrix.gradle_cmd }} "-PwgpuVersion=${{ inputs.wgpuVersion }}" "-Pos=${{ matrix.os_name }}" ':natives:copyWgpuHeaders' - name: Generate bindings - run: ./gradlew -PwgpuVersion=${{ inputs.wgpuVersion }} -Pjextract.home=${{ env.JEXTRACT_HOME }} :lib:bindings + run: ${{ matrix.gradle_cmd }} "--stacktrace" "-PwgpuVersion=${{ inputs.wgpuVersion }}" "-Pjextract.home=${{ env.JEXTRACT_HOME }}" :lib:bindings - name: Publish bindings as artifact uses: actions/upload-artifact@v4 with: - name: webgpu-bindings - path: lib/build/webgpu.jar + name: webgpu-bindings-${{ matrix.os_name }} + path: | + lib/build/webgpu.jar + lib/build/webgpu-sources.jar - name: Publish bindings to GH packages - run: ./gradlew -PwgpuVersion=${{ inputs.wgpuVersion }} :lib:publish + run: ${{ matrix.gradle_cmd }} "-PwgpuVersion=${{ inputs.wgpuVersion }}" :lib:publish env: GITHUB_USER: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.PKG_PUBLISHING_AUTH_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.PKG_PUBLISHING_AUTH_TOKEN }} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e09..23449a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/lib/build.gradle b/lib/build.gradle index cc4ecb5..c63b971 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -1,10 +1,12 @@ import java.nio.file.Paths +import org.gradle.internal.os.OperatingSystem plugins { id 'java-library' id 'maven-publish' } +def isWindows = OperatingSystem.current().isWindows() def wgpuVersion = project.findProperty('wgpuVersion') configurations { @@ -20,13 +22,13 @@ def jextractHome = project.hasProperty('jextract.home') : null java { - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = JavaVersion.VERSION_25 + targetCompatibility = JavaVersion.VERSION_25 } java { toolchain { - languageVersion.set(JavaLanguageVersion.of(21)) + languageVersion.set(JavaLanguageVersion.of(25)) } } @@ -50,15 +52,17 @@ task invokeJextract(type: Exec){ doFirst { file('build/bindings').mkdirs() } + def exeName = isWindows ? 'jextract.bat' : 'jextract' if(jextractHome){ - executable Paths.get(jextractHome as String, 'bin', 'jextract') + executable Paths.get(jextractHome as String, 'bin', exeName).toString() }else{ - executable 'jextract' + executable exeName } args ( configurations.headers.files[0], '-t', 'com.myworldvw.webgpu', - '--output', 'build/bindings' + '--output', 'build/bindings', + '--library', 'wgpu_native' ) } @@ -77,8 +81,15 @@ task jextract(dependsOn: [invokeJextract, cleanupExtras]) tasks.findByName('compileJava').dependsOn jextract -task bindings(type: Copy, dependsOn: [jextract, jar]){ +task sourcesJar(type: Jar, dependsOn: jextract) { + archiveBaseName = 'webgpu' + archiveClassifier = 'sources' + from 'build/bindings' +} + +task bindings(type: Copy, dependsOn: [jextract, jar, sourcesJar]){ from jar + from sourcesJar into 'build' } @@ -90,6 +101,7 @@ publishing { version = "$wgpuVersion" artifact file("build/webgpu.jar") + artifact sourcesJar } } repositories { @@ -103,4 +115,4 @@ publishing { } } } -} \ No newline at end of file +} diff --git a/natives/build.gradle b/natives/build.gradle index 9cf46a1..19e8204 100644 --- a/natives/build.gradle +++ b/natives/build.gradle @@ -12,22 +12,27 @@ def wgpuVersion = project.findProperty('wgpuVersion') def os = project.hasProperty('os') ? project.findProperty('os') : 'linux' def arch = project.hasProperty('arch') ? project.findProperty('arch') : 'x86_64' def type = project.hasProperty('type') ? project.findProperty('type') : 'debug' +def toolchain = project.hasProperty('toolchain') ? project.findProperty('toolchain') : (os == 'windows' ? 'msvc' : null) + +// Construct the platform string based on OS +def platformString = (os == 'windows' && toolchain) ? "$os-$arch-$toolchain" : "$os-$arch" +def fileName = "wgpu-$platformString-${type}.zip" task download(type: Download) { - src "https://github.com/gfx-rs/wgpu-native/releases/download/$wgpuVersion/wgpu-$os-$arch-${type}.zip" - dest "bin/$wgpuVersion/$os-$arch-${type}.zip" + src "https://github.com/gfx-rs/wgpu-native/releases/download/$wgpuVersion/$fileName" + dest "bin/$wgpuVersion/$fileName" } task unzip(type: Copy) { - from zipTree("bin/$wgpuVersion/$os-$arch-${type}.zip") - into "bin/$wgpuVersion/$os-$arch-$type" + from zipTree("bin/$wgpuVersion/$fileName") + into "bin/$wgpuVersion/$platformString-$type" } task copyWgpuHeaders(type: Copy) { - from "bin/$wgpuVersion/$os-$arch-$type/webgpu.h" + from "bin/$wgpuVersion/$platformString-$type/include/webgpu/webgpu.h" into 'build/headers/' } artifacts { headers file('build/headers/webgpu.h') -} \ No newline at end of file +}