Commit Graph

116 Commits

Author SHA1 Message Date
antecrescent ecd4c3f172
Mention YARN_BINARY in documentation (#2851) 2023-11-27 11:50:23 +10:00
Damien Elmes f3d8618728 Tweaks to Windows build instructions 2023-11-20 11:59:08 +10:00
Gulshan Singh a230c754b9
Add Sphinx documentation generation functionality (#2720)
* Add Sphinx documentation generation functionality

* sphinx-docs -> python/sphinx

* Use ninja instead of make

* Update copyright info in sphinx docs

* Run sphinx-apidoc before building Sphinx docs

* Cleanup Sphinx path insertion

* Don't write build outputs into source; use autoapi

* aqt -> _aqt

* Mention sphinx in development.md

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2023-10-13 13:03:54 +10:00
Aristotelis 51a322c77e
[Development] Specify `extra` directory as a designated ignored folder (#2593)
* Add `extra` directory as a designated ignored folder

Excludes `extra/` from version tracking, file formatters, and file checks.

* Remove pytest cache from exclusion rules

Python test discovery is easy enough to disable for the workspace in VS Code's settings and pytest does not serve any purpose in the context of the project anyway.
2023-07-27 22:27:07 +10:00
Damien Elmes 51efcabf4a Update n2 for Windows console fix; recommend it on Windows as well 2023-07-02 19:03:37 +10:00
Damien Elmes c6f429ab17 Add option to use LTO in release builds
Shrinks rslib.so from about 40MB to about 26MB, at the cost of considerably
higher build time in a release build.
2023-07-02 18:22:44 +10:00
Damien Elmes 0f079779e2 Bump n2 rev for CI fix, and mention it in development.md 2023-06-19 15:34:03 +10:00
Damien Elmes 09c57369ad Migrate pylib/anki qt/aqt to group syntax (eg pylib:anki) 2023-06-15 17:17:55 +10:00
Damien Elmes 45f5709214
Migrate to protobuf-es (#2547)
* Fix .no-reduce-motion missing from graphs spinner, and not being honored

* Begin migration from protobuf.js -> protobuf-es

Motivation:

- Protobuf-es has a nicer API: messages are represented as classes, and
fields which should exist are not marked as nullable.
- As it uses modules, only the proto messages we actually use get included
in our bundle output. Protobuf.js put everything in a namespace, which
prevented tree-shaking, and made it awkward to access inner messages.
- ./run after touching a proto file drops from about 8s to 6s on my machine. The tradeoff
is slower decoding/encoding (#2043), but that was mainly a concern for the
graphs page, and was unblocked by
37151213cd

Approach/notes:

- We generate the new protobuf-es interface in addition to existing
protobuf.js interface, so we can migrate a module at a time, starting
with the graphs module.
- rslib:proto now generates RPC methods for TS in addition to the Python
interface. The input-arg-unrolling behaviour of the Python generation is
not required here, as we declare the input arg as a PlainMessage<T>, which
marks it as requiring all fields to be provided.
- i64 is represented as bigint in protobuf-es. We were using a patch to
protobuf.js to get it to output Javascript numbers instead of long.js
types, but now that our supported browser versions support bigint, it's
probably worth biting the bullet and migrating to bigint use. Our IDs
fit comfortably within MAX_SAFE_INTEGER, but that may not hold for future
fields we add.
- Oneofs are handled differently in protobuf-es, and are going to need
some refactoring.

Other notable changes:

- Added a --mkdir arg to our build runner, so we can create a dir easily
during the build on Windows.
- Simplified the preference handling code, by wrapping the preferences
in an outer store, instead of a separate store for each individual
preference. This means a change to one preference will trigger a redraw
of all components that depend on the preference store, but the redrawing
is cheap after moving the data processing to Rust, and it makes the code
easier to follow.
- Drop async(Reactive).ts in favour of more explicit handling with await
blocks/updating.
- Renamed add_inputs_to_group() -> add_dependency(), and fixed it not adding
dependencies to parent groups. Renamed add() -> add_action() for clarity.

* Remove a couple of unused proto imports

* Migrate card info

* Migrate congrats, image occlusion, and tag editor

+ Fix imports for multi-word proto files.

* Migrate change-notetype

* Migrate deck options

* Bump target to es2020; simplify ts lib list

Have used caniuse.com to confirm Chromium 77, iOS 14.5 and the Chrome
on Android support the full es2017-es2020 features.

* Migrate import-csv

* Migrate i18n and fix missing output types in .js

* Migrate custom scheduling, and remove protobuf.js

To mostly maintain our old API contract, we make use of protobuf-es's
ability to convert to JSON, which follows the same format as protobuf.js
did. It doesn't cover all case: users who were previously changing the
variant of a type will need to update their code, as assigning to a new
variant no longer automatically removes the old one, which will cause an
error when we try to convert back from JSON. But I suspect the large majority
of users are adjusting the current variant rather than creating a new one,
and this saves us having to write proxy wrappers, so it seems like a
reasonable compromise.

One other change I made at the same time was to rename value->kind for
the oneofs in our custom study protos, as 'value' was easily confused
with the 'case/value' output that protobuf-es has.

With protobuf.js codegen removed, touching a proto file and invoking
./run drops from about 8s to 6s.

This closes #2043.

* Allow tree-shaking on protobuf types

* Display backend error messages in our ts alert()

* Make sourcemap generation opt-in for ts-run

Considerably slows down build, and not used most of the time.
2023-06-14 22:47:37 +10:00
Damien Elmes ac7b63e81b Mention that checkout path should not include spaces 2023-05-01 15:39:03 +10:00
Mani 5bc75a7885
Use a ninja variable for node binary (#2346)
* Use a ninja variable for node binary

* Update docs (dae)
2023-01-25 21:05:11 +10:00
Mani da7d4dd2fc
Use a ninja variable for Protoc binary (#2345)
* Use a ninja variable for Protoc binary

* fix whitespace
2023-01-23 20:44:47 +10:00
Damien Elmes cf45cbf429
Rework syncing code, and replace local sync server (#2329)
This PR replaces the existing Python-driven sync server with a new one in Rust.
The new server supports both collection and media syncing, and is compatible
with both the new protocol mentioned below, and older clients. A setting has
been added to the preferences screen to point Anki to a local server, and a
similar setting is likely to come to AnkiMobile soon.

Documentation is available here: <https://docs.ankiweb.net/sync-server.html>

In addition to the new server and refactoring, this PR also makes changes to the
sync protocol. The existing sync protocol places payloads and metadata inside a
multipart POST body, which causes a few headaches:

- Legacy clients build the request in a non-deterministic order, meaning the
entire request needs to be scanned to extract the metadata.
- Reqwest's multipart API directly writes the multipart body, without exposing
the resulting stream to us, making it harder to track the progress of the
transfer. We've been relying on a patched version of reqwest for timeouts,
which is a pain to keep up to date.

To address these issues, the metadata is now sent in a HTTP header, with the
data payload sent directly in the body. Instead of the slower gzip, we now
use zstd. The old timeout handling code has been replaced with a new implementation
that wraps the request and response body streams to track progress, allowing us
to drop the git dependencies for reqwest, hyper-timeout and tokio-io-timeout.

The main other change to the protocol is that one-way syncs no longer need to
downgrade the collection to schema 11 prior to sending.
2023-01-18 12:43:46 +10:00
Ren Tatsumoto 7d22053730
Mention how to fix build crash in the readme. (#2286)
* update linux.md

mention how to fix libcrypt.so.1-related build crash

* Mention Fedora as well (dae)
2022-12-30 13:10:37 +10:00
Damien Elmes fa625d7ad8
Minor Rust cleanups (#2272)
* Run cargo +nightly fmt

* Latest prost-build includes clippy workaround

* Tweak Rust protobuf imports

- Avoid use of stringify!(), as JetBrains editors get confused by it
- Stop merging all protobuf symbols into a single namespace

* Remove some unnecessary qualifications

Found via IntelliJ lint

* Migrate some asserts to assert_eq/ne

* Remove mention of node_modules exclusion

This no longer seems to be necessary after migrating away from Bazel,
and excluding it means TS/Svelte files can't be edited properly.
2022-12-16 21:40:27 +10:00
Yoshi ef3cfc561c
Facilitate hook updating/replacement (#2213)
* Facilitate updating of hooks

- Add instructions in contributing.md
- Change addon_config_editor_will_update_json hook to work with the new
  hookslib code

* Fix typo in docs

* Always run replaced hook

* Use lowercase list for typing

* Forbid defining both a replaced and a legacy hook
2022-12-07 15:39:57 +10:00
Damien Elmes a70f8d4dd5 Fix TTS handling on Windows
Also update to winsdk, which unblocks Python updates on Windows
2022-11-29 13:04:51 +10:00
Damien Elmes 1e573de63a Update Linux docs 2022-11-27 16:45:54 +10:00
Damien Elmes 5e0a761b87
Move away from Bazel (#2202)
(for upgrading users, please see the notes at the bottom)

Bazel brought a lot of nice things to the table, such as rebuilds based on
content changes instead of modification times, caching of build products,
detection of incorrect build rules via a sandbox, and so on. Rewriting the build
in Bazel was also an opportunity to improve on the Makefile-based build we had
prior, which was pretty poor: most dependencies were external or not pinned, and
the build graph was poorly defined and mostly serialized. It was not uncommon
for fresh checkouts to fail due to floating dependencies, or for things to break
when trying to switch to an older commit.

For day-to-day development, I think Bazel served us reasonably well - we could
generally switch between branches while being confident that builds would be
correct and reasonably fast, and not require full rebuilds (except on Windows,
where the lack of a sandbox and the TS rules would cause build breakages when TS
files were renamed/removed).

Bazel achieves that reliability by defining rules for each programming language
that define how source files should be turned into outputs. For the rules to
work with Bazel's sandboxing approach, they often have to reimplement or
partially bypass the standard tools that each programming language provides. The
Rust rules call Rust's compiler directly for example, instead of using Cargo,
and the Python rules extract each PyPi package into a separate folder that gets
added to sys.path.

These separate language rules allow proper declaration of inputs and outputs,
and offer some advantages such as caching of build products and fine-grained
dependency installation. But they also bring some downsides:

- The rules don't always support use-cases/platforms that the standard language
tools do, meaning they need to be patched to be used. I've had to contribute a
number of patches to the Rust, Python and JS rules to unblock various issues.
- The dependencies we use with each language sometimes make assumptions that do
not hold in Bazel, meaning they either need to be pinned or patched, or the
language rules need to be adjusted to accommodate them.

I was hopeful that after the initial setup work, things would be relatively
smooth-sailing. Unfortunately, that has not proved to be the case. Things
frequently broke when dependencies or the language rules were updated, and I
began to get frustrated at the amount of Anki development time I was instead
spending on build system upkeep. It's now about 2 years since switching to
Bazel, and I think it's time to cut losses, and switch to something else that's
a better fit.

The new build system is based on a small build tool called Ninja, and some
custom Rust code in build/. This means that to build Anki, Bazel is no longer
required, but Ninja and Rust need to be installed on your system. Python and
Node toolchains are automatically downloaded like in Bazel.

This new build system should result in faster builds in some cases:

- Because we're using cargo to build now, Rust builds are able to take advantage
of pipelining and incremental debug builds, which we didn't have with Bazel.
It's also easier to override the default linker on Linux/macOS, which can
further improve speeds.
- External Rust crates are now built with opt=1, which improves performance
of debug builds.
- Esbuild is now used to transpile TypeScript, instead of invoking the TypeScript
compiler. This results in faster builds, by deferring typechecking to test/check
time, and by allowing more work to happen in parallel.

As an example of the differences, when testing with the mold linker on Linux,
adding a new message to tags.proto (which triggers a recompile of the bulk of
the Rust and TypeScript code) results in a compile that goes from about 22s on
Bazel to about 7s in the new system. With the standard linker, it's about 9s.

Some other changes of note:

- Our Rust workspace now uses cargo-hakari to ensure all packages agree on
available features, preventing unnecessary rebuilds.
- pylib/anki is now a PEP420 implicit namespace, avoiding the need to merge
source files and generated files into a single folder for running. By telling
VSCode about the extra search path, code completion now works with generated
files without needing to symlink them into the source folder.
- qt/aqt can't use PEP420 as it's difficult to get rid of aqt/__init__.py.
Instead, the generated files are now placed in a separate _aqt package that's
added to the path.
- ts/lib is now exposed as @tslib, so the source code and generated code can be
provided under the same namespace without a merging step.
- MyPy and PyLint are now invoked once for the entire codebase.
- dprint will be used to format TypeScript/json files in the future instead of
the slower prettier (currently turned off to avoid causing conflicts). It can
automatically defer to prettier when formatting Svelte files.
- svelte-check is now used for typechecking our Svelte code, which revealed a
few typing issues that went undetected with the old system.
- The Jest unit tests now work on Windows as well.

If you're upgrading from Bazel, updated usage instructions are in docs/development.md and docs/build.md. A summary of the changes:

- please remove node_modules and .bazel
- install rustup (https://rustup.rs/)
- install rsync if not already installed  (on windows, use pacman - see docs/windows.md)
- install Ninja (unzip from https://github.com/ninja-build/ninja/releases/tag/v1.11.1 and
  place on your path, or from your distro/homebrew if it's 1.10+)
- update .vscode/settings.json from .vscode.dist
2022-11-27 15:24:20 +10:00
Stefan Kangas 5551a37f03
Fix typos (#2210) 2022-11-24 20:18:57 +10:00
Abdo c2a3e67b0b
Fix command to run Rust tests in docs (#2147) 2022-10-28 21:42:32 +10:00
RumovZ 52b4e3ad16
Document Protocol Buffers used in Anki (#2042)
* Document Protocol Buffers used in Anki

* Fix typos

* Correct notes about Rust crate
2022-09-01 22:01:14 +10:00
Aristotelis 46746e3e34
Move VS Code settings to .vscode.dist and update docs (#2029) 2022-08-24 16:08:58 +10:00
phwoo 21cc284abe
Updated permalink to architecture visualization (#2001)
* updated permalink to architecture visualization

* updated architecture visualization link
2022-08-05 14:47:38 +10:00
Damien Elmes 1b48d3e3d1 Mention eslint --fix in docs
https://github.com/ankitects/anki/pull/1847#issuecomment-1120954217
2022-05-10 11:39:15 +10:00
Damien Elmes 776631bbf5 Automatically clean up stale files on TS build error 2022-02-25 12:25:55 +10:00
RumovZ 52865cf284
Cleanup (#1676)
* Pass parents to timer() in mediasync.py

* Fix typo

* Fix deleted widget in `closeTooltip()`

* Pass parent in recursive `progress.timer()`
2022-02-22 20:09:43 +10:00
RumovZ 5e1432ff6b
Mention some PowerShell specific issues (#1675)
* Mention Git for Windows as alternative

* Mention powershell path issue
2022-02-18 19:34:44 +10:00
Damien Elmes 95dbf30fb9 updates to the build process and binary bundles
All platforms:

- rename scripts/ to tools/: Bazelisk expects to find its wrapper script
(used by the Mac changes below) in tools/. Rather than have a separate
scripts/ and tools/, it's simpler to just move everything into tools/.
- wheel outputs and binary bundles now go into .bazel/out/dist. While
not technically Bazel build products, doing it this way ensures they get
cleaned up when 'bazel clean' is run, and it keeps them out of the source
folder.
- update to the latest Bazel

Windows changes:

- bazel.bat has been removed, and tools\setup-env.bat has been added.
Other scripts like .\run.bat will automatically call it to set up the
environment.
- because Bazel is now on the path, you can 'bazel test ...' from any
folder, instead of having to do \anki\bazel.
- the bat files can handle being called from any working directory,
so things like running "\anki\tools\python" from c:\ will work.
- build installer as part of bundling process

Mac changes:

- `arch -arch x86_64 bazel ...` will now automatically use a different
build root, so that it is cheap to switch back and forth between archs
on a new Mac.
- tools/run-qt* will now automatically use Rosetta
- disable jemalloc in Mac x86 build for now, as it won't build under
Rosetta (perhaps due to its build scripts using $host_cpu instead of
$target_cpu)
- create app bundle as part of bundling process

Linux changes:

- remove arm64 orjson workaround in Linux bundle, as without a
readily-available, relatively distro-agonstic PyQt/Qt build
we can use, the arm64 Linux bundle is of very limited usefulness.
- update Docker files for release build
- include fcitx5 in both the qt5 and qt6 bundles
- create tarballs as part of the bundling process
2022-02-10 19:23:07 +10:00
Damien Elmes 4653873db9 add file layout visualization from aracelix
https://github.com/ankitects/anki/issues/1010#issuecomment-1032248683
2022-02-09 13:24:07 +10:00
Damien Elmes 78ac1fe3cc split IDE docs into separate file; recommend VS Code 2022-01-24 19:46:09 +10:00
Damien Elmes 37771fac7e clarify wheel building and mention how to free up space 2022-01-24 16:51:29 +10:00
Damien Elmes 23f0fa23b9 fix formatting in docs/ 2022-01-21 21:50:20 +10:00
roxgib 578ef6b2bc
Remove outdated info about VS Code (#1614)
Pylance is now the default for Python on VS Code, so it should no longer be necessary to suggest switching to it.
2022-01-21 21:31:23 +10:00
Damien Elmes 4c49337700 tweaks to development.md 2021-12-24 14:12:36 +10:00
Damien Elmes 04fee0dc10 update Visual Studio instructions 2021-11-29 12:32:39 +10:00
Damien Elmes fc93a3d4d7 Python 3.10 not usable on Windows
No winrt wheel is available yet

https://forums.ankiweb.net/t/editor-did-init-left-buttons-hook-is-not-working/14703
2021-11-08 19:23:00 +10:00
Damien Elmes 7f0384b968 mention glibc requirements
https://forums.ankiweb.net/t/wheel-not-supported-on-the-platform-which-built-it/14432
2021-10-26 18:08:08 +10:00
Damien Elmes ab01677ff1 add dockerfiles for amd64 and arm64 builds 2021-10-23 20:42:16 +10:00
Damien Elmes a80a267cff //ts:format now runs on current working directory, instead of entire repo 2021-10-23 15:48:33 +10:00
Damien Elmes 3b8b71b815 minor tweak to new-platforms.md, and run prettier on docs 2021-10-23 15:40:45 +10:00
Damien Elmes ee644e08a3 fixes and documentation for Linux ARM64
+ add qt6 dep to wheel install docs
+ remove x86_64 constraint on orjson
2021-10-23 15:22:24 +10:00
Damien Elmes ad2c17aced docs: the old TS flakiness should be gone, but renames are a problem 2021-10-18 22:24:06 +10:00
Damien Elmes e58646909f get PyQt working directly with ./run on macOS
It's no longer necessary to copy everything into bazel-copy, and you
can safely remove that folder.
2021-10-16 18:07:29 +10:00
Damien Elmes bdbcb6d7aa default to a vendored copy of Python
Brings Python in line with our other dependencies, and means users
no longer need to install it prior to building, or deal with
issues caused by having the wrong version available.
2021-10-15 22:14:05 +10:00
Jakub Kaczmarzyk 183e45c698
replace dockerfile (#1410)
* replaces Dockerfile using bazel-based build system

This commit updates the Dockerfile to work with anki's bazel-based build
system.

The anki Dockerfile was originally added in
https://github.com/ankitects/anki/pull/753 back in September 2020. The
file was moved to `docs/Dockerfile` in
0d354da93a, with a note that the file had
to be updated to work with anki's updated build system. The file
`docs/Dockerfile` was removed in
7cd2e9618f.

* install setuptools and wheel + xkb libraries

* install anki virtual env in fresh base image

* move Dockerfile out of root directory

* add readme file for dockerized anki
2021-10-15 10:41:15 +10:00
Gesa Stupperich 5d093e1142
Mac bazelrc build tip (#1418)
* Copy build tip from Linux to Mac instructions

* Update build tip

* Accept BSD 3 clause license
2021-10-12 16:58:42 +10:00
Damien Elmes 1e8b02592d mention missing libs in linux.md 2021-10-12 16:19:27 +10:00
Damien Elmes 46b80ca773 move node_modules into root folder [action required]
Recommend removing ts/node_modules folder before attempting to
build after this update.

This moves ts/node_modules into the root of the project to work around
https://github.com/ankitects/anki/pull/1405#issuecomment-936213861

Also fixes the sass errors shown when running scripts/svelte-check
2021-10-07 11:42:27 +10:00
Damien Elmes e9c7b2287f bump minimum Python to 3.9 2021-10-04 15:05:15 +10:00