Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 100 additions & 34 deletions simics-api-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,31 @@ pub mod common {

let bindings = Builder::default()
.clang_arg(
subdir(base_dir_path.as_ref().join(HOST_DIRNAME).join("include")).and_then(
|p| {
subdir(base_dir_path.as_ref().join(HOST_DIRNAME).join("include"))
.and_then(|p| {
p.to_str()
.map(|s| format!("-I{}", s))
.ok_or_else(|| anyhow!("Could not convert path to string"))
},
)?,
})
.or_else(|_| {
// Fallback for Simics 7.28.0+ where Python headers are in separate package (1033)
println!("cargo:warning=Traditional Python include path not found, trying Simics Python package fallback");
let parent_dir = base_dir_path.as_ref().parent().unwrap();
let python_include_path = parent_dir
.join("simics-python-7.10.0")
.join(HOST_DIRNAME)
.join("include");
if python_include_path.exists() {
subdir(&python_include_path)
.and_then(|p| {
p.to_str()
.map(|s| format!("-I{}", s))
.ok_or_else(|| anyhow!("Could not convert path to string"))
})
} else {
bail!("Python include directory not found at {}", python_include_path.display())
}
})?,
)
.clang_arg(format!("-I{}", &wrapper_include_path))
.clang_arg("-fretain-comments-from-system-headers")
Expand Down Expand Up @@ -774,37 +792,67 @@ pub mod common {

let libvtutils = bin_dir.join("libvtutils.so").canonicalize()?;

let sys_lib_dir = base_dir_path
.join(HOST_DIRNAME)
.join("sys")
.join("lib")
.canonicalize()?;
// Try both traditional and fallback sys/lib directories
let sys_lib_dirs = vec![
base_dir_path.join(HOST_DIRNAME).join("sys").join("lib"),
base_dir_path
.parent()
.unwrap()
.join("simics-python-7.10.0")
.join(HOST_DIRNAME)
.join("sys")
.join("lib"),
];

let mut libpython_found = None;
let mut used_sys_lib_dir = None;

for sys_lib_path in &sys_lib_dirs {
println!(
"cargo:warning=Trying libpython path: {}",
sys_lib_path.display()
);
if let Ok(sys_lib_dir) = sys_lib_path.canonicalize() {
if let Some(libpython_path) = read_dir(&sys_lib_dir).ok().and_then(|entries| {
entries
.filter_map(|p| p.ok())
.filter(|p| p.path().is_file())
.filter(|p| {
let path = p.path();
let Some(file_name) = path.file_name() else {
return false;
};
let Some(file_name) = file_name.to_str() else {
return false;
};
file_name.starts_with("libpython")
&& file_name.contains(".so")
&& file_name != "libpython3.so"
})
.map(|p| p.path())
.next()
}) {
println!(
"cargo:warning=Found libpython in: {}",
sys_lib_dir.display()
);
libpython_found = Some(libpython_path);
used_sys_lib_dir = Some(sys_lib_dir);
break;
}
}
}

let libpython = sys_lib_dir.join(
read_dir(&sys_lib_dir)?
.filter_map(|p| p.ok())
.filter(|p| p.path().is_file())
.filter(|p| {
let path = p.path();

let Some(file_name) = path.file_name() else {
return false;
};

let Some(file_name) = file_name.to_str() else {
return false;
};

file_name.starts_with("libpython")
&& file_name.contains(".so")
&& file_name != "libpython3.so"
})
.map(|p| p.path())
.next()
.ok_or_else(|| {
anyhow!("No libpythonX.XX.so.X.X found in {}", sys_lib_dir.display())
})?,
);
let (sys_lib_dir, libpython_path) = match (used_sys_lib_dir, libpython_found) {
(Some(dir), Some(path)) => (dir, path),
_ => {
return Err(anyhow!(
"No libpythonX.XX.so.X.X found in any sys/lib directory"
))
}
};

let libpython = sys_lib_dir.join(libpython_path);

println!(
"cargo:rustc-link-lib=dylib:+verbatim={}",
Expand Down Expand Up @@ -1070,6 +1118,24 @@ fn main() -> Result<()> {
// -s ~/simics/simics-7.18.0 \
// -s ~/simics/simics-7.19.0 \
// -s ~/simics/simics-7.20.0 \
// -s ~/simics/simics-7.21.0 \
// -s ~/simics/simics-7.22.0 \
// -s ~/simics/simics-7.23.0 \
// -s ~/simics/simics-7.24.0 \
// -s ~/simics/simics-7.25.0 \
// -s ~/simics/simics-7.26.0 \
// -s ~/simics/simics-7.27.0 \
// -s ~/simics/simics-7.28.0 \
// -s ~/simics/simics-7.29.0 \
// -s ~/simics/simics-7.30.0 \
// -s ~/simics/simics-7.31.0 \
// -s ~/simics/simics-7.32.0 \
// -s ~/simics/simics-7.33.0 \
// -s ~/simics/simics-7.34.0 \
// -s ~/simics/simics-7.35.0 \
// -s ~/simics/simics-7.36.0 \
// -s ~/simics/simics-7.37.0 \
// -s ~/simics/simics-7.38.0 \
// -o simics-api-sys/simics_api_items.rs
// ```
//
Expand Down
23 changes: 21 additions & 2 deletions simics-api-sys/simics_api_items.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
const SIMICS_API_ITEMS: &[&str; 2480usize] = &[
"A20_INTERFACE",
"ABS_POINTER_ACTIVATE_INTERFACE",
"ABS_POINTER_INTERFACE",
Expand Down Expand Up @@ -269,6 +269,8 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"I2C_SLAVE_INTERFACE",
"I2C_SLAVE_V2_INTERFACE",
"I3C_DAA_SNOOP_INTERFACE",
"I3C_HDR_MASTER_INTERFACE",
"I3C_HDR_SLAVE_INTERFACE",
"I3C_MASTER_INTERFACE",
"I3C_SLAVE_INTERFACE",
"I8051_INTERRUPT_INTERFACE",
Expand Down Expand Up @@ -341,6 +343,7 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"MS1553_TERMINAL_INTERFACE",
"MULTI_LEVEL_SIGNAL_INTERFACE",
"NAND_FLASH_INTERFACE",
"NETWORK_BREAKPOINT_INTERFACE",
"NIOS_CACHE_INTERFACE",
"NIOS_CUSTOM_INTERFACE",
"NIOS_EIC_INTERFACE",
Expand Down Expand Up @@ -432,6 +435,7 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"RECORDER_INTERFACE",
"RECORDER_V2_INTERFACE",
"REGISTER_BREAKPOINT_INTERFACE",
"REGISTER_VIEW_CATALOG_INTERFACE",
"REGISTER_VIEW_INTERFACE",
"REGISTER_VIEW_READ_ONLY_INTERFACE",
"RISCV_CLIC_INTERFACE",
Expand Down Expand Up @@ -506,6 +510,8 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"SIM_DI_PREFIX_SSE_BIT",
"SIM_DI_PREFIX_SS_BIT",
"SIM_MAJOR_VERSION_DIFF",
"SIM_PYOBJECT",
"SIM_PYTYPEOBJECT",
"SIM_STC_flush_cache",
"SIM_VERSION",
"SIM_VERSION_4_8",
Expand Down Expand Up @@ -589,6 +595,7 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"SIM_ensure_partial_attr_order",
"SIM_event_cancel_step",
"SIM_event_cancel_time",
"SIM_event_class_flags",
"SIM_event_find_next_cycle",
"SIM_event_find_next_step",
"SIM_event_find_next_time",
Expand Down Expand Up @@ -626,6 +633,7 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"SIM_get_class_port_interface",
"SIM_get_debugger",
"SIM_get_directories",
"SIM_get_event_class",
"SIM_get_global_message",
"SIM_get_init_arg_boolean",
"SIM_get_init_arg_string",
Expand Down Expand Up @@ -1240,13 +1248,14 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"XTENSA_TIE_OUTPUT_QUEUE_INTERFACE",
"XTENSA_WWDT_CONFIG_INTERFACE",
"XTENSA_WWDT_FAULTINFO_INTERFACE",
"_",
"_LARGEFILE64_SOURCE",
"_LARGEFILE_SOURCE",
"_POSIX_C_SOURCE",
"_XOPEN_SOURCE",
"__FILE",
"__bool_true_false_are_defined",
"_mod",
"_cpu_instrumentation_entry_t",
"_object",
"_typeobject",
"a20_interface",
Expand Down Expand Up @@ -1335,6 +1344,7 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"branch_recorder",
"branch_recorder_direction_t",
"branch_recorder_t",
"break_net_cb_t",
"break_string_cb_t",
"break_strings_v2_interface",
"break_strings_v2_interface_t",
Expand Down Expand Up @@ -1730,6 +1740,8 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"i2c_status_t",
"i3c_ack_t",
"i3c_daa_snoop_interface",
"i3c_hdr_master_interface",
"i3c_hdr_slave_interface",
"i3c_master_interface",
"i3c_slave_interface",
"ieee_802_3_duplex_mode_t",
Expand Down Expand Up @@ -1930,6 +1942,7 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"os_getcwd_nice",
"os_gethostname",
"os_getpid",
"os_gettid",
"os_gmtime",
"os_host_ncpus",
"os_host_phys_mem_size",
Expand Down Expand Up @@ -2029,6 +2042,7 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"pcie_ats_translation_completion_entry_t",
"pcie_byte_count_ret_t",
"pcie_device_interface",
"pcie_ecs_t",
"pcie_error_ret_t",
"pcie_error_t",
"pcie_hotplug_events_interface",
Expand Down Expand Up @@ -2168,6 +2182,8 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"riscv_imsic_interface",
"riscv_imsic_interface_t",
"riscv_instruction_action_interface",
"riscv_io_error_ret_t",
"riscv_io_error_t",
"riscv_memory_transaction",
"riscv_memory_transaction_t",
"riscv_reset_cb_t",
Expand All @@ -2181,6 +2197,7 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"sb_addesc",
"sb_addfmt",
"sb_detach",
"sb_escape",
"sb_fmt",
"sb_free",
"sb_new",
Expand Down Expand Up @@ -2298,6 +2315,8 @@ const SIMICS_API_ITEMS: &[&str; 2461usize] = &[
"transaction_issue_cb_t",
"transaction_subscribe_interface",
"transaction_t",
"transaction_target_type_ret_t",
"transaction_target_type_t",
"transaction_trace_atom_access",
"transaction_trace_atom_access_t",
"translate_interface",
Expand Down
90 changes: 60 additions & 30 deletions simics-build-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,37 +119,67 @@ pub fn emit_link_info() -> Result<()> {

let libvtutils = bin_dir.join("libvtutils.so").canonicalize()?;

let sys_lib_dir = base_dir_path
.join(HOST_DIRNAME)
.join("sys")
.join("lib")
.canonicalize()?;

let libpython = sys_lib_dir.join(
read_dir(&sys_lib_dir)?
.filter_map(|p| p.ok())
.filter(|p| p.path().is_file())
.filter(|p| {
let path = p.path();

let Some(file_name) = path.file_name() else {
return false;
};

let Some(file_name) = file_name.to_str() else {
return false;
};
// Try both traditional and fallback sys/lib directories
let sys_lib_dirs = vec![
base_dir_path.join(HOST_DIRNAME).join("sys").join("lib"),
base_dir_path
.parent()
.unwrap()
.join("simics-python-7.10.0")
.join(HOST_DIRNAME)
.join("sys")
.join("lib"),
];

let mut libpython_found = None;
let mut used_sys_lib_dir = None;

for sys_lib_path in &sys_lib_dirs {
println!(
"cargo:warning=Trying libpython path: {}",
sys_lib_path.display()
);
if let Ok(sys_lib_dir) = sys_lib_path.canonicalize() {
if let Some(libpython_path) = read_dir(&sys_lib_dir).ok().and_then(|entries| {
entries
.filter_map(|p| p.ok())
.filter(|p| p.path().is_file())
.filter(|p| {
let path = p.path();
let Some(file_name) = path.file_name() else {
return false;
};
let Some(file_name) = file_name.to_str() else {
return false;
};
file_name.starts_with("libpython")
&& file_name.contains(".so")
&& file_name != "libpython3.so"
})
.map(|p| p.path())
.next()
}) {
println!(
"cargo:warning=Found libpython in: {}",
sys_lib_dir.display()
);
libpython_found = Some(libpython_path);
used_sys_lib_dir = Some(sys_lib_dir);
break;
}
}
}

let (sys_lib_dir, libpython_path) = match (used_sys_lib_dir, libpython_found) {
(Some(dir), Some(path)) => (dir, path),
_ => {
return Err(anyhow!(
"No libpythonX.XX.so.X.X found in any sys/lib directory"
))
}
};

file_name.starts_with("libpython")
&& file_name.contains(".so")
&& file_name != "libpython3.so"
})
.map(|p| p.path())
.next()
.ok_or_else(|| {
anyhow!("No libpythonX.XX.so.X.X found in {}", sys_lib_dir.display())
})?,
);
let libpython = sys_lib_dir.join(libpython_path);

println!(
"cargo:rustc-link-lib=dylib:+verbatim={}",
Expand Down
Loading
Loading