Skip to content

Commit

Permalink
Native compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
kairoh committed Oct 28, 2022
1 parent 3e09ff8 commit 4be3771
Show file tree
Hide file tree
Showing 23 changed files with 503 additions and 114 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Prevents auto-converting to CRLF on Win
# and convert to LF on checkin
* text=auto eol=lf
22 changes: 8 additions & 14 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Nightly Build
name: Sonar
on:
push:
branches: [ '*' ]
repository_dispatch:
types: [ trigger-nightly ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
java: [ 17 ]
os: [windows-latest, macOS-latest]
include:
- os: ubuntu-latest
java: 17
mode: deploy

steps:
Expand All @@ -28,16 +28,11 @@ jobs:
with:
fetch-depth: 0 # Shallow clone

- name: Use GNU tar
shell: cmd
run: echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"
if: ${{ runner.os == 'Windows' }}

- name: Set up JDK ${{ matrix.java }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java }}
java-version: 17
cache: maven

- name: Test with Maven
Expand All @@ -49,15 +44,14 @@ jobs:
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
if: matrix.mode == 'deploy'

- name: Sonar analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
MVN_SONAR: ${{ 'org.sonarsource.scanner.maven:sonar-maven-plugin' }}
MVN_JACOCO: ${{ 'org.jacoco:jacoco-maven-plugin:0.8.5' }}
MVN_JACOCO: ${{ 'org.jacoco:jacoco-maven-plugin:0.8.8' }}
MVN_PARAMS: '-Pide -Dmaven.test.failure.ignore=true -Dsonar.projectKey=kairoh_studio'
# Ide profile to skip javascript
run: mvn -B ${MVN_JACOCO}:prepare-agent verify ${MVN_JACOCO}:report ${MVN_SONAR}:sonar ${MVN_PARAMS}
Expand Down
138 changes: 102 additions & 36 deletions .github/workflows/native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,152 @@ on:
branches: [ '*' ]
pull_request:
types: [ opened, synchronize, reopened ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-jar:
build-front:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
node-version: 12

- name: Cache JS
uses: actions/cache@v3
- uses: actions/cache@v3
with:
path: web-ui/javascript
path: web-ui/javascript/
key: studio-js-${{ hashFiles('**/yarn.lock') }}

- name: Run yarn
working-directory: web-ui/javascript/
run: |
yarn install --frozen-lockfile
yarn build
- uses: actions/upload-artifact@v3
with:
name: studio-front
path: web-ui/javascript/build/

build-jar:
needs: build-front
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
cache: maven

- name: Build Maven Native src
run: mvn verify -B -Pnative2
- name: Download JS front
uses: actions/download-artifact@v3
with:
name: studio-front
path: web-ui/javascript/build/

- name: Build Maven Jar
run: mvn install -B -DskipTests -Pide

- name: Upload Native src
- name: Upload Quarkus app
uses: actions/upload-artifact@v3
with:
name: studio-native-src
path: web-ui/target/native-sources
name: studio-app
path: web-ui/target/quarkus-app

build-native:
needs: build-jar
needs: build-front
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
java: [11]
include:
# GraalVM: Oracle, Mandrel or Liberica
# Mandrel (mac): no support
# Upx support (win): only<22, see https://github.com/oracle/graal/issues/4340
# AWT support (win & mac): only Liberica>22 see https://bell-sw.com/announcements/2022/08/05/liberica-native-image-kit-22-2-0-and-21-3-3-builds-are-out/#create-a-native-image-for-swingset2-app-linux-and-macos

- os: ubuntu-latest
jdk-suffix: linux-amd64.tar.gz
native-cmd: |
mvn verify -B -Pnative -Pide -DskipTests
echo "artifact_name=$(ls web-ui/target/*runner)" >> $GITHUB_ENV
- os: macOS-latest
jdk-suffix: macos-amd64.tar.gz
native-cmd: |
mvn verify -B -Pnative -Pide -DskipTests
echo "artifact_name=$(ls web-ui/target/*runner)" >> $GITHUB_ENV
- os: windows-latest
jdk-suffix: windows-amd64.zip
native-cmd: |
mvn verify -B -Pnative -Pide -DskipTests
"artifact_name=$((ls web-ui/target/*.exe).FullName)" >> $env:GITHUB_ENV
cp web-ui/target/studio-web-ui-quarkus-SNAPSHOT-native-image-source-jar/*.dll web-ui/target/
steps:
- uses: actions/checkout@v3

- name: Use GNU tar
run: |
"$env:ProgramFiles/Git/usr/bin" >> $env:GITHUB_PATH
if: ${{ runner.os == 'Windows' }}

- name: Download Liberica NIK
env:
liberica-url: https://download.bell-sw.com/vm/22.3.0/bellsoft-liberica-vm-core-openjdk17.0.5+8-22.3.0+2-${{ matrix.jdk-suffix }}
run: curl -sLo ${{ runner.temp }}/${{ matrix.jdk-suffix }} ${{ env.liberica-url }}

- name: Set up GraalVM
uses: graalvm/setup-graalvm@v1
uses: actions/setup-java@v3
with:
version: latest
java-version: ${{ matrix.java }}
components: native-image
github-token: ${{ secrets.GITHUB_TOKEN }}
java-version: 17
distribution: jdkfile
jdkFile: ${{ runner.temp }}/${{ matrix.jdk-suffix }}
cache: maven

- name: (Windows) Set up compiler
uses: ilammy/msvc-dev-cmd@v1.4.1
uses: ilammy/msvc-dev-cmd@v1
if: ${{ runner.os == 'Windows' }}

- name: Download Native src
- name: Download JS front
uses: actions/download-artifact@v3
with:
name: studio-native-src
name: studio-front
path: web-ui/javascript/build/

- name: (Windows) Build native
run: |
native-image $(cat native-image.args).Split()
"artifact_name=$((ls *.exe).Name)" >> $env:GITHUB_ENV
if: ${{ runner.os == 'Windows' }}

- name: (*nix) Build native
run: |
native-image $(cat native-image.args)
echo "artifact_name=$(ls *runner)" >> $GITHUB_ENV
if: ${{ runner.os != 'Windows' }}
- name: Build native
run: ${{ matrix.native-cmd }}

- name: Compress exec
uses: svenstaro/upx-action@v2
with:
file: ${{ env.artifact_name }}
args: -7
args: '-7'
strip: false
if: ${{ runner.os != 'Windows' }}

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: studio-1.0-${{runner.os}}
path: |
*runner
*.exe
*.dll
web-ui/target/*runner
web-ui/target/*.exe
web-ui/target/*.dll
- name: Test native
run: mvn test-compile failsafe:integration-test -B -Pnative -Pide -DskipITs=false

- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
with:
report_paths: '**/failsafe-reports/TEST-*.xml'
check_name: IT (${{ matrix.os }})
if: always()
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ public class VorbisEncoder {

private static final int READ_BLOCK_SIZE = 4096;
// need to randomize seed
private static SecureRandom PRNG;
private static SecureRandom prng;

private VorbisEncoder() {
throw new IllegalArgumentException("Utility class");
}

public static byte[] encode(InputStream is) throws VorbisEncodingException {
LOGGER.debug("Start encoding with {} channels, {}Hz, quality {}", CHANNELS, RATE, QUALITY);
if (PRNG == null) {
PRNG = new SecureRandom();
if (prng == null) {
prng = new SecureRandom();
}
// struct that stores all the static vorbis bitstream settings
Jvorbis_info vi = new Jvorbis_info();
Expand All @@ -100,7 +100,7 @@ public static byte[] encode(InputStream is) throws VorbisEncodingException {

// take physical pages, weld into a logical stream of packets
Jogg_stream_state os = new Jogg_stream_state();
os.ogg_stream_init(PRNG.nextInt(256));
os.ogg_stream_init(prng.nextInt(256));

LOGGER.trace("Writing header.");
Jogg_packet header = new Jogg_packet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.color.ColorSpace;
import java.awt.color.ICC_Profile;
import java.awt.image.BufferedImage;
import java.awt.image.IndexColorModel;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -39,11 +37,13 @@ public class ImageConversion {
// https://bugs.openjdk.java.net/browse/JDK-6986863
// https://stackoverflow.com/questions/26297491/imageio-thread-safety
static {
ICC_Profile.getInstance(ColorSpace.CS_sRGB).getData();
ICC_Profile.getInstance(ColorSpace.CS_PYCC).getData();
ICC_Profile.getInstance(ColorSpace.CS_GRAY).getData();
ICC_Profile.getInstance(ColorSpace.CS_CIEXYZ).getData();
ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB).getData();
if (Runtime.version().version().get(0) < 17) {
java.awt.color.ICC_Profile.getInstance(java.awt.color.ColorSpace.CS_sRGB).getData();
java.awt.color.ICC_Profile.getInstance(java.awt.color.ColorSpace.CS_PYCC).getData();
java.awt.color.ICC_Profile.getInstance(java.awt.color.ColorSpace.CS_GRAY).getData();
java.awt.color.ICC_Profile.getInstance(java.awt.color.ColorSpace.CS_CIEXYZ).getData();
java.awt.color.ICC_Profile.getInstance(java.awt.color.ColorSpace.CS_LINEAR_RGB).getData();
}
}

private ImageConversion() {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<!-- quarkus -->
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.13.0.Final</quarkus.platform.version>
<quarkus.platform.version>2.13.3.Final</quarkus.platform.version>
<!-- Dependencies -->
<lombok.version>1.18.24</lombok.version>
<log4j2.version>2.18.0</log4j2.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
public class Usb4javaLibraryUtil {

private Usb4javaLibraryUtil() {
// empty
}

public static String extractLibrary() {
final String platform = getPlatform();
final String lib = getLibName();
Expand All @@ -25,7 +29,7 @@ public static String extractLibrary(final String platform,
*
* @return The architecture name. Never null.
*/
private static String getPlatform() {
public static String getPlatform() {
return getOS() + "-" + getArch();
}

Expand All @@ -35,7 +39,7 @@ private static String getPlatform() {
*
* @return The usb4java native library name. Never null.
*/
private static String getLibName() {
public static String getLibName() {
return "libusb4java." + getExt();
}

Expand Down
Loading

0 comments on commit 4be3771

Please sign in to comment.