tangled
alpha
login
or
join now
erika.florist
/
maudit
6
fork
atom
Rust library to generate static websites
6
fork
atom
overview
issues
pulls
1
pipelines
fix: use same target finding function in assets
Princesseuh
1 month ago
63629b48
0b052127
+59
-4
2 changed files
expand all
collapse all
unified
split
Cargo.lock
crates
maudit
src
build
options.rs
+8
Cargo.lock
reviewed
···
1960
1960
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
1961
1961
1962
1962
[[package]]
1963
1963
+
name = "hot-reload-optimization"
1964
1964
+
version = "0.1.0"
1965
1965
+
dependencies = [
1966
1966
+
"codspeed-divan-compat",
1967
1967
+
"maudit",
1968
1968
+
]
1969
1969
+
1970
1970
+
[[package]]
1963
1971
name = "http"
1964
1972
version = "1.4.0"
1965
1973
source = "registry+https://github.com/rust-lang/crates.io-index"
+51
-4
crates/maudit/src/build/options.rs
reviewed
···
1
1
-
use std::{env, path::PathBuf};
1
1
+
use std::{fs, path::PathBuf};
2
2
3
3
use crate::{assets::RouteAssetsOptions, is_dev, sitemap::SitemapOptions};
4
4
···
165
165
tailwind_binary_path: "tailwindcss".into(),
166
166
assets_dir: "_maudit".into(),
167
167
image_cache_dir: {
168
168
-
let target_dir =
169
169
-
env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| "target".to_string());
170
170
-
PathBuf::from(target_dir).join("maudit_cache/images")
168
168
+
find_target_dir()
169
169
+
.unwrap_or_else(|_| PathBuf::from("target"))
170
170
+
.join("maudit_cache/images")
171
171
},
172
172
hashing_strategy: if is_dev() {
173
173
AssetHashingStrategy::FastImprecise
···
207
207
}
208
208
}
209
209
}
210
210
+
211
211
+
/// Find the target directory using multiple strategies
212
212
+
///
213
213
+
/// This function tries multiple approaches to locate the target directory:
214
214
+
/// 1. CARGO_TARGET_DIR / CARGO_BUILD_TARGET_DIR environment variables
215
215
+
/// 2. Local ./target directory
216
216
+
/// 3. Workspace root target directory (walking up to find [workspace])
217
217
+
/// 4. Fallback to relative "target" path
218
218
+
fn find_target_dir() -> Result<PathBuf, std::io::Error> {
219
219
+
// 1. Check CARGO_TARGET_DIR and CARGO_BUILD_TARGET_DIR environment variables
220
220
+
for env_var in ["CARGO_TARGET_DIR", "CARGO_BUILD_TARGET_DIR"] {
221
221
+
if let Ok(target_dir) = std::env::var(env_var) {
222
222
+
let path = PathBuf::from(&target_dir);
223
223
+
if path.exists() {
224
224
+
return Ok(path);
225
225
+
}
226
226
+
}
227
227
+
}
228
228
+
229
229
+
// 2. Look for target directory in current directory
230
230
+
let local_target = PathBuf::from("target");
231
231
+
if local_target.exists() {
232
232
+
return Ok(local_target);
233
233
+
}
234
234
+
235
235
+
// 3. Try to find workspace root by looking for Cargo.toml with [workspace]
236
236
+
let mut current = std::env::current_dir()?;
237
237
+
loop {
238
238
+
let cargo_toml = current.join("Cargo.toml");
239
239
+
if cargo_toml.exists()
240
240
+
&& let Ok(content) = fs::read_to_string(&cargo_toml)
241
241
+
&& content.contains("[workspace]") {
242
242
+
let workspace_target = current.join("target");
243
243
+
if workspace_target.exists() {
244
244
+
return Ok(workspace_target);
245
245
+
}
246
246
+
}
247
247
+
248
248
+
// Move up to parent directory
249
249
+
if !current.pop() {
250
250
+
break;
251
251
+
}
252
252
+
}
253
253
+
254
254
+
// 4. Final fallback to relative path
255
255
+
Ok(PathBuf::from("target"))
256
256
+
}