diff --git a/.github/workflows/opus.yml b/.github/workflows/opus.yml new file mode 100644 index 0000000..978fed0 --- /dev/null +++ b/.github/workflows/opus.yml @@ -0,0 +1,128 @@ +# Modified from https://github.com/DSharpPlus/DSharpPlus.Natives/blob/f4391784d99fb2cd0c5e37122b4aa65ec04420ba/.github/workflows/opus.yml + +name: Build opus +on: + workflow_dispatch: + +env: + COMMON_CMAKE_FLAGS: "-DOPUS_BUILD_SHARED_LIBRARY=ON -DCMAKE_BUILD_TYPE=Release" + +jobs: + build: + name: Build opus + runs-on: ${{ matrix.os }} + + outputs: + version: ${{ steps.print-version.outputs.version }} + + strategy: + fail-fast: false # Run the other two OSs even if one fails + matrix: + os: [ windows-latest, ubuntu-latest, macos-latest ] + + steps: + - name: Clone opus repo + uses: actions/checkout@v5 + with: + repository: DSharpPlus/opus # TODO update to repo owned by discord-jda + + # https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/pass-job-outputs#defining-and-using-job-outputs + - name: Checkout latest Tag + id: print-version + shell: bash + run: | + git fetch --tags + LATEST_TAG=$(git tag | grep -E ^v[0-9]+.[0-9]+.[0-9]+$ | tail -1) + git checkout "$LATEST_TAG" + echo "version=$LATEST_TAG" >> $GITHUB_OUTPUT + + - name: Build opus + shell: bash + run: | + if [[ "${{ matrix.os }}" == "windows-latest" ]]; then + for arch in x64 ARM64; do # We dont want Win32 + mkdir -p output/$arch + mkdir build-$arch + cd build-$arch + cmake $COMMON_CMAKE_FLAGS -A $arch .. + cmake --build . -j 4 --config Release + cp Release/opus.dll ../output/$arch/libopus.dll + cd .. + done + elif [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then + for arch in x64 ARM ARM64; do + mkdir -p output/$arch + mkdir build-$arch + cd build-$arch + if [[ "$arch" == "ARM64" ]]; then + sudo apt update + sudo apt install gcc-aarch64-linux-gnu + cmake $COMMON_CMAKE_FLAGS -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc .. + elif [[ "$arch" == "ARM" ]]; then + sudo apt update + sudo apt install gcc-arm-linux-gnueabihf + cmake $COMMON_CMAKE_FLAGS -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc .. + else + cmake $COMMON_CMAKE_FLAGS .. + fi + cmake --build . -j 4 + cp libopus.so ../output/$arch/libopus.so + cd .. + done + elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then + mkdir build output + cd build + cmake $COMMON_CMAKE_FLAGS "-DCMAKE_OSX_ARCHITECTURES=arm64;arm64e;x86_64;x86_64h" .. + cmake --build . -j 4 --config Release + cp libopus.dylib ../output/libopus.dylib + cd .. + fi + + - name: Publish Artifacts + uses: actions/upload-artifact@v4 + with: + name: opus-${{ matrix.os }} + path: output + + publish: + needs: [build] + runs-on: ubuntu-latest + steps: + - name: Checkout opus-java + uses: actions/checkout@v5 + + - name: Set up JDK 17 + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 17 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v5 + with: + cache-disabled: true + + - name: Download Artifacts + uses: actions/download-artifact@v5 + with: + path: temp + pattern: opus-* + merge-multiple: true + + - name: Move Artifacts + run: | + mkdir -p natives/src/main/resources/natives/win32-x86-64 + mkdir -p natives/src/main/resources/natives/win32-aarch64 + mkdir -p natives/src/main/resources/natives/linux-x86-64 + mkdir -p natives/src/main/resources/natives/linux-arm + mkdir -p natives/src/main/resources/natives/linux-aarch64 + mkdir -p natives/src/main/resources/natives/darwin + cp temp/x64/libopus.dll natives/src/main/resources/natives/win32-x86-64/libopus.dll + cp temp/ARM64/libopus.dll natives/src/main/resources/natives/win32-aarch64/libopus.dll + cp temp/x64/libopus.so natives/src/main/resources/natives/linux-x86-64/libopus.so + cp temp/ARM64/libopus.so natives/src/main/resources/natives/linux-aarch64/libopus.so + cp temp/ARM/libopus.so natives/src/main/resources/natives/linux-arm/libopus.so + cp temp/libopus.dylib natives/src/main/resources/natives/darwin/libopus.dylib + + - name: Publish artifact + run: ./gradlew build diff --git a/api/build.gradle b/api/build.gradle deleted file mode 100644 index 166fda9..0000000 --- a/api/build.gradle +++ /dev/null @@ -1,54 +0,0 @@ -plugins { - id 'java-library' - id 'maven-publish' - id 'signing' -} - -tasks.withType(JavaCompile) { - options.incremental = true - options.encoding = 'UTF-8' -} - -project.version = rootProject.version -ext.moduleName = 'opus-java-api' -archivesBaseName = moduleName - -dependencies { - implementation 'net.java.dev.jna:jna:4.4.0' -} - -task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier.set('sources') - from 'src/main/java' -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - archiveClassifier.set('javadoc') - from javadoc.destinationDir -} - -build.dependsOn sourcesJar -build.dependsOn javadocJar - -publishing { - publications { - Release(MavenPublication) { - from components.java - - groupId project.group - artifactId moduleName - version version - - artifact sourcesJar - artifact javadocJar - - generatePom(pom, "jar") - } - } -} - -if (canSign) { - signing { - sign publishing.publications.Release - } -} diff --git a/api/build.gradle.kts b/api/build.gradle.kts new file mode 100644 index 0000000..2e08cd9 --- /dev/null +++ b/api/build.gradle.kts @@ -0,0 +1,21 @@ +plugins { + `opus-java-conventions` + `opus-java-publish-conventions` +} + +java { + withJavadocJar() + withSourcesJar() +} + +dependencies { + api("net.java.dev.jna:jna:5.18.1") +} + +tasks.withType { + archiveBaseName = "opus-java-api" +} + +configurePublishing(artifactId = "opus-java-api") { + from(components["java"]) +} diff --git a/api/src/main/java/club/minnced/opus/util/OpusLibrary.java b/api/src/main/java/club/minnced/opus/util/OpusLibrary.java index f2b1d83..4c3333c 100644 --- a/api/src/main/java/club/minnced/opus/util/OpusLibrary.java +++ b/api/src/main/java/club/minnced/opus/util/OpusLibrary.java @@ -33,9 +33,8 @@ public final class OpusLibrary { platforms.put("darwin", "dylib"); platforms.put("linux-arm", "so"); platforms.put("linux-aarch64", "so"); - platforms.put("linux-x86", "so"); platforms.put("linux-x86-64", "so"); - platforms.put("win32-x86", "dll"); + platforms.put("win32-aarch64", "dll"); platforms.put("win32-x86-64", "dll"); SUPPORTED_SYSTEMS = "Supported Systems: " + platforms.keySet() + "\nCurrent Operating system: " + Platform.RESOURCE_PREFIX; } diff --git a/api/src/main/java/tomp2p/opuswrapper/Opus.java b/api/src/main/java/tomp2p/opuswrapper/Opus.java index 51cbce6..820d780 100644 --- a/api/src/main/java/tomp2p/opuswrapper/Opus.java +++ b/api/src/main/java/tomp2p/opuswrapper/Opus.java @@ -21,11 +21,11 @@ * Thomas Bocek (tbocek) *

