Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 192 additions & 0 deletions .github/workflows/java-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
name: Release Universal JAR

on:
#태그를 트리거로 사용하시려면 주석을 제거하시고 사용하시면 됩니다#
#push:
# tags:
# - 'v*'
workflow_dispatch:
inputs:
version:
description: 'The version to release (e.g., 1.0.11)'
required: true
default: '1.0.11'

jobs:
build-native-libs:
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
rust_target: x86_64-pc-windows-msvc
lib_name: braillify.dll
artifact_name: braillify-dll
native_path: windows-x86_64

- os: ubuntu-latest
rust_target: x86_64-unknown-linux-gnu
lib_name: libbraillify.so
artifact_name: braillify-so
native_path: linux-x86_64

- os: macos-15-intel
rust_target: x86_64-apple-darwin
lib_name: libbraillify.dylib
artifact_name: braillify-dylib-x86
native_path: darwin-x86_64

- os: macos-latest
rust_target: aarch64-apple-darwin
lib_name: libbraillify.dylib
artifact_name: braillify-dylib-aarch64
native_path: darwin-aarch64

runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: packages/java
steps:
- name: Checkout required subtree only
uses: actions/checkout@v4
with:
fetch-depth: 1
sparse-checkout: |
packages/java
sparse-checkout-cone-mode: true


- name: Set version
id: set_version
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION="${GITHUB_REF#refs/tags/v}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Update Cargo.toml on Windows
if: runner.os == 'Windows'
shell: pwsh
run: |
$version = "${{ steps.set_version.outputs.version }}"
(Get-Content src/main/java/com/devfive/Cargo.toml) |
ForEach-Object {
$_ `
-replace '^(version\s*=\s*)".*"', "`$1`"$version`"" `
-replace '^(braillify\s*=\s*)".*"', "`$1`"$version`""
} |
Set-Content src/main/java/com/devfive/Cargo.toml

- name: Update Cargo.toml on Linux/macOS
if: runner.os != 'Windows'
shell: bash
run: |
VERSION="${{ steps.set_version.outputs.version }}"
sed -i'' \
-e "s/^\(version\s*=\s*\)\".*\"/\1\"${VERSION}\"/" \
-e "s/^\(braillify\s*=\s*\)\".*\"/\1\"${VERSION}\"/" \
src/main/java/com/devfive/Cargo.toml

- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'

- name: Set up Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.rust_target }}

- name: Grant execute permission for gradlew
if: runner.os != 'Windows'
run: chmod +x gradlew

- name: Build native library (Windows)
if: runner.os == 'Windows'
shell: cmd
run: gradlew.bat cargoBuild --no-daemon

- name: Build native library (Unix)
if: runner.os != 'Windows'
shell: bash
run: ./gradlew cargoBuild --no-daemon

- name: native output
shell: bash
run: |
echo "Expected:"
echo "src/main/java/com/devfive/target/${{ matrix.rust_target }}/release/${{ matrix.lib_name }}"
ls -R src/main/java/com/devfive/target || true

- name: Upload native library artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: src/main/java/com/devfive/target/${{ matrix.rust_target }}/release/${{ matrix.lib_name }}
if-no-files-found: error

assemble-jar:
runs-on: ubuntu-latest
needs: build-native-libs

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set version
id: set_version
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION="${GITHUB_REF#refs/tags/v}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Set up JDK8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'

- name: Download native library artifacts
uses: actions/download-artifact@v4
with:
path: native-libs

- name: downloaded artifacts
shell: bash
run: ls -R native-libs

- name: Move native libraries
shell: bash
run: |
mkdir -p src/main/resources/natives/windows-x86_64
mv native-libs/braillify-dll/braillify.dll src/main/resources/natives/windows-x86_64/

mkdir -p src/main/resources/natives/linux-x86_64
mv native-libs/braillify-so/libbraillify.so src/main/resources/natives/linux-x86_64/

mkdir -p src/main/resources/natives/darwin-x86_64
mv native-libs/braillify-dylib-x86/libbraillify.dylib src/main/resources/natives/darwin-x86_64/

