askama
askama copied to clipboard
Optional CARGO_MANIFEST_DIR
In askama_shared/src/lib.rs#L36 this will cause the Template macro to fail if the CARGO_MANIFEST_DIR
doesn't exist;
This works well with the default rustc tool chain; however, this also means if for whatever reason CARGO_MANIFEST_DIR
doesn't exist, the crate won't work. (proc-macro panic)
Any chance this can be optional instead?
What do you think it should do if the manifest dit is not available?
Looking at the code now, doesn't seem like it is reasonable to be able to have optional "Root" path; but maybe we can provide it through a template parameter or something; currently we can provide path relative to the manifest root dir, but maybe alternatively we can provide an absolute path?
which I guess will be way less portable -_-
What is your use case anyway? What build system are you using if not Cargo? It doesn't seem too big of a deal to just set CARGO_MANIFEST_DIR in your environment in some other way.
We are using BUCK; there is away to set the env variables in there; but it felt bit hacky; yet I can't think for better solution; the absolute path doesn't seem like an improvement
If there is some other environment variable in a Buck context that we can work off of, I'd be open to having that as a fallback.
doesn't seem like we have an equivalent really, for some reason. The only way that worked just fine, is to create a filegroup buck target, set its location is the value of CARGO_MANIFEST_DIR
and place the templates there. Yet the challenge here is any other project uses askama (directly or transitively, might be required to do some additional work arounds).
few folks suggested to use include_str instead. Also another approach might be to avoid invoking this code path if one uses source
instead of path
in the macro; with some document mentioning that path depends on CARGO_MANIFEST_DIR
Now I'm wondering if include_str!() works in attribute values...
I'm not entirely up to date on this, but as far as I recall using e.g. include_str!()
in an attribute is possible, but it is unstable and requires enabling the extended_key_value_attributes
feature. See https://github.com/rust-lang/rust/issues/78835 and https://github.com/rust-lang/rust/pull/78837.
You can use include_str
in attributes on stable through a declarative macro, I believe. It's a bit of a hack but it works well. See https://github.com/facebookincubator/cargo-guppy/blob/main/tools/determinator/src/rules.rs#L159-L187 for an example, and https://docs.rs/determinator/0.4.0/determinator/rules/struct.DeterminatorRules.html#associatedconstant.DEFAULT_RULES_TOML as the result.