mbedtls icon indicating copy to clipboard operation
mbedtls copied to clipboard

Build a C++ test program (cpp_dummy_build) in most tested configurations

Open gilles-peskine-arm opened this issue 1 year ago • 0 comments

We want our public headers to work in C++. For the most part, this means our headers should contain balanced extern { … } blocks. It also means public headers must refrain from things that don't work in C++, such as using new as a variable name, using forward-defined structures as a return type, etc.

Our testing is currently limited to one program (cpp_dummy_build) that just includes all headers, which we build in the full configuration with Clang in non-pedantic mode. The goal of this task is to extend the build of cpp_dummy_build to most all.sh components.

  • Create a header file that includes all the public headers. Location and method TBD. The most obvious thing is that this should be a generated file. However, having a header file that's generated adds additional complexity to the build scripts; currently we don't have any. Since we don't often add public headers, it may be better to let this file be maintained manually; but if we do that, we should keep a script that checks its content.
    • Note that “all the public headers” must exclude a few headers that can't be excluded independently. As of 3.5.0, this means headers matching /[-_.\/]config[-_.]/ (i.e. containing config as a word). Some psa/crypto_*.h such as psa/crypto_values.h are not meant to be included independently, but they do work as of 3.5.0, so they don't need to be excluded.
  • Change cpp_dummy_build.cpp to be a committed file that includes all_headers.h.
  • Arrange for make and cmake to automatically build cpp_dummy_build.cpp if a C++ compiler is available. Use pedantic flags as much as possible (but not pedantic flags that break the build — that would be a separate issue, such as https://github.com/Mbed-TLS/mbedtls/issues/7087 or the use of a flexible array member).

Out of scope:

  • Expanding cpp_dummy_build to do more than include all the headers.
  • Visual Studio — covered by https://github.com/Mbed-TLS/mbedtls/issues/1767.

gilles-peskine-arm avatar Oct 09 '23 14:10 gilles-peskine-arm