Skip to content

Export CCFLAGS macros to IntelliSense #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
maxgerhardt opened this issue May 22, 2022 · 3 comments
Closed
1 task done

Export CCFLAGS macros to IntelliSense #275

maxgerhardt opened this issue May 22, 2022 · 3 comments

Comments

@maxgerhardt
Copy link

maxgerhardt commented May 22, 2022

What kind of issue is this?

  • PlatformIO Core.
    If you’ve found a bug, please provide an information below.

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 esp8266/Arduino#8579).

Also see community topic here and here.

@ivankravets ivankravets transferred this issue from platformio/platformio-core May 22, 2022
@ivankravets
Copy link
Member

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
Copy link
Author

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
Copy link
Member

An integrator decides on which scopes to put flags. We don't do any manipulation with flags. The correct solution is esp8266/Arduino@c1144c5 because it also fixes ASM builds.

Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants