cc-rs icon indicating copy to clipboard operation
cc-rs copied to clipboard

is_flag_supported only works for C sources

Open nagisa opened this issue 5 years ago • 0 comments

is_flag_supported is implemented by attempting to compile a C file. This will obviously fail to correctly work when check is done in a non-C context.

For example:

    let mut cfg = cc::Build::new();
    cfg.flag_if_supported("-xassembler-with-cpp");
    cfg.file(asm);
    cfg.compile("libanan.a");

will fail to correctly identify that the flag is supported, because -xassembler-with-cpp will try to compile the C file as assembly, which will obviously fail.

This failure condition is not documented.

For at least gcc and clang the file compiled does not need to have any contents within it at all. For example:

echo "" | $CC $TESTED_FLAG -c - -o /tmp/test.o

will correctly test the $TESTED_FLAG.

nagisa avatar Nov 11 '18 10:11 nagisa