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

Use OS temp directory instead of CARGO_TARGET_TMPDIR in bindgen tests #3428

Closed
wants to merge 1 commit into from

Conversation

riverar
Copy link
Collaborator

@riverar riverar commented Jan 9, 2025

In my testing, I found that CARGO_TARGET_TMPDIR is not guaranteed to point to an existing directory, contrary to what is stated in the Cargo documentation. To address this, and stabilize the bindgen tests, I replaced references to CARGO_TARGET_TMPDIR with calls to std::env::temp_dir().

@ChrisDenton
Copy link
Collaborator

I found that CARGO_TARGET_TMPDIR is not guaranteed to point to an existing directory

Can you say more? The docs say Cargo will create it so if it doesn't then that's definitely a bug in Cargo. However, it also says that Cargo doesn't manage it which means that anything could delete it. And if that's happening then it's likely a bug in the testing code somewhere.

@kennykerr
Copy link
Collaborator

Sporadic build failures suddenly started showing up today like this one:

https://github.com/microsoft/windows-rs/actions/runs/12679261715/job/35339673541

@ChrisDenton
Copy link
Collaborator

That's on stable, huh. Which definitely hasn't changed recently. Strange. Possibly some change in CI uncovered a bug somewhere. But seems weird.

@riverar
Copy link
Collaborator Author

riverar commented Jan 9, 2025

@ChrisDenton I noticed on my local machine (and on the runners via SSH) that the directory was missing during the test run. In my local testing, I see Cargo creates the folder once during a compile pass but not during a test run--not conclusive, I realize. (Maybe this is intentional; the documentation isn't clear to me!)

In these bindgen tests, if the failed_to_write_file test runs first, std::fs::create_dir_all is called, inadvertently creating the tmp directory and masking the missing state of the tmp location. My thinking was to rely on the OS temp directory to address several issues at once.

But given the errors we're now encountering in this PR, maybe CI could use a break tonight. 😅

@ChrisDenton
Copy link
Collaborator

What's not clear to me is if Cargo creates the folder once then what deletes it?

@kennykerr
Copy link
Collaborator

kennykerr commented Jan 9, 2025

I'm not sure whether this is causing failures but I've noticed this a few times (on master):

https://github.com/microsoft/windows-rs/actions/runs/12679261715/job/35374800510

"warning: C:\Users\runneradmin\.cargo\config is deprecated in favor of config.toml"

Perhaps because we build with this:

"-D", "warnings",

I assume this runner has just got some old config stuff in it. 🤷

Update: reran a few times and this seems unrelated but perhaps somebody at GitHub can clean up this warning?

@kennykerr
Copy link
Collaborator

It seems this change does not address the problem:

https://github.com/microsoft/windows-rs/actions/runs/12682378553/job/35376701787?pr=3428

@riverar riverar closed this Jan 9, 2025
@kennykerr
Copy link
Collaborator

What I don't understand is this:

image

There are two distinct tests. One is called failed_to_create_directory that uses the failed_to_create_directory path. The other is called failed_to_write_file that uses the failed_to_write_file path.

So why is this error in the failed_to_create_directory test referring to the failed_to_write_file path?

I'm clearly missing something. 😊

@kennykerr
Copy link
Collaborator

kennykerr commented Jan 9, 2025

Oh do these tests possibly run in the same process? That would explain it. 🫢

@kennykerr
Copy link
Collaborator

Thanks for the eyeballs on this issue @riverar @ChrisDenton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants