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

feat(c-api) Implement cross-compilation API in C #2072

Merged
merged 17 commits into from
Feb 2, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Merge branch 'master' into feat-c-api-cross-compilation-2
  • Loading branch information
Hywan committed Feb 2, 2021
commit 4725a5d62333a57ca372f9d683239eebf81e5dcc
280 changes: 0 additions & 280 deletions lib/c-api/wasmer_wasm.h
Original file line number Diff line number Diff line change
@@ -134,111 +134,10 @@ typedef struct wasi_config_t wasi_config_t;
typedef struct wasi_env_t wasi_env_t;
#endif

/**
* Unstable non-standard Wasmer-specific API to represent a set of
* CPU features.
*
* CPU features are identified by their stringified names. The
* reference is the GCC options:
*
* * <https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html>,
* * <https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html>,
* * <https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html>.
*
* At the time of writing this documentation (it might be outdated in
* the future), the supported features are the following:
*
* * `sse2`,
* * `sse3`,
* * `ssse3`,
* * `sse4.1`,
* * `sse4.2`,
* * `popcnt`,
* * `avx`,
* * `bmi`,
* * `bmi2`,
* * `avx2`,
* * `avx512dq`,
* * `avx512vl`,
* * `lzcnt`.
*
* # Example
*
* ```rust
* # use inline_c::assert_c;
* # fn main() {
* # (assert_c! {
* # #include "tests/wasmer_wasm.h"
* #
* int main() {
* // Create a new CPU feature set.
* wasm_cpu_features_t* cpu_features = wasm_cpu_features_new();
*
* // Create a new feature name, here `sse2`, and add it to the set.
* {
* wasm_name_t cpu_feature_name;
* wasm_name_new_from_string(&cpu_feature_name, "sse2");
*
* wasm_cpu_features_add(cpu_features, &cpu_feature_name);
*
* wasm_name_delete(&cpu_feature_name);
* }
*
* wasm_cpu_features_delete(cpu_features);
*
* return 0;
* }
* # })
* # .success();
* # }
* ```
*/
typedef struct wasm_cpu_features_t wasm_cpu_features_t;

/**
* Unstable non-standard Wasmer-specific API to represent a triple +
* CPU features pair.
*
* # Example
*
* See the module's documentation.
*/
typedef struct wasm_target_t wasm_target_t;

/**
* Unstable non-standard Wasmer-specific API to represent a target
* “triple”.
*
* Historically such things had three fields, though they have added
* additional fields over time.
*
* # Example
*
* ```rust
* # use inline_c::assert_c;
* # fn main() {
* # (assert_c! {
* # #include "tests/wasmer_wasm.h"
* #
* int main() {
* wasm_name_t triple_name;
* wasm_name_new_from_string(&triple_name, "x86_64-apple-darwin");
*
* wasm_triple_t* triple = wasm_triple_new(&triple_name);
* assert(triple);
*
* wasm_triple_delete(triple);
* wasm_name_delete(&triple_name);
*
* return 0;
* }
* # })
* # .success();
* # }
* ```
*
* See also [`wasm_triple_new_from_host`].
*/
typedef struct wasm_triple_t wasm_triple_t;

#ifdef __cplusplus
@@ -334,207 +233,28 @@ void wasm_config_set_compiler(wasm_config_t *config, wasmer_compiler_t compiler)

void wasm_config_set_engine(wasm_config_t *config, wasmer_engine_t engine);

/**
* Unstable non-standard Wasmer-specific API to update the
* configuration to specify a particular target for the engine.
*
* # Example
*
* ```rust
* # use inline_c::assert_c;
* # fn main() {
* # (assert_c! {
* # #include "tests/wasmer_wasm.h"
* #
* int main() {
* // Create the configuration.
* wasm_config_t* config = wasm_config_new();
*
* // Set the target.
* {
* wasm_triple_t* triple = wasm_triple_new_from_host();
* wasm_cpu_features_t* cpu_features = wasm_cpu_features_new();
* wasm_target_t* target = wasm_target_new(triple, cpu_features);
*
* wasm_config_set_target(config, target);
* }
*
* // Create the engine.
* wasm_engine_t* engine = wasm_engine_new_with_config(config);
*
* // Check we have an engine!
* assert(engine);
*
* // Free everything.
* wasm_engine_delete(engine);
*
* return 0;
* }
* # })
* # .success();
* # }
* ```
*/
void wasm_config_set_target(wasm_config_t *config, wasm_target_t *target);

