build: add Darwin/macOS support#872
Conversation
There was a problem hiding this comment.
Pull request overview
Adds build-system and portability adjustments to support building and running dlt-daemon/libdlt on Darwin/macOS, primarily by tweaking platform-linked libraries, compiler warning flags, and pthread API differences.
Changes:
- Adjusts CMake platform library selection for Darwin (no
rt, nosocket) in both library and test builds. - Updates thread naming to use the macOS
pthread_setname_np(const char*)signature. - Adds macOS-specific compile-warning suppressions and guards GCC-only warning flags.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| CMakeLists.txt | Guards GCC-only warning suppression and adds macOS warning suppressions under APPLE. |
| src/lib/CMakeLists.txt | Uses empty RT/SOCKET libraries on Darwin. |
| src/lib/dlt_user.c | Adapts pthread_setname_np usage for macOS and skips pthread_condattr_setclock on Apple. |
| tests/CMakeLists.txt | Uses empty extra libraries on Darwin for unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @felipek |
Adds platform handling for macOS: - Guard GCC-only -Wno-stringop-truncation behind a compiler check and silence Clang warnings promoted to errors by -Werror. Probe each Clang flag with check_c_compiler_flag() and only apply it when the compiler is Clang, so older Clang or a GCC build on macOS still works. - Wire up empty RT/SOCKET libraries and test libraries for Darwin. - Use the macOS pthread_setname_np signature (current thread only) and skip pthread_condattr_setclock(CLOCK_MONOTONIC), which is unavailable. On macOS pthread_cond_timedwait() always uses CLOCK_REALTIME, so the deadline timespec is built from CLOCK_REALTIME there as well to avoid premature timeouts or excessively long waits. - In dlt-daemon.c, scope the Linux-only fifo_size local behind __linux__ to silence an unused-variable warning on Darwin, and replace the broken "#elif __QNX__" with "#elif defined(__QNX__)" so the branch is selected by macro presence rather than its value. Signed-off-by: Felipe Kellermann <felipek@me.com>
Yes, done. Thanks! |
Adds platform handling for macOS: - Guard GCC-only -Wno-stringop-truncation behind a compiler check and silence Clang warnings promoted to errors by -Werror. Probe each Clang flag with check_c_compiler_flag() and only apply it when the compiler is Clang, so older Clang or a GCC build on macOS still works. - Wire up empty RT/SOCKET libraries and test libraries for Darwin. - Use the macOS pthread_setname_np signature (current thread only) and skip pthread_condattr_setclock(CLOCK_MONOTONIC), which is unavailable. On macOS pthread_cond_timedwait() always uses CLOCK_REALTIME, so the deadline timespec is built from CLOCK_REALTIME there as well to avoid premature timeouts or excessively long waits. - In dlt-daemon.c, scope the Linux-only fifo_size local behind __linux__ to silence an unused-variable warning on Darwin, and replace the broken "#elif __QNX__" with "#elif defined(__QNX__)" so the branch is selected by macro presence rather than its value. Signed-off-by: Felipe Kellermann <felipek@me.com>
891b5e3 to
0dbba26
Compare
minminlittleshrimp
left a comment
There was a problem hiding this comment.
Other lines is fine, except for the not-yet-covered clock set for APPLE
| } | ||
|
|
||
| clock_gettime(CLOCK_MONOTONIC, &now); | ||
| clock_gettime(DLT_COND_TIMEDWAIT_CLOCK, &now); |
There was a problem hiding this comment.
Hi @felipek
please rework on the APPLE bouding preprocessor here
| * even if we missed the signal | ||
| */ | ||
| clock_gettime(CLOCK_MONOTONIC, &now); | ||
| clock_gettime(DLT_COND_TIMEDWAIT_CLOCK, &now); |
|
Hello @alexmohr |
|
Hello @felipek |
|
The PR has a few conflicts with master, where I fixed already some build issues with darwin, hence this branch is currently not building on macos when using GCC. However, the goal of this PR is to enable building with clang, which is the default way for macos. Aside from a very minor question I posted mainly out of curiosity the change looks good to me. |
|
Hi @felipek |
|
Hi @alexmohr @minminlittleshrimp thanks, will close the PR and check if there is anything missing. |
Adds platform handling for Darwin/macOS:
silence Clang warnings promoted to errors by -Werror. Probe each
Clang flag with check_c_compiler_flag() and only apply it when the
compiler is Clang, so older Clang or a GCC build on macOS still works.
skip pthread_condattr_setclock(CLOCK_MONOTONIC), which is unavailable.
On macOS pthread_cond_timedwait() always uses CLOCK_REALTIME, so the
deadline timespec is built from CLOCK_REALTIME there as well to avoid
premature timeouts or excessively long waits.
__linux__to silence an unused-variable warning on Darwin, andreplace the broken
"#elif __QNX__"with"#elif defined(__QNX__)"so the branch is selected by macro presence rather than its value.
Signed-off-by: Felipe Kellermann felipek@me.com