* Detect and use `sccache` via `RUSTC_WRAPPER`
If no other C/C++ caching tool is found by inspecting `CC` and `CXX`,
`RUSTC_WRAPPER` is tested to see if an output-caching wrapper for
`rustc` is in use. If that is the case and it is a wrapper known to also
support C/C++ caching, use it.
(Also correct/clarify a misnamed variable that caused me some confusion
looking over the code.)
* Support RUSTC_WRAPPER on Windows and with absolute paths
When checking for possible `RUSTC_WRAPPER`s that we can use to cache
C/C++ output, allow for filename extensions (e.g. `sccache.exe`) and
absolute paths (e.g. `/usr/local/bin/sccache`).
Closes#473
Some test cases check that a compiler flag is not present. But
cc::Build loads additional flags from the CFLAGS and CXXFLAGS
environment variables. If these are set, they might interfere with the
test cases.
Therefore we clear the CFLAGS and CXXFLAGS environment variables before
running a test that requires an absent flag.
Tested building https://github.com/trolleyman/cuda-macros with this (the `cuda-macros-test` crate) and it builds & links correctly. Haven't had a chance to test that this runs yet, but will in the morning.
I wasn't sure that this way is the most elegant, but this seemed like the way that did the least amount of changes. I am also not sure that this is the correct way of doing this, especially regarding cross-compiling, but it gets it up and running at least.
To test you can do a `cargo build` in the root of the repo linked above. The build stuff is a bit hacky, but essentially it generates the CUDA function below & calls it.
```c
extern "C" __global__ void hello(int32_t* x, int32_t y) {
printf("Hello from block %d, thread %d (y=%d)\n", blockIdx.x, threadIdx.x, y);
*x = 2;
}
```
```rust
extern "C" unsafe fn hello(x: *mut i32, y: i32);
```
Tests that modify environment variables (e.g. CFLAGS and CXXFLAGS) can
cause tests to fail when run in parallel because they change a shared
context.
This change moves the problematic tests into separate modules. Since
each `tests/*.rs` is compiled as a separate crate, these tests are not
run in parallel with other tests.
In case the temporary director is not deleted, this makes it easy to
find. It also means that it will get removed when `cargo clean` removes
the target directory.
If CFLAGS/CXXFLAGS is defined in the environment, then presumably the consumer has already determined the set of warnings flags to pass to the compiler, so we shouldn't enable warnings by default in that case.
Makefiles/configure scripts are lenient to this and otherwise they are basically
never relevant to the path of the tool itself, so chop it all off!
Closes#297
Right now we add them before, and we add -Wall by default. This allows
users to manually turn off specific warnings, without having to resort
to a dance of:
```
.warnings(false)
.flag("-Wall")
.flag("-Wno-foo")
```
This strikes a good balance of keeping -Wall on by default, while
minimising the surprising experience observed in
https://github.com/alexcrichton/cc-rs/issues/235.
These were accepted in https://github.com/alexcrichton/gcc-rs/pull/212, but never actually worked and weren't being tested. This fixes the logic errors that prevented the new style from working, and also updates the tests to use the new style.
It allows one to add a flag to the compiler on the condition that the
compiler supports it.
We check if the compiler supports the flag by trying to compile a
simple executable. If there is some output on stderr we consider that
the compiler failed and the flag is not supported.
This adds two configuration options to optionally enable or disable
the `-shared` and `-static` flags. If omitted, musl targets enable
`-static` by default.