Commit graph

5 commits

Author SHA1 Message Date
Huang Xin
5d030abf32
fix(build): repair the Docker and Nix builds after #6368 (#6379)
* fix(build): repair the Docker and Nix builds after #6368

Two main-branch builds broke on 8750c310 and both are fallout from that PR.

**Docker** (`pnpm build-web`: "Can't resolve '@pdfjs/pdf.min.mjs'",
"Can't resolve '@simplecc/simplecc_wasm'"). `setup-vendors` runs in the
`dependencies` stage and its output is not in the build context, so every
directory it creates needs an explicit `COPY --from=dependencies`. Splitting
the bundler-imported modules out of `public/vendor` into `vendor/` left the
new directory with no COPY line. The test derives the expected roots from the
`prepare-vendor` script, so adding another one fails until the Dockerfile
copies it.

**Nix** ("no matching package named `sentry-debug-images` found"). The Linux
CEF build vendors from `Cargo.cef.lock`, which `nix/package.nix` copies over
`Cargo.lock`, and that second lock never learned about the two crates the
sentry `debug-images` feature pulls in. Added `findshlibs` and
`sentry-debug-images` there, plus the dependency entry on `sentry`; both need
only packages the lock already had.

This is also why `nix-deps-check` stayed green on #6368: it hashes
`Cargo.cef.lock`, which that PR did not touch, so the stale vendor set only
surfaced when the full Nix build ran on main.

`cargoHash` is updated in a follow-up commit from the hash the deps-check
prints, since the vendor contents change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* style: format the vendor-root docker test

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(nix): update cargoHash for the new sentry debug-images crates

The vendor set gained findshlibs and sentry-debug-images, so the pinned
hash moved. Value taken from the nix-deps-check run on this PR:

  specified: sha256-EPNbiv0YJ79rqBHFCO5gjQwt9Vn1v9HV0ZfH7f2Eo/E=
  got:       sha256-8MIkn2N65P87tG0RncOQtH01SYfRUM4qB6rOzd+fwwQ=

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* refactor: one vendor dir, with the bundler importing from packages

