build: Always define HAVE_SYSTEM #36023

Open
Sjors wants to merge 1 commit from 2026/08/have-system into master AGit
Sjors commented 2026-08-19 13:26:12 +00:00 (Migrated from github.com)

When this feature is unavailable, #cmakedefine leaves its macro undefined, triggering -Wundef. I noticed this while building the kernel for iOs.

Use #cmakedefine01 to always generate 0 or 1.

When this feature is unavailable, `#cmakedefine` leaves its macro undefined, triggering `-Wundef`. I noticed this while building the kernel for iOs. Use `#cmakedefine01` to always generate 0 or 1.
DrahtBot commented 2026-08-19 13:26:20 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36023 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36023.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36023#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--5faf32d7da4f0f540f40219e4f7537a3-->
fanquake commented 2026-08-19 13:35:32 +00:00 (Migrated from github.com)

I haven't observed HAVE_FDATASYNC myself, but applied the same change anyway.

Please don't make random changes for no reason.

> I haven't observed HAVE_FDATASYNC myself, but applied the same change anyway. Please don't make random changes for no reason.
hebasto commented 2026-08-19 13:36:10 +00:00 (Migrated from github.com)

Maybe simply revert 976b034b13?

Maybe simply revert 976b034b13d28877aee641833d5ee28a8cc5d83f?
maflcko commented 2026-08-19 13:46:00 +00:00 (Migrated from github.com)

Ref: https://github.com/bitcoin/bitcoin/issues/16419

Can we not use a single style and enforce it with a linter, similar to the lint_includes_build_config one?

Ref: https://github.com/bitcoin/bitcoin/issues/16419 Can we not use a single style and enforce it with a linter, similar to the `lint_includes_build_config` one?
Sjors commented 2026-08-19 14:04:49 +00:00 (Migrated from github.com)

@fanquake I dropped HAVE_FDATASYNC. It was deliberately made this way in #19803 for some reason.

@hebasto using #if defined(HAVE_SYSTEM) looks ugly imo, but it also risks someone using #if HAVE_SYSTEM accidentally.

@fanquake I dropped `HAVE_FDATASYNC`. It was deliberately made this way in #19803 for some reason. @hebasto using `#if defined(HAVE_SYSTEM)` looks ugly imo, but it also risks someone using `#if HAVE_SYSTEM` accidentally.
First-time contributor

Base: a829aeaac1aff6cb786aab7d2514b49eb233334b
Head: 013fffe371f566387d4d386c21e6d3f9cfd92cf1

No verified findings are available from this partial review.

Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial_glm review did not complete.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `a829aeaac1aff6cb786aab7d2514b49eb233334b` Head: `013fffe371f566387d4d386c21e6d3f9cfd92cf1` No verified findings are available from this partial review. Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial_glm review did not complete. [Full review report](<https://review.fish.foo/traces/36023-013fffe371f566387d4d386c21e6d3f9cfd92cf1-276-1.html>)
sedited commented 2026-11-06 20:03:15 +00:00 (Migrated from github.com)

The change seems fine to me, but it would be nice to be consistent across these definitions.

The change seems fine to me, but it would be nice to be consistent across these definitions.
hebasto commented 2026-11-15 16:03:53 +00:00 (Migrated from github.com)

using #if defined(HAVE_SYSTEM) looks ugly imo...

Is this concern aesthetic or technical?

However, I agree that using #if defined(...) poses a problem. We can't spot a typo in the macro name, for example #if defined(HAVE_SUSTEM). Also see https://github.com/bitcoin/bitcoin/issues/36874.

... but it also risks someone using #if HAVE_SYSTEM accidentally.

In this case, it does not change behavior when bitcoin-build-config.h contains #define HAVE_SYSTEM 1. And it will trigger -Wundef when the macro is undefined.

The problem of detecting misused directives in the source code remains for #cmakedefine01 as well. Perhaps this is a task for the linter.

Can we not use a single style...

... it would be nice to be consistent across these definitions.

The current usage is not uniform either. For example, here are the different patterns for configuration macro definitions:

  1. #define HAVE_FOO or undefined -- is not used.
  2. #define HAVE_FOO 1 or undefined:
$ git grep '#cmakedefine ' -- cmake/bitcoin-build-config.h.in | wc -l
18
  1. #define HAVE_FOO 1 or #define HAVE_FOO 0:
$ git grep '#cmakedefine01' -- cmake/bitcoin-build-config.h.in | wc -l
4

Use #cmakedefine01 to always generate 0 or 1.

This approach gives us free protection against a misspelled macro name, which will trigger the -Wundef compiler warning.

Here are some useful external resources:


Bottom line: I agree with this PR change. I'd really like to see here a new linter check that prevents accidental misuse of #ifdef, #ifndef or defined() for configuration macros set via #cmakedefine01.

> using `#if defined(HAVE_SYSTEM)` looks ugly imo... Is this concern aesthetic or technical? However, I agree that using `#if defined(...)` poses a problem. We can't spot a typo in the macro name, for example `#if defined(HAVE_SUSTEM)`. Also see https://github.com/bitcoin/bitcoin/issues/36874. > ... but it also risks someone using `#if HAVE_SYSTEM` accidentally. In this case, it does not change behavior when `bitcoin-build-config.h` contains `#define HAVE_SYSTEM 1`. And it will trigger `-Wundef` when the macro is undefined. The problem of detecting misused directives in the source code remains for `#cmakedefine01` as well. Perhaps this is a task for the linter. > Can we not use a single style... > ... it would be nice to be consistent across these definitions. The current usage is not uniform either. For example, here are the different patterns for configuration macro definitions: 1. `#define HAVE_FOO` or undefined -- is not used. 2. `#define HAVE_FOO 1` or undefined: ```console $ git grep '#cmakedefine ' -- cmake/bitcoin-build-config.h.in | wc -l 18 ``` 3. `#define HAVE_FOO 1` or `#define HAVE_FOO 0`: ```console $ git grep '#cmakedefine01' -- cmake/bitcoin-build-config.h.in | wc -l 4 ``` > Use `#cmakedefine01` to always generate 0 or 1. This approach gives us free protection against a misspelled macro name, which will trigger the `-Wundef` compiler warning. Here are some useful external resources: - https://sourceware.org/glibc/wiki/Wundef - https://www.gnu.org/prep/standards/html_node/Conditional-Compilation.html - https://libcxx.llvm.org/CodingGuidelines.html#define-configuration-macros-to-0-or-1 --- Bottom line: I agree with this PR change. I'd really like to see here a new linter check that prevents accidental misuse of `#ifdef`, `#ifndef` or `defined()` for configuration macros set via `#cmakedefine01`.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36023
No description provided.