mkdir -p src/main/resources/natives/darwin-aarch64
mv native-libs/braillify-dylib-aarch64/libbraillify.dylib src/main/resources/natives/darwin-aarch64/

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Assemble Universal JAR
run: ./gradlew deployJar -PreleaseVersion=${{ steps.set_version.outputs.version }} --no-daemon

- name: Upload Universal JAR
uses: actions/upload-artifact@v4
with:
name: braillify-universal-jar
path: build/libs/braillify-${{ steps.set_version.outputs.version }}.jar
if-no-files-found: error
25 changes: 25 additions & 0 deletions packages/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*.log
*.lock
*.tmp
*.temp
.DS_Store
Thumbs.db
.idea/
.vscode/
*.iml
*.ipr
*.iws
.project
.classpath
.settings
.factorypath
build/
out/
dist/
bin/
**/target/
Cargo.lock
output.txt

.gradle/
!gradle/wrapper/gradle-wrapper.jar
120 changes: 120 additions & 0 deletions packages/java/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import org.gradle.api.GradleException
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.tasks.bundling.Jar

plugins {
id("java")
application
}

data class NativeConfig(
val rustTarget: String,
val nativeLibName: String,
val nativePath: String
)

val osName = System.getProperty("os.name").lowercase()
val osArch = System.getProperty("os.arch").lowercase()

val nativeConfig: NativeConfig = when {
osName.contains("win") -> NativeConfig(
rustTarget = "x86_64-pc-windows-msvc",
nativeLibName = "braillify_java.dll",
nativePath = "windows-x86_64"
)

osName.contains("nix") || osName.contains("nux") -> NativeConfig(
rustTarget = "x86_64-unknown-linux-gnu",
nativeLibName = "libbraillify_java.so",
nativePath = "linux-x86_64"
)

osName.contains("mac") && osArch == "aarch64" -> NativeConfig(
rustTarget = "aarch64-apple-darwin",
nativeLibName = "libbraillify_java.dylib",
nativePath = "darwin-aarch64"
)

osName.contains("mac") -> NativeConfig(
rustTarget = "x86_64-apple-darwin",
nativeLibName = "libbraillify.dylib",
nativePath = "darwin-x86_64"
)

else -> throw GradleException("Unsupported OS for cargo build: $osName ($osArch)")
}

group = "com.devfive"
version = project.findProperty("releaseVersion") ?: "1.0.11"

application {
mainClass.set("com.devfive.Braillify")
}

repositories {
mavenCentral()
}

dependencies {
implementation("org.scijava:native-lib-loader:2.5.0")
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
useJUnitPlatform()
}

tasks.withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

tasks.register<Jar>("deployJar") {
archiveBaseName.set(project.name)

manifest {
attributes["Main-Class"] = "com.devfive.Braillify"
}

from(sourceSets.main.get().output)
from(configurations.runtimeClasspath.get().map {
if (it.isDirectory) it else zipTree(it)
})
}

tasks.jar {
manifest {
attributes["Main-Class"] = "com.devfive.Braillify"
}

from(sourceSets.main.get().output)
from(configurations.runtimeClasspath.get().map {
if (it.isDirectory) it else zipTree(it)
})
}


val rustProjectDir = file("src/main/java/com/devfive")

tasks.register<Exec>("cargoBuild") {
workingDir(rustProjectDir)
commandLine(
"cargo",
"build",
"--release",
"--target",
nativeConfig.rustTarget
)
}

tasks.register<Copy>("copyNativeLib") {
dependsOn("cargoBuild")
from(
"$rustProjectDir/target/${nativeConfig.rustTarget}/release/${nativeConfig.nativeLibName}"
)
into("src/main/resources/natives/${nativeConfig.nativePath}")
}

tasks.named("processResources") {
dependsOn("copyNativeLib")
}
Binary file added packages/java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions packages/java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Sun Oct 26 16:52:13 KST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading