-
Notifications
You must be signed in to change notification settings - Fork 373
Conditionally compiled extern "C" { blocks do not get #if defined( guards #807
Copy link
Copy link
Closed
Description
While conditional compilation works fine within extern "C" blocks, annotating an entire extern "C" block with #[cfg()] is valid in Rust, but doesn't work in cbindgen.
For example, for the following Rust project:
# Cargo.toml
[package]
name = "extern_block_conditional"
version = "0.1.0"
authors = ["cbindgen"]
[lib]
name = "extern_block_conditional"
crate-type = ["lib", "dylib"]
features = [ "myfeature" ]# cbindgen.toml
[defines]
"feature = myfeature" = "DEFINED"// src/lib.rs
#[repr(C)]
struct Normal {
x: i32,
y: f32,
}
#[cfg(feature = "myfeature")]
extern "C" {
fn foo() -> i32;
fn bar(a: Normal);
}I would expect the following C output:
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct {
int32_t x;
float y;
} Normal;
#if defined(DEFINED)
extern int32_t foo(void);
extern void bar(Normal a);
#endifBut in fact, writing this as a test case in this project, the output I see is:
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct {
int32_t x;
float y;
} Normal;
extern int32_t foo(void);
extern void bar(Normal a);cc @katef
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels