From 2746791205bf4cd8afee2cb147735d142e1c4c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=A5=E4=B8=8B=E7=BA=A2=E8=8D=AF?= Date: Fri, 13 Mar 2026 03:01:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=20MUSL=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E3=80=81Windows=20=E7=94=A8=20PowerShell=20=E6=89=93?= =?UTF-8?q?=E5=8C=85=E3=80=81JNI=20=E6=9C=AA=E4=BD=BF=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=8E=BB=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- .github/workflows/release.yml | 30 ++++++++++++++++++------------ jni/env.rs | 15 +-------------- jni/types.rs | 7 ------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5c71a7e..912e6fd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -64,14 +64,6 @@ jobs: jni_lib: libdht_crawler.so build_features: mimalloc,metrics,jni - # Linux x86_64 (MUSL - 静态链接,无依赖) - - target: x86_64-unknown-linux-musl - os: ubuntu-latest - use_cross: true - platform: linux - jni_lib: libdht_crawler.so - build_features: mimalloc,metrics,jni - # Linux ARM64 - target: aarch64-unknown-linux-gnu os: ubuntu-latest @@ -190,13 +182,14 @@ jobs: if: contains(matrix.target, 'windows') run: | cd target/${{ matrix.target }}/release/examples - zip dht_crawler_example-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.zip dht_crawler_example.exe - mv dht_crawler_example-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.zip ${{ github.workspace }}/ - shell: bash + Compress-Archive -Path dht_crawler_example.exe -DestinationPath dht_crawler_example-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.zip + Move-Item -Path dht_crawler_example-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.zip -Destination ${{ github.workspace }}/ + shell: pwsh # ────────── JNI 动态库打包(仅含单个 so/dll/dylib,体积最小)────────── - - name: Prepare JNI artifacts + - name: Prepare JNI artifacts (Linux/macOS) + if: "!contains(matrix.target, 'windows')" run: | VERSION=${{ steps.get_version.outputs.version }} TARGET=${{ matrix.target }} @@ -208,6 +201,19 @@ jobs: mv dht_crawler_jni-${VERSION}-${TARGET}.zip ${{ github.workspace }}/ shell: bash + - name: Prepare JNI artifacts (Windows) + if: contains(matrix.target, 'windows') + run: | + $VERSION = "${{ steps.get_version.outputs.version }}" + $TARGET = "${{ matrix.target }}" + $LIB = "${{ matrix.jni_lib }}" + $WORKDIR = New-TemporaryFile | ForEach-Object { Remove-Item $_; New-Item -ItemType Directory -Path $_.FullName } + Copy-Item "target/$TARGET/release/$LIB" -Destination $WORKDIR.FullName + Set-Location $WORKDIR.FullName + Compress-Archive -Path $LIB -DestinationPath "dht_crawler_jni-$VERSION-$TARGET.zip" + Move-Item -Path "dht_crawler_jni-$VERSION-$TARGET.zip" -Destination "${{ github.workspace }}/" + shell: pwsh + # ────────── 上传到 Release ────────── - name: Upload Release Assets diff --git a/jni/env.rs b/jni/env.rs index 61b185c..e2b4ff5 100644 --- a/jni/env.rs +++ b/jni/env.rs @@ -1,5 +1,5 @@ use jni::{JavaVM, JNIEnv}; -use jni::objects::{JObject, JValue}; +use jni::objects::JObject; use std::sync::{Arc, Mutex}; /// 跨线程安全的 Java 回调持有者。 @@ -40,19 +40,6 @@ impl JavaCallback { } result } - - /// 调用 Java listener 的方法(用于简单通知)。 - pub fn call_void_method( - &self, - method_name: &str, - sig: &str, - args: &[JValue], - ) -> jni::errors::Result<()> { - self.with_env(|env, obj| { - env.call_method(obj, method_name, sig, args)?; - Ok(()) - }) - } } /// 安全地执行 JNI 代码块,捕获 Rust panic,避免 JVM 崩溃。 diff --git a/jni/types.rs b/jni/types.rs index e685418..5147ed1 100644 --- a/jni/types.rs +++ b/jni/types.rs @@ -8,7 +8,6 @@ use jni::sys::jlong; // ────────────────────────────────────────────────────────────────────────────── const CLASS_TORRENT_INFO: &str = "cn/lmcw/dht/model/TorrentInfo"; const CLASS_FILE_INFO: &str = "cn/lmcw/dht/model/FileInfo"; -const CLASS_DHT_OPTIONS: &str = "cn/lmcw/dht/model/DHTOptions"; const CLASS_ARRAY_LIST: &str = "java/util/ArrayList"; // ────────────────────────────────────────────────────────────────────────────── @@ -24,12 +23,6 @@ pub fn rust_str_to_jstring<'local>( Ok(js.into()) } -/// Java String(JObject)→ Rust String -pub fn jstring_to_rust(env: &mut JNIEnv, obj: &JObject) -> jni::errors::Result { - let jstr = JString::from(env.new_local_ref(obj)?); - Ok(env.get_string(&jstr)?.into()) -} - // ────────────────────────────────────────────────────────────────────────────── // FileInfo: Rust → Java // ──────────────────────────────────────────────────────────────────────────────