/**
* Add a new CPU feature into the set represented by
* [`wasm_cpu_features_t`].
*
* # Example
*
* See [`wasm_cpu_features_t`].
*/
bool wasm_cpu_features_add(wasm_cpu_features_t *cpu_features, const wasm_name_t *feature);

/**
* Delete a [`wasm_cpu_features_t`].
*
* # Example
*
* See [`wasm_cpu_features_t`].
*/
void wasm_cpu_features_delete(wasm_cpu_features_t *_cpu_features);

/**
* Create a new [`wasm_cpu_features_t`].
*
* # Example
*
* See [`wasm_cpu_features_t`].
*/
wasm_cpu_features_t *wasm_cpu_features_new(void);

/**
* Unstable non-standard Wasmer-specific API to get the module's
* name, otherwise `out->size` is set to `0` and `out->data` to
* `NULL`.
*
* # Example
*
* ```rust
* # use inline_c::assert_c;
* # fn main() {
* # (assert_c! {
* # #include "tests/wasmer_wasm.h"
* #
* int main() {
* // Create the engine and the store.
* wasm_engine_t* engine = wasm_engine_new();
* wasm_store_t* store = wasm_store_new(engine);
*
* // Create a WebAssembly module from a WAT definition.
* wasm_byte_vec_t wat;
* wasmer_byte_vec_new_from_string(&wat, "(module $moduleName)");
* // ^~~~~~~~~~~ that's the name!
* wasm_byte_vec_t wasm;
* wat2wasm(&wat, &wasm);
*
* // Create the module.
* wasm_module_t* module = wasm_module_new(store, &wasm);
*
* // Read the module's name.
* wasm_name_t name;
* wasm_module_name(module, &name);
*
* // It works!
* wasmer_assert_name(&name, "moduleName");
*
* // Free everything.
* wasm_byte_vec_delete(&name);
* wasm_module_delete(module);
* wasm_byte_vec_delete(&wasm);
* wasm_byte_vec_delete(&wat);
* wasm_store_delete(store);
* wasm_engine_delete(engine);
*
* return 0;
* }
* # })
* # .success();
* # }
* ```
*/
void wasm_module_name(const wasm_module_t *module, wasm_name_t *out);

bool wasm_module_set_name(wasm_module_t *module, const wasm_name_t *name);

/**
* Delete a [`wasm_target_t`].
*
* # Example
*
* See the module's documentation.
*/
void wasm_target_delete(wasm_target_t *_target);

/**
* Creates a new [`wasm_target_t`].
*
* It takes ownership of `triple` and `cpu_features`.
*
* # Example
*
* See the module's documentation.
*/
wasm_target_t *wasm_target_new(wasm_triple_t *triple, wasm_cpu_features_t *cpu_features);

/**
* Delete a [`wasm_triple_t`].
*
* # Example
*
* See [`wasm_triple_t`].
*/
void wasm_triple_delete(wasm_triple_t *_triple);

/**
* Create a new [`wasm_triple_t`] based on a triple string.
*
* # Example
*
* See [`wasm_triple_t`] or [`wasm_triple_new_from_host`].
*/
wasm_triple_t *wasm_triple_new(const wasm_name_t *triple);

/**
* Create the [`wasm_triple_t`] for the current host.
*
* # Example
*
* ```rust
* # use inline_c::assert_c;
* # fn main() {
* # (assert_c! {
* # #include "tests/wasmer_wasm.h"
* #
* int main() {
* wasm_triple_t* triple = wasm_triple_new_from_host();
* assert(triple);
*
* wasm_triple_delete(triple);
*
* return 0;
* }
* # })
* # .success();
* # }
* ```
*
* See also [`wasm_triple_new`].
*/
wasm_triple_t *wasm_triple_new_from_host(void);

/**
* Gets the length in bytes of the last error if any, zero otherwise.
*
* This can be used to dynamically allocate a buffer with the correct number of
* bytes needed to store a message.
*
* # Example
*
* See this module's documentation to get a complete example.
*/
int wasmer_last_error_length(void);

int wasmer_last_error_message(char *buffer, int length);
You are viewing a condensed version of this merge commit. You can view the full changes here.