Skip to content
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

Merged
merged 14 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[env]
RSLIB_FTL_ROOT = { value = "ftl/core/l10n.toml", relative = true }
BUILDINFO = { value = "rslib-bridge/buildinfo.txt", relative = true }
BUILDINFO = { value = "rsdroid/build/generated/anki_artifacts/buildinfo.txt", relative = true }
BAZEL = "1"
12 changes: 12 additions & 0 deletions .github/workflows/linux_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ jobs:
${{ runner.os }}-rust-v1-assembleRelease
${{ runner.os }}-rust-v1

# Caching node modules and bazel, the bazel cache path on linux, mac and windows are according to following docs
# https://docs.bazel.build/versions/main/output_directories.html
- name: Node and Bazel cache
uses: actions/cache@v2
with:
path: |
~/.cache/bazel
rslib-bridge/anki/node_modules
key: ${{ runner.os }}-v1-node-bazel-cache-${{ hashFiles('rslib-bridge/anki/package.json') }}-${{ hashFiles('rslib-bridge/anki/defs.bzl') }}
mikehardy marked this conversation as resolved.
Show resolved Hide resolved
restore-keys: |
${{ runner.os }}-v1-node-bazel-cache

- name: Build
run: ./gradlew clean assembleRelease -DtestBuildType=release -Dorg.gradle.daemon=false -Dorg.gradle.console=plain # assembleAndroidTest

Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/macos_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ jobs:
${{ runner.os }}-rust-v1-assembleDebug
${{ runner.os }}-rust-v1

# Caching node modules and bazel, the bazel cache path on linux, mac and windows are according to following docs
# https://docs.bazel.build/versions/main/output_directories.html
- name: Node and Bazel cache
uses: actions/cache@v2
with:
path: |
/private/var/tmp/_bazel_runner
rslib-bridge/anki/node_modules
key: ${{ runner.os }}-v1-node-bazel-cache-${{ hashFiles('rslib-bridge/anki/package.json') }}-${{ hashFiles('rslib-bridge/anki/defs.bzl') }}
restore-keys: |
${{ runner.os }}-v1-node-bazel-cache

- name: Build
run: ./gradlew clean assembleDebug -DtestBuildType=debug -Dorg.gradle.daemon=false -Dorg.gradle.console=plain

Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/publish_library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ jobs:
run: |
pip3 install --upgrade protobuf stringcase

# Caching node modules and bazel, the bazel cache path on linux, mac and windows are according to following docs
# https://docs.bazel.build/versions/main/output_directories.html
- name: Node and Bazel cache
uses: actions/cache@v2
with:
path: |
~/.cache/bazel
rslib-bridge/anki/node_modules
key: ${{ runner.os }}-v1-node-bazel-cache-${{ hashFiles('rslib-bridge/anki/package.json') }}-${{ hashFiles('rslib-bridge/anki/defs.bzl') }}
restore-keys: |
${{ runner.os }}-v1-node-bazel-cache

- name: Build
run: ./gradlew clean assembleRelease -DtestBuildType=release -Dorg.gradle.daemon=false -Dorg.gradle.console=plain

Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/publish_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ jobs:
brew install x86_64-unknown-linux-gnu
x86_64-unknown-linux-gnu-gcc -v

# Caching node modules and bazel, the bazel cache path on linux, mac and windows are according to following docs
# https://docs.bazel.build/versions/main/output_directories.html
- name: Node and Bazel cache
uses: actions/cache@v2
with:
path: |
/private/var/tmp/_bazel_runner
rslib-bridge/anki/node_modules
key: ${{ runner.os }}-v1-node-bazel-cache-${{ hashFiles('rslib-bridge/anki/package.json') }}-${{ hashFiles('rslib-bridge/anki/defs.bzl') }}
restore-keys: |
${{ runner.os }}-v1-node-bazel-cache

- name: Build JAR
run: |
export ANKIDROID_LINUX_CC=x86_64-unknown-linux-gnu-gcc
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/robolectric_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ jobs:
${{ runner.os }}-rust-v1-rsdroid-testing:build
${{ runner.os }}-rust-v1

