-
-
Notifications
You must be signed in to change notification settings - Fork 367
Upgrade the getrandom
dependency of gix-diff
#2093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
These steps benefit from showing the `cargo` command that was run before the resulting build output. Most run multiple `cargo build` commands, sometimes in a loop, such that the output can only be properly understood if the commands are shown. `set +x` is the default (in general, as well as in GitHub Actions unless the value of `shell` is modified with `-x` or `-o xtrace`). It looks like `set -x` was already intended here. Work in GitoxideLabs#2093 confirms a practical benefit of `-x` for understanding these logs. `set +x` was part of the original code of these CI steps when they were introduced in 0d4b804 (GitoxideLabs#735). Its use was preserved and expanded in several changes. In 44ff412 (GitoxideLabs#1668), `set +x` was preserved and also positioned where it would make sense for `set -x` to be. Thus, it appears this started as a small typo and gradually expanded through misreadings, including my own. This fixes that. (See #74 for verification that `set +x` had no effect.)
These steps benefit from showing the `cargo` command that was run before the resulting build output. Most run multiple `cargo build` commands, sometimes in a loop, such that the output can only be properly understood if the commands are shown. `set +x` is the default (in general, as well as in GitHub Actions unless the value of `shell` is modified with `-x` or `-o xtrace`). It looks like `set -x` was already intended here. Work in GitoxideLabs#2093 confirms a practical benefit of `-x` for understanding these logs. `set +x` was part of the original code of these CI steps when they were introduced in 0d4b804 (GitoxideLabs#735). Its use was preserved and expanded in several changes. In 44ff412 (GitoxideLabs#1668), `set +x` was preserved and also positioned where it would make sense for `set -x` to be. Thus, it appears this started as a small typo and gradually expanded through misreadings, including my own. This fixes that. (See #74 for verification that `set +x` had no effect.)
cb540a8
to
89e1f4c
Compare
89e1f4c
to
8f51845
Compare
As noted in GitoxideLabs#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 #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 GitoxideLabs#2092.
238461a
to
d229adb
Compare
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 GitoxideLabs#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
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 GitoxideLabs#2092.
2df5d1f
to
f4549a1
Compare
This can't be set in `build.rs`, for the reasons described in: GitoxideLabs#2093 (comment) This commit is just to demonstrate that. It shall be rewound.
This can't be set in `build.rs`, for the reasons described in: GitoxideLabs#2093 (comment) This commit is just to demonstrate that. It shall be rewound.
d5c5e57
to
ec27611
Compare
.github/workflows/ci.yml
Outdated
- name: enable wasm_js backend | ||
if: matrix.target == 'wasm32-unknown-unknown' | ||
run: echo RUSTFLAGS='--cfg getrandom_backend="wasm_js"' >> "$GITHUB_ENV" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe we can cause enabling the wasm
feature of gix-diff
to achieve this effect, nor otherwise achieve this effect for users of gix-diff
in a way that spares them the need to do an extra step.
That is, whoever does the build must do something to achieve the effect of passing --cfg getrandom_backend="wasm_js"
to rustc
, in addition to whatever features are enabled. This can be done in a .cargo/config.toml
file, but having such a configuration here will not affect other projects that are not hosted in this repository and that host gix-diff
.
I believe placing the onus on the downstream developer, rather than library crate developers, to enable the wasm_js
backend, is one of the reasons for the breaking changes in getrandom
0.3. Reasons for this may include security--the JavaScript backend may not always be adequately secure, if I understand correctly. If all possible uses of getrandom
through gix-diff
do not require unpredictable random numbers, then security may not be an issue. I suspect that is the case, but I don't know for sure. Anyway, I still don't know of a way to make it work like it did in 0.2.
Options include:
- Documenting that this is so and going ahead with the upgrade, or
- Holding off on upgrading (or even planning not to upgrade)
getrandom
.
There may be other options I haven't thought of, and there may be gaps or inaccuracies in my understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional documentation might help - users now have to know how to configure getrandom
if they want to build for these targets, and if I am not mistaken the compiler error will also be quite specific about what has to be done.
Thus, maybe additional documentation in a plumbing crate of gitoxide
wouldn't be read anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gix-diff
docstring in lib.rs
is not visible when looking at the diff
module of gix
(diff
pulls in the contents of gix-diff
with pub use gix_diff::*;
but also has its own items). So maybe often not? But people would still search for such documentation. I can try to document it in some way, if we go forward with the approach currently implemented here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you find a good spot for documentation, I think it's absolutely fair to add it. From what I wrote below it seems though that getrandom
has nothing to do with this crate, they are only tangentially related.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #2093 (comment). If this is to be merged in something like its current form, then in addition to documenting the actions developers using gix-diff
will have to take to set the Rust flag to select the optional getrandom
backend, I think I would want to rebase this to make one of the commits that modifies gix-diff/Cargo.toml
conventional.
Per #2092 (comment), even if this should just be closed, it's my hope that helps make the situation clearer than before.
ec27611
to
7845c26
Compare
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
7845c26
to
8f1173d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could be as 'easy' as going with this - it works like it worked before.
Without the wasm_js
Cargo feature I suppose it wouldn't work, but would it work without that feature and without the RUSTFLAGS setting? If that was the case, that might be preferred as it leaves everything to the caller.
Otherwise, I'd be OK merging exactly what we have here.
I don't view this as working the same as it did before, because:
However, it is true that I've avoided changing how it works as much as possible (or at least as much as I know how). If you think that's sufficient, I'd be happy to merge this. It seems to me that something should probably also be done to indicate the change. To elaborate on my previous thinking:
Omitting both--like omitting one or the other--will break the build on |
I noticed something:
I wonder why It feels like I tried to make something work, and it did work because it was only a Cargo feature. Now If this makes sense, this should be a breaking change to indicate the dependency gets removed, and that applications need to configure it entirely themselves. It's a hurdle, but there seems to be no way around it, while also I think what we have now is obviously confusing to us, and more like a hack to make it easier for downstream. But the motivation for the hack, to make it easy, can't be fulfilled anymore. |
Thanks--I had sort of assumed that we did need
I had meant to say:
Is the
I don't think I really understand how it has to be configured. If I remove the So I will need some way of testing for the functionality that requires configuring a JavaScript backend for Taking a look at:
gitoxide/gix-tempfile/Cargo.toml Line 38 in 202bc6d
That transitively depends on |
I don't know actually, I'd expect it to fail building entirely. It's worth noting that
That's great, I wasn't even aware that it could build without the If I had better memory I'd probably know why |
Would fix #2092
I don't know if I'll manage to make this work. But even if not, maybe showing my attempts in this PR will make the situation in #2092 clearer.