-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathbuild.rs
More file actions
54 lines (46 loc) · 1.99 KB
/
build.rs
File metadata and controls
54 lines (46 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
50
51
52
53
54
// File: build.rs
// Code: Claude Code and Codex
// Review: Ryoichi Ando ([email protected])
// License: Apache v2.0
use std::env;
fn main() {
#[cfg(not(target_os = "windows"))]
{
use std::process::Command;
let out_dir = env::var("OUT_DIR").unwrap();
let num_threads = num_cpus::get();
println!("cargo:rerun-if-changed=src/cpp");
println!("cargo:rerun-if-changed=eigsys/eig-hpp");
let output = Command::new("make")
.current_dir("src/cpp")
.arg(format!("OUT_DIR={}", out_dir))
.arg(format!("-j{}", num_threads))
.output()
.expect("Failed to execute make command");
if !output.status.success() {
let error_message = String::from_utf8(output.stderr).unwrap();
println!("make command failed with output: {}", error_message);
std::process::exit(1);
}
let mut dir = std::env::current_dir().expect("Failed to get current directory");
dir.push(out_dir);
dir.push("lib");
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", dir.display());
println!("cargo:rustc-link-search=native={}", dir.display());
println!("cargo:rustc-link-lib=dylib=simplelog");
println!("cargo:rustc-link-lib=dylib=simbackend_cuda");
}
#[cfg(target_os = "windows")]
{
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let lib_dir = format!("{}\\src\\cpp\\build\\lib", manifest_dir);
println!("cargo:rustc-link-search=native={}", lib_dir);
println!("cargo:rustc-link-lib=dylib=libsimbackend_cuda");
// CUDA_PATH must be set by build.bat (points to local cuda directory)
let cuda_path = env::var("CUDA_PATH")
.expect("CUDA_PATH environment variable must be set");
let cuda_lib_path = format!("{}\\lib\\x64", cuda_path);
println!("cargo:rustc-link-search=native={}", cuda_lib_path);
println!("cargo:rustc-link-lib=dylib=cudart");
}
}