Skip to content

Commit 101cde0

Browse files
committed
add the experimental feature
1 parent ad0f161 commit 101cde0

File tree

8 files changed

+36
-18
lines changed

8 files changed

+36
-18
lines changed

bindgen-cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ path = "main.rs"
2121
name = "bindgen"
2222

2323
[dependencies]
24-
bindgen = { path = "../bindgen", version = "=0.63.0", features = ["cli"] }
24+
bindgen = { path = "../bindgen", version = "=0.63.0", features = ["cli", "experimental"] }
2525
shlex = "1"
2626
clap = { version = "4", features = ["derive"] }
2727
env_logger = { version = "0.9.0", optional = true }

bindgen-cli/options.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,20 @@ struct BindgenCommand {
354354
#[arg(long, value_name = "CUSTOM")]
355355
with_derive_custom_union: Vec<String>,
356356
/// Generate extern wrappers for inlined functions
357-
#[arg(long)]
357+
#[arg(long, requires = "experimental")]
358358
generate_extern_functions: bool,
359359
/// Sets the name of the header and source code files that would be created if any extern wrapper functions must be generated due to the presence of inlined functions.
360-
#[arg(long, value_name = "FILENAME")]
360+
#[arg(long, requires = "experimental", value_name = "FILENAME")]
361361
extern_functions_file_name: Option<String>,
362-
#[arg(long, value_name = "DIRECTORY")]
362+
#[arg(long, requires = "experimental", value_name = "DIRECTORY")]
363363
/// Sets the directory path where any extra files must be created due to the presence of inlined functions.
364364
extern_functions_directory: Option<String>,
365365
/// Sets the suffix added to the extern wrapper functions generated for inlined functions.
366-
#[arg(long, value_name = "SUFFIX")]
366+
#[arg(long, requires = "experimental", value_name = "SUFFIX")]
367367
extern_function_suffix: Option<String>,
368+
/// Enables experimental features.
369+
#[arg(long)]
370+
experimental: bool,
368371
/// Prints the version, and exits
369372
#[arg(short = 'V', long)]
370373
version: bool,
@@ -489,6 +492,7 @@ where
489492
extern_functions_file_name,
490493
extern_functions_directory,
491494
extern_function_suffix,
495+
experimental: _,
492496
version,
493497
clang_args,
494498
} = command;

bindgen-integration/build.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,13 @@ fn setup_extern_test() {
211211
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
212212
let out_rust_file = out_path.join("extern.rs");
213213

214-
let input_header_dir = PathBuf::from("../bindgen-tests/tests/headers/").canonicalize()
214+
let input_header_dir = PathBuf::from("../bindgen-tests/tests/headers/")
215+
.canonicalize()
215216
.expect("Cannot canonicalize libdir path");
216-
let input_header_file_path = input_header_dir.join("generate-extern-functions.h");
217-
let input_header_file_path_str = input_header_file_path.to_str()
217+
let input_header_file_path =
218+
input_header_dir.join("generate-extern-functions.h");
219+
let input_header_file_path_str = input_header_file_path
220+
.to_str()
218221
.expect("Path could not be converted to a str");
219222

220223
// generate external bindings with the external .c and .h files
@@ -226,7 +229,7 @@ fn setup_extern_test() {
226229
.generate()
227230
.expect("Unable to generate bindings");
228231

229-
println!("cargo:rustc-link-lib=extern"); // tell cargo to link libextern
232+
println!("cargo:rustc-link-lib=extern"); // tell cargo to link libextern
230233
println!("bindings generated: {}", bindings);
231234

232235
let obj_path = out_path.join("extern.o");
@@ -243,7 +246,8 @@ fn setup_extern_test() {
243246
.output()
244247
.expect("`clang` command error")
245248
.status
246-
.success() {
249+
.success()
250+
{
247251
panic!("Could not compile object file");
248252
}
249253

@@ -254,11 +258,13 @@ fn setup_extern_test() {
254258
.output()
255259
.expect("`ar` command error")
256260
.status
257-
.success() {
261+
.success()
262+
{
258263
panic!("Could not emit library file");
259264
}
260265

261-
bindings.write_to_file(out_rust_file)
266+
bindings
267+
.write_to_file(out_rust_file)
262268
.expect("Cound not write bindings to the Rust file");
263269
}
264270

bindgen-tests/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version = "0.1.0"
55
publish = false
66

77
[dev-dependencies]
8-
bindgen = { path = "../bindgen", features = ["cli"] }
8+
bindgen = { path = "../bindgen", features = ["cli", "experimental"] }
99
diff = "0.1"
1010
shlex = "1"
1111
clap = { version = "4", features = ["derive"] }

bindgen-tests/tests/headers/generate-extern-functions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// bindgen-flags: --generate-extern-functions
1+
// bindgen-flags: --experimental --generate-extern-functions
22

33
static inline int foo() {
44
return 11;

bindgen-tests/tests/tests.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ fn test_extern_generated_headers() {
749749
None,
750750
Path::new(expect_path.join("extern.c").to_str().unwrap()),
751751
)
752-
.unwrap();
752+
.unwrap();
753753
}
754754

755755
if expected_h != actual_h {
@@ -759,7 +759,6 @@ fn test_extern_generated_headers() {
759759
None,
760760
Path::new(expect_path.join("extern.h").to_str().unwrap()),
761761
)
762-
.unwrap();
762+
.unwrap();
763763
}
764-
765-
}
764+
}

bindgen/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ runtime = ["clang-sys/runtime"]
4848
# Dynamically discover a `rustfmt` binary using the `which` crate
4949
which-rustfmt = ["which"]
5050
cli = []
51+
experimental = []
5152

5253
# These features only exist for CI testing -- don't use them if you're not hacking
5354
# on bindgen!

bindgen/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ impl Builder {
677677
output_vector.push(suffix.clone());
678678
}
679679

680+
if cfg!(feature = "experimental") {
681+
output_vector.push("--experimental".into());
682+
}
683+
680684
// Add clang arguments
681685

682686
output_vector.push("--".into());
@@ -1815,6 +1819,7 @@ impl Builder {
18151819
self
18161820
}
18171821

1822+
#[cfg(feature = "experimental")]
18181823
/// Whether to generate extern wrappers for inline functions. Defaults to false.
18191824
pub fn generate_extern_functions(mut self, doit: bool) -> Self {
18201825
self.options.generate_extern_functions = if doit {
@@ -1825,6 +1830,7 @@ impl Builder {
18251830
self
18261831
}
18271832

1833+
#[cfg(feature = "experimental")]
18281834
/// Set the name of the header and source code files that would be created if any extern
18291835
/// wrapper functions must be generated due to the presence of inlined functions.
18301836
pub fn extern_functions_file_name<T: AsRef<str>>(
@@ -1836,6 +1842,7 @@ impl Builder {
18361842
self
18371843
}
18381844

1845+
#[cfg(feature = "experimental")]
18391846
/// Set the directory path where any extra files must be created due to the presence of inlined
18401847
/// functions.
18411848
pub fn extern_functions_directory<T: AsRef<str>>(
@@ -1847,6 +1854,7 @@ impl Builder {
18471854
self
18481855
}
18491856

1857+
#[cfg(feature = "experimental")]
18501858
/// Set the suffix added to the extern wrapper functions generated for inlined functions.
18511859
pub fn extern_function_suffix<T: AsRef<str>>(mut self, suffix: T) -> Self {
18521860
self.options.extern_function_suffix = Some(suffix.as_ref().to_owned());

0 commit comments

Comments
 (0)