Skip to content

Commit f3116d9

Browse files
committed
Fix wasm build
1 parent 0b2512a commit f3116d9

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cfg-if = "1"
2121
cidr = { version = "0.2", features = ["serde"] }
2222
criterion = "0.5"
2323
fnv = "1.0.6"
24+
getrandom = { version = "0.3" }
2425
indoc = "2"
2526
libc = "0.2.42"
2627
memmem = "0.1.1"

engine/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ indoc.workspace = true
4040
[features]
4141
default = [ "regex" ]
4242
regex = ["dep:regex-automata"]
43+
44+
[target.'cfg(target_family = "wasm")'.dependencies]
45+
# By default, getrandom doesn't have any source of randomness on wasm32-unknown.
46+
# This optional dependency allows us to build with `--features getrandom/wasm_js`.
47+
# For more information see: https://docs.rs/getrandom/#webassembly-support
48+
getrandom.workspace = true

engine/src/ast/field_expr.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,20 +655,24 @@ impl Expr for ComparisonExpr {
655655
use rand::{Rng, rng};
656656
use sliceslice::wasm32::*;
657657

658-
impl Compare<U> for Wasm32Searcher {
658+
struct WasmSearcher(Wasm32Searcher<Box<[u8]>>);
659+
660+
impl<U> Compare<U> for WasmSearcher {
659661
#[inline]
660662
fn compare<'e>(
661663
&self,
662664
value: &LhsValue<'e>,
663665
_: &'e ExecutionContext<'e, U>,
664666
) -> bool {
665-
self.search_in(cast_value!(value, Bytes))
667+
unsafe { self.0.search_in(cast_value!(value, Bytes)) }
666668
}
667669
}
668670

669671
let position = rng().random_range(1..bytes.len());
670672

671-
return unsafe { search!(Wasm32Searcher::with_position(bytes, position)) };
673+
return unsafe {
674+
search!(WasmSearcher(Wasm32Searcher::with_position(bytes, position)))
675+
};
672676
}
673677

674678
search!(TwoWaySearcher::new(bytes))

0 commit comments

Comments
 (0)