-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
Cleanup build.rs
and friends issue #1111
#1112
Conversation
…X_HOME, should not also be creating that path.
build.rs
and friends issue #1111
build.rs
and friends issue #1111build.rs
and friends issue #1111
I'm throwing the Will It Blend tests at this just to make sure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Largely looks good. Some mild nits. Somewhat concerned about duplicating the tracking command confusing cargo.
pgrx-pg-sys/build.rs
Outdated
== "1"; | ||
println!("cargo:rerun-if-env-changed=PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE"); | ||
let is_for_release = | ||
env_tracked("PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE").unwrap_or("0".to_string()) == "1"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trivial, I know, and preexisting, but it bugs me these aren't consistent.
env_tracked("PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE").unwrap_or("0".to_string()) == "1"; | |
env_tracked("PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE").unwrap_or_else(|| "0".to_string()) == "1"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also looking again this should actually be another case of .as_ref() == Some("1")
@@ -760,7 +763,7 @@ fn env_tracked(s: &str) -> Option<String> { | |||
} | |||
|
|||
fn target_env_tracked(s: &str) -> Option<String> { | |||
let target = std::env::var("TARGET").unwrap(); | |||
let target = env_tracked("TARGET").unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised that we need to add env_tracked
to this, I thought Cargo was already tracking this? Are we sure we won't confuse Cargo on this point?
let manifest_dir = env_tracked("CARGO_MANIFEST_DIR").map(PathBuf::from).unwrap(); | ||
let out_dir = env_tracked("OUT_DIR").map(PathBuf::from).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concerns re: "should we really be adding this to the env tracking"?
so... I blindly did this for every environment variable. My thought process was that if build.rs uses an envar, then it'll need to be rerun when that envar changes. |
Whee, errant mouseclicks. |
Co-authored-by: Jubilee <[email protected]>
Co-authored-by: Jubilee <[email protected]>
Co-authored-by: Jubilee <[email protected]>
Hmm. Given the big build test suite passed on a previous version of this PR, we should be okay? I feel like my main concern is really just making sure the commit message or a comment or whatever includes "yeah this was a more... interesting decision" so that if we find an unusual bug later related to the build, shuffling through the |
I updated the PR description. If that works for you, it'll become the commit message -- once CI passes the additional cleanups I just pushed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, looks good to me!
There used to be issues where doing this for the ones cargo manages would cause spurious rebuilds. I think these have been fixed, but it's possibly worth checking. If it helps, https://github.com/rust-lang/cc-rs/blob/main/src/lib.rs#L3132-L3139 is what I've used in the past (although the main reason cc-rs tries to avoid it is not that bug, but because emitting any |
It's funny, I had this same thought yesterday afternoon while walking the dog.
Well, we use I feel like this should be fine. If it causes rebuilds when it shouldn't then I'd argue that's a |
As usual, @thomcc was correct! :) I've put up PR #1127 to address the constant rebuilds that started happening after this PR was merged. I didn't narrow it down specifically because I got bored, but it's at least caused by one of the envars we access that begins with "CARGO": I still say this is some kind of cargo bug. Crate authors shouldn't have to do this. |
This PR "cleans up"
build.rs
so that it now tracks, viacargo:rerun-if-env-changed
, every environment variable it uses. The justification here is that ifbuild.rs
uses an environment variable, thenbuild.rs
will need to re-run if that envar changes. It could be this is overly aggressive in thatcargo
probably does this for us for things likeTARGET
orCARGO_MANIFEST_DIR
orOUT_DIR
, but it seems prudent to not have to then justify why we track some envars and not others.It also doesn't try to open
$PGRX_HOME/config.toml
in the case where thepg_config
data is wholly described as environment variables.And it also removes from
Pgrx::home()
the code that would just blindly try to create$PGRX_HOME
if it doesn't exist. It instead moves that to the Err case when it's called viacargo pgrx init
.