Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ rustflags = ["-C", "link-args=-rdynamic"]
[target.x86_64-pc-windows-msvc]
# https://github.com/dtolnay/inventory/issues/58
rustflags = ["-C", "codegen-units=1"]

[target.'cfg(target_arch = "wasm32")']
# https://docs.rs/getrandom/latest/getrandom/#webassembly-support
rustflags = ["--cfg", "getrandom_backend=\"wasm_js\""]
100 changes: 68 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ stdlib = [
"dep:uaparser",
"dep:url",
"dep:utf8-width",
"dep:getrandom",
"dep:uuid",
"dep:woothee",
"dep:zstd",
Expand Down Expand Up @@ -172,7 +173,7 @@ quoted_printable = { version = "0.5", optional = true }
psl = { version = "2", optional = true }
psl-types = { version = "2", optional = true }
publicsuffix = { version = "2", optional = true }
rand = { version = "0.8", optional = true }
rand = { version = "0.9.0", optional = true }
regex = { version = "1", default-features = false, optional = true, features = ["std", "perf", "unicode"] }
roxmltree = { version = "0.20", optional = true }
rustyline = { version = "15", default-features = false, optional = true }
Expand Down Expand Up @@ -227,10 +228,12 @@ grok = { version = "2", optional = true }
onig = { version = "6", default-features = false, optional = true }
tokio = { version = "1.44", optional = true, features = ["io-util", "macros", "net", "time", "sync", "rt", "rt-multi-thread"] }
uuid = { version = "1", features = ["v4", "v7"], optional = true }
getrandom = { version = "0.3", default-features = false, optional = true }

# Dependencies used for WASM
[target.'cfg(target_arch = "wasm32")'.dependencies]
uuid = { version = "1", features = ["v4", "v7", "js"], optional = true }
getrandom = { version = "0.3", default-features = false, features = ["wasm_js"], optional = true }

[dev-dependencies]
anyhow = "1"
Expand Down
2 changes: 2 additions & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ uuid,https://github.com/uuid-rs/uuid,Apache-2.0 OR MIT,"Ashley Mannix<ashleymann
valuable,https://github.com/tokio-rs/valuable,MIT,The valuable Authors
vte,https://github.com/alacritty/vte,Apache-2.0 OR MIT,"Joe Wilm <[email protected]>, Christian Duerr <[email protected]>"
wasi,https://github.com/bytecodealliance/wasi,Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT,The Cranelift Project Developers
wasi,https://github.com/bytecodealliance/wasi-rs,Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT,The Cranelift Project Developers
wasm-bindgen,https://github.com/rustwasm/wasm-bindgen,MIT OR Apache-2.0,The wasm-bindgen Developers
wasm-bindgen-backend,https://github.com/rustwasm/wasm-bindgen/tree/master/crates/backend,MIT OR Apache-2.0,The wasm-bindgen Developers
wasm-bindgen-macro,https://github.com/rustwasm/wasm-bindgen/tree/master/crates/macro,MIT OR Apache-2.0,The wasm-bindgen Developers
Expand All @@ -270,6 +271,7 @@ winapi,https://github.com/retep998/winapi-rs,MIT OR Apache-2.0,Peter Atashian <r
winapi-util,https://github.com/BurntSushi/winapi-util,Unlicense OR MIT,Andrew Gallant <[email protected]>
windows,https://github.com/microsoft/windows-rs,MIT OR Apache-2.0,Microsoft
winnow,https://github.com/winnow-rs/winnow,MIT,The winnow Authors
wit-bindgen-rt,https://github.com/bytecodealliance/wasi-rs,Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT,The wit-bindgen-rt Authors
woothee,https://github.com/woothee/woothee-rust,Apache-2.0,hhatto <[email protected]>
write16,https://github.com/hsivonen/write16,Apache-2.0 OR MIT,The write16 Authors
writeable,https://github.com/unicode-org/icu4x,Unicode-3.0,The ICU4X Project Developers
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_wasm32.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ echo "Add wasm32-unknown-unknown target"
rustup target add wasm32-unknown-unknown

echo "Run check"
cargo check --target wasm32-unknown-unknown --no-default-features --features stdlib
cargo check -v --target wasm32-unknown-unknown --no-default-features --features stdlib
4 changes: 2 additions & 2 deletions src/stdlib/random_bool.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::compiler::prelude::*;
use rand::{thread_rng, Rng};
use rand::{rng, Rng};

#[allow(clippy::unnecessary_wraps)] // match other VRL function implementations
fn random_bool() -> Resolved {
let b: bool = thread_rng().gen();
let b: bool = rng().random();

Ok(Value::Boolean(b))
}
Expand Down
4 changes: 2 additions & 2 deletions src/stdlib/random_bytes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::compiler::prelude::*;
use rand::{thread_rng, RngCore};
use rand::{rng, RngCore};

const MAX_LENGTH: i64 = 1024 * 64;
const LENGTH_TOO_LARGE_ERR: &str = "Length is too large. Maximum is 64k";
Expand All @@ -9,7 +9,7 @@ fn random_bytes(length: Value) -> Resolved {
let mut output = vec![0_u8; get_length(length)?];

// ThreadRng is a cryptographically secure generator
thread_rng().fill_bytes(&mut output);
rng().fill_bytes(&mut output);

Ok(Value::Bytes(Bytes::from(output)))
}
Expand Down
4 changes: 2 additions & 2 deletions src/stdlib/random_float.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::compiler::prelude::*;
use rand::{thread_rng, Rng};
use rand::{rng, Rng};
use std::ops::Range;

const INVALID_RANGE_ERR: &str = "max must be greater than min";
Expand All @@ -12,7 +12,7 @@ fn random_float(min: Value, max: Value) -> Resolved {
return Err("max must be greater than min".into());
}

let f: f64 = thread_rng().gen_range(min..max);
let f: f64 = rng().random_range(min..max);

Ok(Value::Float(NotNan::new(f).expect("always a number")))
}
Expand Down
Loading
Loading