Skip to content

Commit 4018a0d

Browse files
RobertJacobsonCDCestk
authored andcommitted
Modified getrandom dependency only for target family wasm *and* feature "time_trigger".
Clarified requirement in `.cargo/config.toml`. Added building Wasm target in CI (`main.yml`).
1 parent 9c63042 commit 4018a0d

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

.cargo/config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# The following is required for Wasm support in the `getrandom` crate, a transitive dependency of the `rand` crate.
2-
# See: https://docs.rs/getrandom/0.3.3/getrandom/#webassembly-support
1+
# The following is required for Wasm support in the `getrandom` crate, a transitive dependency of the `time_trigger`
2+
# feature. See: https://docs.rs/getrandom/0.3.3/getrandom/#webassembly-support
33
#
44
# If you are using `wasm-pack`, this config may not be respected. Use an environment variable instead:
55
# RUSTFLAGS='--cfg getrandom_backend="wasm_js"' wasm-pack build --target web

.github/workflows/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,17 @@ jobs:
7474

7575
- name: Bench features
7676
run: cargo bench --all-features
77+
78+
wasm:
79+
name: Build for WebAssembly (wasm32-unknown-unknown)
80+
runs-on: ubuntu-latest
81+
steps:
82+
- name: Checkout the source code
83+
uses: actions/checkout@v4
84+
85+
- uses: dtolnay/rust-toolchain@stable
86+
with:
87+
targets: wasm32-unknown-unknown
88+
89+
- name: Build for wasm32-unknown-unknown
90+
run: cargo build --target wasm32-unknown-unknown

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ libc = { version = "0.2", optional = true }
112112
[target.'cfg(not(target_family = "wasm"))'.dependencies]
113113
thread-id = { version = "5", optional = true }
114114

115-
[target.'cfg(target_family = "wasm")'.dependencies]
115+
[target.'cfg(all(target_family = "wasm", feature="time_trigger"))'.dependencies]
116116
getrandom = { version = "0.3.3", features = ["wasm_js"], optional = true }
117117

118118

src/encode/pattern/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,7 @@ impl FormattedChunk {
640640
TID.with(|tid| w.write_all(tid.to_string().as_bytes()))
641641
}
642642
#[cfg(target_family = "wasm")]
643-
FormattedChunk::SystemThreadId => {
644-
w.write_all("0".as_bytes())
645-
}
643+
FormattedChunk::SystemThreadId => w.write_all("0".as_bytes()),
646644
FormattedChunk::Target => w.write_all(record.target().as_bytes()),
647645
FormattedChunk::Newline => w.write_all(NEWLINE.as_bytes()),
648646
FormattedChunk::Align(ref chunks) => {

src/encode/writer/console.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ mod imp {
237237
self,
238238
writer::{
239239
ansi::AnsiWriter,
240-
console::{ColorMode, COLOR_MODE},
240+
console::{color_mode, ColorMode},
241241
},
242242
Style,
243243
},
@@ -249,18 +249,16 @@ mod imp {
249249
impl Writer {
250250
pub fn stdout() -> Option<Writer> {
251251
let writer = || Writer(AnsiWriter(StdWriter::stdout()));
252-
match *COLOR_MODE {
253-
ColorMode::Auto
254-
| ColorMode::Always => Some(writer()),
252+
match color_mode() {
253+
ColorMode::Auto | ColorMode::Always => Some(writer()),
255254
ColorMode::Never => None,
256255
}
257256
}
258257

259258
pub fn stderr() -> Option<Writer> {
260259
let writer = || Writer(AnsiWriter(StdWriter::stderr()));
261-
match *COLOR_MODE {
262-
ColorMode::Auto
263-
| ColorMode::Always => Some(writer()),
260+
match color_mode() {
261+
ColorMode::Auto | ColorMode::Always => Some(writer()),
264262
ColorMode::Never => None,
265263
}
266264
}

0 commit comments

Comments
 (0)