diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2025-07-09 10:22:00 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2025-07-26 14:19:51 -0400 |
commit | 1b1e5a4707d681e4b38df56e83db1be9c07723b8 (patch) | |
tree | 818d23177c1b2ab338c28ad84ff4a496dc0c9602 | |
parent | 54260a40b37890bb6ee3b62659abd3b13c89a0aa (diff) | |
download | bfs-1b1e5a4707d681e4b38df56e83db1be9c07723b8.tar.xz |
build: Use C23 if possible
For broader compiler support, we try both -std=c23 and -std=c2x. If
neither is supported, we fall back to -std=c17, but we will start
requiring some C23 features as extensions in this mode.
-rw-r--r-- | .github/workflows/codecov.yml | 2 | ||||
-rw-r--r-- | build/flags.mk | 14 | ||||
-rw-r--r-- | build/flags/std.c | 12 | ||||
-rw-r--r-- | docs/CONTRIBUTING.md | 3 | ||||
-rw-r--r-- | src/diag.h | 2 |
5 files changed, 23 insertions, 10 deletions
diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index e4e8f71..7231aa0 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -24,7 +24,7 @@ jobs: - name: Generate coverage run: | - ./configure --enable-gcov + ./configure --enable-gcov EXTRA_CFLAGS="-std=gnu2x" make -j$(nproc) check TEST_FLAGS="--sudo" gcov -abcfpu obj/*/*.o diff --git a/build/flags.mk b/build/flags.mk index d6f9499..00876d1 100644 --- a/build/flags.mk +++ b/build/flags.mk @@ -8,7 +8,7 @@ include gen/vars.mk # Internal flags _CPPFLAGS := -Isrc -Igen -include src/prelude.h -_CFLAGS := -std=c17 +_CFLAGS := _LDFLAGS := _LDLIBS := @@ -58,8 +58,7 @@ _CFLAGS += ${SAN_CFLAGS,${SAN}} YESLIBS := ${NOT,${_MSAN}${_TSAN}${_TYSAN}} NOLIBS ?= ${NOT,${YESLIBS}} -# gcov only intercepts fork()/exec() with -std=gnu* -GCOV_CFLAGS,y := -std=gnu17 --coverage +GCOV_CFLAGS,y := --coverage _CFLAGS += ${GCOV_CFLAGS,${_GCOV}} LINT_CPPFLAGS,y := -D_FORTIFY_SOURCE=3 -DBFS_LINT @@ -91,6 +90,10 @@ include build/exports.mk # Conditionally-supported flags AUTO_FLAGS := \ + gen/flags/std.mk \ + gen/flags/bind-now.mk \ + gen/flags/deps.mk \ + gen/flags/pthread.mk \ gen/flags/Wformat.mk \ gen/flags/Wimplicit-fallthrough.mk \ gen/flags/Wimplicit.mk \ @@ -99,10 +102,7 @@ AUTO_FLAGS := \ gen/flags/Wshadow.mk \ gen/flags/Wsign-compare.mk \ gen/flags/Wstrict-prototypes.mk \ - gen/flags/Wundef-prefix.mk \ - gen/flags/bind-now.mk \ - gen/flags/deps.mk \ - gen/flags/pthread.mk + gen/flags/Wundef-prefix.mk gen/flags.mk: ${AUTO_FLAGS} ${MSG} "[ GEN] $@" diff --git a/build/flags/std.c b/build/flags/std.c new file mode 100644 index 0000000..6030d1f --- /dev/null +++ b/build/flags/std.c @@ -0,0 +1,12 @@ +// Copyright © Tavian Barnes <tavianator@tavianator.com> +// SPDX-License-Identifier: 0BSD + +/// _CFLAGS += -std=c23 +/// --- +/// _CFLAGS += -std=c2x +/// --- +/// _CFLAGS += -std=c17 + +int main(void) { + return 0; +} diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 099157d..e411fde 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -17,7 +17,8 @@ This enables machine processing of license information based on the SPDX License Implementation -------------- -`bfs` is written in [C](https://en.wikipedia.org/wiki/C_(programming_language)), specifically [C17](https://en.wikipedia.org/wiki/C17_(C_standard_revision)). +`bfs` is written in [C](https://en.wikipedia.org/wiki/C_(programming_language)). +The build defaults to [C23](https://en.wikipedia.org/wiki/C23_(C_standard_revision)), but it also supports [C17](https://en.wikipedia.org/wiki/C17_(C_standard_revision)) as long as some popular C23 features are available as extensions. You can get a feel for the coding style by skimming the source code. [`main.c`](/src/main.c) contains an overview of the rest of source files. A quick summary: @@ -55,9 +55,9 @@ void bfs_diagf(const char *format, ...); /** * Print a message to standard error and abort. */ +_noreturn _cold _printf(1, 2) -_noreturn void bfs_abortf(const char *format, ...); /** |