Skip to content

Conversation

@hanna-kruppe
Copy link
Contributor

@hanna-kruppe hanna-kruppe commented Jun 7, 2024

Fixed #1082

src/tool.rs Outdated
.write_all(include_bytes!("detect_compiler_family.c"))?;
// Close the file handle *now*, otherwise the compiler may fail to open it on Windows
// (#1082). The file stays on disk and its path remains valid until `tmp` is dropped.
tmp.close();
Copy link
Contributor

@NobodyXu NobodyXu Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also do a tmp.file().flush()?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would call the Write::flush method, which for File is a no-op on all mainstream platforms including all that cc supports right now: Windows, Unix, and wasi. If you intend the call as precaution against adding a BufWriter or something in the future, sure, I can add it. However, if you want to surface I/O errors that would otherwise be detected while closing the file and ignored by dropping, we'll need File::sync_all as discussed in File's documentation. Which option do you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for investigating this, I'd like file.flush()?; and file.sync_data()?; to be called.

I don't think we need file.sync_metadata()?;, since it's a tempfile.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/tempfile.rs Outdated
&self.path
}

pub(super) fn file(&self) -> &File {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this method, to fn take_file() -> Option<File>, so we don't need the close() method

@NobodyXu
Copy link
Contributor

NobodyXu commented Jun 7, 2024

Thank you! Just two suggestions I'd want you to change

Copy link
Contributor

@NobodyXu NobodyXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@NobodyXu NobodyXu merged commit 04e4443 into rust-lang:main Jun 8, 2024
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.

Compiler family detection failed - cl.exe "cannot open source file"

2 participants