Skip to content

"Auto import" of superfluous transitive dependencies can cause spurious compilation failure #3085

@KurtE

Description

@KurtE

Describe the problem

A library may specify dependencies on other libraries. These specified dependencies may fall into any one of the following categories:

  • Universal: Referenced via an #include directive always processed when compiling the library.
  • Conditional: Referenced via a conditional #include directive (e.g., only when compiling for specific boards), or only via an optional application-specific header file.
  • Example: Referenced via one of the library's example sketches, but not by the library itself.

Library dependencies may be added to a build profile via the ProfileLibAdd method of the gRPC interface. When the add_dependencies field of the request message is set to true, additional entries are added to the build profile for the list of dependencies specified by the added library.

When a build profile is used, all specified library dependencies are compiled (without regards to whether they are referenced by the sketch program) for the sake of efficiency (#2951). This behavior is referred to as "auto import".

🐛 This behavior results in a spurious compilation failure under the following conditions:

  • A build profile is used to compile the sketch
  • A library was added to the build profile via the ProfileLibAdd method, with the add_dependencies field of the request message set to true
  • That library specifies a dependency on a library that is incompatible with the build (e.g., incompatible with the selected board)

To reproduce

Setup

Create test sketch
$ arduino-cli version

arduino-cli  Version: 1.4.1 Commit: e39419312 Date: 2026-01-25T02:01:36Z

$ mkdir /tmp/FooSketch

$ echo '#include <Arduino_ConnectionHandler.h>
void setup() {}
void loop() {}
' > /tmp/FooSketch/FooSketch.ino
Verify test sketch

This procedure is performed to demonstrate that the sketch will compile successfully when not subjected to the fault reported here.

$ arduino-cli core install arduino:renesas_uno

[...]

$ arduino-cli lib install Arduino_ConnectionHandler

[...]

$ arduino-cli compile --fqbn arduino:renesas_uno:unor4wifi /tmp/FooSketch

Sketch uses 52164 bytes (19%) of program storage space. Maximum is 262144 bytes.
Global variables use 7532 bytes (22%) of dynamic memory, leaving 25236 bytes for local variables. Maximum is 32768 bytes.

🙂 The sketch compiled successfully.

Start daemon
$ arduino-cli daemon

Daemon is now listening on 127.0.0.1:50051
{"IP":"127.0.0.1","Port":"50051"}

Demo

Run the following Buf CLI commands in another terminal:

$ buf curl \
  --http2-prior-knowledge \
  --protocol grpc \
  --schema ./rpc \
  http://localhost:50051/cc.arduino.cli.commands.v1.ArduinoCoreService/Create

{
  "instance": {
    "id": 1
  }
}

$ buf curl \
  --data '{"instance": {"id": 1}}' \
  --http2-prior-knowledge \
  --protocol grpc \
  --schema ./rpc \
  http://localhost:50051/cc.arduino.cli.commands.v1.ArduinoCoreService/Init

$ buf curl \
  --data '
    {
      "instance": {"id": 1},
      "sketch_path": "/tmp/FooSketch",
      "profile_name": "foo",
      "fqbn": "arduino:renesas_uno:unor4wifi"
    }
    ' \
  --http2-prior-knowledge \
  --protocol grpc \
  --schema ./rpc \
  http://localhost:50051/cc.arduino.cli.commands.v1.ArduinoCoreService/ProfileCreate

{}

$ buf curl \
  --data '
    {
      "instance": {"id": 1},
      "sketch_path": "/tmp/FooSketch",
      "profile_name": "foo",
      "library": {
        "index_library": {
          "name": "Arduino_ConnectionHandler",
          "version": "1.2.0"
        }
      },
      "add_dependencies": true
    }
    ' \
  --http2-prior-knowledge \
  --protocol grpc \
  --schema ./rpc \
  http://localhost:50051/cc.arduino.cli.commands.v1.ArduinoCoreService/ProfileLibAdd

{
  "addedLibraries": [
    {
      "indexLibrary": {
        "name": "Arduino_ConnectionHandler",
        "version": "1.2.0"
      }
    },
    {
      "indexLibrary": {
        "name": "Arduino_DebugUtils",
        "version": "1.5.0",
        "isDependency": true
      }
    },
    {
      "indexLibrary": {
        "name": "Blues Wireless Notecard",
        "version": "1.8.2",
        "isDependency": true
      }
    },
    {
      "indexLibrary": {
        "name": "MKRGSM",
        "version": "1.5.0",
        "isDependency": true
      }
    },
    {
      "indexLibrary": {
        "name": "MKRNB",
        "version": "1.6.0",
        "isDependency": true
      }
    },
    {
      "indexLibrary": {
        "name": "MKRWAN",
        "version": "1.1.2",
        "isDependency": true
      }
    },
    {
      "indexLibrary": {
        "name": "WiFi101",
        "version": "0.16.1",
        "isDependency": true
      }
    },
    {
      "indexLibrary": {
        "name": "WiFiNINA",
        "version": "1.9.1",
        "isDependency": true
      }
    }
  ],
  "profileName": "foo"
}

$ arduino-cli compile --profile foo /tmp/FooSketch

[...]

C:\Users\per\AppData\Local\Arduino15\internal\MKRGSM_1.5.0_d33f27a4fbc69700\MKRGSM\src\Modem.cpp:360:49: error: 'GSM_DTR' was not declared in this scope
 ModemClass MODEM(SerialGSM, 921600, GSM_RESETN, GSM_DTR);
                                                 ^~~~~~~

Used library              Version Path
Arduino_ConnectionHandler 1.2.0   C:\Users\per\AppData\Local\Arduino15\internal\Arduino_ConnectionHandler_1.2.0_3cd25ee389abd563\Arduino_ConnectionHandler
Arduino_DebugUtils        1.5.0   C:\Users\per\AppData\Local\Arduino15\internal\Arduino_DebugUtils_1.5.0_0cbc35381b30f4f0\Arduino_DebugUtils
Blues Wireless Notecard   1.8.2   C:\Users\per\AppData\Local\Arduino15\internal\Blues_Wireless_Notecard_1.8.2_1a68120f44eafc2d\Blues Wireless Notecard
MKRGSM                    1.5.0   C:\Users\per\AppData\Local\Arduino15\internal\MKRGSM_1.5.0_d33f27a4fbc69700\MKRGSM
MKRNB                     1.6.0   C:\Users\per\AppData\Local\Arduino15\internal\MKRNB_1.6.0_f15be8bfba7f756a\MKRNB
MKRWAN                    1.1.2   C:\Users\per\AppData\Local\Arduino15\internal\MKRWAN_1.1.2_3f262be4959c4869\MKRWAN
WiFi101                   0.16.1  C:\Users\per\AppData\Local\Arduino15\internal\WiFi101_0.16.1_0a99f7d11ea09f08\WiFi101
WiFiNINA                  1.9.1   C:\Users\per\AppData\Local\Arduino15\internal\WiFiNINA_1.9.1_7cc9ca1b1de1ea6a\WiFiNINA
Wire                              C:\Users\per\AppData\Local\Arduino15\internal\arduino_renesas_uno_1.5.2_13accb25d0a9f684\libraries\Wire
SPI                               C:\Users\per\AppData\Local\Arduino15\internal\arduino_renesas_uno_1.5.2_13accb25d0a9f684\libraries\SPI

Used platform       Version Path
arduino:renesas_uno 1.5.2   C:\Users\per\AppData\Local\Arduino15\internal\arduino_renesas_uno_1.5.2_13accb25d0a9f684
Error during build: exit status 1

🐛 Compilation failed spuriously due to incompatible libraries such as "MKRGSM" being compiled, even though the sketch has no dependency on that library.

Expected behavior

Exclude the libraries specified via a dependency key of a build profile libraries element from auto import.

Arduino CLI version

e394193

Operating system

All

Operating system version

Any

Additional context

The conditions for this fault may occur when using Arduino App Lab:


Related discussion, and an example of the fault occurring in a real world application:

https://forum.arduino.cc/t/sketch-using-adafruit-ft6206-h-and-adafruit-st77xx-library-builds-with-ide-fails-with-app-lab/1426553

Additional reports

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: build-processRelated to the sketch build processtopic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions