Skip to content

Commit 9884e4e

Browse files
committed
fix: copy extension to resources folder
1 parent 84c0583 commit 9884e4e

3 files changed

Lines changed: 55 additions & 31 deletions

File tree

standalone/src-tauri/build.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{env, fs, path::PathBuf};
1+
use std::{env, fs, path::PathBuf, process::Command};
22

33
fn main() {
44
prepare_sqlite_extension();
@@ -35,20 +35,33 @@ fn prepare_sqlite_extension() {
3535
target_dir.join(&profile).join(dylib_name),
3636
];
3737

38-
let extension_path = candidates.into_iter().find(|path| path.exists()).unwrap_or_else(|| {
39-
panic!(
40-
"absurd_sqlite_extension artifact not found. Build it with `cargo build -p absurd_sqlite_extension --target {target_triple} {}` first.",
41-
if profile == "debug" {
42-
"".to_string()
43-
} else {
44-
format!("--profile {profile}")
45-
}
46-
);
47-
});
48-
49-
let bin_dir = manifest_dir.join("bin");
50-
fs::create_dir_all(&bin_dir).expect("create bin directory");
51-
let dest = bin_dir.join(format!("absurd-extension-{}", target_triple));
38+
if candidates.iter().all(|path| !path.exists()) {
39+
let mut cmd = Command::new("cargo");
40+
cmd.current_dir(workspace_root)
41+
.args(["build", "-p", "absurd_sqlite_extension"])
42+
.arg("--target")
43+
.arg(&target_triple);
44+
if profile != "debug" {
45+
cmd.arg("--profile").arg(&profile);
46+
}
47+
let status = cmd
48+
.status()
49+
.expect("failed to invoke cargo build for absurd-sqlite-extension");
50+
if !status.success() {
51+
panic!("cargo build -p absurd-sqlite-extension failed");
52+
}
53+
}
54+
55+
let extension_path = candidates
56+
.into_iter()
57+
.find(|path| path.exists())
58+
.unwrap_or_else(|| {
59+
panic!("absurd_sqlite_extension artifact not found after build");
60+
});
61+
62+
let resources_dir = manifest_dir.join("resources");
63+
fs::create_dir_all(&resources_dir).expect("create resources directory");
64+
let dest = resources_dir.join(dylib_name);
5265
fs::copy(&extension_path, &dest).expect("copy SQLite extension into resources");
5366
println!(
5467
"cargo:info=Copying absurd_sqlite_extension from {} to {}",

standalone/src-tauri/src/db.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,28 @@ impl DatabaseHandle {
106106
}
107107
}
108108

109-
fn resolve_extension_path(_app_handle: &AppHandle) -> Option<PathBuf> {
110-
let mut candidates: Vec<(&str, PathBuf)> = Vec::new();
111-
match std::env::current_exe() {
112-
Ok(current_exe) => {
113-
if let Some(exe_dir) = current_exe.parent() {
114-
candidates.push(("sidecar", exe_dir.join("absurd-extension")));
115-
candidates.push(("sidecar bin", exe_dir.join("bin").join("absurd-extension")));
116-
} else {
117-
log::warn!("Failed to resolve current executable directory");
109+
fn resolve_extension_path(app_handle: &AppHandle) -> Option<PathBuf> {
110+
let lib_name = extension_lib_name();
111+
match app_handle.path().resource_dir() {
112+
Ok(resource_dir) => {
113+
let resource_path = resource_dir.join(&lib_name);
114+
log::debug!(
115+
"Checking resource SQLite extension at {}",
116+
resource_path.display()
117+
);
118+
if resource_path.exists() {
119+
log::info!(
120+
"Using resource SQLite extension at {}",
121+
resource_path.display()
122+
);
123+
return Some(resource_path);
118124
}
125+
log::warn!(
126+
"SQLite extension not found in resources at {}",
127+
resource_path.display()
128+
);
119129
}
120-
Err(err) => log::warn!("Failed to resolve current executable path: {}", err),
130+
Err(err) => log::warn!("Failed to resolve resource directory: {}", err),
121131
}
122132

123133
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
@@ -126,9 +136,10 @@ fn resolve_extension_path(_app_handle: &AppHandle) -> Option<PathBuf> {
126136
.and_then(Path::parent)
127137
.unwrap_or(&manifest_dir);
128138
let target_dir = workspace_root.join("target");
129-
let lib_name = extension_lib_name();
130-
candidates.push(("debug build", target_dir.join("debug").join(&lib_name)));
131-
candidates.push(("release build", target_dir.join("release").join(&lib_name)));
139+
let candidates = [
140+
("debug build", target_dir.join("debug").join(&lib_name)),
141+
("release build", target_dir.join("release").join(&lib_name)),
142+
];
132143

133144
for (label, path) in candidates {
134145
log::debug!("Checking {} SQLite extension at {}", label, path.display());
@@ -139,7 +150,7 @@ fn resolve_extension_path(_app_handle: &AppHandle) -> Option<PathBuf> {
139150
}
140151

141152
log::warn!(
142-
"SQLite extension not found. Checked bundled resource and build outputs in {}",
153+
"SQLite extension not found. Checked bundled resources and build outputs in {}",
143154
target_dir.display()
144155
);
145156
None

standalone/src-tauri/tauri.conf.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"bundle": {
2626
"active": true,
2727
"targets": "all",
28-
"externalBin": [
29-
"bin/absurd-extension"
28+
"resources": [
29+
"resources/*"
3030
],
3131
"icon": [
3232
"icons/logo-32x32.png",

0 commit comments

Comments
 (0)