diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8340af02..30086c6c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -106,11 +106,21 @@ jobs: RUSTFLAGS: -D warnings -C link-args=-S run: cargo build --release --all-targets --target=wasm32-wasi + - name: Build (wasm32-wasi with wee-alloc) + env: + RUSTFLAGS: -D warnings -C link-args=-S + run: cargo build --release --all-targets --target=wasm32-wasi --features=wee-alloc + - name: Clippy (wasm32-wasi) env: RUSTFLAGS: -D warnings -C link-args=-S run: cargo clippy --release --all-targets --target=wasm32-wasi + - name: Clippy (wasm32-wasi with wee-alloc) + env: + RUSTFLAGS: -D warnings -C link-args=-S + run: cargo clippy --release --all-targets --target=wasm32-wasi --features=wee-alloc + - name: Format (rustfmt) run: cargo fmt -- --check @@ -151,11 +161,21 @@ jobs: RUSTFLAGS: -D warnings -C link-args=-S run: cargo build --release --all-targets --target=wasm32-wasi + - name: Build (wasm32-wasi with wee-alloc) + env: + RUSTFLAGS: -D warnings -C link-args=-S + run: cargo build --release --all-targets --target=wasm32-wasi --features=wee-alloc + - name: Clippy (wasm32-wasi) env: RUSTFLAGS: -D warnings -C link-args=-S run: cargo clippy --release --all-targets --target=wasm32-wasi + - name: Clippy (wasm32-wasi with wee-alloc) + env: + RUSTFLAGS: -D warnings -C link-args=-S + run: cargo clippy --release --all-targets --target=wasm32-wasi --features=wee-alloc + - name: Format (rustfmt) run: cargo fmt -- --check diff --git a/BUILD b/BUILD index f323a4bf..53d433f6 100644 --- a/BUILD +++ b/BUILD @@ -8,6 +8,5 @@ rust_library( deps = [ "//bazel/cargo:hashbrown", "//bazel/cargo:log", - "//bazel/cargo:wee_alloc", ], ) diff --git a/Cargo.toml b/Cargo.toml index 25fd5a25..2f436eff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,10 +8,13 @@ license = "Apache-2.0" repository = "https://github.com/proxy-wasm/proxy-wasm-rust-sdk" edition = "2018" +[features] +wee-alloc = ["wee_alloc"] + [dependencies] hashbrown = "0.9" log = "0.4" -wee_alloc = "0.4" +wee_alloc = { version = "0.4", optional = true } [dev-dependencies] chrono = "0.4" diff --git a/README.md b/README.md index c2823fe7..002b7764 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,14 @@ + [Extending Envoy with WASM and Rust](https://antweiss.com/blog/extending-envoy-with-wasm-and-rust/) + [Extending Istio with Rust and WebAssembly](https://blog.red-badger.com/extending-istio-with-rust-and-webassembly) + +# Updating dependencies + +When updating dependencies, you need to regenerate `BUILD` files to match updated `Cargo.toml`: +``` +cargo install cargo-raze --version 0.3.8 +rm -rf bazel/cargo/ +cargo generate-lockfile +cargo raze --output=bazel/cargo +mv Cargo.lock bazel/cargo/ +``` \ No newline at end of file diff --git a/bazel/cargo/BUILD b/bazel/cargo/BUILD index 4a095b98..b72a27f6 100644 --- a/bazel/cargo/BUILD +++ b/bazel/cargo/BUILD @@ -23,8 +23,3 @@ alias( actual = "@raze__log__0_4_11//:log", tags = ["cargo-raze"], ) -alias( - name = "wee_alloc", - actual = "@raze__wee_alloc__0_4_5//:wee_alloc", - tags = ["cargo-raze"], -) diff --git a/bazel/cargo/crates.bzl b/bazel/cargo/crates.bzl index e133346e..d7dbf9bb 100644 --- a/bazel/cargo/crates.bzl +++ b/bazel/cargo/crates.bzl @@ -79,15 +79,6 @@ def raze_fetch_remote_crates(): build_file = Label("//bazel/cargo/remote:log-0.4.11.BUILD"), ) - _new_http_archive( - name = "raze__memory_units__0_4_0", - url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/memory_units/memory_units-0.4.0.crate", - type = "tar.gz", - sha256 = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3", - strip_prefix = "memory_units-0.4.0", - build_file = Label("//bazel/cargo/remote:memory_units-0.4.0.BUILD"), - ) - _new_http_archive( name = "raze__num_integer__0_1_44", url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/num-integer/num-integer-0.1.44.crate", @@ -124,15 +115,6 @@ def raze_fetch_remote_crates(): build_file = Label("//bazel/cargo/remote:wasi-0.10.0+wasi-snapshot-preview1.BUILD"), ) - _new_http_archive( - name = "raze__wee_alloc__0_4_5", - url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/wee_alloc/wee_alloc-0.4.5.crate", - type = "tar.gz", - sha256 = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e", - strip_prefix = "wee_alloc-0.4.5", - build_file = Label("//bazel/cargo/remote:wee_alloc-0.4.5.BUILD"), - ) - _new_http_archive( name = "raze__winapi__0_3_9", url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/winapi/winapi-0.3.9.crate", diff --git a/bazel/cargo/remote/memory_units-0.4.0.BUILD b/bazel/cargo/remote/memory_units-0.4.0.BUILD deleted file mode 100644 index a8964bfa..00000000 --- a/bazel/cargo/remote/memory_units-0.4.0.BUILD +++ /dev/null @@ -1,43 +0,0 @@ -""" -cargo-raze crate build file. - -DO NOT EDIT! Replaced on runs of cargo-raze -""" -package(default_visibility = [ - # Public for visibility by "@raze__crate__version//" targets. - # - # Prefer access through "//bazel/cargo", which limits external - # visibility to explicit Cargo.toml dependencies. - "//visibility:public", -]) - -licenses([ - "reciprocal", # MPL-2.0 from expression "MPL-2.0" -]) - -load( - "@io_bazel_rules_rust//rust:rust.bzl", - "rust_library", - "rust_binary", - "rust_test", -) - - - -rust_library( - name = "memory_units", - crate_type = "lib", - deps = [ - ], - srcs = glob(["**/*.rs"]), - crate_root = "src/lib.rs", - edition = "2015", - rustc_flags = [ - "--cap-lints=allow", - ], - version = "0.4.0", - tags = ["cargo-raze"], - crate_features = [ - ], -) - diff --git a/bazel/cargo/remote/wee_alloc-0.4.5.BUILD b/bazel/cargo/remote/wee_alloc-0.4.5.BUILD deleted file mode 100644 index 26e2bc58..00000000 --- a/bazel/cargo/remote/wee_alloc-0.4.5.BUILD +++ /dev/null @@ -1,48 +0,0 @@ -""" -cargo-raze crate build file. - -DO NOT EDIT! Replaced on runs of cargo-raze -""" -package(default_visibility = [ - # Public for visibility by "@raze__crate__version//" targets. - # - # Prefer access through "//bazel/cargo", which limits external - # visibility to explicit Cargo.toml dependencies. - "//visibility:public", -]) - -licenses([ - "reciprocal", # MPL-2.0 from expression "MPL-2.0" -]) - -load( - "@io_bazel_rules_rust//rust:rust.bzl", - "rust_library", - "rust_binary", - "rust_test", -) - - -# Unsupported target "build-script-build" with type "custom-build" omitted - -rust_library( - name = "wee_alloc", - crate_type = "lib", - deps = [ - "@raze__cfg_if__0_1_10//:cfg_if", - "@raze__memory_units__0_4_0//:memory_units", - ], - srcs = glob(["**/*.rs"]), - crate_root = "src/lib.rs", - edition = "2015", - rustc_flags = [ - "--cap-lints=allow", - ], - version = "0.4.5", - tags = ["cargo-raze"], - crate_features = [ - "default", - "size_classes", - ], -) - diff --git a/bazel/cargo/remote/winapi-0.3.9.BUILD b/bazel/cargo/remote/winapi-0.3.9.BUILD index 49b1e59a..ed409429 100644 --- a/bazel/cargo/remote/winapi-0.3.9.BUILD +++ b/bazel/cargo/remote/winapi-0.3.9.BUILD @@ -39,16 +39,13 @@ rust_library( version = "0.3.9", tags = ["cargo-raze"], crate_features = [ - "memoryapi", "minwinbase", "minwindef", "ntdef", "profileapi", "std", - "synchapi", "sysinfoapi", "timezoneapi", - "winbase", ], ) diff --git a/src/allocator.rs b/src/allocator.rs index 3c708a60..c7e1199c 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#[cfg(feature = "wee-alloc")] #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;