#6368 split the vendored modules into a second `vendor/` directory to stop
them shipping twice (Tauri embeds every published file, and `public/` is
published whole). Two vendor directories is the wrong shape, and the copies
were never needed: the aliases can resolve straight at the sources, which is
how `jieba-wasm` has always been imported.

  @pdfjs/*    -> packages/foliate-js/node_modules/pdfjs-dist/legacy/build/*
  @simplecc/* -> packages/simplecc-wasm/dist/web/*

`public/vendor/pdfjs` now holds only what the reader fetches by URL at
runtime — the worker, the WASM decoders, cmaps, standard fonts and the layer
CSS — and `vendor/` is gone, along with `copy-pdfjs-lib`, `copy-simplecc`,
`setup-simplecc`, its Dockerfile COPY and its worktree copy.

Two details this turned up:

- The @pdfjs alias needs an explicit `declare module`. TypeScript inferred
  types for the minified JS while it sat inside the app, but skips JavaScript
  under node_modules, and pdfjs-dist ships `pdf.d.mts`, not the
  `pdf.min.d.mts` that would sit beside the minified build. Only the import's
  side effect is used, so the declaration is bare.
- `packages/simplecc-wasm` is a submodule the worktree script skips, so the
  script now copies its committed `dist/web` into a new worktree instead of a
  vendor directory.

A true `import ... from 'simplecc-wasm'`, matching jieba exactly, would need a
change in that submodule: its `exports` map points at `pkg/`, which is build
output and not committed (only `dist/web` is), and the map forbids other
subpaths.

Verified with a real build: modules resolve with no `vendor/` present,
`out/vendor` holds only pdfjs, `pdf.min.mjs` is bundled into a chunk and not
published, and both jieba and simplecc WASM are emitted once each.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* docs: say why the @pdfjs alias points at the package, not public/

The comments still described a vendored copy. Record the constraint
instead: a module the bundler imports must not also be published, or
Tauri embeds it twice.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* test: drop the vendor/docker config assertions

These assert on config files rather than behaviour: the alias-target test,
the Dockerfile vendor-COPY test, and the pdfjs wasm copy-script test.

The SELF_HOSTED default check in docker-image-defaults.test.ts stays; it
predates this work (#6100) and guards runtime behaviour of the published
image rather than a config shape.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 15:13:35 +02:00
Huang Xin
8750c31043
perf(android): cut the arm64 apk from 90MB to 57MB (#6368)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
* perf(android): cut the arm64 apk from 90MB to 57MB

The Rust library is 95% of the APK, and most of what it carried was not
code. Measured on an aarch64 release build: 89.7MB -> 57.5MB.

- Build `release` with fat LTO and one codegen unit. Cross-crate inlining
  cuts .text by 5.2MB and the unwind/exception tables by 2.1MB, at the
  cost of a longer final link.
- Strip the packaged library. AGP's own strip step only drops the
  .debug_* sections, so 22MB of symbol tables (10MB after LTO) reached
  every download. The strip runs on AGP's output, so `target/` keeps the
  unstripped copy, which the release and nightly workflows now upload to
  Sentry as debug files; Rust frames stay symbolicated. Android builds
  also link with a build id, which is how Sentry matches them, and the
  `debug-images` feature attaches the loaded modules to each event.
- Stop shipping jieba's WASM twice (2.7MB). The wasm-bindgen glue
  defaults to the file the bundler already emits; pointing `init()` at a
  public/vendor copy embedded both.
- Keep the browser-only turso WASM out of native builds (3.3MB). The
  alias that excluded it still named `@tursodatabase/database-wasm`,
  which the web database service stopped importing in #4086.

simplecc is still embedded twice (0.4MB): its glue is imported through
the `@simplecc/*` path alias out of public/vendor, so deduping it means
moving that directory.

Verified: the built APK's library carries no symbol tables and a build
id; `target/` keeps its; the bundle requests exactly the one embedded
jieba asset key and no /vendor/jieba path; the turso WASM is absent from
`out/`. The APK installs and runs on a Xiaomi 2211133C, library and a
Chinese book render, and RSVP runs on it. Whether jieba's WASM is
actually fetched at runtime is NOT verified: release webviews are not
inspectable and the fallback to Intl.Segmenter is silent.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* perf(android): drop fat LTO, codegen-units=1 is the whole win

The previous commit credited the code-size saving to fat LTO. That was
wrong. Measured on aarch64-linux-android with the flags rustc actually
received (`cargo build -v`):

  codegen-units=16, lto=false   .text 29.66MB  .eh_frame 3.69  .except 2.51
  codegen-units=1,  lto=off     .text 24.43MB  .eh_frame 2.28  .except 1.84
  codegen-units=1,  lto=thin    .text 24.43MB  .eh_frame 2.28  .except 1.84
  codegen-units=1,  lto=fat     .text 24.44MB  .eh_frame 2.28  .except 1.84

One codegen unit accounts for all of it; LTO changes nothing once it is
set, so fat LTO was buying only link time and peak memory on every
release target. The rebuilt APK confirms it: 57.49MB without LTO against
57.50MB with it.

What `codegen-units = 1` costs, from a clean aarch64 build on an
M-series: 5m54s against 4m15s, and 3.3GB peak RSS against 2.9GB. That
answers the review's question about the 75-minute Android and 45-minute
desktop step limits in nightly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* perf: stop shipping vendored modules the bundler already embeds

Tauri embeds every file under `out/`, and `public/` is copied there whole. So
a module imported through a path alias that points into `public/` ships twice:
once bundled into a chunk, once as a published file nobody fetches. jieba cost
2.7MB that way; `@pdfjs/*` and `@simplecc/*` had the same shape.

Split the vendored assets by how they are loaded. What the reader fetches by
URL at runtime stays in `public/vendor/pdfjs` — the worker, the WASM decoders,
cmaps, standard fonts, the layer CSS, all built as runtime URLs in
foliate-js/pdf.js, which is why the bundler never emitted copies of them.
What the bundler imports moves to `vendor/` (outside `public/`):
`pdf.min.mjs` + its types, and the simplecc glue and WASM.

Measured on the embedded frontend, brotli as tauri compresses it: 23.7MB ->
16.96MB across this and the earlier jieba/turso fixes. That comes out of every
Tauri target, not just the APK.

The new test states the invariant that was broken rather than the three
symptoms: no tsconfig path alias may resolve into `public/`. It failed on
`@pdfjs/*` and `@simplecc/*` before this change.

Desktop stripping was measured and deliberately NOT done. On macOS it saves
4.76MB in the binary but only 1.44MB of DMG (36.59 -> 35.15MB), because a DMG
compresses symbol strings while an APK stores the .so uncompressed (verified:
`Stored`, 0%) — which is why Android got the full 22MB. Buying 1.4MB would
mean either a profile-level `strip`, which deletes the unstripped artifact
Sentry symbolicates Rust panics from, or pulling the release job apart from
tauri-action, which builds, bundles, signs and notarizes in one step. deb, rpm
and AppImage are compressed too, and MSVC keeps symbols in the PDB.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: init simplecc from the emitted WASM, not a URL that no longer exists

Moving the simplecc glue out of `public/` left `initSimpleCC` still asking for
`/vendor/simplecc/simplecc_wasm_bg.wasm`, a URL nothing publishes any more, so
Chinese variant conversion would fail to initialize at runtime. Caught in
review of #6368.

`init()` with no path uses the glue's default
`new URL('simplecc_wasm_bg.wasm', import.meta.url)` — the copy the bundler
emits and Tauri embeds — the same shape as the jieba fix.

The existing WASM-init test covered jieba only, which is why this slipped
through; it now covers both. Verified against a fresh build: the chunk
references `static/media/simplecc_wasm_bg.<hash>.wasm` and no runtime
`/vendor/simplecc` reference remains (the two textual hits left are the
bundled package.json script strings and a source-map path, and maps are
stripped before packaging).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 10:45:14 +02:00
Huang Xin
1a2e43e659
chore(worktree): copy src-tauri/gen/apple per-worktree so iOS builds the worktree (#4251)
Worktrees set up by `pnpm worktree:new` symlinked `src-tauri/gen/apple` back
to the bare repo. The Xcode "Run Script" build phase
(`pnpm tauri ios xcode-script`) walks up from `Readest.xcodeproj` to find
`Cargo.toml`, but the symlink target resolves to the bare repo's
`src-tauri` — so `pnpm tauri ios dev` from a worktree silently built the
bare repo's Rust source, not the worktree's.

Switch to a filtered copy. `project.yml` references `../../src` and the
xcode-script walks up to `../../Cargo.toml`; with the project copied into
the worktree, both paths resolve to the worktree's source. Mirrors what the
script already does for Android (`tauri android init` per worktree).

Skipped on the copy:

- `build/` (~300 MB of Xcode derived output)
- `Externals/<arch>/{debug,release}/` (Rust static libs — rebuilt from the
  worktree's `src-tauri` on first build; the `target/` symlink the script
  already sets up keeps the Rust object cache shared)
- per-user Xcode state (`xcuserdata`, `*.xcuserstate`)
- `Pods/` (defensive; Readest's iOS uses SPM, not Cocoapods)

Result: ~2.7 MB copy, ~30 ms locally, no `pod install`, no
`tauri ios init`. Signing config, scheme, asset catalogs and Tauri's
generated Swift glue all preserved verbatim from the bare repo.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 11:13:28 +02:00
Huang Xin
b0cc5461af
refactor(toc): cache navigable structure per book (#3869)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
* refactor(toc): cache TOC + section fragments per book

Moves the TOC regrouping and section-fragment computation out of
foliate-js/epub.js #updateSubItems into the readest client as
computeBookNav / hydrateBookNav in utils/toc.ts. The result is
persisted to Books/{hash}/nav.json — capturing the book's full
navigable structure (TOC hierarchy + sections with hierarchical
fragments). Compute once, persist locally, hydrate on subsequent
opens. Designed to serve current human-facing navigation (TOC
sidebar, progress math) and future agentic navigation (LLM-driven
seeking by structural location).

Versioned by BOOK_NAV_VERSION for forward invalidation. Existing
books regenerate transparently on next open.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: update worktree scripts

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 20:15:10 +02:00
Huang Xin
a07bf23e18
chore(docs): add worktree management for isolated PR review and feature work (#3810)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 19:42:47 +02:00