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
15#![cfg_attr(all(test, nightly), feature(test))]
16
17#[cfg(all(test, nightly))]
18extern crate test;
19
20pub mod hostcalls;
21pub mod traits;
22pub mod types;
23
24mod allocator;
25mod dispatcher;
26mod logger;
27
28// For crate-type="cdylib".
29#[cfg(not(wasi_exec_model_reactor))]
30#[macro_export]
31macro_rules! main {
32    ($code:block) => {
33        #[cfg(target_os = "wasi")]
34        extern "C" {
35            fn __wasm_call_ctors();
36        }
37
38        #[no_mangle]
39        pub extern "C" fn _initialize() {
40            #[cfg(target_os = "wasi")]
41            unsafe {
42                __wasm_call_ctors();
43            }
44
45            $code;
46        }
47    };
48}
49
50// For crate-type="bin" with RUSTFLAGS="-Z wasi-exec-model=reactor".
51#[cfg(wasi_exec_model_reactor)]
52#[macro_export]
53macro_rules! main {
54    ($code:block) => {
55        pub fn main() -> Result<(), Box<dyn std::error::Error>> {
56            $code;
57            Ok(())
58        }
59    };
60}
61
62pub fn set_log_level(level: types::LogLevel) {
63    logger::set_log_level(level);
64}
65
66pub fn set_root_context(callback: types::NewRootContext) {
67    dispatcher::set_root_context(callback);
68}
69
70pub fn set_stream_context(callback: types::NewStreamContext) {
71    dispatcher::set_stream_context(callback);
72}
73
74pub fn set_http_context(callback: types::NewHttpContext) {
75    dispatcher::set_http_context(callback);
76}
77
78#[no_mangle]
79pub extern "C" fn proxy_abi_version_0_2_1() {}