From a5c16e97d721dad1c66053a7bd78f341c4c861f1 Mon Sep 17 00:00:00 2001 From: huntedbytheirs Date: Mon, 31 Aug 2026 19:49:49 -0400 Subject: [PATCH] feat(profile): generate installed features.h exposing VLIBC_LEVEL Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .gitignore | 3 ++ configure.ac | 2 ++ include/vlibc/features.h.in | 58 +++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 include/vlibc/features.h.in diff --git a/.gitignore b/.gitignore index 9297fff..9d3cdcf 100644 --- a/.gitignore +++ b/.gitignore @@ -85,6 +85,9 @@ Makefile.in /build-aux/ /m4/ +# Generated feature header (from include/vlibc/features.h.in); the template is tracked. +/include/vlibc/features.h + # Libtool build directories and artifacts. .deps/ .libs/ diff --git a/configure.ac b/configure.ac index 2897664..fc3c996 100644 --- a/configure.ac +++ b/configure.ac @@ -116,6 +116,7 @@ AS_CASE([$vlibc_profile], [vlibc], [AC_DEFINE([VLIBC_PROFILE_VLIBC], [1], [vlibc (glibc-ext) profile])]) AC_SUBST([vlibc_profile]) +AC_SUBST([vlibc_level]) # ---- Install method ------------------------------------------------------ # "alongside" installs vlibc next to the system libc: headers and libraries go @@ -168,6 +169,7 @@ LT_INIT AC_CONFIG_FILES([Makefile benchmarks/Makefile + include/vlibc/features.h tools/vlibc-gcc tools/vlibc-clang]) diff --git a/include/vlibc/features.h.in b/include/vlibc/features.h.in new file mode 100644 index 0000000..1837cc3 --- /dev/null +++ b/include/vlibc/features.h.in @@ -0,0 +1,58 @@ +#ifndef VLIBC_FEATURES_H +#define VLIBC_FEATURES_H + +/* + * vlibc — compatibility feature gate. + * + * This header is generated by configure from include/vlibc/features.h.in; do + * not edit the generated file. It exposes the active compatibility profile as + * build-time constants, so headers and sources can gate declarations on the + * profile level (see configure.ac and docs/compatibility.md): + * + * 1 onlyposix pure POSIX, nothing more + * 2 muslmimic musl-like, light + * 3 muslext musl-extended + * 4 spoof glibc replica (drop-in compatibility) + * 5 vlibc glibc-extended, the default + * + * VLIBC_LEVEL is the numeric level (1..5); VLIBC_PROFILE is the profile name. + * Both are emitted only when not already defined: the library's own sources + * include config.h first (via HAVE_CONFIG_H), whose values win, and this + * header skips the redefinition. Consumers of the installed header get the + * values baked in at configure time. + */ + +#ifndef VLIBC_LEVEL +#define VLIBC_LEVEL @vlibc_level@ +#endif + +#ifndef VLIBC_PROFILE +#define VLIBC_PROFILE "@vlibc_profile@" +#endif + +/* True when the active profile is at least level n. */ +#define VLIBC_LEVEL_GE(n) (VLIBC_LEVEL >= (n)) + +/* + * Per-profile feature booleans, derived from VLIBC_LEVEL. Levels are + * cumulative: level 3 implies the POSIX and musl feature sets as well. A + * macro is defined (as 1) when its feature set is present and left undefined + * otherwise, so `#if VLIBC_HAS_MUSL` works in both cases. + */ +#if VLIBC_LEVEL >= 1 +#define VLIBC_HAS_POSIX 1 +#endif +#if VLIBC_LEVEL >= 2 +#define VLIBC_HAS_MUSL 1 +#endif +#if VLIBC_LEVEL >= 3 +#define VLIBC_HAS_MUSLEXT 1 +#endif +#if VLIBC_LEVEL >= 4 +#define VLIBC_HAS_GLIBC 1 +#endif +#if VLIBC_LEVEL >= 5 +#define VLIBC_HAS_VLIBC 1 +#endif + +#endif /* VLIBC_FEATURES_H */