-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2072: feat(c-api) Implement cross-compilation API in C r=Hywan a=Hywan # Description Depends on #2071 (merged). This patch implements `wasm_target_t`, `wasm_triple_t`, `wasm_cpu_features_t`. This patch also implements `wasm_config_set_target` to set… a `wasm_target_t`. The `wasm_config_new_with_engine` function has been updated to handle the new `wasm_target_t`. # Example ```c int main() { // Create the configuration. wasm_config_t* config = wasm_config_new(); // Set the target. { // Declare the target triple. wasm_triple_t* triple; { wasm_name_t triple_name; wasm_name_new_from_string(&triple_name, "x86_64-apple-darwin"); triple = wasm_triple_new(&triple_name); wasm_name_delete(&triple_name); } assert(triple); // Declare the target CPU features. wasm_cpu_features_t* cpu_features = wasm_cpu_features_new(); { 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); } assert(cpu_features); // Create the target! wasm_target_t* target = wasm_target_new(triple, cpu_features); assert(target); // Set the target onto the configuration! 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; } ``` # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Ivan Enderlin <[email protected]>
- Loading branch information
Showing
11 changed files
with
459 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! Unstable non-standard Wasmer-specific types for the | ||
//! `wasm_engine_t` and siblings. | ||
use super::super::engine::wasm_config_t; | ||
use super::target_lexicon::wasm_target_t; | ||
|
||
/// 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(); | ||
/// # } | ||
/// ``` | ||
#[no_mangle] | ||
pub extern "C" fn wasm_config_set_target(config: &mut wasm_config_t, target: Box<wasm_target_t>) { | ||
config.target = Some(target); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
pub mod engine; | ||
pub mod module; | ||
pub mod target_lexicon; |
Oops, something went wrong.