Skip to content
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

Allow post scripts in library.json #4305

Closed
1 task done
maxgerhardt opened this issue Jun 6, 2022 · 6 comments
Closed
1 task done

Allow post scripts in library.json #4305

maxgerhardt opened this issue Jun 6, 2022 · 6 comments
Labels
build system docs feature ldf Library Dependency Finder
Milestone

Comments

@maxgerhardt
Copy link
Contributor

maxgerhardt commented Jun 6, 2022

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

-/-

@ivankravets ivankravets added ldf Library Dependency Finder build system feature help wanted and removed feature labels Jun 10, 2022
@ivankravets ivankravets added this to the 6.0.3 milestone Jun 10, 2022
@ivankravets
Copy link
Member

ivankravets commented Jun 16, 2022

Thanks for the report! Could you re-test with pio upgrade --dev?

Example in docs https://docs.platformio.org/en/latest/manifests/library-json/fields/build/extrascript.html

@cziter15
Copy link

cziter15 commented Jun 16, 2022

Looks like projenv access feature is working as expected :)

@cziter15
Copy link

cziter15 commented Jun 16, 2022

After digging some more in projects it doesn't look as good. Don't really know what's wrong, but using ProcessUnFlags (-f-nortti) gives unexpected linker errors in some projects. Using board_build.unflags in platformio.ini does not bring these issues. More detais at https://community.platformio.org/t/force-rtti-from-library/28176

@cziter15
Copy link

cziter15 commented Jun 21, 2022

Just FYI - all problems have been resolved. Thanks!
https://community.platformio.org/t/force-rtti-from-library/28176

@mathemaphysics
Copy link

This doesn't work. It ignores me and builds e.g. libFS.a with no RTTI. I have no idea what is going on.

I have no control over this and typeinfo vanishes for things I need it for randomly.

@cziter15
Copy link

cziter15 commented Jul 6, 2024

@mathemaphysics see https://community.platformio.org/t/issue-with-defines-that-target-platform-module/41345/3
I've been thinking everything was okay with this issue, but it looks like platform env is not affected by these flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system docs feature ldf Library Dependency Finder
Projects
None yet
Development

No branches or pull requests

4 participants