Skip to content

Allow post scripts in library.json #4305

@maxgerhardt

Description

@maxgerhardt

What kind of issue is this?

  • Feature Request.
    Start by telling us what problem you’re trying to solve. Often a solution
    already exists! Don’t send pull requests to implement new features without first getting our
    support. Sometimes we leave features out on purpose to keep the project small.

Configuration

Operating system: Win10 x64

PlatformIO Version (platformio --version): 6.0.2

Description of problem

When writing a library, it sometimes is necessary to affect build settings of the projenv environment which is used to build the src/ folder. Such as in this example, where the inclusion of the library should cause all -fno-rtti flags to vanish.

This is only partially possible in the extraScript of a library. Using e.g. as script

Import("env")
global_env = DefaultEnvironment()
for e in (env, global_env):
    try:
        # key may or may not exist
        e['CXXFLAGS'].remove("-fno-rtti")
    except:
        pass
    e['CXXFLAGS'].append("-frtti")

leads to all -fno-rtti flags being removed in the library and framework compilation, but not for the files in src/. This is because the Arduino-ESP8266 adds them back in after it was executed, which the library build script cannot affect.

{
    "name": "MyLib",
    "version": "1.0.0",
    "build": {
        "unflags": "-fno-rtti"
    }
}

does not work either.

Of course, build_unflags = -fno-rtti can be set in the platformio.ini to counter this, but then the user has to do an extra step when including the library.

Another use case is e.g. this library where users are being told to add extra_script to their platformio.ini that points into the library, because the library.json has no mechanism for post and pre scripts.

lib_deps =
  https://github.com/likeablob/ulptool-pio

extra_scripts =
  pre:/$PROJECT_LIBDEPS_DIR/$PIOENV/ulptool-pio/pre_extra_script_ulptool.py
  post:/$PROJECT_LIBDEPS_DIR/$PIOENV/ulptool-pio/post_extra_script_ulptool.py

It would be nice to specify pre: and post: in the extraScripts field / array of the library.json to allow this better without user interaction.

Steps to Reproduce

  1. Download and open https://github.com/maxgerhardt/rtti-repro
  2. Inspect lib/MyLib/with_rtti.py
  3. Build project

Actual Results

Compilation failure, -fno-rtti not fully removed.

src\main.cpp: In function 'void setup()':
src\main.cpp:12:40: error: cannot use 'typeid' with '-fno-rtti'
   12 |     const std::type_info& ti1 = typeid(d);
      |                                        ^

Expected Results

Possibility to affect src/ compilation in extraScript, e.g. removing build flags added by later framework builder scripts.

If problems with PlatformIO Build System:

See linked project.

Additional info

-/-

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions