mlabs-haskell / lambda-buffers

LambdaBuffers toolkit for sharing types and their semantics between different languages
https://mlabs-haskell.github.io/lambda-buffers/
Apache License 2.0
29 stars 0 forks source link

Adding rustfmt to pre-commit-hooks #109

Closed szg251 closed 10 months ago

szg251 commented 11 months ago

By default, rustfmt looks for a Cargo.toml file in the root directory to determines which files should be formatted. However, as we're using a monorepo structure there's no such file, so the pre-commit-hook fails. We must find a way to tell rustfmt where the package roots are. Previously I configured cargo workspaces, which solved the problem, but it is not in alignment with the rules of our monorepo (the repo should be language agnostic), so this is a no-go.

bladyjoker commented 11 months ago

Thank you for opening this issue.

I looked into https://github.com/cachix/pre-commit-hooks.nix/blob/master/modules/hooks.nix and found that there's a Rust wide option to set the location of the Cargo manifest file (I think that's it right?).

Both rustfmt and clippy are using this.

That being said, can we add clippy as well?

szg251 commented 11 months ago

Ok, this was easy... I will add both

szg251 commented 11 months ago

I found a problem, this only allows configuring one manifest file, but we will have multiple ones eventually... I guess we will need to request a new feature, or implement it ourselves.

bladyjoker commented 11 months ago

Legitimate problem that's making monorepos more difficult. Hmmm...

bladyjoker commented 11 months ago

Stupid question! What's the content of said Manifest? Is it something generic? If so, we can just have it provided as a derivation :)

szg251 commented 11 months ago

It's basically the same as a xyz.cabal file in Haskell. I wouldn't go in that direction. I think we could define a custom hook, at least as a temporary solution..

szg251 commented 11 months ago

Maybe we could trick the system by providing a workspace root manifest file as derivation... I'll give this a go