Skip to content

cmake: improve: configure proxyres_config.h for preprocessor conditions#129

Merged
sergio-nsk merged 1 commit into
masterfrom
sergey/cmake_configure_file/1
Mar 31, 2026
Merged

cmake: improve: configure proxyres_config.h for preprocessor conditions#129
sergio-nsk merged 1 commit into
masterfrom
sergey/cmake_configure_file/1

Conversation

@sergio-nsk
Copy link
Copy Markdown
Collaborator

@sergio-nsk sergio-nsk commented Mar 28, 2026

This will make possible future patches simpler: adding new lines rather than changing them (i.e. removing and adding).

Summary by CodeRabbit

  • Chores
    • Refactored build configuration to dynamically detect platform-specific system headers and conditionally include them based on availability, improving build reliability and cross-platform compatibility.

@sergio-nsk sergio-nsk requested review from Copilot and nmoinvaz March 28, 2026 03:24
@sergio-nsk sergio-nsk added the enhancement New feature or request label Mar 28, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 28, 2026

📝 Walkthrough

Walkthrough

The pull request introduces a build-time configuration system that detects system header availability via CMake, generating proxyres_config.h with feature-test macros. Multiple C source files are refactored to conditionally include netdb.h based on the HAVE_NETDB_H compile-time setting rather than platform-specific logic.

Changes

Cohort / File(s) Summary
CMake Configuration Setup
CMakeLists.txt, proxyres_config.h.in
Added build-time header detection via check_include_file() for net/if_arp.h and netdb.h, and configured CMake to generate proxyres_config.h from a template with #cmakedefine directives. Extended private include directories to search the binary directory for generated headers.
POSIX Source Files with Conditional Header Inclusion
fetch_posix.c, net_adapter_linux.c, net_adapter_mac.c, net_util.c, wpad_dhcp_posix.c, wpad_dns.c
Added #include "proxyres_config.h" and replaced unconditional or platform-based netdb.h includes with conditional inclusion guarded by #if HAVE_NETDB_H preprocessor directives, moving from platform-specific logic to feature-based detection.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A header dance in CMake's land,
Where features now are built by hand,
From config templates, detection flows,
Each platform gets what it most knows! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing CMake configuration of proxyres_config.h for preprocessor conditions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sergey/cmake_configure_file/1

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.83%. Comparing base (df114f1) to head (f582705).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #129      +/-   ##
==========================================
+ Coverage   58.57%   63.83%   +5.26%     
==========================================
  Files          32       34       +2     
  Lines        2607     2912     +305     
  Branches      526      546      +20     
==========================================
+ Hits         1527     1859     +332     
+ Misses        745      707      -38     
- Partials      335      346      +11     
Flag Coverage Δ
macos 60.91% <ø> (+5.84%) ⬆️
macos_duktape 66.00% <ø> (+6.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a CMake-generated configuration header (proxyres_config.h) and updates several source files to use CMake-detected header-availability macros (e.g., HAVE_NETDB_H) to control conditional includes, aiming to make future portability patches simpler.

Changes:

  • Add a new proxyres_config.h.in template and generate proxyres_config.h via CMake.
  • Replace unconditional <netdb.h> includes with #if HAVE_NETDB_H guards across multiple source files.
  • Update CMake target include paths and header lists to include the generated config header from the build directory.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
wpad_dns.c Includes generated config header and gates <netdb.h> behind HAVE_NETDB_H.
wpad_dhcp_posix.c Includes generated config header and gates <netdb.h> behind HAVE_NETDB_H.
proxyres_config.h.in New CMake config header template defining HAVE_NET_IF_ARP_H / HAVE_NETDB_H.
net_util.c Includes generated config header and gates <netdb.h> behind HAVE_NETDB_H.
net_adapter_mac.c Includes generated config header (used for HAVE_NET_IF_ARP_H).
net_adapter_linux.c Includes generated config header and gates <netdb.h> behind HAVE_NETDB_H.
fetch_posix.c Includes generated config header and gates <netdb.h> behind HAVE_NETDB_H.
CMakeLists.txt Adds header checks and configure_file() to generate proxyres_config.h; adds build dir include path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CMakeLists.txt
Comment thread proxyres_config.h.in
Comment thread net_util.c
Comment thread fetch_posix.c
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@fetch_posix.c`:
- Around line 11-13: Replace the fragile preprocessor guard that uses `#if
HAVE_NETDB_H` with a defined() check to avoid -Wundef/MSVC C4668 warnings;
specifically change the conditional before the `#include <netdb.h>` lines to use
`#if defined(HAVE_NETDB_H) && HAVE_NETDB_H` (or at minimum `#if
defined(HAVE_NETDB_H)`) in every place the `HAVE_NETDB_H` macro is checked so
all occurrences are updated consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2d8387f2-f28c-440b-a954-bb7658b7233a

📥 Commits

Reviewing files that changed from the base of the PR and between 2bd7289 and f582705.

📒 Files selected for processing (8)
  • CMakeLists.txt
  • fetch_posix.c
  • net_adapter_linux.c
  • net_adapter_mac.c
  • net_util.c
  • proxyres_config.h.in
  • wpad_dhcp_posix.c
  • wpad_dns.c

Comment thread fetch_posix.c
@sergio-nsk sergio-nsk enabled auto-merge (rebase) March 28, 2026 04:18
Comment thread CMakeLists.txt
check_include_file("netdb.h" HAVE_NETDB_H)
endif()

configure_file(proxyres_config.h.in proxyres_config.h @ONLY NEWLINE_STYLE UNIX)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is roxyres_config.h.in defined?

Copy link
Copy Markdown
Collaborator Author

@sergio-nsk sergio-nsk Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proxyres_config.h.in - is a new file in the commit.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the name build_config.h?

Copy link
Copy Markdown
Collaborator Author

@sergio-nsk sergio-nsk Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other projects use such template <project>_config.h because build_config.h from distinct client projects would conflict. build_config.h is a free name in our code, but proxyres is OSS and we can break other user projects.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I wonder about this now that I approved it, because proxyres_config.h is only used internally. Not externally. But you are suggesting that it would be used externally?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't suggest it, and -I${PROJECT_BINARY_DIR} is in the private target properties. User -I order is unpredictable, so it's better to use a more unique header name than a less unique one.

Comment thread CMakeLists.txt
Comment thread CMakeLists.txt
check_include_file("netdb.h" HAVE_NETDB_H)
endif()

configure_file(proxyres_config.h.in proxyres_config.h @ONLY NEWLINE_STYLE UNIX)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the name build_config.h?

@sergio-nsk sergio-nsk merged commit c34bf91 into master Mar 31, 2026
20 checks passed
@sergio-nsk sergio-nsk deleted the sergey/cmake_configure_file/1 branch March 31, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants