Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use #[feature(core_ffi_c)] when available #2267

Merged
merged 3 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 13 additions & 3 deletions src/codegen/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,19 @@ pub mod ast_ty {
#prefix::#ident
}
}
None => quote! {
::std::os::raw::#ident
},
None => {
if ctx.options().use_core &&
ctx.options().rust_features().core_ffi_c
{
quote! {
::core::ffi::#ident
}
} else {
quote! {
::std::os::raw::#ident
}
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ macro_rules! rust_target_base {
/// Nightly rust
/// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
/// * `vectorcall` calling convention (no tracking issue)
/// * `core_ffi_c` ([Tracking issue](https://github.com/rust-lang/rust/issues/94501))
=> Nightly => nightly;
);
}
Expand Down Expand Up @@ -236,6 +237,7 @@ rust_feature_def!(
Nightly {
=> thiscall_abi;
=> vectorcall_abi;
=> core_ffi_c;
}
);

Expand Down
21 changes: 21 additions & 0 deletions tests/expectations/tests/core_ffi_c.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/headers/core_ffi_c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// bindgen-flags: --rust-target nightly --raw-line '#![cfg(feature = "nightly")]' --use-core --no-convert-floats
typedef char c_char;
typedef double c_double;
typedef float c_float;
typedef int c_int;
typedef long c_long;
typedef long long c_longlong;
typedef signed char c_schar;
typedef short c_short;
typedef unsigned char c_uchar;
typedef unsigned int c_uint;
typedef unsigned long c_ulong;
typedef unsigned long long c_ulonglong;
typedef unsigned short c_ushort;