Skip to content

Commit 5ed1666

Browse files
committed
simics-api-sys: add fallback to detect python headers/lib (1033)
1 parent 5afb179 commit 5ed1666

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

simics-api-sys/build.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,31 @@ pub mod common {
450450

451451
let bindings = Builder::default()
452452
.clang_arg(
453-
subdir(base_dir_path.as_ref().join(HOST_DIRNAME).join("include")).and_then(
454-
|p| {
453+
subdir(base_dir_path.as_ref().join(HOST_DIRNAME).join("include"))
454+
.and_then(|p| {
455455
p.to_str()
456456
.map(|s| format!("-I{}", s))
457457
.ok_or_else(|| anyhow!("Could not convert path to string"))
458-
},
459-
)?,
458+
})
459+
.or_else(|_| {
460+
// Fallback for Simics 7.28.0+ where Python headers are in separate package (1033)
461+
println!("cargo:warning=Traditional Python include path not found, trying Simics Python package fallback");
462+
let parent_dir = base_dir_path.as_ref().parent().unwrap();
463+
let python_include_path = parent_dir
464+
.join("simics-python-7.10.0")
465+
.join(HOST_DIRNAME)
466+
.join("include");
467+
if python_include_path.exists() {
468+
subdir(&python_include_path)
469+
.and_then(|p| {
470+
p.to_str()
471+
.map(|s| format!("-I{}", s))
472+
.ok_or_else(|| anyhow!("Could not convert path to string"))
473+
})
474+
} else {
475+
bail!("Python include directory not found at {}", python_include_path.display())
476+
}
477+
})?,
460478
)
461479
.clang_arg(format!("-I{}", &wrapper_include_path))
462480
.clang_arg("-fretain-comments-from-system-headers")
@@ -778,7 +796,18 @@ pub mod common {
778796
.join(HOST_DIRNAME)
779797
.join("sys")
780798
.join("lib")
781-
.canonicalize()?;
799+
.canonicalize()
800+
.or_else(|_| {
801+
// Fallback for Simics 7.28.0+ where libpython is in separate package (1033)
802+
println!("cargo:warning=Traditional libpython path not found, trying Simics Python package fallback");
803+
let parent_dir = base_dir_path.parent().unwrap();
804+
parent_dir
805+
.join("simics-python-7.10.0")
806+
.join(HOST_DIRNAME)
807+
.join("sys")
808+
.join("lib")
809+
.canonicalize()
810+
})?;
782811

783812
let libpython = sys_lib_dir.join(
784813
read_dir(&sys_lib_dir)?

0 commit comments

Comments
 (0)