Skip to content

Commit 17de34c

Browse files
bors[bot]nlewycky
andauthored
Merge #2066
2066: Include 'extern "C"' in our C header files when included in a C++ build. r=nlewycky a=nlewycky # Description Fixes #1952 # Review - [ ] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Nick Lewycky <nick@wasmer.io>
2 parents cfc8f04 + 95887af commit 17de34c

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

lib/c-api/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ fn new_builder(language: Language, crate_dir: &str, include_guard: &str, header:
240240
Builder::new()
241241
.with_config(cbindgen::Config {
242242
sort_by: cbindgen::SortKey::Name,
243+
cpp_compat: true,
243244
..cbindgen::Config::default()
244245
})
245246
.with_language(language)

lib/c-api/wasmer.h

+29-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@
5555
#include <stdlib.h>
5656

5757
#if defined(WASMER_WASI_ENABLED)
58-
enum Version {
58+
enum Version
59+
#ifdef __cplusplus
60+
: uint8_t
61+
#endif // __cplusplus
62+
{
5963
#if defined(WASMER_WASI_ENABLED)
6064
/**
6165
* Version cannot be detected or is unknown.
@@ -82,13 +86,19 @@ enum Version {
8286
Snapshot1 = 3,
8387
#endif
8488
};
89+
#ifndef __cplusplus
8590
typedef uint8_t Version;
91+
#endif // __cplusplus
8692
#endif
8793

8894
/**
8995
* List of export/import kinds.
9096
*/
91-
enum wasmer_import_export_kind {
97+
enum wasmer_import_export_kind
98+
#ifdef __cplusplus
99+
: uint32_t
100+
#endif // __cplusplus
101+
{
92102
/**
93103
* The export/import is a function.
94104
*/
@@ -106,7 +116,9 @@ enum wasmer_import_export_kind {
106116
*/
107117
WASM_TABLE = 3,
108118
};
119+
#ifndef __cplusplus
109120
typedef uint32_t wasmer_import_export_kind;
121+
#endif // __cplusplus
110122

111123
/**
112124
* The `wasmer_result_t` enum is a type that represents either a
@@ -128,7 +140,11 @@ typedef enum {
128140
*
129141
* See `wasmer_value_t` to get a complete example.
130142
*/
131-
enum wasmer_value_tag {
143+
enum wasmer_value_tag
144+
#ifdef __cplusplus
145+
: uint32_t
146+
#endif // __cplusplus
147+
{
132148
/**
133149
* Represents the `i32` WebAssembly type.
134150
*/
@@ -146,7 +162,9 @@ enum wasmer_value_tag {
146162
*/
147163
WASM_F64,
148164
};
165+
#ifndef __cplusplus
149166
typedef uint32_t wasmer_value_tag;
167+
#endif // __cplusplus
150168

151169
typedef struct {
152170

@@ -409,6 +427,10 @@ typedef struct {
409427
} wasmer_wasi_map_dir_entry_t;
410428
#endif
411429

430+
#ifdef __cplusplus
431+
extern "C" {
432+
#endif // __cplusplus
433+
412434
/**
413435
* Creates a new Module from the given wasm bytes.
414436
*
@@ -1579,4 +1601,8 @@ wasmer_import_object_t *wasmer_wasi_generate_import_object_for_version(unsigned
15791601
Version wasmer_wasi_get_version(const wasmer_module_t *module);
15801602
#endif
15811603

1604+
#ifdef __cplusplus
1605+
} // extern "C"
1606+
#endif // __cplusplus
1607+
15821608
#endif /* WASMER_H */

lib/c-api/wasmer_wasm.h

+8
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ typedef struct wasi_env_t wasi_env_t;
124124
typedef struct wasi_version_t wasi_version_t;
125125
#endif
126126

127+
#ifdef __cplusplus
128+
extern "C" {
129+
#endif // __cplusplus
130+
127131
#if defined(WASMER_WASI_ENABLED)
128132
void wasi_config_arg(wasi_config_t *config, const char *arg);
129133
#endif
@@ -567,4 +571,8 @@ const char *wasmer_version_pre(void);
567571
*/
568572
void wat2wasm(const wasm_byte_vec_t *wat, wasm_byte_vec_t *out);
569573

574+
#ifdef __cplusplus
575+
} // extern "C"
576+
#endif // __cplusplus
577+
570578
#endif /* WASMER_WASM_H */

0 commit comments

Comments
 (0)