Skip to content
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

Liquid placeholders make cargo and rust-analyzer fail #10

Closed
benfrankel opened this issue Sep 16, 2024 · 4 comments · Fixed by #11
Closed

Liquid placeholders make cargo and rust-analyzer fail #10

benfrankel opened this issue Sep 16, 2024 · 4 comments · Fixed by #11
Labels
bug Something isn't working

Comments

@benfrankel
Copy link
Collaborator

benfrankel commented Sep 16, 2024

For example, "{{project-name}}" in Cargo.toml is not a valid crate name, so the template itself cannot be compiled. This makes it harder for maintainers of the template to make changes.

Generated repos are not affected by this issue, only the template itself.

@benfrankel benfrankel added the bug Something isn't working label Sep 16, 2024
@benfrankel
Copy link
Collaborator Author

benfrankel commented Sep 16, 2024

Okay I found an approach that works:

  1. Split Cargo.toml into a Cargo.toml.template (or w/e) with Liquid placeholders, and a Cargo.toml with valid syntax.
  2. Add "Cargo.toml.template" to the include list in cargo-generate.toml (this can be "*.template" so it only has to be added once).
  3. Add file::rename("Cargo.toml.template", "Cargo.toml"); to the post-generate hook.

@richchurcher
Copy link
Collaborator

Oh, funny I was just strongly considering using sed in a pre-commit lol... nice one.

@benfrankel
Copy link
Collaborator Author

benfrankel commented Sep 16, 2024

This does mean that there will be 2 copies of each templated file that should be kept in sync, but that's a sacrifice I was prepared to make for a working solution anyways. Better than 2 branches of the entire repo :P

@janhohenheim
Copy link
Member

@BD103 if you feel like doing some CI magic at some point, we could issue a warning if a PR touches only one file when there exist both foo.rs and foo.rs.template 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants