diff options
author | Christian Poveda <christian.poveda@ferrous-systems.com> | 2022-09-07 15:37:48 -0500 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2022-09-22 21:18:25 -1000 |
commit | 3ec5c8746204ad82bfbf0239d3e9d95d92c2e331 (patch) | |
tree | d31b152420e2fb41987f9394aee2799aa921b037 | |
parent | c84897d33846b4cf0d8494e20326cbc6fc3bb0d8 (diff) |
use `#[feature(core_ffi_c)]` when available
-rw-r--r-- | src/codegen/helpers.rs | 16 | ||||
-rw-r--r-- | src/features.rs | 2 | ||||
-rw-r--r-- | tests/expectations/tests/core_ffi_c.rs | 20 | ||||
-rw-r--r-- | tests/headers/core_ffi_c.h | 14 |
4 files changed, 49 insertions, 3 deletions
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs index 75c169c6..5bf36acb 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -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 + } + } + } } } diff --git a/src/features.rs b/src/features.rs index 59467703..f18ffa88 100644 --- a/src/features.rs +++ b/src/features.rs @@ -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; ); } @@ -236,6 +237,7 @@ rust_feature_def!( Nightly { => thiscall_abi; => vectorcall_abi; + => core_ffi_c; } ); diff --git a/tests/expectations/tests/core_ffi_c.rs b/tests/expectations/tests/core_ffi_c.rs new file mode 100644 index 00000000..7e138a89 --- /dev/null +++ b/tests/expectations/tests/core_ffi_c.rs @@ -0,0 +1,20 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub type c_char = ::core::ffi::c_char; +pub type c_double = ::core::ffi::c_double; +pub type c_float = ::core::ffi::c_float; +pub type c_int = ::core::ffi::c_int; +pub type c_long = ::core::ffi::c_long; +pub type c_longlong = ::core::ffi::c_longlong; +pub type c_schar = ::core::ffi::c_schar; +pub type c_short = ::core::ffi::c_short; +pub type c_uchar = ::core::ffi::c_uchar; +pub type c_uint = ::core::ffi::c_uint; +pub type c_ulong = ::core::ffi::c_ulong; +pub type c_ulonglong = ::core::ffi::c_ulonglong; +pub type c_ushort = ::core::ffi::c_ushort; diff --git a/tests/headers/core_ffi_c.h b/tests/headers/core_ffi_c.h new file mode 100644 index 00000000..3e180fd8 --- /dev/null +++ b/tests/headers/core_ffi_c.h @@ -0,0 +1,14 @@ +// bindgen-flags: --rust-target 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; |