build.rs 1.21 KB
Newer Older
1
2
3
4
5
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

use std::env;
use std::process::Command;
6
use vergen_gitcl::{Emitter, GitclBuilder};
7

8
fn main() -> anyhow::Result<()> {
9
10
11
12
13
14
    if has_cuda_toolkit() && !has_feature("cuda") && is_cuda_engine() {
        println!("cargo:warning=CUDA not enabled, re-run with `--features cuda`");
    }
    if is_mac() && !has_feature("metal") {
        println!("cargo:warning=Metal not enabled, re-run with `--features metal`");
    }
15
16
17
18
19
20
21
22

    let git_config = GitclBuilder::default()
        .describe(true, false, None)
        .build()?;

    Emitter::default().add_instructions(&git_config)?.emit()?;

    Ok(())
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
}

fn has_feature(s: &str) -> bool {
    env::var(format!("CARGO_FEATURE_{}", s.to_uppercase())).is_ok()
}

fn has_cuda_toolkit() -> bool {
    if let Ok(output) = Command::new("nvcc").arg("--version").output() {
        output.status.success()
    } else {
        false
    }
}

fn is_cuda_engine() -> bool {
    has_feature("mistralrs") || has_feature("llamacpp")
}

#[cfg(target_os = "macos")]
fn is_mac() -> bool {
    true
}

#[cfg(not(target_os = "macos"))]
fn is_mac() -> bool {
    false
}