Skip to content

Commit

Permalink
Java API:ビルドWorkflowを追加 (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi authored Oct 9, 2023
1 parent 8209633 commit ae8d247
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 1 deletion.
101 changes: 100 additions & 1 deletion .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ jobs:
run: |
cargo set-version "$VERSION" --exclude voicevox_core_python_api --exclude download --exclude xtask
if ${{ !!matrix.whl_local_version }}; then cargo set-version "$VERSION+"${{ matrix.whl_local_version }} -p voicevox_core_python_api; fi
- name: cache target
uses: Swatinem/rust-cache@v2
if: github.event.inputs.is_production != 'true'
- name: build voicevox_core_c_api
shell: bash
run: |
Expand All @@ -275,6 +278,7 @@ jobs:
if: matrix.whl_local_version
id: build-voicevox-core-python-api
run: |
rm -rf ./target/wheels
pip install -r ./crates/voicevox_core_python_api/requirements.txt
function build() {
maturin build --manifest-path ./crates/voicevox_core_python_api/Cargo.toml --features ${{ matrix.features }}, --target ${{ matrix.target }} --release
Expand All @@ -287,6 +291,17 @@ jobs:
echo "whl=$(find ./target/wheels -type f)" >> "$GITHUB_OUTPUT"
env:
ORT_USE_CUDA: ${{ matrix.use_cuda }}
- name: build voicevox_core_java_api
if: "contains(matrix.target, 'android')"
run: |
function build() {
cargo build -p voicevox_core_java_api -vv --features ${{ matrix.features }}, --target ${{ matrix.target }} --release
}
if ${{ github.event.inputs.is_production != 'true' }}; then
build
else
build > /dev/null 2>&1
fi
- name: Set ASSET_NAME env var
run: echo "ASSET_NAME=voicevox_core-${{ matrix.artifact_name }}-${{ env.VERSION }}" >> "$GITHUB_ENV"
- name: Organize artifact
Expand All @@ -301,6 +316,9 @@ jobs:
cp -v README.md "artifact/${{ env.ASSET_NAME }}/README.txt"
cp -vr model "artifact/${{ env.ASSET_NAME }}/"
echo "${{ env.VERSION }}" > "artifact/${{ env.ASSET_NAME }}/VERSION"
mkdir java_artifact
cp -v target/${{ matrix.target }}/release/libvoicevox_core_java_api.so java_artifact/ || true
- name: Code signing (Windows)
if: startsWith(matrix.os, 'windows') && github.event.inputs.code_signing == 'true'
run: |
Expand All @@ -311,7 +329,7 @@ jobs:
ESIGNERCKA_TOTP_SECRET: ${{ secrets.ESIGNERCKA_TOTP_SECRET }}
- name: Upload artifact to build XCFramework
if: contains(matrix.target, 'ios')
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: voicevox_core-${{ matrix.target }}
path: artifact/${{ env.ASSET_NAME }}
Expand All @@ -337,6 +355,12 @@ jobs:
files: |-
${{ steps.build-voicevox-core-python-api.outputs.whl }}
target_commitish: ${{ github.sha }}
- name: Upload voicevox_core_java_api artifact
if: env.VERSION != '0.0.0' && contains(matrix.target, 'android')
uses: actions/upload-artifact@v3
with:
name: voicevox_core_java_api-${{ matrix.artifact_name }}
path: java_artifact

build_xcframework:
if: ${{ !(github.event_name != 'release' && github.event_name != 'workflow_dispatch') }} # !env.IS_SIMPLE_TEST と同じ
Expand Down Expand Up @@ -392,6 +416,81 @@ jobs:
${{ env.ASSET_NAME }}.zip
target_commitish: ${{ github.sha }}

build_java_package:
runs-on: ubuntu-latest
if: ${{ !(github.event_name != 'release' && github.event_name != 'workflow_dispatch') }} # !env.IS_SIMPLE_TEST と同じ
needs:
- build_and_deploy
steps:
- uses: actions/checkout@v3
- name: Set up Rust
uses: ./.github/actions/rust-toolchain-from-file
- name: Set up Java
uses: actions/setup-java@v2
with:
java-version: "17"
distribution: "adopt"
- uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r25b
- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall
- name: Install cargo-edit
run: cargo binstall cargo-edit@^0.11 --no-confirm
- name: set cargo version
run: |
cargo set-version "$VERSION" -p voicevox_core_java_api
- name: "Download artifact (android-arm64-cpu)"
uses: actions/download-artifact@v3
with:
name: voicevox_core_java_api-android-arm64-cpu
path: artifact/android-arm64-cpu

- name: "Download artifact (android-x86_64-cpu)"
uses: actions/download-artifact@v3
with:
name: voicevox_core_java_api-android-x86_64-cpu
path: artifact/android-x86_64-cpu

- name: Print tree
run: tree artifact

- name: Build voicevoxcore-android
run: |
rm -rf crates/voicevox_core_java_api/lib/src/main/resources/dll
cat <<EOF | while read -r line; do
android-arm64-cpu|arm64-v8a
android-x86_64-cpu|x86_64
EOF
IFS='|' read -r artifact_name target <<< "$line"
mkdir "crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/${target}/"
cp -v "artifact/$artifact_name"/* "crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/${target}/"
done
cp ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/arm64-v8a/
cp ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/libc++_shared.so crates/voicevox_core_java_api/lib/src/main/resources/jniLibs/x86_64/
cd crates/voicevox_core_java_api
OS=android DEVICE=cpu gradle publishToMavenLocal
- name: Package
run: |
cd ~/.m2/repository
rm -rf dev || true
zip -r /tmp/java_packages.zip .
- name: Upload to Release
if: env.VERSION != '0.0.0' && env.SKIP_UPLOADING_RELEASE_ASSET == '0'
uses: softprops/action-gh-release@v1
with:
prerelease: true
tag_name: ${{ env.VERSION }}
files: |-
/tmp/java_packages.zip
target_commitish: ${{ github.sha }}

download_test:
needs: [config, build_and_deploy]
if: needs.config.outputs.deploy == 'true'
Expand Down
3 changes: 3 additions & 0 deletions crates/voicevox_core_java_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ publish.workspace = true
[lib]
crate-type = ["cdylib"]

[features]
directml = ["voicevox_core/directml"]

[dependencies]
android_logger = "0.13.1"
anyhow.workspace = true
Expand Down
20 changes: 20 additions & 0 deletions crates/voicevox_core_java_api/lib/build-android.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'com.android.library' version '8.1.1'
id 'maven-publish'
id 'org.jetbrains.kotlin.android' version '1.9.10'
}

Expand Down Expand Up @@ -53,4 +54,23 @@ android {
jniLibs.srcDirs = ["./src/main/resources/jniLibs"]
}
}
publishing {
singleVariant("release") {
withJavadocJar()
}
}
}

publishing {
publications {
maven(MavenPublication) {
groupId = 'jp.hiroshiba.voicevoxcore'
artifactId = gradle.ext.targetDevice == 'cpu' ? 'voicevoxcore-android' : "voicevoxcore-android-${gradle.ext.targetDevice}"
version = gradle.ext.version

afterEvaluate {
from components.release
}
}
}
}
14 changes: 14 additions & 0 deletions crates/voicevox_core_java_api/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
id 'maven-publish'
id "com.diffplug.spotless" version "6.20.0"
}

Expand Down Expand Up @@ -47,6 +48,8 @@ java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}

withJavadocJar()
}
tasks.named('test') {
// Use JUnit Platform for unit tests.
Expand All @@ -61,3 +64,14 @@ spotless {
googleJavaFormat()
}
}

publishing {
publications {
maven(MavenPublication) {
groupId = 'jp.hiroshiba.voicevoxcore'
artifactId = gradle.ext.targetDevice == 'cpu' ? 'voicevoxcore' : "voicevoxcore-${gradle.ext.targetDevice}"
version = gradle.ext.version
from components.java
}
}
}

0 comments on commit ae8d247

Please sign in to comment.