fix: 移除 MUSL 构建、Windows 用 PowerShell 打包、JNI 未使用代码去警告

Made-with: Cursor
This commit is contained in:
桥下红药
2026-03-13 03:01:16 +08:00
parent b1bc2bedbe
commit 2746791205
3 changed files with 19 additions and 33 deletions
+18 -12
View File
@@ -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
+1 -14
View File
@@ -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 崩溃。
-7
View File
@@ -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 StringJObject)→ Rust String
pub fn jstring_to_rust(env: &mut JNIEnv, obj: &JObject) -> jni::errors::Result<String> {
let jstr = JString::from(env.new_local_ref(obj)?);
Ok(env.get_string(&jstr)?.into())
}
// ──────────────────────────────────────────────────────────────────────────────
// FileInfo: Rust → Java
// ──────────────────────────────────────────────────────────────────────────────