Skip to content

Expose version macros through the C header - #277

Draft
moelomda wants to merge 1 commit into
google:mainfrom
moelomda:codex/snappy-c-version-271
Draft

moelomda wants to merge 1 commit into
google:mainfrom
moelomda:codex/snappy-c-version-271

Conversation

@moelomda

Copy link
Copy Markdown

Including snappy-c.h currently leaves SNAPPY_MAJOR, SNAPPY_MINOR, SNAPPY_PATCHLEVEL, and SNAPPY_VERSION undefined. C applications cannot use those macros for feature checks, and including snappy-stubs-public.h is not a workaround because it contains C++ declarations.

Move the existing definitions into a generated snappy-version.h shared by both public interfaces. The values and encoding remain unchanged. The new header uses C comments and no C++ declarations, so strict C90 consumers continue to compile. CMake installs it with the other public headers, and Bazel declares the corresponding generated-header dependencies.

Closes #271.

The regression helper is compiled as C and returns all four macros to the existing C++ unit suite, which checks that both interfaces report the same version. CMake compiles that helper as standard C90. No compression behavior, function signatures, dependency versions, or workflow files change.

Validation on Ubuntu 22.04, GCC/G++ 11.4, CMake 3.22.1, and Ninja:

  • Before the change, compiling the C helper with gcc -std=c90 -Wall -Wextra -Werror -pedantic-errors -I. -fsyntax-only snappy_c_version_test.c fails on all four undefined macros.
  • Release CMake build with tests enabled and benchmarks disabled; ctest --test-dir .git/build-static --output-on-failure -V: all 26 unit tests pass. The existing DISABLED_MoreThan4GB test remains disabled.
  • Static and shared builds install successfully into private prefixes. Twenty installed-header checks pass: C90/C99/C11/C17 compression round trips for both builds, plus C++11/C++17/C++20 compilation in both C/C++ header orders. These also verify the configured version values.
  • Separate CMake find_package(Snappy CONFIG REQUIRED) consumers build and run against each installed Snappy::snappy target.
  • git diff --check passes.

Bazel 9.3.2's normal test //:snappy_unittest fails in unchanged snappy-test.h because ::gettimeofday is undeclared. I reproduced that failure on pristine base 946606459314e55d029c85f9a8c46f8809467f0f. With the local compiler workaround --cxxopt=-include --cxxopt=sys/time.h, the patched Bazel test target passes, including the C-header regression. The workaround is not committed. Bazel used two jobs, a 512 MiB JVM heap, and --repo_contents_cache= to keep its private cache layout compatible with Bazel 9.

This is a draft because the normal Bazel test invocation still fails on the baseline. Other compilers and operating systems have not been tested locally.

Implemented and tested with Codex assistance.

Share a generated C-compatible version header between both public APIs.
Compile a C90 helper in the unit suite and compare its version values
with the C++ interface; wire the header into CMake and Bazel.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request : Access Snappy library version define in C header

1 participant