feat: add USE_SYSTEM_DLIB option and fix typo in vendor message#21804
feat: add USE_SYSTEM_DLIB option and fix typo in vendor message#21804ashfak99 wants to merge 2 commits intonetdata:masterfrom
Conversation
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant User as Developer / Build Env
participant CMake as CMake Build System
participant OS as System Environment (libdlib-dev)
participant Fetch as FetchContent (Vendored dlib)
Note over User,Fetch: CMake Configuration Phase (ENABLE_ML=ON)
User->>CMake: Run cmake -DUSE_SYSTEM_DLIB=[ON|OFF]
alt NEW: USE_SYSTEM_DLIB is ON
CMake->>OS: find_package(dlib REQUIRED)
OS-->>CMake: dlib headers & libs found
Note right of CMake: NEW: Create 'dlib' ALIAS to 'dlib::dlib'
CMake->>CMake: add_library(dlib ALIAS dlib::dlib)
CMake-->>User: Status: "Using system-installed dlib"
else Default Path: USE_SYSTEM_DLIB is OFF
CMake->>Fetch: netdata_bundle_dlib()
Fetch->>Fetch: Download/Unpack source
Note right of Fetch: CHANGED: Fix status message typo ("dlib" vs "JSON-C")
Fetch-->>CMake: Internal 'dlib' target available
CMake-->>User: Status: "Finished preparing vendored copy of dlib"
end
Note over CMake: Linking Phase
CMake->>CMake: Link Netdata ML targets to 'dlib' target
Note over CMake: (Seamless linking regardless of source)
|
All CI checks have passed successfully. This PR is now ready for review. Looking forward to your feedback. |
Ferroin
left a comment
There was a problem hiding this comment.
Overall I’m personally in favor of this, but I would ideally like to get some input from @vkalintiris (the other person responsible for managing our build system code) and possibly @netdata/product (in theory this is an additional support burden for us).
In addition to the other comments on the changes, we ideally need to flag in the netdata -W buildinfo output whether or not dlib was vendored. That would involve adding a #cmakedefine to packaging/cmake/config.cmake.h.in for the new option and then updating src/daemon/buildinfo.c to include the feature information there. I would hold off on that specifically though until we get some confirmation that the rest of the stakeholders on our end are OK with adding this feature.
|
|
||
| if(ENABLE_ML) | ||
| netdata_bundle_dlib() | ||
| option(USE_SYSTEM_DLIB "Use system-installed dlib instead of downloading" OFF) |
There was a problem hiding this comment.
A few requests regarding handling of the option:
- Please define it up with the other options for vendoring of libraries (currently around line 170 of this file). We actively try to keep options together so that it’s easier to figure out what options are available from looking at the file itself.
- Please make this a
cmake_dependent_option()that depends onENABLE_ML. This ensures it gets correctly tracked as an option regardless of whether ML is enabled or not, but forced to be False if ML is not enabled. - Not sure if the rest of the team will agree on this, but I would personally prefer for this to be consistent with the rest of the options for optionally vendored libraries. This would mean an option name of
ENABLE_BUNDLED_DLIBdefaulting to true, and when true using the vendoring code path instead of a system copy.
Taken together that would all translate to removing this line, updating all the references to USE_SYSTEM_DLIB to NOT ENABLE_VENDORED_DLIB, and then adding the following up around line 170: cmake_dependent_option(ENABLE_VENDORED_DLIB "Use a vendored copy of Dlib" True ENABLE_ML False)
| if(USE_SYSTEM_DLIB) | ||
| find_package(dlib REQUIRED) | ||
| message(STATUS "Using system-installed dlib") | ||
|
|
||
| if(TARGET dlib::dlib AND NOT TARGET dlib) | ||
| add_library(dlib ALIAS dlib::dlib) | ||
| endif() | ||
| else() | ||
| netdata_bundle_dlib() | ||
| endif() |
There was a problem hiding this comment.
It would be preferred to push all of this logic into the NetdataDlib module, ideally in a similar manner to how we handle protobuf (IOW, define a function that encapsulates this logic which will be called here, and that function then calls out to netdata_bundle_dlib() if a vendored copy is being used).
I welcome this change. As long as |
|
Thank you @vkalintiris and @prologic for the feedback! I've noted the requirements. Since. I will update the PR with the following changes: Naming & Default: I'll rename the option to ENABLE_VENDORED_DLIB and set it to ON by default (so system dlib remains 'off' unless specified). Organization: I'll move the definition to around line 170 using cmake_dependent_option() to keep it consistent with other vendored library options. Modularity: I will encapsulate this logic into a function within the NetdataDlib module (similar to the Protobuf implementation) and call it from the main CMakeLists.txt. I'll push the updated commits shortly. |
This PR introduces a new CMake option, USE_SYSTEM_DLIB (default OFF), which allows developers and package maintainers to use a pre-installed system dlib library instead of vendoring/downloading it during the build process.
Design Decisions:
Added find_package(dlib REQUIRED) conditionally based on the USE_SYSTEM_DLIB flag in the main CMakeLists.txt.
Created an alias add_library(dlib ALIAS dlib::dlib) to ensure seamless linking with the rest of the Netdata codebase if the system package is utilized.
Retained the existing netdata_bundle_dlib() behavior when the option is OFF to ensure backward compatibility and avoid breaking existing build setups.
Minor Fix: Corrected a copy-paste typo in NetdataDlib.cmake where the vendoring status message incorrectly referenced "JSON-C" instead of "dlib".
Fixes #20147 Test Plan
Relying on the repository's robust CI/CD pipeline (GitHub Actions) to verify that the default build (vendored dlib) continues to compile successfully across all supported environments.
Manual verification (if testing locally): Run cmake -S . -B build -DENABLE_ML=ON -DUSE_SYSTEM_DLIB=ON on a system with dlib pre-installed to ensure find_package correctly locates and configures the system library.
Additional Information
This change addresses the feature request to avoid redundant downloads of dlib during the CMake build phase. It provides a standard "opt-in" approach widely used in C++ projects to prefer externally installed libraries.
For users: How does this change affect me?
Which area of Netdata is affected by the change? The CMake build system, specifically when compiling Machine Learning (ML) features.
Can they see the change or is it under the hood? It is strictly an under-the-hood change for developers and package maintainers building Netdata from source.
How is the user impacted by the change? Users building from source can now pass the -DUSE_SYSTEM_DLIB=ON flag to CMake. Standard end-users downloading pre-compiled binaries will not see any difference.
What are the benefits of the change? Faster build times, reuse of existing system resources, bandwidth savings, and better alignment with Linux distribution packaging guidelines (which generally prefer linking against system libraries over vendored dependencies).
Summary by cubic
Adds a CMake option USE_SYSTEM_DLIB (default OFF) to let builds use a system-installed dlib instead of a vendored copy. Fixes a typo in the dlib vendoring status message.
Written for commit b4230c4. Summary will update on new commits.