Skip to content

build: install a self-contained package (archive API in #101) - #104

Merged
blocksmith314 merged 2 commits into
mainfrom
build/83-self-contained-package
Nov 28, 2026
Merged

blocksmith314 merged 2 commits into
mainfrom
build/83-self-contained-package

Conversation

@blocksmith314

@blocksmith314 blocksmith314 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Make cmake --install produce a package a downstream project can actually consume.

  • Bundle LZ4/xxhash into libctar.a: lz4 becomes an OBJECT library (lz4.c, lz4hc.c, xxhash.c; lz4frame.c dropped because nothing uses the frame API) whose objects are merged into the static archive. Consumers no longer need lz4 installed, and the exported target has no compression dependency.
  • Public headers only: install include/ctar/ctar.h and include/ctar/version.h (the single source of truth for tool/format versions). Internal api/, src/core/ and src/utils/ headers are no longer installed. src/core/version.h forwards to the public header for internal includes.
  • Targets and names: ctar::ctar (install name libctar.a), cxx_std_23 propagated as a PUBLIC compile feature; ctar_cli_lib is no longer exported.
  • Packaging fixes: include(GNUInstallDirs) moved ahead of the targets; ctar.pc uses -lctar, Libs.private: -pthread and a relocatable prefix=${pcfiledir}/...; Cflags carries -std=c++23 because the public header uses std::format; ctarConfig.cmake keeps only find_dependency(Threads); INSTALL_GTEST OFF keeps googletest out of the install prefix.
  • Public symbol: ctar::VersionString() is defined in the library so a consumer test can prove it linked the archive, not just the headers.
  • Consumer smoke test: scripts/consumer_smoke_test.sh installs to a private prefix, configures/builds test/consumer with find_package(ctar CONFIG REQUIRED), runs it, compiles and runs a pkg-config consumer, verifies the pkg-config prefix resolves to the install prefix, asserts that no gtest/gmock files were installed, and checks with nm that LZ4_* symbols are inside libctar.a. The CI matrix runs it on Linux GCC, Linux Clang and macOS.
  • README/README_CN document <ctar/ctar.h> and ctar::ctar.

No archive-format change.

Scope

This PR delivers the packaging foundation and the version API only. The archive read API (ctar::ArchiveReader, #101) will be added to the same installed header layout without changing it, and the consumer test will be extended then to perform a real pack/unpack through the installed headers. Installing the internal BlockStore headers was rejected on purpose: internal types are not the long-term public API.

#83 therefore stays open: this PR fixes the packaging mechanics, and #101 closes it once the archive API is exposed through the installed headers.

Bundled LZ4_*/XXH* symbols are part of libctar.a and may collide with a consumer that links its own copies; this is documented in the README.

Tests

  • Release ctest: 201/201 passed
  • ASan ctest: 201/201 passed
  • Clean default build (BUILD_TEST=ON) → install → consumer: passed, including the no-gtest/gmock assertion, the pkg-config relocation check, and the bundled-lz4 check
  • Installed tree: bin/ctar, include/ctar/{ctar.h,version.h}, lib/libctar.a, lib/cmake/ctar/*, lib/pkgconfig/ctar.pc

Performance gate

  • Isolated review-fix delta (d327f64 → e215424), 10 unpack runs: +0.7% wall time / -1.4% peak RSS.
  • Same-code A/A control: +3.0% wall time / -2.6% RSS, i.e. the machine drift is larger than the change; no attributable regression.

Refs #83

The install rule installed headers flat, omitted the headers block_store.h depends on, and linked lz4 through a BUILD_INTERFACE, so the exported target had no compression dependency. A downstream find_package(ctar) could neither compile nor link.

Bundle the LZ4 and xxhash objects into libctar.a with an OBJECT library, install only the public include/ctar headers, expose the ctar::ctar target with cxx_std_23, fix the pkg-config library name and add -pthread, and move GNUInstallDirs ahead of the targets. Add ctar::VersionString() as a real library symbol.

Add a consumer smoke test that installs to a private prefix, builds a tiny find_package(ctar) project, runs it, and checks that LZ4 symbols are inside libctar.a. Run it on Linux GCC/Clang and macOS in CI.

Refs #83

@blocksmith314 blocksmith314 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review

The static-library bundling and CMake target mostly work, and the consumer smoke test passes. The installed package is not yet consumable/clean, though. I would not merge yet.

1. The public header exposes no archive API

include/ctar/ctar.h only includes <ctar/version.h>. api/ctar.h and src/core/block_store.h are deliberately not installed, so a downstream project cannot declare a BlockStore or call pack/unpack; the archive exports the symbols (nm shows ctar::BlockStore::PackPipeline), but the headers do not. The consumer test only calls VersionString(), so it proves the archive links, not that it is usable.

Either install a real public API (rewrite/install the headers preserving paths), or explicitly scope this package to version/CLI use and adjust the title/docs. A consumer test that performs an actual pack/unpack through the installed headers would catch this.

2. cmake --install installs gtest/gmock

With the default BUILD_TEST=ON, the install prefix contains:

include/gtest/*, include/gmock/*
libgtest.a, libgtest_main.a, libgmock.a, libgmock_main.a
lib/pkgconfig/gtest*.pc

That contradicts the PR's listed install tree and pollutes downstream packages. Set INSTALL_GTEST OFF before add_subdirectory/FetchContent_MakeAvailable (tests still use gmock), and make the consumer test assert that no test artifacts are installed.

3. ctar.pc is not relocatable

@prefix@ is expanded from CMAKE_INSTALL_PREFIX at configure time. Installing with cmake --install ... --prefix /tmp/ctar-prefix produces:

prefix=/usr/local
libdir=${exec_prefix}/lib
includedir=${prefix}/include

so pkg-config --cflags ctar returns -I/usr/local/include, not the installed prefix. Use a relocatable prefix, e.g.:

prefix=${pcfiledir}/../..

4. ctar.pc does not provide the required C++ standard

version.h uses std::format, but pkg-config --cflags ctar returns only -I.... A default C++17 consumer fails:

error: no member named 'format' in namespace 'std'

Add -std=c++23 to Cflags (consistent with the exported cxx_std_23 feature), or make the public header C++17-compatible.

Minor

  • Document that LZ4_*/XXH* symbols are now inside libctar.a and can collide with a consumer's own lz4/xxhash (issue #83 called this out).
  • cmake/ctar.pc.in still has no trailing newline.
  • The consumer test should also exercise pkg-config and verify the package contains no gtest/gmock files.

Verified locally: Release ctest 201/201, CMake consumer smoke test passes, CI 5/5 green. The failures above are reproducible from the installed prefix.

- Keep googletest out of the install prefix: set INSTALL_GTEST OFF before the local add_subdirectory or FetchContent path, so the prefix no longer contains gtest/gmock headers, archives or .pc files.

- Make ctar.pc relocatable via ${pcfiledir} and add -std=c++23 to Cflags (the public version header uses std::format).

- Move the version header to include/ctar/version.h as the public single source of truth; src/core/version.h now forwards to it, and cmake/utils.cmake parses the public path.

- Extend the consumer smoke test: reject gtest/gmock in the prefix, verify pkg-config resolves the installed prefix, and compile/run a pkg-config consumer.

- Document that the public API is version-only until #101 and note the bundled LZ4/XXH symbol collision.

Refs #83

@blocksmith314 blocksmith314 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Re-reviewed e215424.

The concrete packaging bugs from the last review are fixed:

  • INSTALL_GTEST OFF keeps gtest/gmock out of the install prefix (verified: only bin/ctar, include/ctar/{ctar.h,version.h}, lib/libctar.a, lib/cmake/ctar/*, lib/pkgconfig/ctar.pc)
  • ctar.pc now derives prefix from ${pcfiledir}, so cmake --install --prefix ... is relocatable
  • Cflags includes -std=c++23; the pkg-config consumer compiles, links and runs
  • version.h is the single public source of truth; the internal header forwards to it
  • collision note and README scope note added
  • the smoke test checks pollution, pkg-config and LZ4 symbols

Verified locally: Release ctest 201/201, scripts/consumer_smoke_test.sh passes (including pkg-config), CI 5/5 green.

One remaining scope blocker, not a code bug:

include/ctar/ctar.h still exposes only version information. The actual archive API (ctar::BlockStore, pack/unpack) is not declared by any installed header; nm shows the symbols, but a downstream cannot call them. The consumer test only calls VersionString(). README now honestly says the archive read API is tracked in #101, but the PR still says Closes #83 ("installed CMake package cannot be consumed") and the title/body claim a usable package.

Please choose one:

  1. Do not close #83 with this PR; re-scope it to packaging/version smoke test and point the archive API to #101, or
  2. Install a real public API header for the archive operations (or otherwise expose the supported API) before closing #83.

Once that scope is settled, the packaging mechanics look good from my side.

@blocksmith314
blocksmith314 force-pushed the build/83-self-contained-package branch from e215424 to e160e97 Compare November 28, 2026 03:11
@blocksmith314 blocksmith314 changed the title build: make the installed package self-contained and consumable build: install a self-contained package (archive API in #101) Nov 28, 2026
@blocksmith314
blocksmith314 merged commit 99693d3 into main Nov 28, 2026
5 checks passed
@blocksmith314
blocksmith314 deleted the build/83-self-contained-package branch November 28, 2026 03:14
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.

1 participant