Skip to content

Commit 3162981

Browse files
flaviojsemilio
authored andcommitted
Output condition for globals.
1 parent e469e44 commit 3162981

File tree

12 files changed

+85
-0
lines changed

12 files changed

+85
-0
lines changed

src/bindgen/language_backend/clike.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,9 @@ impl LanguageBackend for CLikeLanguageBackend<'_> {
770770
}
771771

772772
fn write_static<W: Write>(&mut self, out: &mut SourceWriter<W>, s: &Static) {
773+
let condition = s.cfg.to_condition(self.config);
774+
condition.write_before(self.config, out);
775+
773776
self.write_documentation(out, &s.documentation);
774777
out.write("extern ");
775778
if let Type::Ptr { is_const: true, .. } = s.ty {
@@ -778,6 +781,8 @@ impl LanguageBackend for CLikeLanguageBackend<'_> {
778781
}
779782
cdecl::write_field(self, out, &s.ty, &s.export_name, self.config);
780783
out.write(";");
784+
785+
condition.write_after(self.config, out);
781786
}
782787

783788
fn write_type<W: Write>(&mut self, out: &mut SourceWriter<W>, t: &Type) {

src/bindgen/language_backend/cython.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ impl LanguageBackend for CythonLanguageBackend<'_> {
315315
}
316316

317317
fn write_static<W: Write>(&mut self, out: &mut SourceWriter<W>, s: &Static) {
318+
let condition = s.cfg.to_condition(self.config);
319+
condition.write_before(self.config, out);
320+
318321
self.write_documentation(out, &s.documentation);
319322
out.write("extern ");
320323
if let Type::Ptr { is_const: true, .. } = s.ty {
@@ -323,6 +326,8 @@ impl LanguageBackend for CythonLanguageBackend<'_> {
323326
}
324327
cdecl::write_field(self, out, &s.ty, &s.export_name, self.config);
325328
out.write(";");
329+
330+
condition.write_after(self.config, out);
326331
}
327332

328333
fn write_type<W: Write>(&mut self, out: &mut SourceWriter<W>, t: &Type) {

tests/expectations/cfg.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ typedef struct {
8383
float y;
8484
} Normal;
8585

86+
#if defined(PLATFORM_WIN)
87+
extern int32_t global_array_with_different_sizes[2];
88+
#endif
89+
90+
#if defined(PLATFORM_UNIX)
91+
extern int32_t global_array_with_different_sizes[1];
92+
#endif
93+
8694
#if (defined(PLATFORM_UNIX) && defined(X11))
8795
void root(FooHandle a, C c);
8896
#endif

tests/expectations/cfg.compat.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ typedef struct {
105105
extern "C" {
106106
#endif // __cplusplus
107107

108+
#if defined(PLATFORM_WIN)
109+
extern int32_t global_array_with_different_sizes[2];
110+
#endif
111+
112+
#if defined(PLATFORM_UNIX)
113+
extern int32_t global_array_with_different_sizes[1];
114+
#endif
115+
108116
#if (defined(PLATFORM_UNIX) && defined(X11))
109117
void root(FooHandle a, C c);
110118
#endif

tests/expectations/cfg.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ struct Normal {
218218

219219
extern "C" {
220220

221+
#if defined(PLATFORM_WIN)
222+
extern int32_t global_array_with_different_sizes[2];
223+
#endif
224+
225+
#if defined(PLATFORM_UNIX)
226+
extern int32_t global_array_with_different_sizes[1];
227+
#endif
228+
221229
#if (defined(PLATFORM_UNIX) && defined(X11))
222230
void root(FooHandle a, C c);
223231
#endif

tests/expectations/cfg.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ cdef extern from *:
6262
int32_t x;
6363
float y;
6464

65+
IF PLATFORM_WIN:
66+
extern int32_t global_array_with_different_sizes[2];
67+
68+
IF PLATFORM_UNIX:
69+
extern int32_t global_array_with_different_sizes[1];
70+
6571
IF (PLATFORM_UNIX and X11):
6672
void root(FooHandle a, C c);
6773

tests/expectations/cfg_both.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ typedef struct Normal {
8383
float y;
8484
} Normal;
8585

86+
#if defined(PLATFORM_WIN)
87+
extern int32_t global_array_with_different_sizes[2];
88+
#endif
89+
90+
#if defined(PLATFORM_UNIX)
91+
extern int32_t global_array_with_different_sizes[1];
92+
#endif
93+
8694
#if (defined(PLATFORM_UNIX) && defined(X11))
8795
void root(struct FooHandle a, union C c);
8896
#endif

tests/expectations/cfg_both.compat.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ typedef struct Normal {
105105
extern "C" {
106106
#endif // __cplusplus
107107

108+
#if defined(PLATFORM_WIN)
109+
extern int32_t global_array_with_different_sizes[2];
110+
#endif
111+
112+
#if defined(PLATFORM_UNIX)
113+
extern int32_t global_array_with_different_sizes[1];
114+
#endif
115+
108116
#if (defined(PLATFORM_UNIX) && defined(X11))
109117
void root(struct FooHandle a, union C c);
110118
#endif

tests/expectations/cfg_tag.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ struct Normal {
8383
float y;
8484
};
8585

86+
#if defined(PLATFORM_WIN)
87+
extern int32_t global_array_with_different_sizes[2];
88+
#endif
89+
90+
#if defined(PLATFORM_UNIX)
91+
extern int32_t global_array_with_different_sizes[1];
92+
#endif
93+
8694
#if (defined(PLATFORM_UNIX) && defined(X11))
8795
void root(struct FooHandle a, union C c);
8896
#endif

tests/expectations/cfg_tag.compat.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ struct Normal {
105105
extern "C" {
106106
#endif // __cplusplus
107107

108+
#if defined(PLATFORM_WIN)
109+
extern int32_t global_array_with_different_sizes[2];
110+
#endif
111+
112+
#if defined(PLATFORM_UNIX)
113+
extern int32_t global_array_with_different_sizes[1];
114+
#endif
115+
108116
#if (defined(PLATFORM_UNIX) && defined(X11))
109117
void root(struct FooHandle a, union C c);
110118
#endif

0 commit comments

Comments
 (0)