Skip to content

Commit fab2b9e

Browse files
committed
more reliable target directory estimation
1 parent 73a346c commit fab2b9e

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[workspace]
22
resolver = "2"
33
members = [
4-
"llama-cpp-sys-2",
5-
"llama-cpp-2",
6-
"examples/embeddings",
7-
"examples/simple", "examples/reranker",
4+
"llama-cpp-sys-2",
5+
"llama-cpp-2",
6+
"examples/embeddings",
7+
"examples/simple",
8+
"examples/reranker",
89
]
910

1011
[workspace.dependencies]

examples/simple/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ edition = "2021"
88
[dependencies]
99
llama-cpp-2 = { path = "../../llama-cpp-2", version = "0.1.69" }
1010
hf-hub = { workspace = true }
11-
clap = { workspace = true , features = ["derive"] }
11+
clap = { workspace = true, features = ["derive"] }
1212
anyhow = { workspace = true }
1313
encoding_rs = { workspace = true }
1414
tracing-subscriber = { workspace = true }
1515

1616
[features]
1717
cuda = ["llama-cpp-2/cuda"]
18-
metal = ["llama-cpp-2/metal"]
18+
metal = ["llama-cpp-2/metal"]
1919
native = ["llama-cpp-2/native"]
2020
vulkan = ["llama-cpp-2/vulkan"]
2121

llama-cpp-sys-2/build.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use cmake::Config;
22
use glob::glob;
3-
use walkdir::DirEntry;
43
use std::env;
54
use std::path::{Path, PathBuf};
65
use std::process::Command;
6+
use walkdir::DirEntry;
77

88
macro_rules! debug_log {
99
($($arg:tt)*) => {
@@ -13,19 +13,13 @@ macro_rules! debug_log {
1313
};
1414
}
1515

16-
fn get_cargo_target_dir() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
17-
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR")?);
18-
let profile = std::env::var("PROFILE")?;
19-
let mut target_dir = None;
20-
let mut sub_path = out_dir.as_path();
21-
while let Some(parent) = sub_path.parent() {
22-
if parent.ends_with(&profile) {
23-
target_dir = Some(parent);
24-
break;
25-
}
26-
sub_path = parent;
27-
}
28-
let target_dir = target_dir.ok_or("not found")?;
16+
fn get_cargo_target_dir() -> Result<PathBuf, Box<dyn std::error::Error>> {
17+
let out_dir = env::var("OUT_DIR")?;
18+
let path = PathBuf::from(out_dir);
19+
let target_dir = path
20+
.ancestors()
21+
.nth(3)
22+
.ok_or("OUT_DIR is not deep enough")?;
2923
Ok(target_dir.to_path_buf())
3024
}
3125

@@ -129,7 +123,10 @@ fn macos_link_search_path() -> Option<String> {
129123
}
130124

131125
fn is_hidden(e: &DirEntry) -> bool {
132-
e.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or_default()
126+
e.file_name()
127+
.to_str()
128+
.map(|s| s.starts_with('.'))
129+
.unwrap_or_default()
133130
}
134131

135132
fn main() {
@@ -167,9 +164,19 @@ fn main() {
167164
llama_src.join("ggml/src"),
168165
llama_src.join("common"),
169166
];
170-
for entry in walkdir::WalkDir::new(&llama_src).into_iter().filter_entry(|e| !is_hidden(e)) {
167+
for entry in walkdir::WalkDir::new(&llama_src)
168+
.into_iter()
169+
.filter_entry(|e| !is_hidden(e))
170+
{
171171
let entry = entry.expect("Failed to obtain entry");
172-
let rebuild = entry.file_name().to_str().map(|f| f.starts_with("CMake")).unwrap_or_default() || rebuild_on_children_of.iter().any(|src_folder| entry.path().starts_with(src_folder));
172+
let rebuild = entry
173+
.file_name()
174+
.to_str()
175+
.map(|f| f.starts_with("CMake"))
176+
.unwrap_or_default()
177+
|| rebuild_on_children_of
178+
.iter()
179+
.any(|src_folder| entry.path().starts_with(src_folder));
173180
if rebuild {
174181
println!("cargo:rerun-if-changed={}", entry.path().display());
175182
}

0 commit comments

Comments
 (0)