Skip to content

Commit f4549a1

Browse files
committed
Adapt to changes in getrandom 0.3
This uses a build script to enable the `wasm_js` backend when the target is exactly `wasm32-unknown-unknown` and the `wasm` feature of `gix-diff` is enabled. The recently added step in the CI `wasm` job to enable it for subsequent steps of that job is accordingly removed. If successful, this creates a situation roughly similar to what we had before: authors of crates that use `gix-diff` will not have to set anything, beyond enabling the `wasm` feature. I don't know if that is ideal or not; see discussion in #2092. However, it seems like it is at least as good as how `gix-diff` used `getrandom` 0.2.
1 parent 037cb8c commit f4549a1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,6 @@ jobs:
457457
for feature in progress parallel io-pipe crc32 zlib cache-efficiency-debug; do
458458
cargo build -p gix-features --features "$feature" --target "$TARGET"
459459
done
460-
- name: enable wasm_js backend
461-
if: matrix.target == 'wasm32-unknown-unknown'
462-
run: echo RUSTFLAGS='--cfg getrandom_backend="wasm_js"' >> "$GITHUB_ENV"
463460
- name: crates with 'wasm' feature
464461
run: |
465462
set -x

gix-diff/build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::env::var_os;
2+
3+
fn main() {
4+
let target = var_os("TARGET").expect("cargo sets TARGET");
5+
if target != "wasm32-unknown-unknown" {
6+
return;
7+
}
8+
9+
if let Some(feature_wasm) = var_os("CARGO_FEATURE_WASM") {
10+
if feature_wasm == "1" {
11+
println!("cargo:rustc-cfg=getrandom_backend=\"wasm_js\"");
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)