Skip to content

Commit

Permalink
Merge pull request #638 from ISAWarden/fix/improved-target-directory-…
Browse files Browse the repository at this point in the history
…estimation

more reliable target directory estimation
  • Loading branch information
MarcusDunn authored Feb 7, 2025
2 parents 73a346c + fab2b9e commit dec1651
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[workspace]
resolver = "2"
members = [
"llama-cpp-sys-2",
"llama-cpp-2",
"examples/embeddings",
"examples/simple", "examples/reranker",
"llama-cpp-sys-2",
"llama-cpp-2",
"examples/embeddings",
"examples/simple",
"examples/reranker",
]

[workspace.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ edition = "2021"
[dependencies]
llama-cpp-2 = { path = "../../llama-cpp-2", version = "0.1.69" }
hf-hub = { workspace = true }
clap = { workspace = true , features = ["derive"] }
clap = { workspace = true, features = ["derive"] }
anyhow = { workspace = true }
encoding_rs = { workspace = true }
tracing-subscriber = { workspace = true }

[features]
cuda = ["llama-cpp-2/cuda"]
metal = ["llama-cpp-2/metal"]
metal = ["llama-cpp-2/metal"]
native = ["llama-cpp-2/native"]
vulkan = ["llama-cpp-2/vulkan"]

Expand Down
41 changes: 24 additions & 17 deletions llama-cpp-sys-2/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use cmake::Config;
use glob::glob;
use walkdir::DirEntry;
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;
use walkdir::DirEntry;

macro_rules! debug_log {
($($arg:tt)*) => {
Expand All @@ -13,19 +13,13 @@ macro_rules! debug_log {
};
}

fn get_cargo_target_dir() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR")?);
let profile = std::env::var("PROFILE")?;
let mut target_dir = None;
let mut sub_path = out_dir.as_path();
while let Some(parent) = sub_path.parent() {
if parent.ends_with(&profile) {
target_dir = Some(parent);
break;
}
sub_path = parent;
}
let target_dir = target_dir.ok_or("not found")?;
fn get_cargo_target_dir() -> Result<PathBuf, Box<dyn std::error::Error>> {
let out_dir = env::var("OUT_DIR")?;
let path = PathBuf::from(out_dir);
let target_dir = path
.ancestors()
.nth(3)
.ok_or("OUT_DIR is not deep enough")?;
Ok(target_dir.to_path_buf())
}

Expand Down Expand Up @@ -129,7 +123,10 @@ fn macos_link_search_path() -> Option<String> {
}

fn is_hidden(e: &DirEntry) -> bool {
e.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or_default()
e.file_name()
.to_str()
.map(|s| s.starts_with('.'))
.unwrap_or_default()
}

fn main() {
Expand Down Expand Up @@ -167,9 +164,19 @@ fn main() {
llama_src.join("ggml/src"),
llama_src.join("common"),
];
for entry in walkdir::WalkDir::new(&llama_src).into_iter().filter_entry(|e| !is_hidden(e)) {
for entry in walkdir::WalkDir::new(&llama_src)
.into_iter()
.filter_entry(|e| !is_hidden(e))
{
let entry = entry.expect("Failed to obtain entry");
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));
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));
if rebuild {
println!("cargo:rerun-if-changed={}", entry.path().display());
}
Expand Down

0 comments on commit dec1651

Please sign in to comment.