-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build anki web assets from rslib-bridge/anki submodule #217
Conversation
While committing into a separate branch of the same repo is a common pattern for actions like doc generators, the artifacts will be multi megabytes, so it will cause the size of this repo to grow in size - I suggest the action publishes an artifact instead. |
I will update it to publish the artifacts. |
After changing some diff --git a/rsdroid/build.gradle b/rsdroid/build.gradle
index fd7bb40..12f8736 100644
--- a/rsdroid/build.gradle
+++ b/rsdroid/build.gradle
@@ -45,10 +45,23 @@ android {
sourceSets {
main {
kotlin.srcDirs += "build/generated/source/fluent"
+ resources {
+ srcDirs "src/main/resources", "build/generated/anki_artifacts"
+ }
}
}
}
+task buildAnkiWebAssets(type: Exec) {
+ workingDir "$rootDir"
+ String toolPath = System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows') ? 'tools\\web\\build-web-assets.bat' : 'tools/web/build-web-assets.sh'
+ if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
+ commandLine 'cmd', '/c', toolPath
+ } else {
+ commandLine 'sh', '-c', toolPath
+ }
+}
+
// Consider upgrade to DSL: https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block
apply plugin: "org.mozilla.rust-android-gradle.rust-android"
@@ -96,6 +109,8 @@ task generateTranslations(type: Exec) {
}
}
+preBuild.dependsOn "buildAnkiWebAssets"
+
preBuild.dependsOn "generateTranslations"
Boolean wantAllPlatforms = System.getenv("CURRENT_ONLY") != "true"
diff --git a/tools/web/build-web-assets.sh b/tools/web/build-web-assets.sh
new file mode 100755
index 0000000..d2329d4
--- /dev/null
+++ b/tools/web/build-web-assets.sh
@@ -0,0 +1,17 @@
+# build web assets with anki submodule in rslib-bridge
+
+SRC_DIR=$(pwd)
+ANKI_SRC=$SRC_DIR/rslib-bridge/anki
+BUILD_DIR=$SRC_DIR/rsdroid/build/generated/anki_artifacts/
+
+# build for ts
+cd $ANKI_SRC/ts
+bazel build ts
+
+# build for web
+cd $ANKI_SRC/qt/aqt/data/web
+bazel build web
+
+# copy pages to build/generated
+mkdir -p $BUILD_DIR/web
+cp -r $ANKI_SRC/.bazel/bin/qt/aqt/data/web/pages/* $BUILD_DIR/web |
This is convenient for testing, and is probably the best long term approach, but the problem in the short term is that it will require work to make sure the Bazel build works in all the different github actions (eg Windows/Mac build) |
One other issue is that the .bazel folder will make AndroidStudio really slow, so you may want to manually specify a different location, or remove the symlink as part of the build. |
I will update the github actions workflows file for other system.
I have used This is working solution with .bazel in /tmp dir and without considering # build for ts
cd $ANKI_SRC/ts
bazel build ts --symlink_prefix=/tmp/.bazel/
# build for web
cd $ANKI_SRC/qt/aqt/data/web/pages
bazel build pages --symlink_prefix=/tmp/.bazel/
# copy pages to build/generated
mkdir -p $BUILD_DIR/web
cp -r /tmp/.bazel/bin/qt/aqt/data/web/pages/* $BUILD_DIR/web I have also tried to symlink the anki dir ( |
That might be enough already? If node_modules is causing a problem, perhaps there's a way to exclude it in AndroidStudio that can be configured in a file in the repo? |
Will it be considered in build.gradle?
|
That could work for me, I don't believe gradle as a build system would ever care about node ecosystem packages. I've never seen a need to mix the two |
Then I will update the github actions with setup bazel for (Windows, mac and linux). |
I will reopen it because I have renamed this branch so that when I push the github action should run. But it get closed. Building/testing on local branch https://github.com/krmanik/Anki-Android-Backend/pull/1/ |
One remaining nice-to-have would be to generate the buildinfo.txt file, so it doesn't need to be checked into this repo/manually updated. |
The latest |
Fixing now
|
Thanks for all your work on this Mani, the caching looks like a nice improvement. |
For linux the build is working as expected but failing on macOS and windows. Linux actions result
Trying now
|
It should be fix now, I have used I have put the cargo task in another Trying now
|
That latest change looks promising. The new error might just be a flake - you could try running that bazel build line a few times in a row. |
Added in ps1
|
No luck :-( Some Googling seems to indicate TypeScript can give that error when using symlinks, but I guess we're not using them there? Maybe it's some other path-related issue. That path is quite long - I wonder if you copied rslib-anki/anki to d:\a\anki and built from there, if it would help at all? Another possible thing you could try is the -win.sh file now that you've fixed the bash issue |
Great work in figuring that out Mani. Assuming you've tested that the pages can be successfully loaded on the AnkiDroid end with this build, it's a 👍 from me. Thank you for all of your hard work! |
I have tested On windows machine it needs |
Could we include the license files too? ankidroid/Anki-Android#11825 (comment) |
Re docs, how about: diff --git a/docs/TESTING.md b/docs/TESTING.md
index 9a95dcfc6..1213ee562 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -8,7 +8,11 @@ so far.
## Setup
-Make sure you can build AnkiDroid first.
+- Make sure you can build AnkiDroid first.
+
+- Follow the initial setup instructions in the computer version
+ (rslib-bridge/anki/docs/{windows,mac,linux}.md) to install prerequisites
+ like Bazelisk and the build tools for your platform.
Install NDK: |
The
Thanks, I have updated the docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting it to the point where it is working is fantastic (and I think it is there right?) - that's the hard part
My comments are now about editing it back down to be minimal by removing any duplication that can be removed, if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly one question on the cache restore keys
One note on the cache paths for bazel action, and a simple comment could get this merged, or variable interpolation if that's fast for you (just a comment if not...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a big advance - thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing major.
I'm out of my comfort zone here and trust dae/Mani/Mike's judgment 100% on this
rename bash to bash_copy
Extracted the bash setup to ps1 so that user can change/revert bash changes. I have used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Mani! I'm going to merge this to unblock things in my last time available for a while, we can always do fixups as needed / if needed
There is need to generate web assets files for showing graphs, card info, import csv etc. The file built using
bazel
, so it needs to add bazel build in build.gradle.The current PR will solve the issue of generating assets for current anki version (rslib-bridge/anki) repo.
Added
task
in build.gradle to executebuildAnkiWebAssets
. It runs scriptbuild-web-assets.(bat/sh)
on windows, macos and linux. The script change directory to$SRC_DIR/rslib-bridge/anki
and run bazel build onts
andpages
. Then the generated web pages copied to resources of the rsdroid project. Theaar
files contains this pages inweb
dir.