|
| 1 | +# Cross-Compilation Fix Summary |
| 2 | + |
| 3 | +## Problem |
| 4 | + |
| 5 | +Cross-compilation for aarch64-unknown-linux-gnu was failing because MuPDF's embedded font object files (.cff.o) were being compiled for x86_64 instead of aarch64, causing linker errors. |
| 6 | + |
| 7 | +## Solution |
| 8 | + |
| 9 | +Disabled embedded fonts entirely using TOFU (TOfu FOr Unicode) flags: |
| 10 | + |
| 11 | +- `CFLAGS="-DTOFU -DTOFU_CJK_LANG -DTOFU_CJK_EXT"` |
| 12 | +- Applied globally to all platforms for consistency |
| 13 | + |
| 14 | +## Changes Made |
| 15 | + |
| 16 | +### 1. Cross.toml (aarch64-linux only) |
| 17 | + |
| 18 | +- Added TOFU CFLAGS to env section |
| 19 | +- Kept make wrapper (doesn't hurt, might help other builds) |
| 20 | + |
| 21 | +### 2. release.yml (all platforms) |
| 22 | + |
| 23 | +- Added TOFU CFLAGS as global env var |
| 24 | +- Applies to macOS, Linux x86_64, and Linux aarch64 |
| 25 | + |
| 26 | +### 3. Cargo.toml |
| 27 | + |
| 28 | +- Stripped unnecessary features from mupdf dependency |
| 29 | +- Before: `["js", "xps", "svg", "cbz", "img", "html", "epub", "system-fonts"]` |
| 30 | +- After: `["system-fonts"]` |
| 31 | +- We only need PDF parsing, not rendering of other formats |
| 32 | + |
| 33 | +## Benefits |
| 34 | + |
| 35 | +### Binary Size |
| 36 | + |
| 37 | +- **Before:** ~50MB per platform |
| 38 | +- **After:** Expected <10MB per platform |
| 39 | +- Embedded CJK fonts were the bulk of the size |
| 40 | + |
| 41 | +### Build Time |
| 42 | + |
| 43 | +- Fewer features to compile |
| 44 | +- Faster cross-compilation |
| 45 | + |
| 46 | +### Consistency |
| 47 | + |
| 48 | +- Same behavior across all platforms |
| 49 | +- No embedded fonts anywhere |
| 50 | + |
| 51 | +### Security |
| 52 | + |
| 53 | +- Smaller attack surface |
| 54 | +- Removed unnecessary format parsers (JS, XPS, etc.) |
| 55 | + |
| 56 | +## Why This Works for Redline Detection |
| 57 | + |
| 58 | +Embedded fonts are for **rendering** PDFs visually. Our use case only needs: |
| 59 | + |
| 60 | +1. Parse PDF structure |
| 61 | +2. Read character positions (x, y, width, height) |
| 62 | +3. Read character colors (RGB values) |
| 63 | +4. Detect red text patterns |
| 64 | + |
| 65 | +None of this requires font rendering or embedded fonts. |
| 66 | + |
| 67 | +## Verification Needed |
| 68 | + |
| 69 | +The Rust code has a fallback for character width: |
| 70 | + |
| 71 | +```rust |
| 72 | +char_width = font_size * 0.6 * scale |
| 73 | +``` |
| 74 | + |
| 75 | +With system fonts, verify that: |
| 76 | + |
| 77 | +1. Character width estimation remains accurate |
| 78 | +2. Paired redline detection (x_gap, y_diff) still works |
| 79 | +3. Multi-line merging doesn't break |
| 80 | + |
| 81 | +Test with real PDFs on all platforms after CI passes. |
| 82 | + |
| 83 | +## Next CI Run |
| 84 | + |
| 85 | +All 9 jobs (3 platforms × 3 NIF versions) should now: |
| 86 | + |
| 87 | +1. ✅ Build successfully |
| 88 | +2. ✅ Create smaller binaries (~10MB each) |
| 89 | +3. ✅ Complete faster |
| 90 | + |
| 91 | +Monitor: https://github.com/EnaiaInc/pdf_redlines/actions |
0 commit comments