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