Skip to content

extra_script global defines not working #5146

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

Open
Levi--G opened this issue May 4, 2025 · 2 comments
Open

extra_script global defines not working #5146

Levi--G opened this issue May 4, 2025 · 2 comments
Milestone

Comments

@Levi--G
Copy link

Levi--G commented May 4, 2025

I am trying to add a global define to a project build extrascript like this:

global_env = DefaultEnvironment()
global_env.Append(CPPDEFINES=[("USBCON", 1),("HAL_PCD_MODULE_ENABLED",1),'USBCON'])
global_env.Append(CCFLAGS=["-D USBCON"])
print("<<<<<GLOBAL ENV DEFINES>>>>>")
print(global_env.get('CPPDEFINES'))
print("<<<<<GLOBAL ENV FLAGS>>>>>")
print(global_env.get('CCFLAGS'))

as per the example here: https://docs.platformio.org/en/latest/manifests/library-json/fields/build/extrascript.html

But defines and flags are not added, if i verbose build they are present in the log, but not present in the build command, build output:

CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F401CD.html
PLATFORM: ST STM32 (19.1.0) > STM32F401CD (96k RAM. 384k Flash)
HARDWARE: STM32F401CDU6 84MHz, 96KB RAM, 384KB Flash
DEBUG: Current (stlink) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 @ 4.21001.0 (2.10.1)
 - framework-cmsis @ 2.50900.0 (5.9.0)
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
<<<<<GLOBAL ENV DEFINES>>>>>
deque([('PLATFORMIO', 60118), 'STM32F4', 'STM32F401xE', 'STM32F4xx', ('USBD_VID', '0x05f3'), ('USBD_PID', '0x00D2'), ('USB_MANUFACTURER_STRING', 'STR(RailDriver)'), ('USB_PRODUCT_STRING', 'STR(RailDriver)'), 'STM32F4xx', ('ARDUINO', 10808), 'ARDUINO_ARCH_STM32', 'NDEBUG', 'ARDUINO_GENERIC_F401CDUX', ('BOARD_NAME', '\\"GENERIC_F401CDUX\\"'), 'HAL_UART_MODULE_ENABLED', 'USE_HAL_DRIVER', 'USE_FULL_LL_DRIVER', ('VARIANT_H', '\\"variant_generic.h\\"'), ('VECT_TAB_OFFSET', '0x0'), ('USBCON', 1), ('HAL_PCD_MODULE_ENABLED', 1), 'USBCON'])
<<<<<GLOBAL ENV FLAGS>>>>>
-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Os -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -D USBCON
Found 15 compatible libraries
Scanning dependencies...
Dependency Graph
|-- USBLibrarySTM32 @ 0.3.0 (License: LGPL-3.0-or-later, Path: D:\Source\GitHub\USBLibrarySTM32\examples\SerialUSB\.pio\libdeps\bluepill_f401\USBLibrarySTM32)
Building in release mode
arm-none-eabi-g++ -o .pio\build\bluepill_f401\src\main.cpp.o -c -std=gnu++17 -fno-threadsafe-statics -fno-rtti -fno-exceptions -fno-use-cxa-atexit -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Os -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -DPLATFORMIO=60118 -DSTM32F4 -DSTM32F401xE -DSTM32F4xx -DUSBD_VID=0x05f3 -DUSBD_PID=0x00D2 -DUSB_MANUFACTURER_STRING=STR(RailDriver) -DUSB_PRODUCT_STRING=STR(RailDriver) -DSTM32F4xx -DARDUINO=10808 -DARDUINO_ARCH_STM32 -DNDEBUG -DARDUINO_GENERIC_F401CDUX -DBOARD_NAME=\"GENERIC_F401CDUX\" -DHAL_UART_MODULE_ENABLED -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -DVARIANT_H=\"variant_generic.h\" -DVECT_TAB_OFFSET=0x0 -Iinclude -Isrc -I.pio\libdeps\bluepill_f401\USBLibrarySTM32\include -I.pio\libdeps\bluepill_f401\USBLibrarySTM32\src -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\cores\arduino\avr -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\cores\arduino\stm32 -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\libraries\SrcWrapper\inc -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\libraries\SrcWrapper\inc\LL -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\libraries\USBDevice\inc -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\libraries\VirtIO\inc -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Drivers\STM32F4xx_HAL_Driver\Inc -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Drivers\STM32F4xx_HAL_Driver\Src -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\STM32F4xx -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\ST\STM32_USB_Device_Library\Core\Inc -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\ST\STM32_USB_Device_Library\Core\Src -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\OpenAMP -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\OpenAMP\open-amp\lib\include -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\OpenAMP\libmetal\lib\include -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Middlewares\OpenAMP\virtual_driver -IC:\Users\Levi\.platformio\packages\framework-cmsis\CMSIS\Core\Include -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Drivers\CMSIS\Device\ST\STM32F4xx\Include -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\system\Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\gcc -IC:\Users\Levi\.platformio\packages\framework-cmsis\CMSIS\DSP\Include -IC:\Users\Levi\.platformio\packages\framework-cmsis\CMSIS\DSP\PrivateInclude -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\cores\arduino -IC:\Users\Levi\.platformio\packages\framework-arduinoststm32\variants\STM32F4xx\F401CC(F-U-Y)_F401C(B-D-E)(U-Y) src\main.cpp
(then the build fails cause the defines are missing)

Am i missing something? I followed the example almost literally but neither the flags or the defines are showing up?

@ivankravets
Copy link
Member

You have you use PRE action https://docs.platformio.org/en/latest/scripting/actions.html

@Levi--G
Copy link
Author

Levi--G commented May 18, 2025

@ivankravets

Adding pre: to the build script name just yields this error:

*** missing SConscript file '.pio\\libdeps\\bluepill\\USBLibrarySTM32\\pre:pio_script\\build_flags.py'

I even tried using the hooks before and that also has no influence at all.

Plus:

This would also mean that the example i linked is wrong, since it also doesn't use pre actions and also sets global build options, from the example i linked https://docs.platformio.org/en/latest/manifests/library-json/fields/build/extrascript.html:

{
    "name": "SomeLib",
    "version": "0.0.0",
    "build": {
        "extraScript": "extra_script.py" //no pre here
    }
}

Adds defines without any callback:

global_env = DefaultEnvironment()
global_env.Append(CPPDEFINES=[("TEST_GLOBAL", 1)])

Please reopen, at least until the examples are fixed then because i can't get the example/actions to work.

@ivankravets ivankravets added this to the 6.1.19 milestone May 18, 2025
@ivankravets ivankravets reopened this May 18, 2025
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

No branches or pull requests

2 participants