Skip to content

Commit 82f0a0a

Browse files
Replace variadic arguments with fixed (#112)
* variadic to fixed args * remove cargo fmt from generated files * remove extra tab * replace tabs by spaces for CI format failures * Update crates/xtask/src/codegen.rs Co-authored-by: Andrew Brown <[email protected]> * Update crates/xtask/Cargo.toml Co-authored-by: Andrew Brown <[email protected]> * cargo lock update --------- Co-authored-by: Andrew Brown <[email protected]>
1 parent 6617fa6 commit 82f0a0a

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

Cargo.lock

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/openvino-sys/src/generated/functions.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ extern "C" {
640640
#[doc = " @brief Sets properties for a device, acceptable keys can be found in ov_property_key_xxx.\n @ingroup ov_compiled_model_c_api\n @param compiled_model A pointer to the ov_compiled_model_t.\n @param ... variadic paramaters The format is <char *property_key, char* property_value>.\n Supported property key please see ov_property.h.\n @return Status code of the operation: OK(0) for success."]
641641
pub fn ov_compiled_model_set_property(
642642
compiled_model: *const ov_compiled_model_t,
643-
...
643+
property_key: *const ::std::os::raw::c_char,
644+
property_value: *const ::std::os::raw::c_char
644645
) -> ov_status_e;
645646
}
646647
extern "C" {
@@ -765,7 +766,8 @@ extern "C" {
765766
pub fn ov_core_set_property(
766767
core: *const ov_core_t,
767768
device_name: *const ::std::os::raw::c_char,
768-
...
769+
property_key: *const ::std::os::raw::c_char,
770+
property_value: *const ::std::os::raw::c_char
769771
) -> ov_status_e;
770772
}
771773
extern "C" {

crates/xtask/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ bindgen = "0.68.1"
1313
clap = { version = "4.4.4", features = ["derive"] }
1414
toml = "0.8.0"
1515
semver = "1.0"
16+
regex = "1.10.4"

crates/xtask/src/codegen.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::util::path_to_crates;
22
use anyhow::{anyhow, ensure, Context, Result};
33
use clap::Args;
4+
use regex::Regex;
45
use std::fs::{File, OpenOptions};
56
use std::io::Write;
67
use std::path::{Path, PathBuf};
@@ -38,6 +39,20 @@ impl CodegenCommand {
3839

3940
// Generate the function bindings into `.../functions.rs`, with a prefix and suffix.
4041
let function_bindings = Self::generate_function_bindings(&header_file)?;
42+
43+
// Runtime linking doesn't work yet with variadic args (...), so we need to convert them
44+
// to a fixed pair of args (property_key, property_value) for a few select functions.
45+
// This is a workaround until the runtime linking is updated to support variadic args.
46+
let functions_to_modify = vec!["ov_core_set_property", "ov_compiled_model_set_property"];
47+
let mut function_bindings_string = function_bindings.to_string();
48+
for function in &functions_to_modify {
49+
let re = Regex::new(&format!(r"(?s){}.*?\.\.\.", function)).unwrap();
50+
if re.is_match(&function_bindings_string) {
51+
function_bindings_string = re.replace(&function_bindings_string, |caps: &regex::Captures| {
52+
caps[0].replace("...", "property_key: *const ::std::os::raw::c_char,\n property_value: *const ::std::os::raw::c_char")
53+
}).to_string();
54+
}
55+
}
4156
let function_bindings_path = output_directory.join(FUNCTIONS_FILE);
4257
{
4358
let mut function_bindings_file = Box::new(File::create(&function_bindings_path)?);
@@ -46,14 +61,12 @@ impl CodegenCommand {
4661
function_bindings_file.write_all(b"type wchar_t = ::std::os::raw::c_char;\n")?;
4762
function_bindings_file.write_all(b"link! {\n")?;
4863
function_bindings_file.write_all(b"\n")?;
49-
function_bindings
50-
.write(function_bindings_file)
51-
.with_context(|| {
52-
format!(
53-
"Failed to write functions to: {}",
54-
&function_bindings_path.display()
55-
)
56-
})?;
64+
function_bindings_file
65+
.write_all(function_bindings_string.as_bytes())
66+
.context(format!(
67+
"Failed to write functions to: {}",
68+
&function_bindings_path.display()
69+
))?;
5770
}
5871

5972
let mut function_bindings_file = OpenOptions::new()

0 commit comments

Comments
 (0)