Commit Graph

44 Commits

Author SHA1 Message Date
Aristotelis
2270ff425a
Add dev tools for live-reloading Anki's web views (#2151)
* Add dev tools for live-reloading the web stack while running Anki

* Handle CDP connection errors more graciously

* Include sass in web stack watchers

* Refactor monitored folder and event definition

* Switch to more specific build target

Thanks to @hikaru-y

* Add PyChromeDevTools to dev requirements

* Update rebuild-web for ninja

* Satisfy mypy

* Remove ts-watch

Superseded by web-watch (the version here was also still based around bazel)

* Simplify calls to other build tools

Given that `./ninja qt/aqt` has to be run from the project root anyways, it doesn't make sense to use calls relative to `rebuild-web` in an ill-guided effort to lower dependencies on hard-coded paths.

* Remove remaining script-relative tool path
2023-01-03 11:55:58 +10:00
RumovZ
55f27779cf Add local copy of percent_encoding crate 2022-12-09 11:46:00 +01:00
Damien Elmes
7f5e3c8106 Add env var to enable sourcemaps
They slow down the build, so are not on by default.
2022-12-04 11:37:16 +10:00
Damien Elmes
e3167c4e3c Update incompatible crates 2022-11-30 12:38:10 +10:00
Damien Elmes
1aae621549 Update dockerfile
- Bazel no longer required
- Python no longer required
- Add back the import check step that got lost at one point
2022-11-27 16:45:50 +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
Damien Elmes
22f54c2c01 Protobuf now ships with a macOS arm64 wheel 2022-10-21 21:13:28 +10:00
Damien Elmes
f855fc67ad Update macOS bundle to Qt 6.4.0
This bumps the minimum OS version to 10.14
2022-10-10 12:56:47 +10:00
Damien Elmes
031fc625fd Update Mac build to Qt 6.3 2022-04-20 21:33:31 +10:00
Damien Elmes
776631bbf5 Automatically clean up stale files on TS build error 2022-02-25 12:25:55 +10:00
Damien Elmes
ac4a1cd8e0 strip fully qualified bazel tools path
tentative fix for https://forums.ankiweb.net/t/anki-2-1-50-beta-3/17501/17
2022-02-14 18:46:50 +10:00
Abdo
af93d8a124
Fix setup-env.bat (#1659)
* Do not assume bazel is in the C drive

* Quote PATH

* make path separator consistent (dae)
2022-02-12 10:10:24 +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
b23b6fbe35 move the separate components back into this monorepo
Earlier today I pushed a change that split this code up into multiple
repos, but that has proved to complicate things too much. So we're
back to a single repo, except the individual submodules are better
separated than they were before.

The README files need updating again; I will push them out soon.

Aside from splitting out the different modules, the sound code has
moved from from anki to aqt.
2020-01-02 19:43:19 +10:00
Damien Elmes
2280a0e58a switch to nose2; nose looks to be on the way out 2019-12-24 19:57:55 +10:00
Damien Elmes
b5fe37d171 hide errors when sudo required for typecheck setup 2019-12-20 10:39:24 +10:00
Damien Elmes
71c0e23b77 do typecheck setup as part of prereqs install 2019-12-18 17:18:24 +10:00
Damien Elmes
52254e0176 avoid sudo in typecheck setup if possible 2019-12-18 17:14:44 +10:00
Damien Elmes
c1cbab0d23 avoid running checks/builds when nothing has changed
with some defaults taken from https://tech.davis-hansson.com/p/make/
2019-12-18 11:12:17 +10:00
Damien Elmes
da2ba2366b make sure failures stop the build 2019-12-16 21:04:32 +10:00
Damien Elmes
86d6352047 add pytype conf file 2019-12-16 18:27:26 +10:00
Damien Elmes
54bfb486e1 enable pytype for anki/ 2019-12-16 17:38:43 +10:00
Damien Elmes
b88de95cd8 bundle sip-generated stubs
the PyQt5-stubs package that's floating around depends on an old
Qt, and throws a bunch of errors
2019-12-16 09:59:18 +10:00
Damien Elmes
c508498ba8 add aqt/ 2019-12-16 08:51:38 +10:00
Damien Elmes
37a239cf38 add basic type checking for anki/ 2019-12-16 08:17:28 +10:00
Damien Elmes
46fa0c2d7b reduce test verbosity 2019-03-05 08:57:00 +10:00
Damien Elmes
8a2a4d827f lint in travis 2019-03-04 17:58:50 +10:00
Damien Elmes
126cbd6534 enable some warnings in pylint 2019-03-04 17:27:39 +10:00
Damien Elmes
ebdd8dae4b tidy up unused imports 2019-03-04 17:25:19 +10:00
Damien Elmes
dfbbeab8db pylint is confused by pyqt subscript notation 2019-03-04 12:25:54 +10:00
Damien Elmes
4a9bb2d396 fix qt-related error messages 2019-03-04 11:43:04 +10:00
Damien Elmes
d802a53161 explicitly import _ in forms/ 2019-03-04 11:34:30 +10:00
Damien Elmes
10ab258501 add basic error checking via pylint 2019-03-04 11:21:20 +10:00
Damien Elmes
0d0c6f94e0 use nosetests3 if available 2018-10-04 17:56:50 +10:00
Damien Elmes
591f5eaeef allow for slow machines
https://anki.tenderapp.com/discussions/ankidesktop/27674-possible-race-condition-in-testtest_cardstest_delete-works-in-isolation
2018-04-12 17:59:51 +10:00
Daniel Drake
4cee3807ff runanki.system: fix prefix at install time
Currently the Makefile lets you choose your own PREFIX, but
the installed runanki.system always hardcodes the prefix as /usr.

Fix runanki.system at install time to install into the designated
PREFIX.
2018-03-08 23:22:41 -06:00
Damien Elmes
d0929e5bab run unit tests in parallel 2017-10-05 14:17:12 +10:00
Damien Elmes
ca9a6fb86c fix make install for source 2017-01-17 11:25:55 +10:00
Damien Elmes
de7e40537d port majority of code to qt5.5+
- a few issues to work out still, and editor changes not done yet
- for communication between webengine and python code, we set window
.location to 'http://anki/<something>' - the leading http is
necessary for qt to call the link handler, which was introduced
in qt5.5
- the designer files now use a promoted qobject to create instances
of AnkiWebView
- we use the css zoom property to alter webengine font size based on
system dpi
- prefs and addons folder stored in new location (at least for now)
2016-05-31 18:51:40 +10:00
Damien Elmes
15b349e3a8 start port to python 3
unit tests pass and main screens of GUI load
2016-05-12 14:45:35 +10:00
WOO-CHEOL CHOI
67f935bf1f PYTHONPATH added when tests script run 2015-12-02 16:02:42 +09:00
Damien Elmes
4a05c736fa tweak build_ui to handle qt5 ui translations 2014-03-30 10:19:48 +09:00
Damien Elmes
5c27e54f0a fix unit tests 2012-12-21 20:17:31 +09:00
Damien Elmes
d477df8c28 merged libanki and ankiqt into single distro 2012-12-21 16:51:59 +09:00