Skip to content

Bundled libraries of other platforms are discoverable #1740

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
3 tasks done
per1234 opened this issue May 29, 2022 · 0 comments · Fixed by #1741
Closed
3 tasks done

Bundled libraries of other platforms are discoverable #1740

per1234 opened this issue May 29, 2022 · 0 comments · Fixed by #1741
Assignees
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented May 29, 2022

Describe the problem

The Arduino boards platform system supports bundling of libraries. These libraries are typically specific to the platform's architecture, often variants of fundamental libraries which are standardized infrastructure of each plaform (e.g., "SPI", "Wire").

For this reason, these libraries must only be discoverable when compiling for a board of that platform or its core dependents.

🐛 Bundled libraries of all installed platforms are discoverable during compilation for any board.

To reproduce

$ ./arduino-cli version
arduino-cli.exe  Version: git-snapshot Commit: f0245bc2 Date: 2022-05-29T10:31:11Z

$ ./arduino-cli core install arduino:avr arduino:samd
[...]

$ mkdir /tmp/FooSketch

$ echo "#include <SAMD_BootloaderUpdater.h>
> void setup () {}
> void loop () {}
> " > /tmp/FooSketch/FooSketch.ino

$ ./arduino-cli compile --fqbn arduino:avr:uno /tmp/FooSketch/
WARNING: library SAMD_BootloaderUpdater claims to run on samd_beta architecture(s) and may be incompatible with your current board which runs on avr architecture(s).
E:\deleteme\arduino-cli\directories\data\packages\arduino\hardware\samd\1.8.13\libraries\SAMD_BootloaderUpdater\src\SAMD_BootloaderUpdater.cpp:32:4: error: #error "Unsupported board!"
   #error "Unsupported board!"
    ^~~~~
E:\deleteme\arduino-cli\directories\data\packages\arduino\hardware\samd\1.8.13\libraries\SAMD_BootloaderUpdater\src\SAMD_BootloaderUpdater.cpp: In function 'void eraseFlash(uint32_t, int)':
E:\deleteme\arduino-cli\directories\data\packages\arduino\hardware\samd\1.8.13\libraries\SAMD_BootloaderUpdater\src\SAMD_BootloaderUpdater.cpp:47:7: error: 'NVMCTRL' was not declared in this scope
       NVMCTRL->ADDR.reg = ((uint32_t)((uint32_t)address + i)) / 2;
       ^~~~~~~
E:\deleteme\arduino-cli\directories\data\packages\arduino\hardware\samd\1.8.13\libraries\SAMD_BootloaderUpdater\src\SAMD_BootloaderUpdater.cpp:48:28: error: 'NVMCTRL_CTRLA_CMDEX_KEY' was not declared in this scope
       NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_ER;
                            ^~~~~~~~~~~~~~~~~~~~~~~
E:\deleteme\arduino-cli\directories\data\packages\arduino\hardware\samd\1.8.13\libraries\SAMD_BootloaderUpdater\src\SAMD_BootloaderUpdater.cpp:48:54: error: 'NVMCTRL_CTRLA_CMD_ER' was not declared in this scope
       NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_ER;
                                                      ^~~~~~~~~~~~~~~~~~~~
E:\deleteme\arduino-cli\directories\data\packages\arduino\hardware\samd\1.8.13\libraries\SAMD_BootloaderUpdater\src\SAMD_BootloaderUpdater.cpp: In function 'void writeFlash(uint32_t, const void*, int)':
E:\deleteme\arduino-cli\directories\data\packages\arduino\hardware\samd\1.8.13\libraries\SAMD_BootloaderUpdater\src\SAMD_BootloaderUpdater.cpp:69:15: error: 'NVMCTRL' was not declared in this scope
       while (!NVMCTRL->INTFLAG.bit.READY);
               ^~~~~~~
E:\deleteme\arduino-cli\directories\data\packages\arduino\hardware\samd\1.8.13\libraries\SAMD_BootloaderUpdater\src\SAMD_BootloaderUpdater.cpp: In member function 'int SAMD_BootloaderUpdaterClass::update(void 
(*)(float))':
E:\deleteme\arduino-cli\directories\data\packages\arduino\hardware\samd\1.8.13\libraries\SAMD_BootloaderUpdater\src\SAMD_BootloaderUpdater.cpp:82:3: error: 'NVMCTRL' was not declared in this scope
   NVMCTRL->CTRLB.bit.MANW = 0;
   ^~~~~~~


Error during build: exit status 1

🐛 The "SAMD_BootloaderUpdater" library of the arduino:samd platform was discovered while compiling for a board of the arduino:avr platform.

Expected behavior

Platform bundled libraries are discoverable only when compiling for a board of that platform or of a platform which references its core.

In the contrived demo above, the compilation was expected to fail, but with a different error:

$ arduino-cli version
arduino-cli.exe  Version: git-snapshot Commit: 7e9e4cac Date: 2022-05-29T10:33:38Z

$ ./arduino-cli compile --fqbn arduino:avr:uno /tmp/FooSketch/
C:\Users\per\AppData\Local\Temp\FooSketch\FooSketch.ino:1:10: fatal error: SAMD_BootloaderUpdater.h: No such file or directory
 #include <SAMD_BootloaderUpdater.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.


Error during build: exit status 1

Arduino CLI version

f0245bc

Operating system

Windows

Operating system version

10

Additional context

I bisected the bug to f0245bc (it does not occur at the previous commit 7e9e4ca)


The more significant (but less suitable for a simple demo) manifestations of the bug result from compiling a sketch that is valid for the target platform which uses one of the common platform bundled libraries such as "Wire". In this case the bug may manifest, at best, as a compilation error cryptic to the target user, at worst, as a subtle runtime fault or degradation.

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details
@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels May 29, 2022
cmaglie added a commit to cmaglie/arduino-cli that referenced this issue May 30, 2022
cmaglie added a commit that referenced this issue May 31, 2022
* Fixed libraries-set selection for discovery

Fix #1740

* removed useless variable

* Added tests

* Updated readme
@per1234 per1234 added the conclusion: resolved Issue was resolved label May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants