File tree 11 files changed +121
-15
lines changed
11 files changed +121
-15
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,41 @@ 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 : grep -v '^crate-type' Cargo.toml > Cargo.tmp && mv Cargo.tmp Cargo.toml
212
+
213
+ - name : Build (wasm32-wasi)
214
+ env :
215
+ RUSTFLAGS : -D warnings -C link-args=-S -Z wasi-exec-model=reactor
216
+ run : cargo build --release --all-targets --target=wasm32-wasi
217
+
218
+ - name : Build (wasm32-wasi with wee-alloc)
219
+ env :
220
+ RUSTFLAGS : -D warnings -C link-args=-S -Z wasi-exec-model=reactor
221
+ run : cargo build --release --all-targets --target=wasm32-wasi --features=wee-alloc
222
+
223
+ - name : Clippy (wasm32-wasi)
224
+ env :
225
+ RUSTFLAGS : -D warnings -C link-args=-S -Z wasi-exec-model=reactor
226
+ run : cargo clippy --release --all-targets --target=wasm32-wasi
227
+
228
+ - name : Clippy (wasm32-wasi with wee-alloc)
229
+ env :
230
+ RUSTFLAGS : -D warnings -C link-args=-S -Z wasi-exec-model=reactor
231
+ run : cargo clippy --release --all-targets --target=wasm32-wasi --features=wee-alloc
232
+
198
233
outdated :
199
234
runs-on : ubuntu-latest
200
235
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 @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
8
8
9
9
### Changed
10
10
11
+ - Added ` proxy_wasm::main ` macro that should be used instead of custom ` _start ` ,
12
+ ` _initialize ` and/or ` main ` exports.
11
13
- Updated ABI to Proxy-Wasm ABI v0.2.1.
12
14
13
15
## [ 0.1.4] - 2021-07-01
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
+ if let Some ( target_os) = std:: env:: var_os ( "CARGO_CFG_TARGET_OS" ) {
17
+ if target_os != "wasi" {
18
+ return ;
19
+ }
20
+ }
21
+ if let Some ( rustflags) = std:: env:: var_os ( "CARGO_ENCODED_RUSTFLAGS" ) {
22
+ for flag in rustflags. to_string_lossy ( ) . split ( '\x1f' ) {
23
+ if flag. ends_with ( "wasi-exec-model=reactor" ) {
24
+ println ! ( "cargo:rustc-cfg=wasi_exec_model_reactor" ) ;
25
+ return ;
26
+ }
27
+ }
28
+ }
29
+ }
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