Commit Graph

33 Commits

Author SHA1 Message Date
Damien Elmes
1a868bcaaf Ensure runner gets rebuilt in Mac CI 2024-04-17 20:23:50 +10:00
Damien Elmes
1a7f8b4fdf Fix cargo deny in CI
The 0.14.12 release appears to have broken "-A duplicate". Fix by
updating our checks to use the latest release/format.

Also update iana-time-zone, which was yanked, and ignore safemem,
which is only used when bundling.
2024-02-24 15:22:57 +07: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
09c57369ad Migrate pylib/anki qt/aqt to group syntax (eg pylib:anki) 2023-06-15 17:17:55 +10:00
Damien Elmes
15dcb09036
Detect incorrect usage of triple slash in TypeScript (#2524)
* Migrate check_copyright to Rust

* Add a new lint to check accidental usages of /// in ts/svelte comments

* Fix a bunch of incorrect jdoc comments

* Move contributor check into minilints

Will allow users to detect the issue locally with './ninja check'
before pushing to CI.

* Make Cargo.toml consistent with other crates
2023-05-26 12:49:44 +10:00
Damien Elmes
c12689160f Support scheduled Rust cache clearing 2023-04-26 17:19:00 +10:00
Damien Elmes
282b051c46 Cleanup tmp files after CI run 2023-04-26 17:11:24 +10:00
Damien Elmes
7f71277514 Whitelist dependabot 2023-01-07 09:53:29 +10:00
Damien Elmes
670bf1ef9a Fix cargo-deny exclusion 2022-11-30 13:52:49 +10:00
Damien Elmes
526707473a Enable cargo-deny in CI
We have quite a few duplicate crate deps at the moment, so those warnings
are currently disabled.
2022-11-30 13:20:50 +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
742e4a5cd2 Make build step optional in Linux docker containers 2022-03-09 18:20:13 +10:00
Damien Elmes
776631bbf5 Automatically clean up stale files on TS build error 2022-02-25 12:25:55 +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
f4ec3bb84a move wheel build test into mac CI; enable symlinks in Linux CI 2022-01-23 19:18:46 +10:00
Damien Elmes
4f64494573 fix linkchecker invocation in CI 2021-12-20 17:41:13 +10:00
Damien Elmes
b714974464 tweak mac CI state folder 2021-12-13 13:12:59 +10:00
Damien Elmes
1fb026cce9 remove superfluous label in Windows CI 2021-12-10 10:50:57 +10:00
Damien Elmes
c51b1c7180 skip superfluous build step in CI; it should be moderately faster 2021-12-09 18:55:19 +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
d73852f272 use separate integration test for links
If we run into issues with unreliable network connections in the future,
we'll be able to mark the test as flaky so Bazel can retry it multiple
times.
2021-07-24 10:12:25 +10:00
Damien Elmes
be140a833a add header check to Linux CI 2021-04-13 23:08:57 +10:00
Damien Elmes
7fbd7ec763 build wheels in Linux CI 2020-12-21 19:31:15 +10:00
Damien Elmes
c72e3987d3 add missing '-' to section marker 2020-12-16 12:02:49 +10:00
Damien Elmes
dcb85a9bb8 remove set -x from Buildkite scripts 2020-12-16 12:01:21 +10:00
Damien Elmes
ed607782de add section markers to Buildkite 2020-12-16 11:59:07 +10:00
Damien Elmes
46b3b1938d add disk and repo cache to Linux CI 2020-12-10 08:49:37 +10:00
Damien Elmes
dffbe2bfdf move author check to top; add hint about GitHub UI 2020-12-09 21:15:38 +10:00
Damien Elmes
f2db4f4996 move contributor check into Buildkite 2020-12-09 21:01:11 +10:00
Damien Elmes
f42ea874fb tweak Windows CI entrypoint 2020-12-09 20:09:07 +10:00
Damien Elmes
0afdbdf7e0 move Linux & Mac tests to Buildkite 2020-12-08 22:23:27 +10:00