File tree 11 files changed +131
-15
lines changed
11 files changed +131
-15
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,43 @@ jobs:
195
195
- name : Package (publish)
196
196
run : cargo publish --dry-run --target=wasm32-unknown-unknown
197
197
198
+ reactor :
199
+ runs-on : ubuntu-latest
200
+
201
+ steps :
202
+ - uses : actions/checkout@v2
203
+
204
+ - name : Update Rust
205
+ run : |
206
+ rustup toolchain install nightly --component clippy
207
+ rustup +nightly target add wasm32-wasi
208
+ rustup default nightly
209
+
210
+ - name : Rewrite Cargo.toml examples
211
+ run : |
212
+ grep -v '^crate-type' Cargo.toml > Cargo.tmp
213
+ mv Cargo.tmp Cargo.toml
214
+
215
+ - name : Build (wasm32-wasi)
216
+ env :
217
+ RUSTFLAGS : -D warnings -C link-args=-S -Z wasi-exec-model=reactor
218
+ run : cargo build --release --all-targets --target=wasm32-wasi
219
+
220
+ - name : Build (wasm32-wasi with wee-alloc)
221
+ env :
222
+ RUSTFLAGS : -D warnings -C link-args=-S -Z wasi-exec-model=reactor
223
+ run : cargo build --release --all-targets --target=wasm32-wasi --features=wee-alloc
224
+
225
+ - name : Clippy (wasm32-wasi)
226
+ env :
227
+ RUSTFLAGS : -D warnings -C link-args=-S -Z wasi-exec-model=reactor
228
+ run : cargo clippy --release --all-targets --target=wasm32-wasi
229
+
230
+ - name : Clippy (wasm32-wasi with wee-alloc)
231
+ env :
232
+ RUSTFLAGS : -D warnings -C link-args=-S -Z wasi-exec-model=reactor
233
+ run : cargo clippy --release --all-targets --target=wasm32-wasi --features=wee-alloc
234
+
198
235
outdated :
199
236
runs-on : ubuntu-latest
200
237
Original file line number Diff line number Diff line change
1
+ load ("@rules_rust//cargo:cargo_build_script.bzl" , "cargo_build_script" )
1
2
load ("@rules_rust//rust:defs.bzl" , "rust_library" )
2
3
4
+ cargo_build_script (
5
+ name = "proxy_wasm_build_script" ,
6
+ srcs = ["build.rs" ],
7
+ edition = "2018" ,
8
+ tags = ["manual" ],
9
+ visibility = ["//visibility:private" ],
10
+ )
11
+
3
12
rust_library (
4
13
name = "proxy_wasm" ,
5
14
srcs = glob (["src/*.rs" ]),
6
15
edition = "2018" ,
7
16
visibility = ["//visibility:public" ],
8
17
deps = [
18
+ ":proxy_wasm_build_script" ,
9
19
"//bazel/cargo:hashbrown" ,
10
20
"//bazel/cargo:log" ,
11
21
],
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
7
7
## [ Unreleased]
8
8
9
+ ### Fixed
10
+
11
+ - Fixed performance degradation with ` wasm32-wasi ` target in Rust v1.56.0
12
+ or newer by adding ` proxy_wasm::main ` macro that should be used instead
13
+ of custom ` _start ` , ` _initialize ` and/or ` main ` exports.
14
+
9
15
### Changed
10
16
11
17
- Updated ABI to Proxy-Wasm ABI v0.2.1.
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ readme = "README.md"
7
7
license = " Apache-2.0"
8
8
repository = " https://github.com/proxy-wasm/proxy-wasm-rust-sdk"
9
9
edition = " 2018"
10
+ build = " build.rs"
10
11
11
12
[features ]
12
13
wee-alloc = [" wee_alloc" ]
Original file line number Diff line number Diff line change
1
+ // Copyright 2022 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
+ fn main ( ) {
16
+ println ! ( "cargo:rerun-if-changed=build.rs" ) ;
17
+ println ! ( "cargo:rerun-if-env-changed=RUSTFLAGS" ) ;
18
+
19
+ if let Some ( target_os) = std:: env:: var_os ( "CARGO_CFG_TARGET_OS" ) {
20
+ if target_os != "wasi" {
21
+ return ;
22
+ }
23
+ }
24
+
25
+ if let Some ( rustflags) = std:: env:: var_os ( "CARGO_ENCODED_RUSTFLAGS" ) {
26
+ for flag in rustflags. to_string_lossy ( ) . split ( '\x1f' ) {
27
+ if flag. ends_with ( "wasi-exec-model=reactor" ) {
28
+ println ! ( "cargo:rustc-cfg=wasi_exec_model_reactor" ) ;
29
+ return ;
30
+ }
31
+ }
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -22,11 +22,10 @@ use std::time::Duration;
22
22
#[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
23
23
use getrandom:: getrandom;
24
24
25
- #[ no_mangle]
26
- pub fn _start ( ) {
25
+ proxy_wasm:: main! { {
27
26
proxy_wasm:: set_log_level( LogLevel :: Trace ) ;
28
27
proxy_wasm:: set_root_context( |_| -> Box <dyn RootContext > { Box :: new( HelloWorld ) } ) ;
29
- }
28
+ } }
30
29
31
30
struct HelloWorld ;
32
31
Original file line number Diff line number Diff line change @@ -17,11 +17,10 @@ use proxy_wasm::traits::*;
17
17
use proxy_wasm:: types:: * ;
18
18
use std:: time:: Duration ;
19
19
20
- #[ no_mangle]
21
- pub fn _start ( ) {
20
+ proxy_wasm:: main! { {
22
21
proxy_wasm:: set_log_level( LogLevel :: Trace ) ;
23
22
proxy_wasm:: set_http_context( |_, _| -> Box <dyn HttpContext > { Box :: new( HttpAuthRandom ) } ) ;
24
- }
23
+ } }
25
24
26
25
struct HttpAuthRandom ;
27
26
Original file line number Diff line number Diff line change 15
15
use proxy_wasm:: traits:: * ;
16
16
use proxy_wasm:: types:: * ;
17
17
18
- #[ no_mangle]
19
- pub fn _start ( ) {
18
+ proxy_wasm:: main! { {
20
19
proxy_wasm:: set_log_level( LogLevel :: Trace ) ;
21
20
proxy_wasm:: set_root_context( |_| -> Box <dyn RootContext > { Box :: new( HttpBodyRoot ) } ) ;
22
- }
21
+ } }
23
22
24
23
struct HttpBodyRoot ;
25
24
Original file line number Diff line number Diff line change 15
15
use proxy_wasm:: traits:: * ;
16
16
use proxy_wasm:: types:: * ;
17
17
18
- #[ no_mangle]
19
- pub fn _start ( ) {
18
+ proxy_wasm:: main! { {
20
19
proxy_wasm:: set_log_level( LogLevel :: Trace ) ;
21
20
proxy_wasm:: set_root_context( |_| -> Box <dyn RootContext > {
22
21
Box :: new( HttpConfigHeaderRoot {
23
22
header_content: String :: new( ) ,
24
23
} )
25
24
} ) ;
26
- }
25
+ } }
27
26
28
27
struct HttpConfigHeader {
29
28
header_content : String ,
Original file line number Diff line number Diff line change @@ -16,11 +16,10 @@ use log::trace;
16
16
use proxy_wasm:: traits:: * ;
17
17
use proxy_wasm:: types:: * ;
18
18
19
- #[ no_mangle]
20
- pub fn _start ( ) {
19
+ proxy_wasm:: main! { {
21
20
proxy_wasm:: set_log_level( LogLevel :: Trace ) ;
22
21
proxy_wasm:: set_root_context( |_| -> Box <dyn RootContext > { Box :: new( HttpHeadersRoot ) } ) ;
23
- }
22
+ } }
24
23
25
24
struct HttpHeadersRoot ;
26
25
Original file line number Diff line number Diff line change @@ -20,6 +20,40 @@ mod allocator;
20
20
mod dispatcher;
21
21
mod logger;
22
22
23
+ // For crate-type="cdylib".
24
+ #[ cfg( not( wasi_exec_model_reactor) ) ]
25
+ #[ macro_export]
26
+ macro_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]
48
+ macro_rules! main {
49
+ ( $code: block) => {
50
+ pub fn main( ) -> Result <( ) , Box <dyn std:: error:: Error >> {
51
+ $code;
52
+ Ok ( ( ) )
53
+ }
54
+ } ;
55
+ }
56
+
23
57
pub fn set_log_level ( level : types:: LogLevel ) {
24
58
logger:: set_log_level ( level) ;
25
59
}
You can’t perform that action at this time.
0 commit comments