proxy_wasm/
lib.rs

1// Copyright 2020 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15pub mod hostcalls;
16pub mod traits;
17pub mod types;
18
19mod allocator;
20mod dispatcher;
21mod logger;
22
23// For crate-type="cdylib".
24#[cfg(not(wasi_exec_model_reactor))]
25#[macro_export]
26macro_rules! main {
27    ($code:block) => {
28        #[cfg(target_os = "wasi")]
29        extern "C" {
30            fn __wasm_call_ctors();
31        }
32
33        #[no_mangle]
34        pub extern "C" fn _initialize() {
35            #[cfg(target_os = "wasi")]
36            unsafe {
37                __wasm_call_ctors();
38            }
39
40            $code;
41        }
42    };
43}
44
45// For crate-type="bin" with RUSTFLAGS="-Z wasi-exec-model=reactor".
46#[cfg(wasi_exec_model_reactor)]
47#[macro_export]
48macro_rules! main {
49    ($code:block) => {
50        pub fn main() -> Result<(), Box<dyn std::error::Error>> {
51            $code;
52            Ok(())
53        }
54    };
55}
56
57pub fn set_log_level(level: types::LogLevel) {
58    logger::set_log_level(level);
59}
60
61pub fn set_root_context(callback: types::NewRootContext) {
62    dispatcher::set_root_context(callback);
63}
64
65pub fn set_stream_context(callback: types::NewStreamContext) {
66    dispatcher::set_stream_context(callback);
67}
68
69pub fn set_http_context(callback: types::NewHttpContext) {
70    dispatcher::set_http_context(callback);
71}
72
73#[no_mangle]
74pub extern "C" fn proxy_abi_version_0_2_1() {}