Skip to content

Commit c7ced61

Browse files
authored
Make dynamic link functions optional and include more error context (#22)
On recent Intel drivers the `Igcl` object failed to be created. As it turns out the most recent Intel drivers deleted these functions: ctlEnumerateMuxDevices: Err( GetProcAddress { source: Os { code: 127, kind: Uncategorized, message: "The specified procedure could not be found.", }, }, ), ctlGetMuxProperties: Err( GetProcAddress { source: Os { code: 127, kind: Uncategorized, message: "The specified procedure could not be found.", }, }, ), ctlSwitchMux: Err( GetProcAddress { source: Os { code: 127, kind: Uncategorized, message: "The specified procedure could not be found.", }, }, ), This matches their removal from the header in the most recent `v268` release: intel/drivers.gpu.control-library#139 While we could just bump and regenerate the crate on that version (see the other PR), that would suddenly require all other newer functions to be present too which may only be the case on relatively new drivers. To err on the side of caution, make function loading optional in "favour" of panicking at runtime if a symbol was missing (where it is unlikely that most existing used functions are deleted to retain backwards compatibility). Also include better error messages to understand where the error is originating from, and add a simple runnable example to confirm that it's working again directly from this repository.
1 parent 354f9af commit c7ced61

File tree

5 files changed

+1303
-669
lines changed

5 files changed

+1303
-669
lines changed

api_gen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() {
2020
.join("../vendor/drivers.gpu.control-library/include/")
2121
.display()
2222
))
23-
.dynamic_link_require_all(true)
23+
.dynamic_link_require_all(false)
2424
.dynamic_library_name("ControlLib")
2525
.clang_arg("-x")
2626
.clang_arg("c++")

examples/devices.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use anyhow::Result;
2+
3+
fn main() -> Result<()> {
4+
let igcl = igcl::Igcl::new()?;
5+
6+
for d in igcl.enumerate_devices()? {
7+
println!("{}", d.name().to_string_lossy());
8+
println!("\tDevice ID (LUID): {:x?}", d.device_id());
9+
println!("\tPCI BDF: {:?}", d.bus_device_function());
10+
println!("\tPCI vendor: {:#x}", d.pci_vendor_id());
11+
println!("\tPCI device: {:#x}", d.pci_device_id());
12+
println!("\tPCI subsys: {:#x}", d.pci_subsys_id());
13+
println!("\tPCI subsys vendor: {:#x}", d.pci_subsys_vendor_id());
14+
println!("\tDevice type: {:?}", d.device_type());
15+
}
16+
17+
Ok(())
18+
}

src/device_adapter.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ pub enum DriverSettingScope<'a> {
3030
impl DriverSettingScope<'_> {
3131
pub fn name(&self) -> String {
3232
match self {
33-
DriverSettingScope::Global => String::default(),
34-
DriverSettingScope::CurrentProcess => {
35-
std::env::current_exe().map_or("".to_string(), |path| {
36-
path.file_name()
37-
.unwrap_or(OsStr::new(""))
38-
.to_string_lossy()
39-
.to_string()
40-
})
41-
}
42-
DriverSettingScope::Process { process_name } => process_name.to_string(),
33+
Self::Global => String::default(),
34+
Self::CurrentProcess => std::env::current_exe().map_or("".to_string(), |path| {
35+
path.file_name()
36+
.unwrap_or(OsStr::new(""))
37+
.to_string_lossy()
38+
.to_string()
39+
}),
40+
Self::Process { process_name } => process_name.to_string(),
4341
}
4442
}
4543

0 commit comments

Comments
 (0)