# Caching node modules and bazel, the bazel cache path on linux, mac and windows are according to following docs
# https://docs.bazel.build/versions/main/output_directories.html
- name: Node and Bazel cache
uses: actions/cache@v2
with:
path: |
/private/var/tmp/_bazel_runner
rslib-bridge/anki/node_modules
key: ${{ runner.os }}-v1-node-bazel-cache-${{ hashFiles('rslib-bridge/anki/package.json') }}-${{ hashFiles('rslib-bridge/anki/defs.bzl') }}
restore-keys: |
${{ runner.os }}-v1-node-bazel-cache

- name: Build JAR
run: |
export ANKIDROID_LINUX_CC=x86_64-unknown-linux-gnu-gcc
Expand Down Expand Up @@ -179,4 +191,10 @@ jobs:

- name: Run Tests (win)
if: matrix.os == 'windows-latest'
run: ./gradlew rsdroid:test -x jar -x cargoBuildArm -x cargoBuildX86 -x cargoBuildArm64 -x cargoBuildX86_64
run: |
echo "Removing Bash from WSL"
mikehardy marked this conversation as resolved.
Show resolved Hide resolved
rm.exe "C:/WINDOWS/system32/bash.EXE"
Set-Alias -Name bash -Value "C:/msys64/usr/bin/bash.exe"
$env:BAZEL_SH = "C:/msys64/usr/bin/bash.exe"
[Environment]::SetEnvironmentVariable('BAZEL_SH', 'C:/msys64/usr/bin/bash.exe', 'Machine')
./gradlew rsdroid:test -x jar -x cargoBuildArm -x cargoBuildX86 -x cargoBuildArm64 -x cargoBuildX86_64
19 changes: 18 additions & 1 deletion .github/workflows/windows_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ jobs:
${{ runner.os }}-rust-v1-assembleRelease
${{ runner.os }}-rust-v1

# Caching node modules and bazel, the bazel cache path on linux, mac and windows are according to following docs
# https://docs.bazel.build/versions/main/output_directories.html
- name: Node and Bazel cache
uses: actions/cache@v2
with:
path: |
C:/Users/runneradmin/_bazel_runneradmin
rslib-bridge/anki/node_modules
key: ${{ runner.os }}-v1-node-bazel-cache-${{ hashFiles('rslib-bridge/anki/package.json') }}-${{ hashFiles('rslib-bridge/anki/defs.bzl') }}
restore-keys: |
${{ runner.os }}-v1-node-bazel-cache

# -Dorg.gradle.daemon=false has been removed
# -Dorg.gradle.console=plain has been removed
# env:
Expand All @@ -105,5 +117,10 @@ jobs:
$Env:ANDROID_NDK_HOME = "C:\ProgramFiles\Android\android-sdk\ndk-bundle"
$Env:ANDROID_NDK_PATH = "C:\ProgramFiles\Android\android-sdk\ndk-bundle"
$Env:ANDROID_SDK_ROOT = "C:\ProgramFiles\Android\android-sdk"
$env:ANDROID_HOME
$env:ANDROID_HOME
echo "Removing Bash from WSL"
krmanik marked this conversation as resolved.
Show resolved Hide resolved
rm.exe "C:/WINDOWS/system32/bash.EXE"
Set-Alias -Name bash -Value "C:/msys64/usr/bin/bash.exe"
$env:BAZEL_SH = "C:/msys64/usr/bin/bash.exe"
[Environment]::SetEnvironmentVariable('BAZEL_SH', 'C:/msys64/usr/bin/bash.exe', 'Machine')
./gradlew clean assembleRelease -DtestBuildType=release # assembleAndroidTest
20 changes: 19 additions & 1 deletion .github/workflows/windows_pure_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,23 @@ jobs:
${{ runner.os }}-rust-v1-assembleRelease
${{ runner.os }}-rust-v1

# Caching node modules and bazel, the bazel cache path on linux, mac and windows are according to following docs
# https://docs.bazel.build/versions/main/output_directories.html
- name: Node and Bazel cache
uses: actions/cache@v2
with:
path: |
C:/Users/runneradmin/_bazel_runneradmin
rslib-bridge/anki/node_modules
key: ${{ runner.os }}-v1-node-bazel-cache-${{ hashFiles('rslib-bridge/anki/package.json') }}-${{ hashFiles('rslib-bridge/anki/defs.bzl') }}
restore-keys: |
${{ runner.os }}-v1-node-bazel-cache

