crane icon indicating copy to clipboard operation
crane copied to clipboard

crane-utils: migrate from toml_edit to toml

Open nrabulinski opened this issue 11 months ago • 3 comments

Motivation

Currently toml_edit is used to resolve Cargo.tomls from workspace crates. This was fine but I recently ran into https://github.com/toml-rs/toml/issues/691 which made it impossible for me to compile my project. I thought of trying to fix toml_edit, but then I thought to myself that realistically there's very little gain in trying to preserve the comments and order in Cargo.toml files which the user won't even see unless, as it was in my case, there's a bug and cargo fails while reading it.

It turned out to be very easy to replace toml_edit with toml, while also making the code shorter, and (in my opinion) a bit cleaner.

Checklist

  • [x] added tests to verify new behavior
  • [ ] added an example template or updated an existing one
  • [ ] updated docs/API.md (or general documentation) with changes
  • [x] updated CHANGELOG.md

nrabulinski avatar Feb 26 '24 22:02 nrabulinski

There unfortunately seem to be packages do do use comments for stuff https://github.com/ipetkov/crane/issues/394

dpc avatar Feb 26 '24 22:02 dpc

Oh, i did not see that, thanks for pointing that out @dpc. Although IMO there's something wrong with document-features if it's supposed to only affect documentation and yet it causes the compilation to fail when there's a missing comment in Cargo.toml

nrabulinski avatar Feb 27 '24 06:02 nrabulinski

Thanks for the PR @nrabulinski! Like @dpc mentioned we switched from toml to toml_edit to accommodate things like document-features. It's pretty unfortunate to be stuck waiting on a fix for an upstream bug, but if I had to pick one use case, I'd rather support document-features (it's hopefully "easier" to tweak/patch a Cargo.toml to move/remove unnecessary comments IMO)

I'm thinking another solution would be to expose a more-first-class way of customizing fetching git checkouts (namely adding the ability to insert custom patch hooks for example). Then affected projects can more easily tweak downstream Cargo.tomls without having to switch to their own patched branch

ipetkov avatar Mar 02 '24 17:03 ipetkov

Thanks again for the PR @nrabulinski ! It looks like https://github.com/ipetkov/crane/pull/583 has a workaround for this by ignoring (stripping) all comments when doing workspace inheritance until https://github.com/toml-rs/toml/issues/691 is fixed. Please take a look and see if that resolves your issue!

In the mean time, I'm going to close this PR in favor of https://github.com/toml-rs/toml/issues/691 since we don't want to regress on supporting comments on feature definitions

ipetkov avatar Apr 21 '24 04:04 ipetkov