You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When adding the Windows CI (with VisualStudio, non mingw), I noticed that the ABI tests fail. At a first glance this is because the do not find a C compiler.
I spent a little bit of time looking into it, but it seems it is a pretty deep rabbit hole, so I am putting some notes on a possible plan here so that it can be discussed/reviewed before starting on it.
Observations:
The code compiles C programs when running cargo test, so it has a Compiler struct and it invokes pkg-config manually. That abstraction does not have all the complexity required to handle different OSes, cross-compilation etc. Ideally we should use the cc and the pkg-config crates which already have all of that
The cc crate however only builds C libraries, not C executables
The cc and pkg-config crates are designed to be run from build.rs and rely on the env set by cargo. I managed to make a small experiment forwarding env vars from build.rs to the test code and then run cc there, but this seems ugly.
There is no way to have code in build.rs which is conditional to tests. This is by design since the build should be the same for tests and normal builds. It is however possible to check env vars to take conditional paths based on cargo features.
Possible plan:
Refactor the C tests in a single C library instead of an executable per test
Add a abi_tests feature to the generated Cargo.toml. This will be off for the library users, while can be turned on by CI
Use cc crate from build.rs, conditionally to the feature to build the C libary
Use ffi in the abi tests to call the C library
The text was updated successfully, but these errors were encountered:
Sebastian suggested it might be worth looking at bindgen (not cbindgen): it can generate various ABI tests for the stuff it binds, we can probably learn from that (and it tests more than our minimal tests currently)
When adding the Windows CI (with VisualStudio, non mingw), I noticed that the ABI tests fail. At a first glance this is because the do not find a C compiler.
I spent a little bit of time looking into it, but it seems it is a pretty deep rabbit hole, so I am putting some notes on a possible plan here so that it can be discussed/reviewed before starting on it.
Observations:
cargo test
, so it has aCompiler
struct and it invokespkg-config
manually. That abstraction does not have all the complexity required to handle different OSes, cross-compilation etc. Ideally we should use thecc
and thepkg-config
crates which already have all of thatcc
crate however only builds C libraries, not C executablescc
andpkg-config
crates are designed to be run frombuild.rs
and rely on the env set bycargo
. I managed to make a small experiment forwarding env vars frombuild.rs
to the test code and then runcc
there, but this seems ugly.build.rs
which is conditional to tests. This is by design since the build should be the same for tests and normal builds. It is however possible to check env vars to take conditional paths based on cargo features.Possible plan:
abi_tests
feature to the generatedCargo.toml
. This will be off for the library users, while can be turned on by CIcc
crate frombuild.rs
, conditionally to the feature to build the C libaryThe text was updated successfully, but these errors were encountered: