Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(build): load the Windows executable's imports from System32 only (#9482)

Thinh Le65488c9d4866
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 7bb17e250..f75911576 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -39,7 +39,6 @@ dependencies = [
"jan-utils",
"keyring",
"libc",
- "libloading 0.8.9",
"log",
"machine-uid",
"nix 0.30.1",
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 8fb280f15..d3042c287 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -127,7 +127,6 @@ hyper-util = { version = "0.1", features = ["tokio"] }
http-body-util = "0.1"
tokio-stream = "0.1"
jan-utils = { path = "./utils" }
-libloading = "0.8.7"
log = "0.4"
# Pulled in by rmcp's `auth` feature; used directly for `TokenResponse`
# accessors on the persisted token record (`core::mcp::oauth`).
diff --git a/src-tauri/build.rs b/src-tauri/build.rs
index 4aff91b66..6dfdee90c 100644
--- a/src-tauri/build.rs
+++ b/src-tauri/build.rs
@@ -4,6 +4,18 @@ fn main() {
tauri_build::build();
}
+ // Windows: resolve the executable's own static imports from System32 only
+ // (LOAD_LIBRARY_SEARCH_SYSTEM32), so a DLL dropped in the install folder
+ // cannot stand in for a system DLL of the same name. Every static import of
+ // Jan-Desktop.exe is a system DLL, so nothing is loaded from the app folder
+ // this way. The flag applies to the binaries only; test executables and
+ // other targets keep the default search.
+ if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows")
+ && std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc")
+ {
+ println!("cargo:rustc-link-arg-bins=/DEPENDENTLOADFLAG:0x800");
+ }
+
#[cfg(target_os = "macos")]
{
println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");
diff --git a/src-tauri/jan-cli/Cargo.lock b/src-tauri/jan-cli/Cargo.lock
index cf83396a9..b054fdeff 100644
--- a/src-tauri/jan-cli/Cargo.lock
+++ b/src-tauri/jan-cli/Cargo.lock
@@ -36,7 +36,6 @@ dependencies = [
"jan-utils",
"keyring",
"libc",
- "libloading",
"log",
"machine-uid",
"nix 0.30.1",
@@ -2774,16 +2773,6 @@ dependencies = [
"pkg-config",
]
-[[package]]
-name = "libloading"
-version = "0.8.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
-dependencies = [
- "cfg-if",
- "windows-link",
-]
-
[[package]]
name = "libm"
version = "0.2.16"
diff --git a/src-tauri/src/core/system/commands.rs b/src-tauri/src/core/system/commands.rs
index 10af6c4d5..f2c625efa 100644
--- a/src-tauri/src/core/system/commands.rs
+++ b/src-tauri/src/core/system/commands.rs
@@ -541,18 +541,6 @@ pub async fn read_logs<R: Runtime>(app: AppHandle<R>) -> Result<String, String>
}
}
-// check if a system library is available
-#[tauri::command]
-pub fn is_library_available(library: &str) -> bool {
- match unsafe { libloading::Library::new(library) } {
- Ok(_) => true,
- Err(e) => {
- log::info!("Library {library} is not available: {e}");
- false
- }
- }
-}
-
#[tauri::command]
pub fn launch_claude_code_with_config(
api_url: String,
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 0a9b96506..d2b8dcaa8 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -74,7 +74,6 @@ macro_rules! invoke_commands_with_extras {
core::system::commands::factory_reset,
core::system::commands::take_pending_webdata_reset,
core::system::commands::read_logs,
- core::system::commands::is_library_available,
core::system::commands::launch_claude_code_with_config,
core::system::commands::clear_claude_code_env,
// Server commands