256 lines
6.5 KiB
Diff
256 lines
6.5 KiB
Diff
From ec1631f3e47686e6e0c1b7641bb08b0e39c59250 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= <emilio@crisal.io>
|
|
Date: Tue, 31 Mar 2020 17:41:48 +0200
|
|
Subject: [PATCH] Allow excluding monomorph structs in C mode.
|
|
|
|
Fixes #500.
|
|
---
|
|
src/bindgen/library.rs | 4 +++-
|
|
.../both/exclude_generic_monomorph.c | 15 ++++++++++++
|
|
.../both/exclude_generic_monomorph.compat.c | 23 +++++++++++++++++++
|
|
.../expectations/exclude_generic_monomorph.c | 15 ++++++++++++
|
|
.../exclude_generic_monomorph.compat.c | 23 +++++++++++++++++++
|
|
.../exclude_generic_monomorph.cpp | 15 ++++++++++++
|
|
.../tag/exclude_generic_monomorph.c | 15 ++++++++++++
|
|
.../tag/exclude_generic_monomorph.compat.c | 23 +++++++++++++++++++
|
|
tests/rust/exclude_generic_monomorph.rs | 10 ++++++++
|
|
tests/rust/exclude_generic_monomorph.toml | 11 +++++++++
|
|
10 files changed, 153 insertions(+), 1 deletion(-)
|
|
create mode 100644 tests/expectations/both/exclude_generic_monomorph.c
|
|
create mode 100644 tests/expectations/both/exclude_generic_monomorph.compat.c
|
|
create mode 100644 tests/expectations/exclude_generic_monomorph.c
|
|
create mode 100644 tests/expectations/exclude_generic_monomorph.compat.c
|
|
create mode 100644 tests/expectations/exclude_generic_monomorph.cpp
|
|
create mode 100644 tests/expectations/tag/exclude_generic_monomorph.c
|
|
create mode 100644 tests/expectations/tag/exclude_generic_monomorph.compat.c
|
|
create mode 100644 tests/rust/exclude_generic_monomorph.rs
|
|
create mode 100644 tests/rust/exclude_generic_monomorph.toml
|
|
|
|
diff --git a/src/bindgen/library.rs b/src/bindgen/library.rs
|
|
index 0cdd07ea..4cb0b8b8 100644
|
|
--- a/src/bindgen/library.rs
|
|
+++ b/src/bindgen/library.rs
|
|
@@ -54,7 +54,6 @@ impl Library {
|
|
}
|
|
|
|
pub fn generate(mut self) -> Result<Bindings, Error> {
|
|
- self.remove_excluded();
|
|
self.transfer_annotations();
|
|
self.simplify_standard_types();
|
|
|
|
@@ -67,7 +66,10 @@ impl Library {
|
|
|
|
if self.config.language == Language::C {
|
|
self.instantiate_monomorphs();
|
|
+ self.remove_excluded();
|
|
self.resolve_declaration_types();
|
|
+ } else {
|
|
+ self.remove_excluded();
|
|
}
|
|
|
|
self.rename_items();
|
|
diff --git a/tests/expectations/both/exclude_generic_monomorph.c b/tests/expectations/both/exclude_generic_monomorph.c
|
|
new file mode 100644
|
|
index 00000000..2d43ce15
|
|
--- /dev/null
|
|
+++ b/tests/expectations/both/exclude_generic_monomorph.c
|
|
@@ -0,0 +1,15 @@
|
|
+#include <stdint.h>
|
|
+
|
|
+typedef uint64_t Option_Foo;
|
|
+
|
|
+
|
|
+#include <stdarg.h>
|
|
+#include <stdbool.h>
|
|
+#include <stdint.h>
|
|
+#include <stdlib.h>
|
|
+
|
|
+typedef struct Bar {
|
|
+ Option_Foo foo;
|
|
+} Bar;
|
|
+
|
|
+void root(Bar f);
|
|
diff --git a/tests/expectations/both/exclude_generic_monomorph.compat.c b/tests/expectations/both/exclude_generic_monomorph.compat.c
|
|
new file mode 100644
|
|
index 00000000..76a0a3bb
|
|
--- /dev/null
|
|
+++ b/tests/expectations/both/exclude_generic_monomorph.compat.c
|
|
@@ -0,0 +1,23 @@
|
|
+#include <stdint.h>
|
|
+
|
|
+typedef uint64_t Option_Foo;
|
|
+
|
|
+
|
|
+#include <stdarg.h>
|
|
+#include <stdbool.h>
|
|
+#include <stdint.h>
|
|
+#include <stdlib.h>
|
|
+
|
|
+typedef struct Bar {
|
|
+ Option_Foo foo;
|
|
+} Bar;
|
|
+
|
|
+#ifdef __cplusplus
|
|
+extern "C" {
|
|
+#endif // __cplusplus
|
|
+
|
|
+void root(Bar f);
|
|
+
|
|
+#ifdef __cplusplus
|
|
+} // extern "C"
|
|
+#endif // __cplusplus
|
|
diff --git a/tests/expectations/exclude_generic_monomorph.c b/tests/expectations/exclude_generic_monomorph.c
|
|
new file mode 100644
|
|
index 00000000..e7178367
|
|
--- /dev/null
|
|
+++ b/tests/expectations/exclude_generic_monomorph.c
|
|
@@ -0,0 +1,15 @@
|
|
+#include <stdint.h>
|
|
+
|
|
+typedef uint64_t Option_Foo;
|
|
+
|
|
+
|
|
+#include <stdarg.h>
|
|
+#include <stdbool.h>
|
|
+#include <stdint.h>
|
|
+#include <stdlib.h>
|
|
+
|
|
+typedef struct {
|
|
+ Option_Foo foo;
|
|
+} Bar;
|
|
+
|
|
+void root(Bar f);
|
|
diff --git a/tests/expectations/exclude_generic_monomorph.compat.c b/tests/expectations/exclude_generic_monomorph.compat.c
|
|
new file mode 100644
|
|
index 00000000..062e71ca
|
|
--- /dev/null
|
|
+++ b/tests/expectations/exclude_generic_monomorph.compat.c
|
|
@@ -0,0 +1,23 @@
|
|
+#include <stdint.h>
|
|
+
|
|
+typedef uint64_t Option_Foo;
|
|
+
|
|
+
|
|
+#include <stdarg.h>
|
|
+#include <stdbool.h>
|
|
+#include <stdint.h>
|
|
+#include <stdlib.h>
|
|
+
|
|
+typedef struct {
|
|
+ Option_Foo foo;
|
|
+} Bar;
|
|
+
|
|
+#ifdef __cplusplus
|
|
+extern "C" {
|
|
+#endif // __cplusplus
|
|
+
|
|
+void root(Bar f);
|
|
+
|
|
+#ifdef __cplusplus
|
|
+} // extern "C"
|
|
+#endif // __cplusplus
|
|
diff --git a/tests/expectations/exclude_generic_monomorph.cpp b/tests/expectations/exclude_generic_monomorph.cpp
|
|
new file mode 100644
|
|
index 00000000..e7178367
|
|
--- /dev/null
|
|
+++ b/tests/expectations/exclude_generic_monomorph.cpp
|
|
@@ -0,0 +1,15 @@
|
|
+#include <stdint.h>
|
|
+
|
|
+typedef uint64_t Option_Foo;
|
|
+
|
|
+
|
|
+#include <stdarg.h>
|
|
+#include <stdbool.h>
|
|
+#include <stdint.h>
|
|
+#include <stdlib.h>
|
|
+
|
|
+typedef struct {
|
|
+ Option_Foo foo;
|
|
+} Bar;
|
|
+
|
|
+void root(Bar f);
|
|
diff --git a/tests/expectations/tag/exclude_generic_monomorph.c b/tests/expectations/tag/exclude_generic_monomorph.c
|
|
new file mode 100644
|
|
index 00000000..32686ad9
|
|
--- /dev/null
|
|
+++ b/tests/expectations/tag/exclude_generic_monomorph.c
|
|
@@ -0,0 +1,15 @@
|
|
+#include <stdint.h>
|
|
+
|
|
+typedef uint64_t Option_Foo;
|
|
+
|
|
+
|
|
+#include <stdarg.h>
|
|
+#include <stdbool.h>
|
|
+#include <stdint.h>
|
|
+#include <stdlib.h>
|
|
+
|
|
+struct Bar {
|
|
+ Option_Foo foo;
|
|
+};
|
|
+
|
|
+void root(struct Bar f);
|
|
diff --git a/tests/expectations/tag/exclude_generic_monomorph.compat.c b/tests/expectations/tag/exclude_generic_monomorph.compat.c
|
|
new file mode 100644
|
|
index 00000000..27408515
|
|
--- /dev/null
|
|
+++ b/tests/expectations/tag/exclude_generic_monomorph.compat.c
|
|
@@ -0,0 +1,23 @@
|
|
+#include <stdint.h>
|
|
+
|
|
+typedef uint64_t Option_Foo;
|
|
+
|
|
+
|
|
+#include <stdarg.h>
|
|
+#include <stdbool.h>
|
|
+#include <stdint.h>
|
|
+#include <stdlib.h>
|
|
+
|
|
+struct Bar {
|
|
+ Option_Foo foo;
|
|
+};
|
|
+
|
|
+#ifdef __cplusplus
|
|
+extern "C" {
|
|
+#endif // __cplusplus
|
|
+
|
|
+void root(struct Bar f);
|
|
+
|
|
+#ifdef __cplusplus
|
|
+} // extern "C"
|
|
+#endif // __cplusplus
|
|
diff --git a/tests/rust/exclude_generic_monomorph.rs b/tests/rust/exclude_generic_monomorph.rs
|
|
new file mode 100644
|
|
index 00000000..78fd1973
|
|
--- /dev/null
|
|
+++ b/tests/rust/exclude_generic_monomorph.rs
|
|
@@ -0,0 +1,10 @@
|
|
+#[repr(transparent)]
|
|
+pub struct Foo(NonZeroU64);
|
|
+
|
|
+#[repr(C)]
|
|
+pub struct Bar {
|
|
+ foo: Option<Foo>,
|
|
+}
|
|
+
|
|
+#[no_mangle]
|
|
+pub extern "C" fn root(f: Bar) {}
|
|
diff --git a/tests/rust/exclude_generic_monomorph.toml b/tests/rust/exclude_generic_monomorph.toml
|
|
new file mode 100644
|
|
index 00000000..82d33617
|
|
--- /dev/null
|
|
+++ b/tests/rust/exclude_generic_monomorph.toml
|
|
@@ -0,0 +1,11 @@
|
|
+language = "C"
|
|
+header = """
|
|
+#include <stdint.h>
|
|
+
|
|
+typedef uint64_t Option_Foo;
|
|
+"""
|
|
+
|
|
+[export]
|
|
+exclude = [
|
|
+ "Option_Foo",
|
|
+]
|