Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

Update to latest rustfmt #4

Merged
merged 1 commit into from
May 23, 2021

Conversation

thomaseizinger
Copy link
Contributor

@thomaseizinger thomaseizinger commented Jan 29, 2021

To make future upgrades easier, we also make the following changes:

  1. Use a rust-toolchain file to clearly specify the requirements of
    our toolchain.
  2. Refer to this toolchain in the CI configuration to avoid duplicating
    the version requirement.
  3. Remove wasm feature in favour of cfg-based dependency declarations.
  4. Remove patches directory as they are now outdated with the recent
    ap-crates releases.
  5. Depend on rustfmt via git because the crates.io release is no longer
    being updated.

This is a draft PR because:

a) I am not sure if you want all the changes to the infrastructure.
b) We need this to be merged and released before this is going to build. I applied the patch locally and it works. We could also patch this the way rustc-ap-rustc_data_structures was patched before however, I thought it is nice to actually be able to get rid of this stuff hence I didn't want to re-introduce it again. We might need to wait for another rustc + rustfmt release though before we can use that.

@CLAassistant
Copy link

CLAassistant commented Jan 29, 2021

CLA assistant check
All committers have signed the CLA.

@dsherret
Copy link
Member

dsherret commented Jan 29, 2021

@thomaseizinger looks great! Yeah, I'd love this change.

I wonder why it's not compiling though. I found this issue rust-lang/rust#56935 Edit: Oh, I see you referenced that already.

@thomaseizinger
Copy link
Contributor Author

rust-lang/rust#81498 has been merged, waiting for it to be included in a nightly build and then rustfmt needs to update to that nightly as well.

@thomaseizinger
Copy link
Contributor Author

The PR is included in the recent nightly but it still fails. I assume we would need to patch more crates with the same workaround 🙄

I'll look into this.

@dsherret
Copy link
Member

dsherret commented Feb 9, 2021

That sucks. Thanks so much for taking this on and looking into it!

@thomaseizinger
Copy link
Contributor Author

Further investigation revealed that rustfmt is just not yet depending on a recent enough version of the rustc-ap-rustc_index crate. The most recent version simply does not yet include the fix so we will need to be patient for some more days :)

That sucks. Thanks so much for taking this on and looking into it!

No worries. I am keen to make use of some recent features in rustfmt, that is why I am willing to push this forward :D

@dsherret
Copy link
Member

dsherret commented May 9, 2021

I investigated this just now... looks like we're still waiting on a rustfmt release (last one was 1.4.36 on Feb 8th).

@thomaseizinger
Copy link
Contributor Author

I investigated this just now... looks like we're still waiting on a rustfmt release (last one was 1.4.36 on Feb 8th).

Correct. I've subscribed to the repo and will pick this up once they cut a new release!

@thomaseizinger
Copy link
Contributor Author

Alternatively, we could depend on a specific commit hash?

@thomaseizinger
Copy link
Contributor Author

@dsherret What is your thought on depending on a specific commit hash vs a tagged one? I am tired of waiting for a release 😅

Additionally, it doesn't really make a big difference for dprint itself so I don't necessarily want to take up resources of the rustfmt team just so we can depend on a more "official" version.

I don't know if tagged releases of rustmft undergo more specific testing than the usual CI? If not, I see little risk in depending on a specific commit on their main branch vs depending on a tagged release.

@dsherret
Copy link
Member

@thomaseizinger yeah depending on a specific commit sounds good to me!

@thomaseizinger thomaseizinger changed the title Update to rustfmt v1.4.33 Update to latest rustfmt May 19, 2021
@thomaseizinger thomaseizinger marked this pull request as ready for review May 19, 2021 06:25
@thomaseizinger
Copy link
Contributor Author

@dsherret I've updated the patch to point to latest master of rustfmt. The specific revision is tracked within Cargo.lock. For future updates, a cargo update -p rustfmt-nightly should do! Potentially, also the rust-toolchain file needs to be updated to a newer Rust version.

From my perspective, this is ready be reviewed!

To make future upgrades easier, we also make the following changes:

1. Use a rust-toolchain file to clearly specify the requirements of
our toolchain.
2. Refer to this toolchain in the CI configuration to avoid duplicating
the version requirement.
3. Remove `wasm` feature in favour of cfg-based dependency declarations.
4. Remove `patches` directory as they are now outdated with the recent
ap-crates releases.
5. Depend on rustfmt via git because the crates.io release is no longer
being updated. The Cargo.lock file tracks which specific Git revision
we depend on. Future updates therefore should only require a `cargo update`.
@dsherret
Copy link
Member

@thomaseizinger great! Thanks! Seems like the release build failed on the CI for some reason. I didn't look into it yet, but it says it can't find "rustc_ast".

@thomaseizinger
Copy link
Contributor Author

Uhm, that should have been installed through rustup, at least locally that worked but then I didn't actually build for wasm32 locally 🤦‍♂️

Let's hope that actually works for wasm ...

@thomaseizinger
Copy link
Contributor Author

thomaseizinger commented May 21, 2021

So here is what happened:

I've opened an issue here to discuss this but I am not very confident that this will be resolved quickly. As far as I understand rustc-dev is literally the entire compiler as a library and I doubt that you can actually compile the entire compiler to wasm?

@dsherret
Copy link
Member

That sucks… I’m thinking it might be time to change this to a dprint “process plugin”, which is unfortunate, but not too big of a deal. I can start on that tomorrow or Monday and then hopefully in the future rustfmt supports compiling to wasm.

@thomaseizinger
Copy link
Contributor Author

Yeah, I found it quite elegant that rustfmt was a wasm plugin :)

If you change it to a process plugin, are you still going to compile it yourself? One of the things I like about dprint is that I can use nightly formatting features but still use stable Rust without having to muck around and install two toolchains in CI etc.

Will that be possible with a process plugin or are you going to rely on rustfmt being installed on the machine?

@dsherret
Copy link
Member

If you change it to a process plugin, are you still going to compile it yourself? One of the things I like about dprint is that I can use nightly formatting features but still use stable Rust without having to muck around and install two toolchains in CI etc.

Will that be possible with a process plugin or are you going to rely on rustfmt being installed on the machine?

@thomaseizinger yup, will be possible!

I'm going to merge this PR even though it doesn't work due to changes in rustfmt. Thanks for all your help on this and hopefully we'll be able to make this a Wasm plugin again in the future so that it's more portable and secure.

@dsherret dsherret merged commit a020cf4 into dprint:main May 23, 2021
@dsherret
Copy link
Member

@thomaseizinger ok, the work here is done. You can update to the process plugin by following the instructions here:

https://github.com/dprint/dprint-plugin-rustfmt/releases/

(Slightly more verbose because a checksum needs to be provided because the plugin doesn't run sandboxed—unlike Wasm plugins)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants