Skip to content

Commit 7a5427a

Browse files
committed
Simplify workspace_root
1 parent b68fd36 commit 7a5427a

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

crates/libduckdb-sys/build.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ mod build_linked {
319319
}
320320

321321
if should_download_libduckdb() {
322-
return download_libduckdb(out_dir)
323-
.unwrap_or_else(|err| panic!("Failed to download DuckDB libraries: {err}"));
322+
return download_libduckdb(out_dir).unwrap_or_else(|err| panic!("Failed to download libduckdb: {err}"));
324323
}
325324

326325
if let Some(header) = try_vcpkg() {
@@ -383,7 +382,7 @@ mod build_linked {
383382
fn download_libduckdb(out_dir: &str) -> Result<HeaderLocation, Box<dyn std::error::Error>> {
384383
let target = env::var("TARGET")?;
385384
let archive = LibduckdbArchive::for_target(&target)
386-
.ok_or_else(|| format!("No prebuilt DuckDB libraries available for target '{target}'"))?;
385+
.ok_or_else(|| format!("No pre-built libduckdb available for target '{target}'"))?;
387386

388387
let version = env!("CARGO_PKG_VERSION").to_string();
389388

@@ -528,22 +527,14 @@ mod build_linked {
528527
}
529528

530529
fn display_path(path: &Path) -> String {
531-
workspace_root()
532-
.and_then(|root| path.strip_prefix(&root).ok())
530+
let root = workspace_root();
531+
path.strip_prefix(&root)
533532
.map(|p| p.display().to_string())
534-
.unwrap_or_else(|| path.display().to_string())
533+
.unwrap_or_else(|_| path.display().to_string())
535534
}
536535

537-
fn workspace_root() -> Option<PathBuf> {
538-
env::var("CARGO_MANIFEST_DIR").ok().and_then(|manifest| {
539-
let manifest_path = PathBuf::from(manifest);
540-
for ancestor in manifest_path.ancestors() {
541-
if ancestor.join("Cargo.lock").exists() {
542-
return Some(ancestor.to_path_buf());
543-
}
544-
}
545-
None
546-
})
536+
fn workspace_root() -> PathBuf {
537+
PathBuf::from(env::var("CARGO_WORKSPACE_DIR").unwrap())
547538
}
548539

549540
struct LibduckdbArchive {
@@ -592,7 +583,6 @@ mod build_linked {
592583
.ok()
593584
.and_then(|value| value.parse().ok())
594585
.unwrap_or(90);
595-
596586
reqwest::blocking::Client::builder()
597587
.timeout(std::time::Duration::from_secs(timeout))
598588
.build()

0 commit comments

Comments
 (0)