File tree Expand file tree Collapse file tree 11 files changed +131
-15
lines changed Expand file tree Collapse file tree 11 files changed +131
-15
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,43 @@ jobs:
195195 - name : Package (publish)
196196 run : cargo publish --dry-run --target=wasm32-unknown-unknown
197197
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+
198235 outdated :
199236 runs-on : ubuntu-latest
200237
Original file line number Diff line number Diff line change 1+ load ("@rules_rust//cargo:cargo_build_script.bzl" , "cargo_build_script" )
12load ("@rules_rust//rust:defs.bzl" , "rust_library" )
23
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+
312rust_library (
413 name = "proxy_wasm" ,
514 srcs = glob (["src/*.rs" ]),
615 edition = "2018" ,
716 visibility = ["//visibility:public" ],
817 deps = [
18+ ":proxy_wasm_build_script" ,
919 "//bazel/cargo:hashbrown" ,
1020 "//bazel/cargo:log" ,
1121 ],
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/).
66
77## [ Unreleased]
88
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+
915### Changed
1016
1117- 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"
77license = " Apache-2.0"
88repository = " https://github.com/proxy-wasm/proxy-wasm-rust-sdk"
99edition = " 2018"
10+ build = " build.rs"
1011
1112[features ]
1213wee-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;
2222#[ cfg( not( all( target_arch = "wasm32" , target_os = "unknown" ) ) ) ]
2323use getrandom:: getrandom;
2424
25- #[ no_mangle]
26- pub fn _start ( ) {
25+ proxy_wasm:: main! { {
2726 proxy_wasm:: set_log_level( LogLevel :: Trace ) ;
2827 proxy_wasm:: set_root_context( |_| -> Box <dyn RootContext > { Box :: new( HelloWorld ) } ) ;
29- }
28+ } }
3029
3130struct HelloWorld ;
3231
Original file line number Diff line number Diff line change @@ -17,11 +17,10 @@ use proxy_wasm::traits::*;
1717use proxy_wasm:: types:: * ;
1818use std:: time:: Duration ;
1919
20- #[ no_mangle]
21- pub fn _start ( ) {
20+ proxy_wasm:: main! { {
2221 proxy_wasm:: set_log_level( LogLevel :: Trace ) ;
2322 proxy_wasm:: set_http_context( |_, _| -> Box <dyn HttpContext > { Box :: new( HttpAuthRandom ) } ) ;
24- }
23+ } }
2524
2625struct HttpAuthRandom ;
2726
Original file line number Diff line number Diff line change 1515use proxy_wasm:: traits:: * ;
1616use proxy_wasm:: types:: * ;
1717
18- #[ no_mangle]
19- pub fn _start ( ) {
18+ proxy_wasm:: main! { {
2019 proxy_wasm:: set_log_level( LogLevel :: Trace ) ;
2120 proxy_wasm:: set_root_context( |_| -> Box <dyn RootContext > { Box :: new( HttpBodyRoot ) } ) ;
22- }
21+ } }
2322
2423struct HttpBodyRoot ;
2524
Original file line number Diff line number Diff line change 1515use proxy_wasm:: traits:: * ;
1616use proxy_wasm:: types:: * ;
1717
18- #[ no_mangle]
19- pub fn _start ( ) {
18+ proxy_wasm:: main! { {
2019 proxy_wasm:: set_log_level( LogLevel :: Trace ) ;
2120 proxy_wasm:: set_root_context( |_| -> Box <dyn RootContext > {
2221 Box :: new( HttpConfigHeaderRoot {
2322 header_content: String :: new( ) ,
2423 } )
2524 } ) ;
26- }
25+ } }
2726
2827struct HttpConfigHeader {
2928 header_content : String ,
Original file line number Diff line number Diff line change @@ -16,11 +16,10 @@ use log::trace;
1616use proxy_wasm:: traits:: * ;
1717use proxy_wasm:: types:: * ;
1818
19- #[ no_mangle]
20- pub fn _start ( ) {
19+ proxy_wasm:: main! { {
2120 proxy_wasm:: set_log_level( LogLevel :: Trace ) ;
2221 proxy_wasm:: set_root_context( |_| -> Box <dyn RootContext > { Box :: new( HttpHeadersRoot ) } ) ;
23- }
22+ } }
2423
2524struct HttpHeadersRoot ;
2625
You can’t perform that action at this time.
0 commit comments