Skip to content

Commit 130a310

Browse files
committed
Add support for unsafe extern blocks
1 parent 35e7078 commit 130a310

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

bindgen/codegen/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,14 @@ impl CodeGenerator for Var {
800800
quote! { mut }
801801
};
802802

803+
let safety = ctx
804+
.options()
805+
.rust_features
806+
.unsafe_extern_blocks
807+
.then(|| quote!(unsafe));
808+
803809
let tokens = quote!(
804-
extern "C" {
810+
#safety extern "C" {
805811
#(#attrs)*
806812
pub static #maybe_mut #canonical_ident: #ty;
807813
}
@@ -4704,9 +4710,16 @@ impl CodeGenerator for Function {
47044710
let ret = utils::fnsig_return_ty(ctx, signature);
47054711

47064712
let ident = ctx.rust_ident(ident);
4713+
4714+
let safety = ctx
4715+
.options()
4716+
.rust_features
4717+
.unsafe_extern_blocks
4718+
.then(|| quote!(unsafe));
4719+
47074720
let tokens = quote! {
47084721
#wasm_link_attribute
4709-
extern #abi {
4722+
#safety extern #abi {
47104723
#(#attributes)*
47114724
pub fn #ident ( #( #args ),* ) #ret;
47124725
}

bindgen/features.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ define_rust_targets! {
255255
ptr_metadata: #81513,
256256
layout_for_ptr: #69835,
257257
},
258+
Stable_1_82(82) => {
259+
unsafe_extern_blocks: #127921,
260+
},
258261
Stable_1_77(77) => {
259262
offset_of: #106655,
260263
literal_cstr(2021)|(2024): #117472,

0 commit comments

Comments
 (0)