Skip to content

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

@messense

Description

@messense
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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    O-appleApple targets and toolchainsbug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions