wasmer_c_api/wasm_c_api/unstable/
engine.rs1use super::{
5 super::engine::{wasm_config_t, wasmer_backend_t},
6 features::wasmer_features_t,
7};
8
9#[unsafe(no_mangle)]
48pub extern "C" fn wasm_config_set_features(
49 config: &mut wasm_config_t,
50 features: Box<wasmer_features_t>,
51) {
52 config.features = Some(features);
53}
54
55#[unsafe(no_mangle)]
58pub extern "C" fn wasmer_is_headless() -> bool {
59 !cfg!(feature = "compiler")
60}
61
62#[unsafe(no_mangle)]
65pub extern "C" fn wasmer_is_backend_available(backend: wasmer_backend_t) -> bool {
66 match backend {
67 wasmer_backend_t::LLVM => cfg!(feature = "llvm"),
68 wasmer_backend_t::CRANELIFT => cfg!(feature = "cranelift"),
69 wasmer_backend_t::SINGLEPASS => cfg!(feature = "singlepass"),
70 wasmer_backend_t::HEADLESS => cfg!(feature = "sys"),
71 wasmer_backend_t::V8 => cfg!(feature = "v8"),
72 wasmer_backend_t::JSC => cfg!(feature = "jsc"),
73 }
74}
75
76#[cfg(test)]
77mod tests {
78 #[cfg(not(target_os = "windows"))]
79 use inline_c::assert_c;
80 use std::env::{remove_var, set_var};
81 #[cfg(target_os = "windows")]
82 use wasmer_inline_c::assert_c;
83
84 #[test]
85 fn test_wasmer_is_headless() {
86 unsafe {
87 set_var(
88 "COMPILER",
89 if cfg!(feature = "compiler") { "0" } else { "1" },
90 );
91 }
92
93 (assert_c! {
94 #include "tests/wasmer.h"
95 #include <stdlib.h>
96
97 int main() {
98 assert(wasmer_is_headless() == (getenv("COMPILER")[0] == '1'));
99
100 return 0;
101 }
102 })
103 .success();
104
105 unsafe {
106 remove_var("COMPILER");
107 }
108 }
109
110 #[test]
111 fn test_wasmer_is_backend_available() {
112 unsafe {
113 set_var(
114 "CRANELIFT",
115 if cfg!(feature = "cranelift") {
116 "1"
117 } else {
118 "0"
119 },
120 );
121 set_var("LLVM", if cfg!(feature = "llvm") { "1" } else { "0" });
122 set_var(
123 "SINGLEPASS",
124 if cfg!(feature = "singlepass") {
125 "1"
126 } else {
127 "0"
128 },
129 );
130 }
131
132 (assert_c! {
133 #include "tests/wasmer.h"
134 #include <stdlib.h>
135
136 int main() {
137 assert(wasmer_is_backend_available(CRANELIFT) == (getenv("CRANELIFT")[0] == '1'));
138 assert(wasmer_is_backend_available(LLVM) == (getenv("LLVM")[0] == '1'));
139 assert(wasmer_is_backend_available(SINGLEPASS) == (getenv("SINGLEPASS")[0] == '1'));
140
141 return 0;
142 }
143 })
144 .success();
145
146 unsafe {
147 remove_var("CRANELIFT");
148 remove_var("LLVM");
149 remove_var("SINGLEPASS");
150 }
151 }
152}