2021-04-12 06:18:30 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
2021-04-16 15:29:21 +02:00
|
|
|
<script lang="ts">
|
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 06:24:20 +01:00
|
|
|
import * as tr from "@tslib/ftl";
|
|
|
|
import { withCollapsedWhitespace } from "@tslib/i18n";
|
|
|
|
import { getPlatformString } from "@tslib/shortcuts";
|
2022-09-05 09:20:00 +02:00
|
|
|
import { createEventDispatcher, tick } from "svelte";
|
2022-11-28 00:17:39 +01:00
|
|
|
|
update to latest rules_nodejs & switch to ts_project
ts_library() is deprecated and will presumably be dropped from a
future rules_nodejs, and it wasn't working with the jest tests
after updating, so we switch over to ts_project().
There are some downsides:
- It's a bit slower, as the worker mode doesn't appear to function
at the moment.
- Getting it working with a mix of source files and generated files
was quite tricky, especially as things behave differently on Windows,
and differently when editing with VS Code. Solved with a small patch
to the rules, and a wrapper script that copies everything into the
bin folder first. To keep VS Code working correctly as well, the built
files are symlinked into the source folder.
- TS libraries are not implicitly linked to node_modules, so they
can't be imported with an absolute name like "lib/proto" - we need
to use relative paths like "../lib/proto" instead. Adjusting "paths"
in tsconfig.json makes it work for TS compilation, but then it fails
at the esbuild stage. We could resolve it by wrapping the TS
libraries in a subsequent js_library() call, but that has the downside
of losing the transient dependencies, meaning they need to be listed
again. Alternatively we might be able to solve it in the future by
adjusting esbuild, but for now the paths have been made relative to
keep things simple.
Upsides:
- Along with updates to the Svelte tooling, Svelte typing has improved.
All exports made in a Svelte file are now visible to other files that
import them, and we no longer rebuild the Svelte files when TS files
are updated, as the Svelte files do no type checking themselves, and
are just a simple transpilation. Svelte-check now works on Windows again,
and there should be no errors when editing in VS Code after you've
built the project. The only downside seems to be that cmd+clicking
on a Svelte imports jumps to the .d.ts file instead of the original now;
presumably they'll fix that in a future plugin update.
- Each subfolder now has its own tsconfig.json, and tsc can be called
directly for testing purposes (but beware it will place build products
in the source tree): ts/node_modules/.bin/tsc -b ts
- We can drop the custom esbuild_toolchain, as it's included in the
latest rules_nodejs.
Other changes:
- "image_module_support" is moved into lib/, and imported with
<reference types=...>
- Images are now imported directly from their npm package; the
extra copy step has been removed.
Windows users may need to use "bazel clean" before building this,
due to old files lying around in the build folder.
2021-09-30 14:16:29 +02:00
|
|
|
import DropdownDivider from "../components/DropdownDivider.svelte";
|
2022-02-04 09:36:34 +01:00
|
|
|
import DropdownItem from "../components/DropdownItem.svelte";
|
2022-09-27 04:16:45 +02:00
|
|
|
import LabelButton from "../components/IconButton.svelte";
|
2022-09-05 09:20:00 +02:00
|
|
|
import IconButton from "../components/IconButton.svelte";
|
|
|
|
import Popover from "../components/Popover.svelte";
|
2022-01-24 02:43:09 +01:00
|
|
|
import Shortcut from "../components/Shortcut.svelte";
|
2022-09-05 09:20:00 +02:00
|
|
|
import WithFloating from "../components/WithFloating.svelte";
|
|
|
|
import { chevronDown } from "./icons";
|
2022-02-04 09:36:34 +01:00
|
|
|
import type { DeckOptionsState } from "./lib";
|
2021-05-18 16:32:29 +02:00
|
|
|
|
2022-11-02 12:47:07 +01:00
|
|
|
const rtl: boolean = window.getComputedStyle(document.body).direction == "rtl";
|
|
|
|
|
2021-05-25 19:18:25 +02:00
|
|
|
const dispatch = createEventDispatcher();
|
2021-04-16 15:29:21 +02:00
|
|
|
|
2021-05-25 19:18:25 +02:00
|
|
|
export let state: DeckOptionsState;
|
2021-04-16 15:29:21 +02:00
|
|
|
|
2021-06-01 07:54:07 +02:00
|
|
|
function commitEditing(): void {
|
|
|
|
if (document.activeElement instanceof HTMLElement) {
|
|
|
|
document.activeElement.blur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 09:20:00 +02:00
|
|
|
async function removeConfig(): Promise<void> {
|
2021-04-18 03:56:41 +02:00
|
|
|
// show pop-up after dropdown has gone away
|
2022-09-05 09:20:00 +02:00
|
|
|
await tick();
|
|
|
|
|
|
|
|
if (state.defaultConfigSelected()) {
|
|
|
|
alert(tr.schedulingTheDefaultConfigurationCantBeRemoved());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const msg =
|
|
|
|
(state.removalWilLForceFullSync()
|
|
|
|
? tr.deckConfigWillRequireFullSync() + " "
|
|
|
|
: "") +
|
|
|
|
tr.deckConfigConfirmRemoveName({ name: state.getCurrentName() });
|
|
|
|
|
|
|
|
if (confirm(withCollapsedWhitespace(msg))) {
|
|
|
|
try {
|
|
|
|
state.removeCurrentConfig();
|
|
|
|
dispatch("remove");
|
|
|
|
} catch (err) {
|
|
|
|
alert(err);
|
2021-04-16 15:29:21 +02:00
|
|
|
}
|
2022-09-05 09:20:00 +02:00
|
|
|
}
|
2021-04-16 15:29:21 +02:00
|
|
|
}
|
2021-04-20 11:50:05 +02:00
|
|
|
|
|
|
|
function save(applyToChildDecks: boolean): void {
|
2021-06-01 07:54:07 +02:00
|
|
|
commitEditing();
|
2021-04-20 11:50:05 +02:00
|
|
|
state.save(applyToChildDecks);
|
|
|
|
}
|
2021-06-30 14:01:33 +02:00
|
|
|
|
2022-01-24 02:43:09 +01:00
|
|
|
const saveKeyCombination = "Control+Enter";
|
2022-09-05 09:20:00 +02:00
|
|
|
|
|
|
|
let showFloating = false;
|
2021-04-16 15:29:21 +02:00
|
|
|
</script>
|
|
|
|
|
2022-09-27 04:16:45 +02:00
|
|
|
<LabelButton
|
|
|
|
primary
|
|
|
|
on:click={() => save(false)}
|
|
|
|
tooltip={getPlatformString(saveKeyCombination)}
|
2022-11-02 12:47:07 +01:00
|
|
|
--border-left-radius={!rtl ? "var(--border-radius)" : "0"}
|
|
|
|
--border-right-radius={rtl ? "var(--border-radius)" : "0"}
|
2022-09-27 04:16:45 +02:00
|
|
|
>
|
|
|
|
<div class="save">{tr.deckConfigSaveButton()}</div>
|
|
|
|
</LabelButton>
|
|
|
|
<Shortcut keyCombination={saveKeyCombination} on:action={() => save(false)} />
|
2021-04-12 06:18:30 +02:00
|
|
|
|
2022-09-27 04:16:45 +02:00
|
|
|
<WithFloating
|
|
|
|
show={showFloating}
|
|
|
|
closeOnInsideClick
|
|
|
|
inline
|
|
|
|
on:close={() => (showFloating = false)}
|
|
|
|
>
|
|
|
|
<IconButton
|
|
|
|
class="chevron"
|
|
|
|
slot="reference"
|
|
|
|
on:click={() => (showFloating = !showFloating)}
|
2022-11-02 12:47:07 +01:00
|
|
|
--border-right-radius={!rtl ? "var(--border-radius)" : "0"}
|
|
|
|
--border-left-radius={rtl ? "var(--border-radius)" : "0"}
|
2022-09-27 04:16:45 +02:00
|
|
|
iconSize={80}
|
2022-09-05 09:20:00 +02:00
|
|
|
>
|
2022-09-27 04:16:45 +02:00
|
|
|
{@html chevronDown}
|
|
|
|
</IconButton>
|
|
|
|
<Popover slot="floating">
|
|
|
|
<DropdownItem on:click={() => dispatch("add")}
|
|
|
|
>{tr.deckConfigAddGroup()}</DropdownItem
|
|
|
|
>
|
|
|
|
<DropdownItem on:click={() => dispatch("clone")}
|
|
|
|
>{tr.deckConfigCloneGroup()}</DropdownItem
|
2022-09-05 09:20:00 +02:00
|
|
|
>
|
2022-09-27 04:16:45 +02:00
|
|
|
<DropdownItem on:click={() => dispatch("rename")}>
|
|
|
|
{tr.deckConfigRenameGroup()}
|
|
|
|
</DropdownItem>
|
|
|
|
<DropdownItem on:click={removeConfig}>{tr.deckConfigRemoveGroup()}</DropdownItem
|
|
|
|
>
|
|
|
|
<DropdownDivider />
|
|
|
|
<DropdownItem on:click={() => save(true)}>
|
|
|
|
{tr.deckConfigSaveToAllSubdecks()}
|
|
|
|
</DropdownItem>
|
|
|
|
</Popover>
|
|
|
|
</WithFloating>
|
2022-09-05 09:20:00 +02:00
|
|
|
|
2022-09-27 04:16:45 +02:00
|
|
|
<style lang="scss">
|
|
|
|
.save {
|
2022-12-01 10:24:26 +01:00
|
|
|
margin: 0 0.75rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Todo: find more elegant fix for misalignment */
|
|
|
|
:global(.chevron) {
|
|
|
|
height: 100% !important;
|
2022-09-27 04:16:45 +02:00
|
|
|
}
|
|
|
|
</style>
|