TinyUSB Library confusion

I have this

[env:m0]
platform = atmelsam
board = adafruit_feather_m0_express
framework = arduino
build_flags =
	-std=gnu++17
	-D__SAMD21G18A__
	-DADAFRUIT_FEATHER_M0
	-DADAFRUIT_FEATHER_M0_EXPRESS
	-DARDUINO_SAMD_ZERO
	-DARM_MATH_CM0PLUS
	-D USE_TINYUSB
	-D SH110X_NO_SPLASH
lib_deps =
	adafruit/Adafruit DAP library@^1.8.3
	adafruit/Adafruit SleepyDog Library@^1.8.4
	adafruit/Adafruit SSD1306@^2.5.17

When I build this project, it seems to pull in a local version of TinyUSB For example:

Dependency Graph
|-- Adafruit DAP library @ 1.8.3 (License: Unknown, Path: /Users/mark/Projects/multi-flash/.pio/libdeps/m0/Adafruit DAP library)
|   |-- Adafruit TinyUSB Library @ 3.7.7 (License: Unknown, Path: /Users/mark/Projects/multi-flash/.pio/libdeps/m0/Adafruit TinyUSB Library)
|   |   |-- SdFat - Adafruit Fork @ 2.3.103 (License: MIT, Path: /Users/mark/Projects/multi-flash/.pio/libdeps/m0/SdFat - Adafruit Fork)

But that library is already included in the framework, and when compiled, things get confused because there are two sets of include files:

.pio/libdeps/m0/Adafruit TinyUSB Library/src/common/tusb_common.h:197:45:
error: redefinition of 'uint8_t tu_u16_low(uint16_t)'
  197 | TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_low (uint16_t ui16) { return TU_U16_LOW(ui16); }
      |                                             ^~~~~~~~~~

/Users/mark/.platformio/packages/framework-arduino-samd-adafruit/libraries/Adafruit_TinyUSB_Arduino/src/arduino/../common/tusb_common.h:141:45:
note: 'uint8_t tu_u16_low(uint16_t)' previously defined here
  141 | TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_low (uint16_t ui16) { return TU_U16_LOW(ui16); }
      |                                             ^~~~~~~~~~

How do I keep the library manager from trying to include a second copy of the library?

Temporary fix: Explicitly name the same version of TinyUSB as the one included in the platform already:

lib_deps =
	adafruit/Adafruit TinyUSB Library@3.1.0
	adafruit/Adafruit DAP library@^1.8.3
	adafruit/Adafruit SleepyDog Library@^1.8.4
	adafruit/Adafruit SSD1306@^2.5.17

This isn’t great: It is still download and locally installing a copy of that library in the project’s .pio directory, rather than using the one that is in the platform already.

This is a general library resolution problem with the PlatformIO core. It reads the library’s library.properties as

and blindly looks up Adafruit TinyUSB Library to install it from the registry. Doesn’t look into core at library install-time apparently.

I think if you wanted it to use the TinyUSB library from the core, it would have to be something like

lib_deps =
	Adafruit TinyUSB Library=${platformio.packages_dir}/framework-arduino-samd-adafruit/libraries/Adafruit TinyUSB Library
	adafruit/Adafruit DAP library@^1.8.3
	adafruit/Adafruit SleepyDog Library@^1.8.4
	adafruit/Adafruit SSD1306@^2.5.17