Skip to content

pkg-config: stop forcing a language mode in Cflags (issue #13) - #16

Merged
wolfgitpr merged 2 commits into
v2from
fix/pkg-config-cflags
Nov 21, 2026
Merged

wolfgitpr merged 2 commits into
v2from
fix/pkg-config-cflags

Conversation

@wolfgitpr

Copy link
Copy Markdown
Owner

Fixes #13. Scope: this branch touches no source file, no dictionary, and nothing from the vcpkg port other
than what #14 already upstreamed -- vcpkg-dict-layout.patch is deliberately untouched.

The problem. Cflags named -std=c++17. pkg-config has no per-language flag channel and cannot express
"at least 17", so that one flag did two measurably bad things (compiled as C with pkg-config --cflags as the
only flags, on Win64 with MinGW GCC 16.1.0 + pkgconf 3.0.11):

shape before after
C consumer (ext/c_api.h) built by clang error: invalid argument '-std=c++17' not allowed with 'C' compiles
the same, built by gcc warning '-std=c++17' is valid for C++/ObjC++ but not for C no warning
C++20 consumer whose own -std=c++20 comes first silently dropped to 17 (last option wins) stays at 20

The change. Cflags: -I${includedir}@CPP_PINYIN2_PC_EXTRA_CFLAGS@. The requirement moves to a cxx_std
variable (pkg-config --variable=cxx_std cpp-pinyin2 -> -std=c++17), which nothing applies unless the
consumer copies it. -DCPP_PINYIN2_STATIC stays: it is a PUBLIC compile definition, not a language mode. The
CMake target is untouched -- cxx_std_17 already means "at least", which is what the headers need.

The gate. check_install_consumer.cmake asserted the flag was PRESENT; it now asserts that no Cflags
entry names a standard mode and that cxx_std is exported. It was shown able to fail: doctoring the generated
.pc back to Cflags: ... -std=c++17 makes it exit 1 with "Cflags names a language standard mode".

Measured here: the table above; pkg-config --cflags prints no -std=; --variable=cxx_std ->
-std=c++17; --variable=dictdir -> the installed dictionary root; ctest -R InstallConsumerSmoke 3/3;
tools/run_all_gates.py 17 build-free gates pass; tools/check_doc_claims.py --ctest-inventory clean; the
public headers also compile clean in C++20.

Not measurable here: the manylinux step-10 additions (compile exit code, C++20 non-downgrade probe, clang C
consumer) run only inside the container, so this PR's CI is their first execution. Docs: README gained a
pkg-config consumer section, RELEASE_RUNBOOK 4.2/4.2b gained the two criteria, and RELEASE_CHECKLIST's
pkg-config row got dated corrections rather than a rewrite.

…t as a variable

Issue #13: `Cflags` named `-std=c++17`, and this file has no business doing that. Two consequences, both
measured on this machine (Win64, MinGW GCC 16.1.0, pkgconf 3.0.11, install prefix .tmp/pkg-prefix):

  * pkg-config has no per-language flag channel, so the flag reached a C compiler too -- and this package
    serves a C header (`ext/c_api.h`). Compiled as C with `pkg-config --cflags` as the only flags, clang
    rejects the option outright ("error: invalid argument '-std=c++17' not allowed with 'C'") while gcc only
    warns ("command-line option '-std=c++17' is valid for C++/ObjC++ but not for C"). A C consumer's build
    therefore depended on which compiler it used -- and this repository's own manylinux step 10 is exactly
    such a consumer: it compiles c_api.h with gcc and would have gone red under clang.
  * pkg-config cannot express "at least 17": a consumer that put its own `-std=c++20` FIRST and the package's
    flags second was dropped back to 17, because the last option on a command line wins. Reproduced with a TU
    that asserts `#if __cplusplus < 202002L`: it passes after this change and fails with the old `-std=c++17`
    appended.

The requirement did not disappear with the flag. cpp-pinyin2.pc now exports `cxx_std=-std=c++17`, which
`pkg-config --variable=cxx_std cpp-pinyin2` answers with and which nothing applies unless the consumer copies
it onto its own command line; README's consumer section and the RELEASE_RUNBOOK's step 4.2b say where to find
it. The CMake target is untouched: `cxx_std_17` already means "at least", which is what the headers need.

`-DCPP_PINYIN2_STATIC` STAYS in Cflags. It is a PUBLIC compile definition (it selects the no-dllimport branch
of PinyinGlobal.h), so a pkg-config consumer of a static install that does not get it compiles against the
wrong branch -- a different kind of fact from a language mode, and one pkg-config can express correctly.

The install-consumer gate is INVERTED rather than deleted: it fails if `Cflags` names any standard mode and
fails if `cxx_std` is missing. It was shown able to fail -- doctoring the generated .pc back to
`Cflags: -I${includedir} -std=c++17` makes it exit 1 with "Cflags names a language standard mode".

Measured: `pkg-config --cflags` -> -I.../include, no -std=; `--variable=cxx_std` -> -std=c++17;
`--variable=dictdir` -> .../share/cpp-pinyin2/dict; `ctest -R InstallConsumerSmoke` -> 3/3 passed;
`tools/run_all_gates.py` -> 17 build-free gates pass (5 need a build tree);
`tools/check_doc_claims.py --ctest-inventory` -> "every recognised claim matches what the tree measures".
The public headers also compile clean in C++20 (`g++ -std=c++20 -fsyntax-only` on core/Engine.h).

docs/RELEASE_CHECKLIST.md's pkg-config row keeps its 2026-10-21 reading and gains dated corrections instead
of a rewrite: the Windows leg no longer excludes InstallConsumerSmoke (withdrawn 2026-10-27, c3a728c), and
the static-consumer face is no longer a gap (Libs.private landed 746a67e, measured by step 10).
…tic leg's first run

Two CI-side follow-ups, one per workflow:

  * ci_manylinux_aarch64.sh step 10 asserted only the LINK exit code, so a failing compile still read as a
    link verdict. It now asserts the C compile too, and compiles the two shapes issue #13 describes: a C++ TU
    that asks for C++20 first and takes the package's flags second (asserting `#if __cplusplus < 202002L`), and
    the same C consumer under clang when the image has one -- clang errors on a C++ standard option in C mode
    while gcc only warns, so the gcc compile that was already there could not see that case. clang absent
    prints NOT MEASURED and is not a failure: the same distinction the ninja probe in that file draws.
  * ci.yml's macOS static leg comment said no run had confirmed it. Run 44859037261 (push of 9938d3d) ran it:
    step 10 of the `macos` job is green there, as it is in #15's own run 44858155866 -- which is also the
    first independent confirmation that #14 fixed Apple's archive step, because this build reaches that step
    and passes no `D`.

Verified here: `python -B tools/check_parsable.py --require` -> exit 0 (bash -n over both tracked scripts,
yaml.safe_load over the five workflows). NOT verified: the container step itself, which only runs inside
manylinux.
@wolfgitpr
wolfgitpr merged commit 10d1023 into v2 Nov 21, 2026
19 checks passed
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