From adc3a41429ee0084e097b79b32ad5162fa18c55f Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 2 Aug 2025 18:13:21 -0400 Subject: [PATCH 1/4] Add `gix-diff` WASM check, even though `gix-path` covers it As noted in #2092, the `wasm` jobs on CI do not test `gix-diff` directly. However, my prediction there that breakage would not be detected on CI was mistaken, because those jobs do test the `wasm` feature of `gix-pack`. The `gix-pack` crate depends on `gix-diff`, and its `wasm` feature enable the `gix-diff` one. This nonetheless adds an explicit check for `gix-diff`. This `gix-diff` check does not attempt to build default features, since some fail on some WASM targets. But the preexisting `gix-pack` check does still build the default features of `gix-pack`, which are compatible with WASM targets. The efficacy of these checks, as well as the need to pass `--no-default-features` for `gix-diff`, can be confirmed by examining CI results for various fragments of this change experimented on in EliahKagan#75. This also demonstrates that CI is capable of catching at least some breakages related to the `wasm` feature of `gix-diff`, and thus may be sufficient to support moving forward with #2092. --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73417387ded..65c68f04032 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -460,9 +460,8 @@ jobs: - name: crates with 'wasm' feature run: | set -x - for crate in gix-pack; do - cargo build -p "$crate" --features wasm --target "$TARGET" - done + cargo build -p gix-diff --no-default-features --features wasm --target "$TARGET" + cargo build -p gix-pack --features wasm --target "$TARGET" - name: gix-pack with all features (including wasm) run: cargo build -p gix-pack --all-features --target "$TARGET" From 8283f89a8748cef6f960001957b4fd49c168a4d8 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 2 Aug 2025 18:23:28 -0400 Subject: [PATCH 2/4] Bump `gix-diff` dependency `getrandom` to 0.3.3 Other changes will need to be made to adapt to this, including in `gix-diff/Cargo.toml` itself. As previously observed in attempts by Dependabot to do this upgrade, and reported in #2092, we get: > cargo check -p gix-diff Updating crates.io index error: failed to select a version for `getrandom`. ... required by package `gix-diff v0.53.0 (C:\Users\ek\source\repos\gitoxide\gix-diff)` ... which satisfies path dependency `gix-diff` (locked to 0.53.0) of package `gix-pack v0.60.0 (C:\Users\ek\source\repos\gitoxide\gix-pack)` ... which satisfies path dependency `gix-pack` (locked to 0.60.0) of package `gix-odb v0.70.0 (C:\Users\ek\source\repos\gitoxide\gix-odb)` ... which satisfies path dependency `gix-odb` (locked to 0.70.0) of package `gix-object v0.50.0 (C:\Users\ek\source\repos\gitoxide\gix-object)` ... which satisfies path dependency `gix-object` (locked to 0.50.0) of package `gix-ref v0.53.0 (C:\Users\ek\source\repos\gitoxide\gix-ref)` ... which satisfies path dependency `gix-ref` (locked to 0.53.0) of package `gix-discover v0.41.0 (C:\Users\ek\source\repos\gitoxide\gix-discover)` ... which satisfies path dependency `gix-discover` (locked to 0.41.0) of package `gix-testtools v0.17.0 (C:\Users\ek\source\repos\gitoxide\tests\tools)` ... which satisfies path dependency `gix-testtools` (locked to 0.17.0) of package `gix-path v0.10.19 (C:\Users\ek\source\repos\gitoxide\gix-path)` ... which satisfies path dependency `gix-path` (locked to 0.10.19) of package `gix-fs v0.16.0 (C:\Users\ek\source\repos\gitoxide\gix-fs)` ... which satisfies path dependency `gix-fs` (locked to 0.16.0) of package `gix-tempfile v18.0.0 (C:\Users\ek\source\repos\gitoxide\gix-tempfile)` ... which satisfies path dependency `gix-tempfile` (locked to 18.0.0) of package `gix-lock v18.0.0 (C:\Users\ek\source\repos\gitoxide\gix-lock)` versions that meet the requirements `^0.3.3` are: 0.3.3 package `gix-diff` depends on `getrandom` with feature `js` but `getrandom` does not have that feature. package `getrandom` does have feature `std` failed to select a version for `getrandom` which could resolve this conflict --- gix-diff/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gix-diff/Cargo.toml b/gix-diff/Cargo.toml index 2bd93358f12..b90c3c1d37b 100644 --- a/gix-diff/Cargo.toml +++ b/gix-diff/Cargo.toml @@ -44,7 +44,7 @@ gix-traverse = { version = "^0.47.0", path = "../gix-traverse", optional = true thiserror = "2.0.0" imara-diff = { version = "0.1.8", optional = true } serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] } -getrandom = { version = "0.2.8", optional = true, default-features = false, features = ["js"] } +getrandom = { version = "0.3.3", optional = true, default-features = false, features = ["js"] } bstr = { version = "1.12.0", default-features = false } document-features = { version = "0.2.0", optional = true } From 63ae5c5fff1f34f20cc08a77dfa480a53cd7ecf7 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 2 Aug 2025 18:25:47 -0400 Subject: [PATCH 3/4] Use `wasm_js` feature of `getrandom` in `gix-diff` This is instead of the old `js` feature, which is absent in `getrandom` 0.3. This change makes it possible to resolve dependencies, as `Cargo.lock` now reflects. However, the features are not equivalent, and further changes will need to be made, at least to how building is done, to allow `getrandom` 0.3 to work on `wasm32-unknown-unknown`. See #2092. --- Cargo.lock | 18 +++++++++--------- gix-diff/Cargo.toml | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8685cbf1010..20380f7a251 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1281,9 +1281,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "js-sys", @@ -1654,7 +1654,7 @@ version = "0.53.0" dependencies = [ "bstr", "document-features", - "getrandom 0.2.15", + "getrandom 0.3.3", "gix-attributes", "gix-command", "gix-filter", @@ -2868,7 +2868,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2 0.5.10", + "socket2 0.6.0", "system-configuration", "tokio", "tower-service", @@ -3196,7 +3196,7 @@ version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" dependencies = [ - "getrandom 0.3.2", + "getrandom 0.3.3", "libc", ] @@ -3899,7 +3899,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49df843a9161c85bb8aae55f101bc0bac8bcafd637a620d9122fd7e0b2f7422e" dependencies = [ "bytes", - "getrandom 0.3.2", + "getrandom 0.3.3", "lru-slab", "rand", "ring", @@ -3968,7 +3968,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "getrandom 0.3.2", + "getrandom 0.3.3", ] [[package]] @@ -4697,7 +4697,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" dependencies = [ "fastrand", - "getrandom 0.3.2", + "getrandom 0.3.3", "once_cell", "rustix 1.0.8", "windows-sys 0.59.0", @@ -5347,7 +5347,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/gix-diff/Cargo.toml b/gix-diff/Cargo.toml index b90c3c1d37b..13731b37ad3 100644 --- a/gix-diff/Cargo.toml +++ b/gix-diff/Cargo.toml @@ -44,7 +44,7 @@ gix-traverse = { version = "^0.47.0", path = "../gix-traverse", optional = true thiserror = "2.0.0" imara-diff = { version = "0.1.8", optional = true } serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] } -getrandom = { version = "0.3.3", optional = true, default-features = false, features = ["js"] } +getrandom = { version = "0.3.3", optional = true, default-features = false, features = ["wasm_js"] } bstr = { version = "1.12.0", default-features = false } document-features = { version = "0.2.0", optional = true } From 069fd5e1dad5340525bf5ec73bc58e500ff87dd2 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 2 Aug 2025 18:48:46 -0400 Subject: [PATCH 4/4] Enable `wasm_js` backend on CI where needed This enables it through the `RUSTFLAGS` environment variable, doing so for the `wasm32-unknown-unknown` target only. This is to address: error: The wasm32-unknown-unknown targets are not supported by default; you may need to enable the "wasm_js" configuration flag. Note that enabling the `wasm_js` feature flag alone is insufficient. For more information see: https://docs.rs/getrandom/0.3.3/#webassembly-support --> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/getrandom-0.3.3/src/backends.rs:168:9 | 168 | / compile_error!(concat!( 169 | | "The wasm32-unknown-unknown targets are not supported by default; \ 170 | | you may need to enable the \"wasm_js\" configuration flag. Note \ 171 | | that enabling the `wasm_js` feature flag alone is insufficient. \ 172 | | For more information see: \ 173 | | https://docs.rs/getrandom/", env!("CARGO_PKG_VERSION"), "/#webassembly-support" 174 | | )); However, it is not necessarily the best way to do it. If we want the `wasm` feature, which is intentionally not a default feature even on WASM targets, to be sufficient to enable this behavior, then we might not be able to use `getrandom` 0.3. The documentation at https://docs.rs/getrandom/0.3.3/getrandom suggests doing something like this in `.cargo/config.toml`: [target.wasm32-unknown-unknown] rustflags = ['--cfg', 'getrandom_backend="wasm_js"'] However, this would be done in the crate that uses `gix-diff`. Doing it here would not alleviate those using `gix-diff` of the need to do so. It could be done here for WASM tests, but we don't currently run tests on WASM. It could be done for the checks that WASM builds that are done in the `wasm` job on CI, but we probably shouldn't do that, because the current approach there of setting `RUSTFLAGS` is more granular; we would want to find out if more crates start needing this functionality in order to build. For more on backends including the `wasm_js` backend, see: https://docs.rs/getrandom/0.3.3/getrandom/#opt-in-backends --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65c68f04032..6f137ef843e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -457,6 +457,9 @@ jobs: for feature in progress parallel io-pipe crc32 zlib cache-efficiency-debug; do cargo build -p gix-features --features "$feature" --target "$TARGET" done + - name: Enable wasm_js backend + if: matrix.target == 'wasm32-unknown-unknown' + run: echo RUSTFLAGS='--cfg getrandom_backend="wasm_js"' >> "$GITHUB_ENV" - name: crates with 'wasm' feature run: | set -x