-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Always set the OUT_DIR environment variable #9084
Comments
I think there may be a misunderstanding about how proc-macros work and how they are intended to work and how build scripts work. Generally, proc-macros should not persist any data to disk, and should be idempotent transformations on the input, without side-effects. It is not clear from the description why you are using proc-macros to interface with other tooling, but I recommend considering other approaches to what you are trying to accomplish. If you want help discussing different ideas, I would suggest one of the user forums. |
IMO |
If this isn't to be changed, it'd be helpful to document this behaviour, that OUT_DIR (EDIT: Or maybe more than just OUT_DIR) is only set if there's a build script. We had an issue where we accidentally removed our build script (that generated Rust source files), but our include code panicked saying OUT_DIR was not set. It took me a while to realise this was the source of the issue I could open a PR on the Cargo Book to make this change if that's alright |
Thanks for your advice! It seems to be documented already. cargo/src/doc/src/reference/environment-variables.md Lines 230 to 232 in 8494149
|
Describe the problem you are trying to solve
I want to create a procedural attribute macro that analyzes a function signature and exports this information into a file. This file will be used later by another program, so it's definitely needed. However, the environment variable
OUT_DIR
isn't always set, which would tell me a good spot to write the file to. If the crate that uses the macro has a build script,OUT_DIR
is set, but if it doesn't have a build script,OUT_DIR
isn't set. Therefore, I would need to tell my users to always have a build script so that the macro works. This does not work well when there are many users of that macro.Describe the solution you'd like
My requested solution is simple: Always set the
OUT_DIR
environment variable to a valid output directory, if the built crate has a build script or not.Notes
One point against this is that
OUT_DIR
might collide with other uses of the variable, or that the nameOUT_DIR
isn't a good name for that in general. However, this would be a whole other discussion since it is already set for and used by build scripts.The text was updated successfully, but these errors were encountered: