-
Notifications
You must be signed in to change notification settings - Fork 504
Fix compile family detection: Use C macros instead of $compiler -v
#1000
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a7e0c6a
Impl `NamedTempfile`
NobodyXu 8a2efd7
Detect compiler family by using C macros
NobodyXu d214af4
Add `detect_compiler_family.c`
NobodyXu 779bed4
Fix `gnu_flag_if_supported` and `gnu_flag_if_supported_cpp`
NobodyXu 681a1f9
Disable warning for compiler family detection
NobodyXu 093848c
Enable stderr forwarding for compiler family detection if debugging o…
NobodyXu aa2b4b6
Print stdout from compiler family detection if debugging output is en…
NobodyXu 1d8cf41
Enable debugging output for CI
NobodyXu ea72216
Fix `flag_if_supported` failure due to `OUT_DIR` not set
NobodyXu f70eafa
Fix test on cargo warnings
NobodyXu ada78b9
Revert changes to `src/bin/gcc-shim.rs`
NobodyXu f3b5946
Remove unnecessary `.stderr(Stdio::null())` in `tool.rs`
NobodyXu 805f9b4
Merge branch 'main' into fix/compile-family-detection
NobodyXu 1ab8a9d
Run `cargo fmt`
NobodyXu 467bd8c
Add comment to `disable_debug_output` in `cc-test/build.rs`
NobodyXu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifdef __clang__ | ||
#pragma message "clang" | ||
#endif | ||
|
||
#ifdef __GNUC__ | ||
#pragma message "gcc" | ||
#endif | ||
|
||
#ifdef _MSC_VER | ||
#pragma message "msvc" | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use std::{ | ||
collections::hash_map::RandomState, | ||
fs::{remove_file, File, OpenOptions}, | ||
hash::{BuildHasher, Hasher}, | ||
io, os, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
#[cfg(not(any(unix, target_os = "wasi", windows)))] | ||
compile_error!("Your system is not supported since cc cannot create named tempfile"); | ||
|
||
fn rand() -> u64 { | ||
RandomState::new().build_hasher().finish() | ||
} | ||
|
||
fn tmpname(suffix: &str) -> String { | ||
format!("{}{}", rand(), suffix) | ||
} | ||
|
||
fn create_named(path: &Path) -> io::Result<File> { | ||
let mut open_options = OpenOptions::new(); | ||
|
||
open_options.read(true).write(true).create_new(true); | ||
|
||
#[cfg(all(unix, not(target_os = "wasi")))] | ||
<OpenOptions as os::unix::fs::OpenOptionsExt>::mode(&mut open_options, 0o600); | ||
|
||
#[cfg(windows)] | ||
<OpenOptions as os::windows::fs::OpenOptionsExt>::custom_flags( | ||
&mut open_options, | ||
crate::windows::windows_sys::FILE_ATTRIBUTE_TEMPORARY, | ||
); | ||
|
||
open_options.open(path) | ||
} | ||
|
||
pub(super) struct NamedTempfile { | ||
path: PathBuf, | ||
file: Option<File>, | ||
} | ||
|
||
impl NamedTempfile { | ||
pub(super) fn new(base: &Path, suffix: &str) -> io::Result<Self> { | ||
for _ in 0..10 { | ||
let path = base.join(tmpname(suffix)); | ||
match create_named(&path) { | ||
Ok(file) => { | ||
return Ok(Self { | ||
file: Some(file), | ||
path, | ||
}) | ||
} | ||
Err(e) if e.kind() == io::ErrorKind::AlreadyExists => continue, | ||
Err(e) => return Err(e), | ||
}; | ||
} | ||
|
||
Err(io::Error::new( | ||
io::ErrorKind::AlreadyExists, | ||
format!( | ||
"too many temporary files exist in base `{}` with suffix `{}`", | ||
base.display(), | ||
suffix | ||
), | ||
)) | ||
} | ||
|
||
pub(super) fn path(&self) -> &Path { | ||
&self.path | ||
} | ||
|
||
pub(super) fn file(&self) -> &File { | ||
self.file.as_ref().unwrap() | ||
} | ||
} | ||
|
||
impl Drop for NamedTempfile { | ||
fn drop(&mut self) { | ||
// On Windows you have to close all handle to it before | ||
// removing the file. | ||
self.file.take(); | ||
let _ = remove_file(&self.path); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.