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

Compiler family detection issue with clang-cl on macOS #1327

Open
messense opened this issue Dec 22, 2024 · 0 comments · May be fixed by #1328
Open

Compiler family detection issue with clang-cl on macOS #1327

messense opened this issue Dec 22, 2024 · 0 comments · May be fixed by #1328

Comments

@messense
Copy link

messense commented Dec 22, 2024

warning: [email protected]: clang-cl: warning: '/Users/messense/Projects/crfsuite-rs/target/x86_64-pc-windows-msvc/debug/build/crfsuite-sys-a73da6d4e4774cd8/out/14314275059944146007detect_compiler_family.c' treated as the '/U' option [-Wslash-u-filename]
warning: [email protected]: clang-cl: note: use '--' to treat subsequent arguments as filenames
warning: [email protected]: clang-cl: error: no input files
warning: [email protected]: Compiler family detection failed due to error: ToolExecError: Command "clang-cl" "-E" "/Users/messense/Projects/crfsuite-rs/target/x86_64-pc-windows-msvc/debug/build/crfsuite-sys-a73da6d4e4774cd8/out/14314275059944146007detect_compiler_family.c" with args clang-cl did not execute successfully (status code exit status: 1).

It seems like the /Users/... absolute path on macOS does not work well with clang-cl.

To reproduce:

$ touch empty.c
$ ln -s $(xcrun -f clang) clang-cl
$ ./clang-cl -E $(realpath ./empty.c)
clang-cl: warning: '/Users/messense/Projects/cargo-xwin/empty.c' treated as the '/U' option [-Wslash-u-filename]
clang-cl: note: use '--' to treat subsequent arguments as filenames
clang-cl: error: no input files

# this works fine
$ ./clang-cl -E ./empty.c 
# 1 "./empty.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 375 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "./empty.c" 2

This is handled in

cc-rs/src/lib.rs

Lines 1791 to 1797 in 9138052

if compiler.family == (ToolFamily::Msvc { clang_cl: true }) && !is_assembler_msvc {
// #513: For `clang-cl`, separate flags/options from the input file.
// When cross-compiling macOS -> Windows, this avoids interpreting
// common `/Users/...` paths as the `/U` flag and triggering
// `-Wslash-u-filename` warning.
cmd.arg("--");
}
but does not seem to be handled when doing compiler family detection:

cc-rs/src/tool.rs

Lines 136 to 145 in 9138052

tmp_file.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_file.flush()?;
tmp_file.sync_data()?;
drop(tmp_file);
let stdout = run_output(
Command::new(path).arg("-E").arg(tmp.path()),
path,

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 a pull request may close this issue.

1 participant