- name: Build
run: ./gradlew clean assembleRelease -DtestBuildType=release
run: |
echo "Removing Bash from WSL"
krmanik marked this conversation as resolved.
Show resolved Hide resolved
rm.exe "C:/WINDOWS/system32/bash.EXE"
Set-Alias -Name bash -Value "C:/msys64/usr/bin/bash.exe"
$env:BAZEL_SH = "C:/msys64/usr/bin/bash.exe"
[Environment]::SetEnvironmentVariable('BAZEL_SH', 'C:/msys64/usr/bin/bash.exe', 'Machine')
./gradlew clean assembleRelease -DtestBuildType=release
9 changes: 9 additions & 0 deletions build-web-assets.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
task buildAnkiWebAssets(type: Exec) {
workingDir "$rootDir"
String toolPath = System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows') ? 'tools/web/build-web-assets.ps1' : 'tools/web/build-web-assets.sh'
krmanik marked this conversation as resolved.
Show resolved Hide resolved
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
commandLine 'PowerShell', '-File', toolPath
} else {
commandLine 'sh', '-c', toolPath
}
}
4 changes: 4 additions & 0 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ so far.

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:

- Download https://developer.android.com/studio#command-tools
Expand Down
5 changes: 5 additions & 0 deletions rsdroid-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ apply plugin: 'kotlin'
apply plugin: 'signing'
apply plugin: 'com.vanniktech.maven.publish'

apply from: "$rootDir/build-web-assets.gradle"

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// obtaining the OS
Expand Down Expand Up @@ -118,6 +120,7 @@ def toCommandLine(Platform targetPlatform) {
}

