Skip to content

Commit d159da4

Browse files
authored
Make wee-alloc an optional feature. (#38)
Signed-off-by: Yuval Kohavi <yuval.kohavi@gmail.com>
1 parent 9f179f8 commit d159da4

File tree

10 files changed

+36
-119
lines changed

10 files changed

+36
-119
lines changed

.github/workflows/rust.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,21 @@ jobs:
106106
RUSTFLAGS: -D warnings -C link-args=-S
107107
run: cargo build --release --all-targets --target=wasm32-wasi
108108

109+
- name: Build (wasm32-wasi with wee-alloc)
110+
env:
111+
RUSTFLAGS: -D warnings -C link-args=-S
112+
run: cargo build --release --all-targets --target=wasm32-wasi --features=wee-alloc
113+
109114
- name: Clippy (wasm32-wasi)
110115
env:
111116
RUSTFLAGS: -D warnings -C link-args=-S
112117
run: cargo clippy --release --all-targets --target=wasm32-wasi
113118

119+
- name: Clippy (wasm32-wasi with wee-alloc)
120+
env:
121+
RUSTFLAGS: -D warnings -C link-args=-S
122+
run: cargo clippy --release --all-targets --target=wasm32-wasi --features=wee-alloc
123+
114124
- name: Format (rustfmt)
115125
run: cargo fmt -- --check
116126

@@ -151,11 +161,21 @@ jobs:
151161
RUSTFLAGS: -D warnings -C link-args=-S
152162
run: cargo build --release --all-targets --target=wasm32-wasi
153163

164+
- name: Build (wasm32-wasi with wee-alloc)
165+
env:
166+
RUSTFLAGS: -D warnings -C link-args=-S
167+
run: cargo build --release --all-targets --target=wasm32-wasi --features=wee-alloc
168+
154169
- name: Clippy (wasm32-wasi)
155170
env:
156171
RUSTFLAGS: -D warnings -C link-args=-S
157172
run: cargo clippy --release --all-targets --target=wasm32-wasi
158173

174+
- name: Clippy (wasm32-wasi with wee-alloc)
175+
env:
176+
RUSTFLAGS: -D warnings -C link-args=-S
177+
run: cargo clippy --release --all-targets --target=wasm32-wasi --features=wee-alloc
178+
159179
- name: Format (rustfmt)
160180
run: cargo fmt -- --check
161181

BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ rust_library(
88
deps = [
99
"//bazel/cargo:hashbrown",
1010
"//bazel/cargo:log",
11-
"//bazel/cargo:wee_alloc",
1211
],
1312
)

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ license = "Apache-2.0"
88
repository = "https://github.com/proxy-wasm/proxy-wasm-rust-sdk"
99
edition = "2018"
1010

11+
[features]
12+
wee-alloc = ["wee_alloc"]
13+
1114
[dependencies]
1215
hashbrown = "0.9"
1316
log = "0.4"
14-
wee_alloc = "0.4"
17+
wee_alloc = { version = "0.4", optional = true }
1518

1619
[dev-dependencies]
1720
chrono = "0.4"

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,14 @@
2525

2626
+ [Extending Envoy with WASM and Rust](https://antweiss.com/blog/extending-envoy-with-wasm-and-rust/)
2727
+ [Extending Istio with Rust and WebAssembly](https://blog.red-badger.com/extending-istio-with-rust-and-webassembly)
28+
29+
# Updating dependencies
30+
31+
When updating dependencies, you need to regenerate `BUILD` files to match updated `Cargo.toml`:
32+
```
33+
cargo install cargo-raze --version 0.3.8
34+
rm -rf bazel/cargo/
35+
cargo generate-lockfile
36+
cargo raze --output=bazel/cargo
37+
mv Cargo.lock bazel/cargo/
38+
```

bazel/cargo/BUILD

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,3 @@ alias(
2323
actual = "@raze__log__0_4_11//:log",
2424
tags = ["cargo-raze"],
2525
)
26-
alias(
27-
name = "wee_alloc",
28-
actual = "@raze__wee_alloc__0_4_5//:wee_alloc",
29-
tags = ["cargo-raze"],
30-
)

bazel/cargo/crates.bzl

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,6 @@ def raze_fetch_remote_crates():
7979
build_file = Label("//bazel/cargo/remote:log-0.4.11.BUILD"),
8080
)
8181

82-
_new_http_archive(
83-
name = "raze__memory_units__0_4_0",
84-
url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/memory_units/memory_units-0.4.0.crate",
85-
type = "tar.gz",
86-
sha256 = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3",
87-
strip_prefix = "memory_units-0.4.0",
88-
build_file = Label("//bazel/cargo/remote:memory_units-0.4.0.BUILD"),
89-
)
90-
9182
_new_http_archive(
9283
name = "raze__num_integer__0_1_44",
9384
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():
124115
build_file = Label("//bazel/cargo/remote:wasi-0.10.0+wasi-snapshot-preview1.BUILD"),
125116
)
126117

127-
_new_http_archive(
128-
name = "raze__wee_alloc__0_4_5",
129-
url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/wee_alloc/wee_alloc-0.4.5.crate",
130-
type = "tar.gz",
131-
sha256 = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e",
132-
strip_prefix = "wee_alloc-0.4.5",
133-
build_file = Label("//bazel/cargo/remote:wee_alloc-0.4.5.BUILD"),
134-
)
135-
136118
_new_http_archive(
137119
name = "raze__winapi__0_3_9",
138120
url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/winapi/winapi-0.3.9.crate",

bazel/cargo/remote/memory_units-0.4.0.BUILD

Lines changed: 0 additions & 43 deletions
This file was deleted.

bazel/cargo/remote/wee_alloc-0.4.5.BUILD

Lines changed: 0 additions & 48 deletions
This file was deleted.

bazel/cargo/remote/winapi-0.3.9.BUILD

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@ rust_library(
3939
version = "0.3.9",
4040
tags = ["cargo-raze"],
4141
crate_features = [
42-
"memoryapi",
4342
"minwinbase",
4443
"minwindef",
4544
"ntdef",
4645
"profileapi",
4746
"std",
48-
"synchapi",
4947
"sysinfoapi",
5048
"timezoneapi",
51-
"winbase",
5249
],
5350
)
5451

src/allocator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#[cfg(feature = "wee-alloc")]
1516
#[global_allocator]
1617
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
1718

0 commit comments

Comments
 (0)