platformio / platform-espressif8266

Espressif 8266: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif8266
Apache License 2.0
320 stars 218 forks source link

Export CCFLAGS macros to IntelliSense #275

Closed maxgerhardt closed 2 years ago

maxgerhardt commented 2 years ago

What kind of issue is this?

You can erase any parts of this template not applicable to your Issue.


Configuration

Operating system: Win 10 x64

PlatformIO Version (platformio --version): 6.0.2a2

Description of problem

The PlatformIO core does not extract -D<macro> definitions from CCFLAGS into the e.g. VSCode Intellisense c_cpp_properties.json. Only macros in CPPDEFINES are.

Steps to Reproduce

  1. Create a new Nodemcuv2 + Arduino (ESP8266) project
  2. Add a call to tzset(); in setup()

Actual Results

Intellisense does not know about this function and highlights it as error.

Expected Results

Intellisense knows about this function since Arduino.h is included which includes time.h which says

#if __POSIX_VISIBLE
void      tzset     (void);
#endif

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino

Source file to reproduce issue:

#include <Arduino.h>
#include <string.h>
#include <string>

void setup() {}
void loop()
{
    const char *s = "test";
    char buf[64];
    strlcpy(buf, s, sizeof(buf));

    setenv("TZ", "CST-8", 1);
    tzset();

    int res = strcasecmp("A", "a");
}

Additional info

Intellisense does not recognize tzset() because that needs the _GNU_SOURCE to be defined (which through a specific chain enables POSIX_VISIBLE). The Arduino-ESP8266 build process activates that macro through CCFLAGS here and it correctly shows up in the build commands. However, the .vscode/c_cpp_properties.json does not have _GNU_SOURCE in the defines section because -D flags in CCFLAGS is not considered during the generation of this file.

I considered this fixing this by moving -D flags from CCFLAGS to CPPDEFINES, but this is then specific to Arduino-ESP8266. I think in general it would be good if the core is able to recognize this situation and relays the activated macros to the IDEs correctly. (See https://github.com/esp8266/Arduino/pull/8579).

Also see community topic here and here.

ivankravets commented 2 years ago

Thanks for the report! We need to fix a build script and put macro to the right scope.

Regarding CCFLAGS. I remember we had a problem with VSCode's C/C++ plugin if we pass GCC flags. So, we don't pass all compiler flags. The only flags related to the C/C++ preprocessed are passed.

maxgerhardt commented 2 years ago

So, we don't pass all compiler flags. The only flags related to the C/C++ preprocessed are passed.

But how about transforming known -D.. flags and putting them in the defines section of the c_cpp_properties.json? They don't have to be in the compiler arguments section. This fix would be more general and no build script adaptions needed.

ivankravets commented 2 years ago

An integrator decides on which scopes to put flags. We don't do any manipulation with flags. The correct solution is https://github.com/esp8266/Arduino/commit/c1144c5740406693808e92f072872260c7f069a0 because it also fixes ASM builds.

Thanks for the PR!