Converting between UTF-8 and legacy character encodings, as the WHATWG Encoding Standard and glibc's iconv define them.
zig-charset CONTRIBUTING.md
3.8 kB · 84 lines
Markdown
at main

Contributing to zig-charset #

Issues and pull requests go to the Tangled mirror, https://tangled.org/jcollie.dev/zig-charset.

Setting up #

Everything runs inside the Nix devshell, which provides Zig 0.17.1, Python for the crosschecks, glibc 2.44 for the glibc ones, and reuse:

nix develop

What a change has to pass #

CI (.forgejo/workflows/test.yaml) runs all of these, and a change should pass them locally first:

nix develop -c reuse lint                        # every file has a licence
nix develop -c zig fmt --check .                 # formatting
nix develop -c zig build test --summary all      # unit, conformance and fuzz seeds
nix develop -c zig build check                   # tools nothing else compiles
nix develop -c zig build gen-tables && git diff --exit-code -- src/tables
nix develop -c python3 tools/crosscheck.py       # against CPython's codecs
nix develop -c python3 tools/glibc_names.py --check
nix develop -c python3 tools/crosscheck_glibc.py # against glibc's iconv
nix develop -c zig build fuzz-run -- --iterations=200000

The rules the code keeps #

  • Three definitions of an encoding are kept apart. Encoding is the WHATWG Encoding Standard's closed set, and only Encoding.fromLabel resolves labels. EBCDIC and the Korean encodings outside the standard are reached only by naming them in code. Glibc is glibc 2.44's charsets, and only Glibc.lookup resolves glibc's names. Nothing outside the standard goes into Encoding. GLOSSARY.md has the words for these, and docs/adr/ has the reasons.
  • Tables come from published sources. The files in data/ are copies of what the WHATWG and Unicode.org publish, kept byte for byte, and src/tables/ is generated from them by zig build gen-tables. Never edit a generated table by hand.
  • glibc is checked against, never copied from. A glibc charset is built from a table the library already has, plus exceptions observed from glibc and written in our own words (src/codecs/glibc_single_byte.zig shows the shape). The one thing taken from glibc is the list of its names, data/glibc-names.txt, which tools/glibc_names.py writes.
  • A Glibc member matches glibc exactly. Adding one means tools/crosscheck_glibc.py finds no difference on any input. A charset that is close but not exact stays out, and Glibc.lookup reports it as unsupported. Every exception goes in the README's list of differences.
  • The WHATWG codecs do not change for glibc's sake. A glibc variant is a flag on a shared codec, or a codec of its own, and tools/crosscheck.py should print exactly what it printed before.
  • Tests do not read the tables they test. A conformance test's expected value comes from the standard's worked examples or from arithmetic done by hand. The crosschecks are what cover every input.

Moving to a new glibc #

The glibc tools refuse to run on any glibc but the one in GLIBC_VERSION, so a nixpkgs update that moves glibc fails CI on purpose. To move:

  1. Change GLIBC_VERSION in tools/glibc_names.py and tools/crosscheck_glibc.py.
  2. Run tools/glibc_names.py and zig build gen-tables, and read the diff to data/glibc-names.txt.
  3. Run tools/crosscheck_glibc.py. Fix or remove any charset that no longer matches.
  4. Update the version wherever the README, src/glibc.zig and GLOSSARY.md name it.

Licensing #

Code is MIT, and every file carries an SPDX header or is covered by REUSE.toml. A new data file from somewhere else needs an annotation there giving its own licence, as the WHATWG and Unicode files have.