From 10f3eddc6a62456ae96f3ed3b6a5f783e7eef68a Mon Sep 17 00:00:00 2001 From: William Barnhart Date: Fri, 24 Jul 2026 13:38:59 +0000 Subject: [PATCH] ci: test building against a system uchardet The existing Tests workflow only builds the bundled uchardet default, so the system-uchardet path is never exercised in CI. Add a Linux job that builds uchardet from git, installs it, then builds cChardet with -Dsystem-uchardet=enabled and runs the test suite. The job also asserts (via ldd) that the built extension links the shared system libuchardet rather than silently falling back to the bundled sources, and checks that the system header exposes uchardet_get_n_candidates (the symbol the enabled/auto probe requires). Stacked on the system-uchardet feature-option change; the option it exercises does not exist on master yet. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01BnTZQEXqpedyrFAgwRnbsA --- .github/workflows/test-system-uchardet.yml | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/test-system-uchardet.yml diff --git a/.github/workflows/test-system-uchardet.yml b/.github/workflows/test-system-uchardet.yml new file mode 100644 index 0000000..d7602a4 --- /dev/null +++ b/.github/workflows/test-system-uchardet.yml @@ -0,0 +1,70 @@ +name: Test (system uchardet) + +# Exercises the `system-uchardet` feature option (see meson.options): build +# cChardet against a system uchardet built from git and confirm the resulting +# extension links the shared library instead of the bundled sources. The +# regular Tests workflow only covers the bundled default. +on: + pull_request: + push: + branches: + - master + +jobs: + system-uchardet: + name: Build against system uchardet (from git) + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + # meson's files() validates the vendored uchardet sources exist at + # configure time even for a system build, so the submodule still has + # to be checked out. + submodules: recursive + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Build and install uchardet from git + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends cmake ninja-build pkg-config + git clone --depth 1 \ + https://gitlab.freedesktop.org/uchardet/uchardet.git /tmp/uchardet-src + cmake -S /tmp/uchardet-src -B /tmp/uchardet-build \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DBUILD_BINARY=OFF + sudo cmake --build /tmp/uchardet-build --target install + sudo ldconfig + + - name: Confirm the system uchardet exposes the candidate API + run: | + pkg-config --exists uchardet + echo "system uchardet version: $(pkg-config --modversion uchardet)" + # `enabled`/`auto` reject a uchardet without this symbol; the last + # tagged release still reports 0.0.8 but only the git build ships it. + grep -q uchardet_get_n_candidates /usr/include/uchardet/uchardet.h + + - name: Build cChardet against the system uchardet + run: | + python -m pip install --upgrade pip + python -m pip install pytest + python -m pip install . \ + --config-settings=setup-args=-Dsystem-uchardet=enabled + + - name: Verify the extension links the system libuchardet + run: | + so=$(python -c "import cchardet._cchardet as m; print(m.__file__)") + echo "built extension: $so" + ldd "$so" + # Fail if it did not link the shared system library -- i.e. it + # silently fell back to compiling the bundled sources. + ldd "$so" | grep -q libuchardet + + - name: Run tests + run: python -m pytest src/tests