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

use std::env;
5
use std::fs;
6
7
8
9
use std::path::Path;

fn main() {
    let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
10
    let out_dir = env::var("OUT_DIR").unwrap();
11

12
13
14
15
16
17
18
19
20
21
    let bindings = cbindgen::generate(&crate_dir).expect("Unable to generate bindings");

    // Primary output: write to OUT_DIR (inside target/) so the header survives
    // Docker BuildKit cache mounts across rebuilds.
    let out_dir_header = Path::new(&out_dir).join("llm_engine.h");
    bindings.write_to_file(&out_dir_header);

    // Convenience copy: write to source tree for local development workflows
    // (e.g. `make build` which expects the header under the crate directory).
    let src_tree_header = Path::new(&crate_dir)
22
23
        .join("include")
        .join("nvidia")
Neelay Shah's avatar
Neelay Shah committed
24
        .join("dynamo_llm")
25
        .join("llm_engine.h");
26
27
    fs::create_dir_all(src_tree_header.parent().unwrap()).ok();
    fs::copy(&out_dir_header, &src_tree_header).ok();
28
}