platformio / platform-atmelsam

Atmel SAM: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelsam
Apache License 2.0
78 stars 105 forks source link

Zephyr Menuconfig vs prj.conf: Multiple ways to build same target were specified #153

Open liquiddandruff opened 3 years ago

liquiddandruff commented 3 years ago

What kind of issue is this?

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


Configuration

Operating system: Win10 x64

PlatformIO Version (platformio --version): PlatformIO Core, version 5.1.0

Device: Adafruit Feather M0 RFM95

Description of problem

Running Zephyr's Menuconfig from the PlatformIO Tasks->adafruit_feather_m0->Platform->Run Menuconfig and enabling LORA and SX1276 device generates a final .config in <project_root>\.pio\build\adafruit_feather_m0\zephyr\.config that builds successfully.

However this is not ideal since modifications done through Menuconfig cannot be easily tracked in .git.

Luckily Zephyr build system supports a prj.conf in <project_root>\zephyr\prj.conf that gets merged with the board provided defaults.

Diffing before and after the Menuconfig modifications (and removing some options that are not supposed to be set manually) produce the following changes:

CONFIG_HAS_SEMTECH_LORAMAC=y
# CONFIG_HAS_SEMTECH_SOFT_SE is not set
CONFIG_HAS_SEMTECH_RADIO_DRIVERS=y

CONFIG_LORA=y
CONFIG_LORA_INIT_PRIORITY=90
CONFIG_LORA_SX12XX=y
CONFIG_LORA_SX1276=y

However adding the above to prj.conf and performing a PIO build causes PIO's custom build logic to fail with:

*** Multiple ways to build the same target were specified for: C:\Users\steven\projects\stofl-trailer\.pio\build\adafruit_feather_m0\loramac-node\zephyr\drivers\lora\sx1276.c.o  (from ['C:\\Users\\steven\\.platformio\\packages\\framework-zephyr\\drivers\\lora\\sx1276.c'] and from ['C:\\Users\\steven\\.platformio\\packages\\framework-zephyr-loramac-node\\src\\radio\\sx1276\\sx1276.c'])
File "C:\Users\steven\.platformio\packages\framework-zephyr\scripts\platformio\platformio-build.py", line 665, in compile_source_files

This might be due to compile_source_files being confused because they have the same file names, but it is correct (framework-zephyr\\drivers\\lora\\sx1276.c depends on the actual implementation defined in framework-zephyr-loramac-node\\src\\radio\\sx1276\\sx1276.c)

There should be no difference after merging since the final .config as generated by Zephyr's Menuconfig builds successfully, but we seem to not be able to get to that point due to possibly erroneous target generation/dependency/name clash in compile_source_files.

Steps to Reproduce

  1. Create new PIO project with provided platformio.ini
  2. Perform a fresh build, it should work
  3. Copy <project_root>\.pio\build\adafruit_feather_m0\zephyr\.config somewhere as clean.config
  4. Run the Menuconfig. Press (j/k) to navigate up/down and toggle everything up to: image
  5. Perform a build, it should work
  6. Copy <project_root>\.pio\build\adafruit_feather_m0\zephyr\.config somewhere as lora.config
  7. Now diff clean.config and lora.config, the relevant changes are as illustrated above.
  8. Now add the diff contents to new file <project_root>\zephyr\prj.conf
  9. Try to do a build and you'll get the error illustrated above.

Actual Results

When specifying the same configs generated by Menuconfig in prj.conf, attempting to build returns multiple targets error.

Expected Results

Should build successfully when the same configurations that would have been generated by Menuconfig are included in prj.conf.

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:adafruit_feather_m0]
platform = atmelsam
board = adafruit_feather_m0
framework = zephyr
liquiddandruff commented 3 years ago

The fix is as suspected, rename the .c and edit the CMakeLists.txt to work around compile_source_files for the build to progress.

1) rename

cd %HOMEPATH%\.platformio\packages\framework-zephyr-loramac-node\src\radio\sx1276
mv sx1276.c radio_sx1276.c

2) edit cmakelists.txt vim %HOMEPATH%\.platformio\packages\framework-zephyr-loramac-node\zephyr\CMakeLists.txt

- zephyr_library_sources_ifdef(CONFIG_HAS_SEMTECH_SX1276 ../src/radio/sx1276/sx1276.c)
+ zephyr_library_sources_ifdef(CONFIG_HAS_SEMTECH_SX1276 ../src/radio/sx1276/radio_sx1276.c)

After above changes, enabling the LoRa in the prj.conf builds successfully.