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 }
73}
74
75#[cfg(test)]
76mod tests {
77 #[cfg(not(target_os = "windows"))]
78 use inline_c::assert_c;
79 use std::env::{remove_var, set_var};
80 #[cfg(target_os = "windows")]
81 use wasmer_inline_c::assert_c;
82
83 #[test]
84 fn test_wasmer_is_headless() {
85 unsafe {
86 set_var(
87 "COMPILER",
88 if cfg!(feature = "compiler") { "0" } else { "1" },
89 );
90 }
91
92 (assert_c! {
93 #include "tests/wasmer.h"
94 #include <stdlib.h>
95
96 int main() {
97 assert(wasmer_is_headless() == (getenv("COMPILER")[0] == '1'));
98
99 return 0;
100 }
101 })
102 .success();
103
104 unsafe {
105 remove_var("COMPILER");
106 }
107 }
108
109 #[test]
110 fn test_wasmer_is_backend_available() {
111 unsafe {
112 set_var(
113 "CRANELIFT",
114 if cfg!(feature = "cranelift") {
115 "1"
116 } else {
117 "0"
118 },
119 );
120 set_var("LLVM", if cfg!(feature = "llvm") { "1" } else { "0" });
121 set_var(
122 "SINGLEPASS",
123 if cfg!(feature = "singlepass") {
124 "1"
125 } else {
126 "0"
127 },
128 );
129 }
130
131 (assert_c! {
132 #include "tests/wasmer.h"
133 #include <stdlib.h>
134
135 int main() {
136 assert(wasmer_is_backend_available(CRANELIFT) == (getenv("CRANELIFT")[0] == '1'));
137 assert(wasmer_is_backend_available(LLVM) == (getenv("LLVM")[0] == '1'));
138 assert(wasmer_is_backend_available(SINGLEPASS) == (getenv("SINGLEPASS")[0] == '1'));
139
140 return 0;
141 }
142 })
143 .success();
144
145 unsafe {
146 remove_var("CRANELIFT");
147 remove_var("LLVM");
148 remove_var("SINGLEPASS");
149 }
150 }
151}