rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.86k stars 448 forks source link

Use `--` to separate flags and options from input filenames #513

Open ncalexan opened 4 years ago

ncalexan commented 4 years ago

I'm in the unusual position of trying to cross-compile from macOS to Windows with clang-cl (building Firefox, but that's not really relevant). I'm running into the [-Wslash-u-filename] warning, like so:

running: "/Users/nalexander/.mozbuild/clang/bin/clang-cl" "-Xclang" "-std=gnu99" "-nologo" "-MD" "-O1" "-Z7" "-Brepro" "-m64" "-Xclang" "-ftrivial-auto-var-init=pattern" "-guard:cf" "-DDEBUG=1" "-I/Users/nalexander/Mozilla/gecko/toolkit/library/rust" "-I/Users/nalexander/Mozilla/objdirs/objdir-windows-compile/toolkit/library/rust" "-I/Users/nalexander/Mozilla/objdirs/objdir-windows-compile/dist/include" "-I/Users/nalexander/Mozilla/objdirs/objdir-windows-compile/dist/include/nspr" "-I/Users/nalexander/Mozilla/objdirs/objdir-windows-compile/dist/include/nss" "-MD" "-FI" "/Users/nalexander/Mozilla/objdirs/objdir-windows-compile/mozilla-config.h" "-DMOZILLA_CLIENT" "-Qunused-arguments" "-D_HAS_EXCEPTIONS=0" "-W3" "-Gy" "-Zc:inline" "-Gw" "-Wno-unknown-pragmas" "-Wno-ignored-pragmas" "-Wno-deprecated-declarations" "-Wno-invalid-noreturn" "-Z7" "-O2" "-Oy-" "-DMOZILLA_CONFIG_H" "-DMDB_IDL_LOGN=9" "-Fo/Users/nalexander/Mozilla/objdirs/objdir-windows-compile/x86_64-pc-windows-msvc/debug/build/lmdb-rkv-sys-e159e1f997d95e72/out/mdb.o" "-c" "/Users/nalexander/Mozilla/gecko/third_party/rust/lmdb-rkv-sys/lmdb/libraries/liblmdb/mdb.c"
cargo:warning=clang-9: warning: '/Users/nalexander/Mozilla/gecko/third_party/rust/lmdb-rkv-sys/lmdb/libraries/liblmdb/mdb.c' treated as the '/U' option [-Wslash-u-filename]
cargo:warning=clang-9: note: Use '--' to treat subsequent arguments as filenames
cargo:warning=clang-9: error: no input files
exit code: 1

What's needed in these situations is to insert -- before the input filename. Given that cc-rs must already be normalizing its Builder outputs, this seems straight-forward enough, but it's technically possible that supported C/C++ compilers wouldn't accept --.

Would the project take a patch?

alexcrichton commented 4 years ago

Thanks for the report! This should be relatively easy to fix I think since we should already know whether the type of the compiler is clang/gnu/etc. Given that we could just arrange for the filename to always be at the end and then, for clang-cl, always use -- before the filename?

mathewhodson commented 11 months ago

@ncalexan I believe this is fixed by #514