I’m trying to develop a library, and I am using platform.io core to do my development. I can easily make sketches, and define their dependencies, and I’ve seen the documentation on library.json. What I’m missing is a howto on building the library during development.
I want to make my library similar to how it would be published. Something with a src/ examples/ and library files. I want to work on the examples, and have their dependencies all worked out, and I want to kick off the builds of the examples and occasionally upload them to the target platform (esp32).
Am I missing this information in the documentation somewhere?
Rather than start a new topic, I thought I’d revive this old thread to propose an alternative strategy for library development in case anyone else happens to be searching through the forum for a solution to this problem. The challenge I struggled with was building an example project within a local PlatformIO library without any special platformio.ini settings.
While developing a library, I formed a working project in a fashion similar to that described in @ivankravets response. However, when I changed the structure of my library to make it compatible with the Library Manager, it became incompatible with the lib_extra_dirs approach because the directory structures are different; my source was now in a src subdirectory, not in the root of a directory named for the library as required by lib_extra_dirs.
I found the simplest solution to be the following. Unfortunately, this will only work on a Linux OS:
In the pio global storage directory, create a symlink to the library directory named for the library. In my case, something like this: ln -s "/home/user/repository/library_directory/" /home/user/.platformio/lib/CustomLibraryName
Add the library dependency to the project environment: lib_deps = CustomLibraryName
Changes to the library source code will immediately be available during PlatformIO build and allow rapid library development. The example can be easily modified and kept up to date during development. Be careful not to accidentally install or update an older version of your library from the Library Manager server; this will happen if you run a library update and don’t have version set in library.json.
I apologize if this is an obvious solution, but I didn’t encounter any such strategy in the documentation or in this forum and thought it might benefit any others trying to develop publicly available libraries. If there is a better solution for development of a library using its example sketches, I’d love to hear it!
I tried to fake the src directory but didn’t have success. I assumed that was because I didn’t have all source files in sub directories, but I was simultaneously dealing with linker issues, so I’m not sure.
It seems like you could organize the library source in such a way that adding the src directory to lib_extra_dirs and then specify a source filter in library.json so that the project builds successfully both ways, but that would still require a change to platform.ini. I’m lazy and forgetful, so I like not having to modify the example depending on whether I’m developing the library or pushing a new release version.