Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include 'extern "C"' in our C header files when included in a C++ build. #2066

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Include 'extern "C"' in our C header files when included in a C++ build.
  • Loading branch information
nlewycky committed Jan 27, 2021
commit 95887af4da919e198bf4cf7e91a6991f152b6282
1 change: 1 addition & 0 deletions lib/c-api/build.rs
Original file line number Diff line number Diff line change
@@ -240,6 +240,7 @@ fn new_builder(language: Language, crate_dir: &str, include_guard: &str, header:
Builder::new()
.with_config(cbindgen::Config {
sort_by: cbindgen::SortKey::Name,
cpp_compat: true,
..cbindgen::Config::default()
})
.with_language(language)
32 changes: 29 additions & 3 deletions lib/c-api/wasmer.h
Original file line number Diff line number Diff line change
@@ -55,7 +55,11 @@
#include <stdlib.h>

#if defined(WASMER_WASI_ENABLED)
enum Version {
enum Version
#ifdef __cplusplus
: uint8_t
#endif // __cplusplus
{
#if defined(WASMER_WASI_ENABLED)
/**
* Version cannot be detected or is unknown.
@@ -82,13 +86,19 @@ enum Version {
Snapshot1 = 3,
#endif
};
#ifndef __cplusplus
typedef uint8_t Version;
#endif // __cplusplus
#endif

/**
* List of export/import kinds.
*/
enum wasmer_import_export_kind {
enum wasmer_import_export_kind
#ifdef __cplusplus
: uint32_t
#endif // __cplusplus
{
/**
* The export/import is a function.
*/
@@ -106,7 +116,9 @@ enum wasmer_import_export_kind {
*/
WASM_TABLE = 3,
};
#ifndef __cplusplus
typedef uint32_t wasmer_import_export_kind;
#endif // __cplusplus

/**
* The `wasmer_result_t` enum is a type that represents either a
@@ -128,7 +140,11 @@ typedef enum {
*
* See `wasmer_value_t` to get a complete example.
*/
enum wasmer_value_tag {
enum wasmer_value_tag
#ifdef __cplusplus
: uint32_t
#endif // __cplusplus
{
/**
* Represents the `i32` WebAssembly type.
*/
@@ -146,7 +162,9 @@ enum wasmer_value_tag {
*/
WASM_F64,
};
#ifndef __cplusplus
typedef uint32_t wasmer_value_tag;
#endif // __cplusplus

typedef struct {

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

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
* Creates a new Module from the given wasm bytes.
*
@@ -1579,4 +1601,8 @@ wasmer_import_object_t *wasmer_wasi_generate_import_object_for_version(unsigned
Version wasmer_wasi_get_version(const wasmer_module_t *module);
#endif

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

#endif /* WASMER_H */
8 changes: 8 additions & 0 deletions lib/c-api/wasmer_wasm.h
Original file line number Diff line number Diff line change
@@ -124,6 +124,10 @@ typedef struct wasi_env_t wasi_env_t;
typedef struct wasi_version_t wasi_version_t;
#endif

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

#if defined(WASMER_WASI_ENABLED)
void wasi_config_arg(wasi_config_t *config, const char *arg);
#endif
@@ -567,4 +571,8 @@ const char *wasmer_version_pre(void);
*/
void wat2wasm(const wasm_byte_vec_t *wat, wasm_byte_vec_t *out);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

#endif /* WASMER_WASM_H */