task preBuildWindows(type: Exec) {
dependsOn "buildAnkiWebAssets"
doFirst {
logger.lifecycle(toCommandLine(Platform.WINDOWS).join(" "))
}
Expand All @@ -126,6 +129,7 @@ task preBuildWindows(type: Exec) {
}

task preBuildMac(type: Exec) {
dependsOn "buildAnkiWebAssets"
doFirst {
logger.lifecycle(toCommandLine(Platform.MACOS).join(" "))
}
Expand All @@ -147,6 +151,7 @@ task preBuildMac(type: Exec) {
}

task preBuildLinux(type: Exec) {
dependsOn "buildAnkiWebAssets"
doFirst {
logger.lifecycle(toCommandLine(Platform.LINUX).join(" "))
}
Expand Down
20 changes: 16 additions & 4 deletions rsdroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ apply plugin: "kotlin-android"
apply plugin: 'signing'
apply plugin: 'com.vanniktech.maven.publish'

apply from: "$rootDir/build-web-assets.gradle"

def getAnkiCommitHash = { ->
def hashStdOut = new ByteArrayOutputStream()
exec {
Expand Down Expand Up @@ -45,6 +47,9 @@ android {
sourceSets {
main {
kotlin.srcDirs += "build/generated/source/fluent"
resources {
srcDirs "src/main/resources", "build/generated/anki_artifacts"
}
}
}
}
Expand Down Expand Up @@ -100,12 +105,19 @@ preBuild.dependsOn "generateTranslations"

Boolean wantAllPlatforms = System.getenv("CURRENT_ONLY") != "true"

if (wantAllPlatforms) {
preBuild.dependsOn "cargoBuild"
} else {
preBuild.dependsOn "cargoBuildX86_64"
task cargoBuildTask {
if (wantAllPlatforms) {
preBuild.dependsOn "cargoBuild"
} else {
preBuild.dependsOn "cargoBuildX86_64"
}

mustRunAfter "buildAnkiWebAssets"
}

preBuild.dependsOn "buildAnkiWebAssets"
preBuild.dependsOn "cargoBuildTask"

signing {
def hasPrivate = project.hasProperty('SIGNING_PRIVATE_KEY')
def hasPassword = project.hasProperty('SIGNING_PASSWORD')
Expand Down
2 changes: 0 additions & 2 deletions rslib-bridge/buildinfo.txt

This file was deleted.

24 changes: 24 additions & 0 deletions tools/web/build-web-assets.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Set-Alias -Name bash -Value "C:/msys64/usr/bin/bash.exe"
$env:BAZEL_SH = "C:/msys64/usr/bin/bash.exe"
krmanik marked this conversation as resolved.
Show resolved Hide resolved

$SRC_DIR = (Get-Item .).FullName
$ROOT_DIR = (Get-Item D:/a/).FullName
$ANKI_SRC = (Get-Item $SRC_DIR/rslib-bridge/anki).FullName
$TEMP_DIR = (Get-Item $ENV:TEMP).FullName

New-Item -P $SRC_DIR/rsdroid/build/generated/anki_artifacts/web -itemType Directory
$BUILD_DIR = (Get-Item $SRC_DIR/rsdroid/build/generated/anki_artifacts).FullName

Set-Location -Path $ANKI_SRC

bazel --output_user_root=$ROOT_DIR/_bzl build -c opt buildinfo.txt --symlink_prefix=$TEMP_DIR/.bazel/ --verbose_failures
Copy-Item -Path $TEMP_DIR/.bazel/bin/buildinfo.txt -Destination $BUILD_DIR/buildinfo.txt -PassThru

bazel --output_user_root=$ROOT_DIR/_bzl build ts/reviewer/reviewer_extras_bundle --symlink_prefix=$TEMP_DIR/.bazel/ --verbose_failures
Copy-Item -Path $TEMP_DIR/.bazel/bin/ts/reviewer/reviewer_extras_bundle.js -Destination $BUILD_DIR/web -PassThru

bazel --output_user_root=$ROOT_DIR/_bzl build qt/aqt/data/web/pages --symlink_prefix=$TEMP_DIR/.bazel/ --verbose_failures
Get-Childitem $TEMP_DIR/.bazel/bin/qt/aqt/data/web/pages -Recurse -Include *.html,*.js,*.css | Copy-Item -Destination $BUILD_DIR/web -PassThru

Copy-Item -Path $ANKI_SRC/cargo/licenses.json -Destination $BUILD_DIR/web/licenses-cargo.json -PassThru
Copy-Item -Path $ANKI_SRC/ts/licenses.json -Destination $BUILD_DIR/web/licenses-ts.json -PassThru
32 changes: 32 additions & 0 deletions tools/web/build-web-assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# build web assets with anki submodule in rslib-bridge

# check if bazel exist or not
if ! bazel --version > /dev/null 2>&1; then
echo "bazel: command not found. Please install Bazelisk. Your distro may have it,"
echo "or you can fetch the binary from https://github.com/bazelbuild/bazelisk/releases"
echo "and rename it to /usr/local/bin/bazel"
exit 1
fi

SRC_DIR=$(pwd)
ANKI_SRC=$SRC_DIR/rslib-bridge/anki
BUILD_DIR=$SRC_DIR/rsdroid/build/generated/anki_artifacts
mkdir -p $BUILD_DIR/web

# build buildinfo.txt, reviewer_extras_bundle and pages files
cd $ANKI_SRC

bazel build --symlink_prefix=/tmp/.bazel/ -c opt buildinfo.txt
cp /tmp/.bazel/bin/buildinfo.txt $BUILD_DIR/buildinfo.txt

bazel build ts/reviewer/reviewer_extras_bundle --symlink_prefix=/tmp/.bazel/
cp /tmp/.bazel/bin/ts/reviewer/reviewer_extras_bundle.js $BUILD_DIR/web

bazel build qt/aqt/data/web/pages --symlink_prefix=/tmp/.bazel/
cp -r /tmp/.bazel/bin/qt/aqt/data/web/pages/* $BUILD_DIR/web

cp $ANKI_SRC/cargo/licenses.json $BUILD_DIR/web/licenses-cargo.json
cp $ANKI_SRC/ts/licenses.json $BUILD_DIR/web/licenses-ts.json

chmod -R a+w $BUILD_DIR/web