Skip to content

Building

YadeWira edited this page Nov 7, 2026 · 4 revisions

Building

It needs FreePascal 3.2 and a C compiler, clang or gcc (and Python 3 for the tests' source guards). clang's code is about 8% faster, with the same bytes: the releases use it (CC=clang ./build_c.sh build/c).

git clone https://github.com/YadeWira/PJA.git
cd PJA/pas
./build_c.sh build/c                               # the C part
fpc -O3 -dPJA_FAST -Fobuild/c pjacli.pas -opja     # the command
cd .. && ./run_tests.sh                            # every test

The C part is stream version 7's model (pjav7c.c), the work around it (pjasysc.c: BLAKE3 chunks, Huffman scans) and JPEG 2000's tier 1 and models (pjaj2k*.c). It calls no library, so build_c.sh works the same with a cross compiler: CC=x86_64-w64-mingw32-gcc, CC=i686-w64-mingw32-gcc, CC="gcc -m32", CC="clang -m32". The zpaq-std plugin links the same C since 0.6.0.

-dPJA_FAST turns off range and overflow checks in the models and encoders, where they cost 2.3x. The JPEG and JPEG-LS decoders keep their checks in every build. A build without it is the checked reference; the test suite demands that both write the same streams.

x86-64 builds use PJA's assembly routines; every other target uses the Pascal versions, which give the same results.

Windows

Cross-compiled from Linux:

  • 64-bit: the C part with CC=x86_64-w64-mingw32-gcc, then fpc -Twin64 -Px86_64 -O3 -dPJA_FAST -Fo<c dir> pjacli.pas, with the units FreePascal ships.
  • 32-bit: CC=i686-w64-mingw32-gcc, and an i386-win32 cross compiler built from FreePascal's sources.

pas/tests/windows_pkg.sh DIR builds a test package; windows.ps1, run on Windows, checks that it writes the very same .pja files as Linux.

libpja and the 7-Zip codec

pas/lib/build.sh DIR builds pja.so (or, with FPC="fpc -Twin64 -Px86_64" and CC=x86_64-w64-mingw32-gcc, pja.dll); pas/lib/test_lib.c tests it, and CI also runs it inside a real 7-Zip on Linux x86-64.

The zpaq-std plugin

pas/plugin/build.sh DIR builds pja.so and pja.dll (and, with PPC386 and RTL386 set, the 32-bit pja.dll).

Tests

./run_tests.sh runs both suites:

  • pas/run_codec_tests.sh: each codec layer, round trips, every bit flip and truncation of the first bytes of every sample and stream, and the reference, fast, no-assembly and threaded builds giving identical streams. JPEG_CORPUS=dir1:dir2 adds round trips over your own files.
  • pas/run_tests.sh: BLAKE3, every format error, more than a million damaged .pja variants, safe output writing, and the command.

Each test demands its own minimum number of cases, so one that runs none is not green. CI runs all of it on every push, on six platforms.

FreePascal pitfalls lists the traps found along the way.

Clone this wiki locally