* Completely removed all of the javadoc in this class because it was terrible and throwing errors when gradle - * attempted to create javadoc for it. If you want to see the javadoc, please refer to the the original developer's + * attempted to create javadoc for it. If you want to see the javadoc, please refer to the original developer's * Github repo. */ public interface Opus extends Library { - public static final Opus INSTANCE = (Opus)Native.loadLibrary(System.getProperty("opus.lib"), Opus.class); + public static final Opus INSTANCE = Native.load(System.getProperty("opus.lib"), Opus.class); // ****** Constants diff --git a/build.gradle b/build.gradle deleted file mode 100644 index cac6caa..0000000 --- a/build.gradle +++ /dev/null @@ -1,132 +0,0 @@ -import java.time.Duration - -plugins { - id 'java-library' - id 'maven-publish' - id 'signing' - - id("io.github.gradle-nexus.publish-plugin") version "1.1.0" -} - -group = 'club.minnced' -project.version = '1.1.1' - -def getProjectProperty(String name) { return project.properties.getOrDefault(name, null) } - -def generatePom(Object pom, String packaging) { - pom.packaging = packaging - pom.name.set(project.name) - pom.description.set("Modular java binding for opus natives.") - pom.url.set("https://github.com/discord-java/opus-java") - pom.scm { - url.set("https://github.com/discord-java/opus-java") - connection.set("scm:git:git://github.com/discord-java/opus-java") - developerConnection.set("scm:git:ssh:git@github.com:discord-java/opus-java") - } - pom.licenses { - license { - name.set("The Apache Software License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - distribution.set("repo") - } - } - pom.developers { - developer { - id.set("Minn") - name.set("Florian Spieß") - email.set("business@minn.dev") - } - } -} - -allprojects { - repositories { - mavenCentral() - } - - apply plugin: 'java-library' - apply plugin: 'maven-publish' - - group = 'club.minnced' - sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 - - ext.canSign = "signing.keyId" in properties - - task signModule(type: Sign) { - sign(file("${buildDir}/publications/Release/module.json")) - } - - task signPom(type: Sign) { - sign(file("${buildDir}/publications/Release/pom-default.xml")) - } -} - -dependencies { - api project(':api') - api project(':natives') -} - - -publishing { - publications { - Release(MavenPublication) { - from components.java - - groupId project.group - artifactId project.name - version version - - generatePom(pom, "jar") - } - } -} - -if (canSign) { - signing { - sign publishing.publications.Release - } -} - -nexusPublishing { - repositories.sonatype { - username.set(getProjectProperty("ossrhUser")) - password.set(getProjectProperty("ossrhPassword")) - stagingProfileId.set(getProjectProperty("stagingProfileId")) - } - - // Sonatype is very slow :) - connectTimeout.set(Duration.ofMinutes(1)) - clientTimeout.set(Duration.ofMinutes(10)) - - transitionCheckOptions { - maxRetries.set(100) - delayBetween.set(Duration.ofSeconds(5)) - } -} - -subprojects { - initializeSonatypeStagingRepository { - mustRunAfter(tasks.withType(Sign)) - } - - tasks.withType(Sign) { - enabled = canSign - } -} - -// To publish run ./gradlew release - -task release { - afterEvaluate { - // Collect all the publishing task which upload the archives to nexus staging - def publishingTasks = [ - ":", ":api:", ":natives:" - ].collect { it + "publishAllPublicationsToSonatypeRepository" } - - dependsOn(publishingTasks) - - // Make sure the close and release happens after uploading - dependsOn(closeAndReleaseSonatypeStagingRepository) - closeAndReleaseSonatypeStagingRepository.mustRunAfter(publishingTasks) - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..4667574 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + `opus-java-conventions` + `opus-java-publish-conventions` +} + +dependencies { + api(project(":api")) + api(project(":natives")) +} + +configurePublishing(artifactId = "opus-java") { + // We don't have any sources as this is a POM artifact, + // but if we don't include it, dependencies won't be added + from(components["java"]) + + pom { + packaging = "pom" + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..618aa09 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() + gradlePluginPortal() +} + +dependencies { + implementation("org.jreleaser:org.jreleaser.gradle.plugin:1.20.0") +} diff --git a/buildSrc/src/main/kotlin/opus-java-conventions.gradle.kts b/buildSrc/src/main/kotlin/opus-java-conventions.gradle.kts new file mode 100644 index 0000000..30bc8ed --- /dev/null +++ b/buildSrc/src/main/kotlin/opus-java-conventions.gradle.kts @@ -0,0 +1,24 @@ +plugins { + java +} + +group = "club.minnced" +version = "1.2.0" + +repositories { + mavenCentral() +} + +tasks.withType { + (options as? StandardJavadocDocletOptions)?.apply { + addBooleanOption("html5", true) // Adds search bar + addStringOption("-release", "8") + links("https://docs.oracle.com/javase/8/docs/api/") + addBooleanOption("Xdoclint:all,-missing", true) + } +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} diff --git a/buildSrc/src/main/kotlin/opus-java-publish-conventions.gradle.kts b/buildSrc/src/main/kotlin/opus-java-publish-conventions.gradle.kts new file mode 100644 index 0000000..eef7e57 --- /dev/null +++ b/buildSrc/src/main/kotlin/opus-java-publish-conventions.gradle.kts @@ -0,0 +1,53 @@ +import org.jreleaser.model.Active + +plugins { + `java-library` + `maven-publish` + + id("org.jreleaser") +} + +val stagingDirectory = layout.buildDirectory.dir("staging-deploy").get() + +publishing { + repositories.maven { + url = stagingDirectory.asFile.toURI() + } +} + +jreleaser { + gitRootSearch = true + + project { + versionPattern = "CUSTOM" + } + + release { + github { + enabled = false + } + } + + signing { + active = Active.RELEASE + armored = true + } + + deploy { + maven { + mavenCentral { + register("sonatype") { + active = Active.RELEASE + url = "https://central.sonatype.com/api/v1/publisher" + stagingRepository(stagingDirectory.asFile.relativeTo(projectDir).path) + } + } + } + } +} + +afterEvaluate { + check(isPublishedArtifactConfigured(project)) { + "Project '${project.path}' did not call 'configurePublishing'" + } +} diff --git a/buildSrc/src/main/kotlin/publish.kt b/buildSrc/src/main/kotlin/publish.kt new file mode 100644 index 0000000..6042686 --- /dev/null +++ b/buildSrc/src/main/kotlin/publish.kt @@ -0,0 +1,70 @@ +import org.gradle.api.Project +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPom +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.jvm.tasks.Jar +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.register +import org.gradle.kotlin.dsl.registering + +private val configuredPublishedArtifacts = hashSetOf() + +fun isPublishedArtifactConfigured(project: Project) = project.path in configuredPublishedArtifacts + +private fun MavenPom.populate(artifactId: String) { + packaging = "jar" + + name.set(artifactId) // Maven central requires it + description.set("Modular java binding for opus natives") + url.set("https://github.com/discord-java/opus-java") + + scm { + url.set("https://github.com/discord-java/opus-java") + connection.set("scm:git:git://github.com/discord-java/opus-java") + developerConnection.set("scm:git:ssh:git@github.com:discord-java/opus-java") + } + + licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") + } + } + + developers { + developer { + id.set("Minn") + name.set("Florian Spieß") + email.set("business@minn.dev") + } + } +} + +fun Project.registerEmptySources(archiveBaseName: String) = tasks.registering(Jar::class) { + this.archiveBaseName.set(archiveBaseName) + archiveClassifier.set("sources") + // Empty by design +} + +fun Project.registerEmptyJavadocs(archiveBaseName: String) = tasks.registering(Jar::class) { + this.archiveBaseName.set(archiveBaseName) + archiveClassifier.set("javadoc") + // Empty by design +} + +fun Project.configurePublishing(artifactId: String, configuration: MavenPublication.() -> Unit = {}) { + configuredPublishedArtifacts += this.path + + extensions.configure { + publications { + register("Release") { + this.artifactId = artifactId + + pom.populate(artifactId) + + configuration() + } + } + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index f6b961f..8bdaf60 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e750102..2e11132 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 index cccdd3d..adff685 --- a/gradlew +++ b/gradlew @@ -1,78 +1,128 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,92 +131,118 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index e95643d..e509b2d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,22 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -9,25 +27,29 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -35,48 +57,35 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/natives/build.gradle b/natives/build.gradle deleted file mode 100644 index 31c20f1..0000000 --- a/natives/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -plugins { - id 'java-library' - id 'maven-publish' - id 'signing' -} - -project.version = rootProject.version -ext.moduleName = 'opus-java-natives' -archivesBaseName = moduleName - -publishing { - publications { - Release(MavenPublication) { - from components.java - - groupId project.group - artifactId moduleName - version version - - generatePom(pom, "jar") - } - } -} - -if (canSign) { - signing { - sign publishing.publications.Release - } -} \ No newline at end of file diff --git a/natives/build.gradle.kts b/natives/build.gradle.kts new file mode 100644 index 0000000..d867302 --- /dev/null +++ b/natives/build.gradle.kts @@ -0,0 +1,43 @@ +plugins { + `opus-java-conventions` + `opus-java-publish-conventions` +} + +dependencies { + testImplementation("org.junit.platform:junit-platform-launcher:1.14.0") + testImplementation("org.junit.jupiter:junit-jupiter:5.14.0") + + testImplementation(project(":api")) +} + +val isGithubAction = System.getenv("GITHUB_ACTION") != null +val isJitpack = System.getenv("JITPACK") == "true" +val isCI = isGithubAction || isJitpack + +tasks.withType { + useJUnitPlatform() + failOnNoDiscoveredTests = false + + filter { + isFailOnNoMatchingTests = false + + // Only the CI will put the natives in the expected spot + if (!isCI) { + excludeTestsMatching("TestNatives") + } + } +} + +tasks.withType { + archiveBaseName = "opus-java-natives" +} + +val emptySources by registerEmptySources(archiveBaseName = "opus-java-natives") +val emptyJavadocs by registerEmptyJavadocs(archiveBaseName = "opus-java-natives") + +configurePublishing(artifactId = "opus-java-natives") { + from(components["java"]) + + artifact(emptySources) + artifact(emptyJavadocs) +} diff --git a/natives/src/main/resources/natives/darwin/libopus.dylib b/natives/src/main/resources/natives/darwin/libopus.dylib deleted file mode 100644 index f8a5102..0000000 Binary files a/natives/src/main/resources/natives/darwin/libopus.dylib and /dev/null differ diff --git a/natives/src/main/resources/natives/linux-aarch64/libopus.so b/natives/src/main/resources/natives/linux-aarch64/libopus.so deleted file mode 100644 index 72d230a..0000000 Binary files a/natives/src/main/resources/natives/linux-aarch64/libopus.so and /dev/null differ diff --git a/natives/src/main/resources/natives/linux-arm/libopus.so b/natives/src/main/resources/natives/linux-arm/libopus.so deleted file mode 100644 index ba01e48..0000000 Binary files a/natives/src/main/resources/natives/linux-arm/libopus.so and /dev/null differ diff --git a/natives/src/main/resources/natives/linux-x86-64/libopus.so b/natives/src/main/resources/natives/linux-x86-64/libopus.so deleted file mode 100644 index 7203aba..0000000 Binary files a/natives/src/main/resources/natives/linux-x86-64/libopus.so and /dev/null differ diff --git a/natives/src/main/resources/natives/linux-x86/libopus.so b/natives/src/main/resources/natives/linux-x86/libopus.so deleted file mode 100644 index 8ed2015..0000000 Binary files a/natives/src/main/resources/natives/linux-x86/libopus.so and /dev/null differ diff --git a/natives/src/main/resources/natives/win32-x86-64/libopus.dll b/natives/src/main/resources/natives/win32-x86-64/libopus.dll deleted file mode 100644 index 00c5d95..0000000 Binary files a/natives/src/main/resources/natives/win32-x86-64/libopus.dll and /dev/null differ diff --git a/natives/src/main/resources/natives/win32-x86/libopus.dll b/natives/src/main/resources/natives/win32-x86/libopus.dll deleted file mode 100644 index 3ef0934..0000000 Binary files a/natives/src/main/resources/natives/win32-x86/libopus.dll and /dev/null differ diff --git a/natives/src/test/java/TestNatives.java b/natives/src/test/java/TestNatives.java new file mode 100644 index 0000000..ed10ee7 --- /dev/null +++ b/natives/src/test/java/TestNatives.java @@ -0,0 +1,39 @@ +import club.minnced.opus.util.OpusLibrary; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class TestNatives { + + @MethodSource("platforms") + @ParameterizedTest + public void testNativesArePresent(String path) { + assertNotNull(TestNatives.class.getResource(path), "Native not found at " + path); + } + + public static List platforms() { + List args = new ArrayList<>(); + for (String platform : OpusLibrary.getSupportedPlatforms()) { + final String path = String.format("/natives/%s/libopus.%s", platform, getExtension(platform)); + args.add(Arguments.of(path)); + } + + return args; + } + + private static String getExtension(String platform) { + if (platform.equals("darwin")) + return "dylib"; + else if (platform.startsWith("linux")) + return "so"; + else if (platform.startsWith("win32")) + return "dll"; + else + throw new IllegalArgumentException("Unhandled platform: " + platform); + } +}