ankidroid / Anki-Android-Backend

JNI bridge between AnkiDroid and Anki Desktop's rust code
GNU General Public License v3.0
67 stars 24 forks source link

Add installation instructions #9

Closed david-allison closed 1 year ago

david-allison commented 3 years ago

Consider a doctor.sh script

TarekkMA commented 3 years ago

Do you mean to make a script which:

What does these steps mean:

david-allison commented 3 years ago

Sorry! Was writing the instructions for myself.

Please also feel free to mark where the below needs to be moved in the documentation

4 Android targets

https://github.com/david-allison-1/Anki-Android-Backend/blob/6c16f621080382923f287dff089e86a235e8026b/rsdroid/build.gradle#L39

These need to be installed as targets for Rust:

https://github.com/david-allison-1/Anki-Android-Backend/blob/6c16f621080382923f287dff089e86a235e8026b/.github/scripts/install_rust_targets.sh#L1-L5

2/3 targets for testing

In Anki-Android, we run a lot of unit tests under Robolectric: https://github.com/robolectric/robolectric

This runs a simulated Android runtime under the JVM.

The problem with this is that the Rust libraries are built for Android, not for your native PC OS.

To fix this, we have rsdroid-testing, which is a jar, containing the rust code compiled as native libraries for Windows (dll), macOS (dylib), and Linux (.so)

So we need rust targets for these

https://github.com/david-allison-1/Anki-Android-Backend/blob/6c16f621080382923f287dff089e86a235e8026b/.github/scripts/install_rust_targets.sh#L6-L9

macOS

To my knowledge, a rust target cannot legally be cross-compiled for macOS unless on a macOS computer, as it requires the Apple SDK, which is protected by a license: https://www.apple.com/legal/sla/docs/xcode.pdf

We're fine with this on GitHub, as we can use macOS on our CI to generate a full build.

So, a warning/mention that you'd only be cross-compiling Windows/Linux targets on Windows/Linux machines - a "release-quality .jar" for the .jar wouldn't be possible (as it'd be missing the .dylib), but you could create one for your local machine for testing.

Nightly for testing

rsdroid-testing currently uses cargo's --out-dir flag, which (for now) requires that a rust nightly build is set up.

https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#out-dir

C compiler

I believe this is Microsoft C++ Build Tools: https://users.rust-lang.org/t/why-do-i-need-microsoft-c-build-tools/18581/2 on Windows. Needed for the linker.

Note: WSL should be the preferred environment for anything on Windows at this point

TarekkMA commented 3 years ago

So we want a script to do all the checks and possibly to install things that can be installed like targets, rust itself, etc.

And to write a dev doc with the exact steps that should be considered, so the environment is ready.

And if WSL will be used, so bash script would be a universal script that doesn't need any dependency

david-allison commented 3 years ago

Yep - sounds good to me!

Feel free to take the design in any way that you feel is best - I have a few scripts which may be useful as reference: https://github.com/david-allison-1/Anki-Android-Backend/tree/rust-wip/.github/scripts

TarekkMA commented 3 years ago

Thank you will work on that, and keep you updated.

mikehardy commented 3 years ago

macOS

To my knowledge, a rust target cannot legally be cross-compiled for macOS unless on a macOS computer, as it requires the Apple SDK, which is protected by a license: https://www.apple.com/legal/sla/docs/xcode.pdf

We're fine with this on GitHub, as we can use macOS on our CI to generate a full build.

So, a warning/mention that you'd only be cross-compiling Windows/Linux targets on Windows/Linux machines - a "release-quality .jar" for the .jar wouldn't be possible (as it'd be missing the .dylib), but you could create one for your local machine for testing.

It might be useful to mention that for people experimenting with macOS that is possible to virtualize it https://github.com/kholia/OSX-KVM - the license considerations are the same but it is (for instance) possible to run linux on mac hardware so it's fine to mention. You can even run OSX in Docker nowadays https://github.com/sickcodes/Docker-OSX

Note: WSL should be the preferred environment for anything on Windows at this point

Yes yes yes

TarekkMA commented 3 years ago

This is nice, there is a rust project named cross, which aims to make cross compilation easier using dockers. https://github.com/rust-embedded/cross

And also if we run on the CI on macOS we can compile for the 3 platforms at once without docker. I have manged to compile for windows from macOS

david-allison commented 3 years ago

This is nice, there is a rust project named cross, which aims to make cross compilation easier using dockers. https://github.com/rust-embedded/cross

And also if we run on the CI on macOS we can compile for the 3 platforms at once without docker. I have manged to compile for windows from macOS

CI was already set up for this: https://github.com/david-allison-1/Anki-Android-Backend/actions/runs/556385657 and does exactly that. Note: I'll need to look into the CI failures - GitHub Actions changed. Shouldn't be too hard.

AFAIK, cross doesn't support x86_64-apple-darwin

I had a full build working with https://github.com/tpoechtrager/osxcross on Windows (WSL), but ran across: https://github.com/tpoechtrager/osxcross#packaging-the-sdk

TarekkMA commented 3 years ago

Yes I didn't find it, but thought it could be extended with custom platform-docker image

TarekkMA commented 3 years ago

I think we will also need to add all PC target nightly tool chains.

I had issues with error: could not compilecfg-if` andcan't find crate for core` solved using

rustup toolchain install nightly-x86_64-unknown-linux-gnu #in gradle comments
rustup target add x86_64-unknown-linux-gnu --toolchain nightly #but after this the issue did go away

And for macOS I had to install this

rustup component add rustfmt --toolchain nightly-x86_64-apple-darwin

Linker for Linux, do you have an idea how to solve the linker issue?

# cc is clang macOS     [FAIL]
sudo ln -s /usr/bin/cc /usr/local/bin/x86_64-unknown-linux-gnu-gcc
# Also fail
sudo ln -s /usr/local/bin/gcc-10 /usr/local/bin/x86_64-unknown-linux-gnu-gcc
TarekkMA commented 3 years ago

The environment of this project is so hard to set up

Yesterday I faced the issue of being unable to install protobuf-compiler becase I needed to have an older version of python (3.7), tried to install pyenv as done in scripts but i faced issues and it seems like other users have these same issues also. I did install python 3.7 via homebrew and it worked but still fails on gradle.

I couldn't run grade from the command line so changed this line in gradle-wapper.properties

- distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
+ distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

And still figuring out the rest of the issues

david-allison commented 3 years ago

This isn't going to be an easy one to solve at all. There's a lot of moving parts.

One of the main intentions of having this in Anki-Android-Backend is that contributors to Anki-Android don't get discouraged by the complexity and can immediately contribute.

I /really/ appreciate the help with this, feel free to PR any incremental work/commits, as it will save a lot of hassle for others.

TarekkMA commented 3 years ago

Currently, the pain points of setting the environment is not the rust or NDK, but it is the rsdriod-testing module and the nature of cross compilation. And also generating the protobuf classes (on macOS at least).

I was thinking if it's okay to utilize cross pakage. And we don't cross compile osx binaries anyway ?

As they say it's

“Zero setup” cross compilation and “cross testing” of Rust crates

And I think we really need that 😄

And I think we can integrate https://hub.docker.com/r/sickcodes/docker-osx to work with corss via a custom docker setup. I didn't look into the details, but I think it's doable. The only bad part about it is the image is about 20 GB, so if we get to enable it, we should make a flag on local.properties for example to enable it. So anyone who wishes to generate a full "release-quality .jar" can.

I will leave the protobuf issue for now. Will tackle it after I get the cross compilation sorted

mikehardy commented 3 years ago

Food for thought, in other projects where I have a lot of environment difficulty, I maintain a 'doctor' script that examines the environment for expected versions of all toolchain items, and knows how to install them or upgrade them in order to confirm that the environment is ready to go at the end

I think maintaining a Docker image may be useful but that implies that development will be done in the Docker image yes? Will that be high performance enough? I think it might be so this could be a good direction

At that point the doctor.sh script I'm attaching - as an idea - would be implemented instead as a Dockerfile right? Or a set of Dockerfiles if needed (unix, mac, windows) if possible.

doctor.sh.txt

TarekkMA commented 3 years ago

I wanted to do this at first, build a doctor utility script in bash or in gradle, but I found out that instillation of some components will be cumbersome and will be different from user to user even if they have same os.

And the only part that we need docker(cross package) for is the rsdriod-testing module. Where cross compilation is required. If the user is running macOS for example he will use his OS for compiling macOS and other 2 OSs with docker.

I don't know if it will affect the performance drastically as it is only for rsdriod-testing, @david-allison-1 may know if that is the case But if t I think we can make 2 versions of the build, one where the user only compile his OS binaries for use during development, and the other for the full "release-quality.jar"

Using cross we wouldn't need to maintain any Dockerfiles. Maybe we would need it for the osx one, but we will leave that as the last thing we think about.

We might still need doctor script to check NDK, Rust, Java, Docker, etc and those are very straight forward to install on any system

TarekkMA commented 3 years ago

I don't know why cross giving me this error about linker not found. Cross did work on my toy projects just fine with no extra setup.

Error ``` > Task :rsdroid-testing:preBuildLinux Outputting to: /Users/tarekkma/Developer/Projects/Anki-Android-Backend/rsdroid-testing/assets /Users/tarekkma/Developer/Projects/Anki-Android-Backend/rsdroid-testing/assets bash --login -c CC=$ANKIDROID_LINUX_CC cross +nightly build --verbose --release -Z unstable-options --features no-android --out-dir /Users/tarekkma/Developer/Projects/Anki-Android-Backend/rsdroid-testing/assets --target x86_64-unknown-linux-gnu + "rustc" "--print" "sysroot" + "rustup" "toolchain" "list" + "rustup" "target" "list" "--toolchain" "nightly-x86_64-unknown-linux-gnu" + "rustup" "component" "list" "--toolchain" "nightly-x86_64-unknown-linux-gnu" + "/usr/local/bin/docker" "run" "--userns" "host" "-e" "PKG_CONFIG_ALLOW_CROSS=1" "--rm" "--user" "501:20" "-e" "XARGO_HOME=/xargo" "-e" "CARGO_HOME=/cargo" "-e" "CARGO_TARGET_DIR=/target" "-e" "USER=tarekkma" "-e" "CROSS_RUNNER=" "-v" "/Users/tarekkma/.xargo:/xargo:Z" "-v" "/Users/tarekkma/.cargo:/cargo:Z" "-v" "/cargo/bin" "-v" "/Users/tarekkma/Developer/Projects/Anki-Android-Backend/rslib-bridge:/project:Z" "-v" "/Users/tarekkma/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu:/rust:Z,ro" "-v" "/Users/tarekkma/Developer/Projects/Anki-Android-Backend/rslib-bridge/target:/target:Z" "-w" "/project" "rustembedded/cross:x86_64-unknown-linux-gnu-0.2.1" "sh" "-c" "PATH=$PATH:/rust/bin cargo build --verbose --release -Z unstable-options --features no-android --out-dir /Users/tarekkma/Developer/Projects/Anki-Android-Backend/rsdroid-testing/assets --target x86_64-unknown-linux-gnu" Compiling proc-macro2 v1.0.19 Compiling syn v1.0.38 Fresh autocfg v1.0.0 Running `rustc --crate-name build_script_build --edition=2018 /cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.19/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=42a840f9306058b8 -C extra-filename=-42a840f9306058b8 --out-dir /target/release/build/proc-macro2-42a840f9306058b8 -C linker=x86_64-unknown-linux-gnu-gcc -L dependency=/target/release/deps --cap-lints allow` Running `rustc --crate-name build_script_build --edition=2018 /cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.38/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="clone-impls"' --cfg 'feature="default"' --cfg 'feature="derive"' --cfg 'feature="extra-traits"' --cfg 'feature="fold"' --cfg 'feature="full"' --cfg 'feature="parsing"' --cfg 'feature="printing"' --cfg 'feature="proc-macro"' --cfg 'feature="quote"' --cfg 'feature="visit"' --cfg 'feature="visit-mut"' -C metadata=76a83cc140ff1b90 -C extra-filename=-76a83cc140ff1b90 --out-dir /target/release/build/syn-76a83cc140ff1b90 -C linker=x86_64-unknown-linux-gnu-gcc -L dependency=/target/release/deps --cap-lints allow` Compiling libc v0.2.76 Running `rustc --crate-name build_script_build /cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.76/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=04e5e51966ec2f28 -C extra-filename=-04e5e51966ec2f28 --out-dir /target/release/build/libc-04e5e51966ec2f28 -C linker=x86_64-unknown-linux-gnu-gcc -L dependency=/target/release/deps --cap-lints allow` Compiling memchr v2.3.3 Running `rustc --crate-name build_script_build /cargo/registry/src/github.com-1ecc6299db9ec823/memchr-2.3.3/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="std"' --cfg 'feature="use_std"' -C metadata=e3724a544fc83b26 -C extra-filename=-e3724a544fc83b26 --out-dir /target/release/build/memchr-e3724a544fc83b26 -C linker=x86_64-unknown-linux-gnu-gcc -L dependency=/target/release/deps --cap-lints allow` error: linker `x86_64-unknown-linux-gnu-gcc` not found | = note: No such file or directory (os error 2) error: aborting due to previous error error: could not compile `memchr` Caused by: process didn't exit successfully: `rustc --crate-name build_script_build /cargo/registry/src/github.com-1ecc6299db9ec823/memchr-2.3.3/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="std"' --cfg 'feature="use_std"' -C metadata=e3724a544fc83b26 -C extra-filename=-e3724a544fc83b26 --out-dir /target/release/build/memchr-e3724a544fc83b26 -C linker=x86_64-unknown-linux-gnu-gcc -L dependency=/target/release/deps --cap-lints allow` (exit code: 1) warning: build failed, waiting for other jobs to finish... error: linker `x86_64-unknown-linux-gnu-gcc` not found | = note: No such file or directory (os error 2) error: aborting due to previous error error: linker `x86_64-unknown-linux-gnu-gcc` not found | = note: No such file or directory (os error 2) error: aborting due to previous error error: linker `x86_64-unknown-linux-gnu-gcc` not found | = note: No such file or directory (os error 2) error: aborting due to previous error error: build failed > Task :rsdroid-testing:preBuildLinux FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':rsdroid-testing:preBuildLinux'. > Process 'command 'bash'' finished with non-zero exit value 101 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.8.3/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 8s 2 actionable tasks: 1 executed, 1 up-to-date ```

Edit: FIXED

Oh, I forgot about the symbolic link trick.

Using a custom docker and making the link seems to make it work.

FROM rustembedded/cross:x86_64-unknown-linux-gnu

RUN ln -s /usr/bin/cc /usr/local/bin/x86_64-unknown-linux-gnu-gcc

But the issue with anki/rslib still exists.

TarekkMA commented 3 years ago

The above error about the linker does only happen when compiling rsdriod-bridge

In rslib it does fetch and compile all packages under cross docker (win/linux) but it gives me this error.

When I do compile it natively it does work.

BTW I moved anki to be in the same directory as rsdriod-bridge, since this is a limitation in cross being unable to get local crates outside the project directory.

Caused by:
  process didn't exit successfully: `/target/release/build/anki-127f4a73d84ce9fa/build-script-build` (exit code: 101)
  --- stdout
  cargo:rerun-if-changed=./ftl/card-stats.ftl
  cargo:rerun-if-changed=./ftl/card-template-rendering.ftl
  cargo:rerun-if-changed=./ftl/card-templates.ftl
  cargo:rerun-if-changed=./ftl/custom-study.ftl
  cargo:rerun-if-changed=./ftl/database-check.ftl
  cargo:rerun-if-changed=./ftl/deck-config.ftl
  cargo:rerun-if-changed=./ftl/empty-cards.ftl
  cargo:rerun-if-changed=./ftl/filtering.ftl
  cargo:rerun-if-changed=./ftl/findreplace.ftl
  cargo:rerun-if-changed=./ftl/importing.ftl
  cargo:rerun-if-changed=./ftl/media-check.ftl
  cargo:rerun-if-changed=./ftl/network.ftl
  cargo:rerun-if-changed=./ftl/notetypes.ftl
  cargo:rerun-if-changed=./ftl/scheduling.ftl
  cargo:rerun-if-changed=./ftl/search.ftl
  cargo:rerun-if-changed=./ftl/statistics.ftl
  cargo:rerun-if-changed=./ftl/sync.ftl
  cargo:rerun-if-changed=../proto/backend.proto
  cargo:rerun-if-changed=../proto/sqlite.proto

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', anki/rslib/build.rs:217:10
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error compiling rslib under cross ``` ~/Developer/Projects/Anki-Android-Backend/anki/rslib ⟩ cross +nightly build --verbose --release --target x86_64-pc-windows-gnu + "rustc" "--print" "sysroot" + "rustup" "toolchain" "list" + "rustup" "target" "list" "--toolchain" "nightly-x86_64-unknown-linux-gnu" + "rustup" "component" "list" "--toolchain" "nightly-x86_64-unknown-linux-gnu" + "/usr/local/bin/docker" "run" "--userns" "host" "-e" "PKG_CONFIG_ALLOW_CROSS=1" "--rm" "--user" "501:20" "-e" "XARGO_HOME=/xargo" "-e" "CARGO_HOME=/cargo" "-e" "CARGO_TARGET_DIR=/target" "-e" "USER=tarekkma" "-e" "CROSS_RUNNER=" "-v" "/Users/tarekkma/.xargo:/xargo:Z" "-v" "/Users/tarekkma/.cargo:/cargo:Z" "-v" "/cargo/bin" "-v" "/Users/tarekkma/Developer/Projects/Anki-Android-Backend/anki/rslib:/project:Z" "-v" "/Users/tarekkma/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu:/rust:Z,ro" "-v" "/Users/tarekkma/Developer/Projects/Anki-Android-Backend/anki/rslib/target:/target:Z" "-w" "/project" "-i" "-t" "rustembedded/cross:x86_64-pc-windows-gnu-0.2.1" "sh" "-c" "PATH=$PATH:/rust/bin cargo build --verbose --release --target x86_64-pc-windows-gnu" Fresh autocfg v1.0.1 Fresh version_check v0.9.3 /////// redacted Fresh slog-envlogger v2.2.0 Fresh fluent-bundle v0.10.2 (https://github.com/ankitects/fluent-rs.git?branch=32bit-panic#f61c5e10) Fresh h2 v0.2.7 Compiling num_enum v0.5.1 Compiling anki v2.1.34 (/project) Fresh fluent v0.10.2 (https://github.com/ankitects/fluent-rs.git?branch=32bit-panic#f61c5e10) Running `/target/release/build/anki-426ab66b4f37ac30/build-script-build` Compiling askama v0.10.5 Fresh hyper v0.13.10 Running `rustc --crate-name num_enum --edition=2018 /cargo/registry/src/github.com-1ecc6299db9ec823/num_enum-0.5.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=6810ff4c3cfaf7b2 -C extra-filename=-6810ff4c3cfaf7b2 --out-dir /target/x86_64-pc-windows-gnu/release/deps --target x86_64-pc-windows-gnu -C linker=x86_64-w64-mingw32-gcc -L dependency=/target/x86_64-pc-windows-gnu/release/deps -L dependency=/target/release/deps --extern derivative=/target/release/deps/libderivative-5fc9734329193226.so --extern num_enum_derive=/target/release/deps/libnum_enum_derive-f5dd5331cf1788ef.so --cap-lints allow` Running `rustc --crate-name askama --edition=2018 /cargo/registry/src/github.com-1ecc6299db9ec823/askama-0.10.5/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="config"' --cfg 'feature="default"' --cfg 'feature="humansize"' --cfg 'feature="num-traits"' --cfg 'feature="urlencode"' -C metadata=9d2586b177d34170 -C extra-filename=-9d2586b177d34170 --out-dir /target/x86_64-pc-windows-gnu/release/deps --target x86_64-pc-windows-gnu -C linker=x86_64-w64-mingw32-gcc -L dependency=/target/x86_64-pc-windows-gnu/release/deps -L dependency=/target/release/deps --extern askama_derive=/target/release/deps/libaskama_derive-223ce488abb9c807.so --extern askama_escape=/target/x86_64-pc-windows-gnu/release/deps/libaskama_escape-deb3b3313e87730e.rmeta --extern askama_shared=/target/x86_64-pc-windows-gnu/release/deps/libaskama_shared-c243829cf6dda5ec.rmeta --cap-lints allow` error: failed to run custom build command for `anki v2.1.34 (/project)` Caused by: process didn't exit successfully: `/target/release/build/anki-426ab66b4f37ac30/build-script-build` (exit code: 1) --- stdout cargo:rerun-if-changed=./ftl/card-stats.ftl cargo:rerun-if-changed=./ftl/card-template-rendering.ftl cargo:rerun-if-changed=./ftl/card-templates.ftl cargo:rerun-if-changed=./ftl/custom-study.ftl cargo:rerun-if-changed=./ftl/database-check.ftl cargo:rerun-if-changed=./ftl/deck-config.ftl cargo:rerun-if-changed=./ftl/empty-cards.ftl cargo:rerun-if-changed=./ftl/filtering.ftl cargo:rerun-if-changed=./ftl/findreplace.ftl cargo:rerun-if-changed=./ftl/importing.ftl cargo:rerun-if-changed=./ftl/media-check.ftl cargo:rerun-if-changed=./ftl/network.ftl cargo:rerun-if-changed=./ftl/notetypes.ftl cargo:rerun-if-changed=./ftl/scheduling.ftl cargo:rerun-if-changed=./ftl/search.ftl cargo:rerun-if-changed=./ftl/statistics.ftl cargo:rerun-if-changed=./ftl/sync.ftl --- stderr Error: Os { code: 2, kind: NotFound, message: "No such file or directory" } warning: build failed, waiting for other jobs to finish... error: build failed ```

Edit: Another error output with more details

it seems to be diffrent one.

output with more details ``` ⟩ RUST_BACKTRACE=1 cross +nightly build --verbose --release --target x86_64-unknown-linux-gnu + "rustc" "--print" "sysroot" + "rustup" "toolchain" "list" + "rustup" "target" "list" "--toolchain" "nightly-x86_64-unknown-linux-gnu" + "rustup" "component" "list" "--toolchain" "nightly-x86_64-unknown-linux-gnu" + "/usr/local/bin/docker" "run" "--userns" "host" "-e" "PKG_CONFIG_ALLOW_CROSS=1" "--rm" "--user" "501:20" "-e" "XARGO_HOME=/xargo" "-e" "CARGO_HOME=/cargo" "-e" "CARGO_TARGET_DIR=/target" "-e" "USER=tarekkma" "-e" "CROSS_RUNNER=" "-v" "/Users/tarekkma/.xargo:/xargo:Z" "-v" "/Users/tarekkma/.cargo:/cargo:Z" "-v" "/cargo/bin" "-v" "/Users/tarekkma/Developer/Projects/Anki-Android-Backend/rslib-bridge:/project:Z" "-v" "/Users/tarekkma/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu:/rust:Z,ro" "-v" "/Users/tarekkma/Developer/Projects/Anki-Android-Backend/rslib-bridge/target:/target:Z" "-w" "/project" "-i" "-t" "rslib-bridge:linux" "sh" "-c" "PATH=$PATH:/rust/bin cargo build --verbose --release --target x86_64-unknown-linux-gnu" Fresh autocfg v1.0.0 Fresh version_check v0.9.2 Fresh lazy_static v1.4.0 /////// redacted Fresh askama v0.10.3 Fresh num_enum v0.5.1 Fresh fluent v0.10.2 (https://github.com/ankitects/fluent-rs.git?branch=32bit-panic#f61c5e10) Compiling anki v2.1.34 (/project/anki/rslib) Compiling rsdroid v0.1.0 (/project) Running `/target/release/build/anki-127f4a73d84ce9fa/build-script-build` Running `/target/release/build/rsdroid-87c29494811e47ee/build-script-build` error: failed to run custom build command for `rsdroid v0.1.0 (/project)` Caused by: process didn't exit successfully: `/target/release/build/rsdroid-87c29494811e47ee/build-script-build` (exit code: 101) --- stdout cargo:rerun-if-changed=proto/AdBackend.proto --- stderr thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', build.rs:100:10 stack backtrace: 0: rust_begin_unwind at /rustc/f5f33ec0e0455eefa72fc5567eb1280a4d5ee206/library/std/src/panicking.rs:493:5 1: core::panicking::panic_fmt at /rustc/f5f33ec0e0455eefa72fc5567eb1280a4d5ee206/library/core/src/panicking.rs:92:14 2: core::option::expect_none_failed at /rustc/f5f33ec0e0455eefa72fc5567eb1280a4d5ee206/library/core/src/option.rs:1329:5 3: core::result::Result::unwrap 4: build_script_build::main 5: core::ops::function::FnOnce::call_once note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. warning: build failed, waiting for other jobs to finish... error: build failed ```
david-allison commented 3 years ago

This implies that rslib\ftl\anki-core-i18n\core doesn't exist - error message could be improved (I thought I'd already done this, apologies)

Creating anki-core-i18n was handled by the Makefile in Anki, I changed anki-core-i18n to refer to a submodule (to allow for reproducible builds)

The issues are going to be associated with the files: anki\rslib\build.rs or rslib-bridge\build.rs

TarekkMA commented 3 years ago

I checked from within docker and the rslib\ftl\anki-core-i18n\core was there

the issue on rslib-bridge\build.rs is with this code https://github.com/david-allison-1/Anki-Android-Backend/blob/6c16f621080382923f287dff089e86a235e8026b/rslib-bridge/build.rs#L96-L100

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }'

But I wrote some debug code before the faling code in build.rs to see if cross for example missed something up. But all files were there and noting was missing

    println!("{:?}",Path::new("src/backend_proto.rs").canonicalize()?);

    let pwd_out = Command::new("pwd").output().unwrap();
    println!("pwd status: {}", pwd_out.status);
    println!("stdout: {}", String::from_utf8_lossy(&pwd_out.stdout));
    println!("stderr: {}", String::from_utf8_lossy(&pwd_out.stderr));

    for entry in WalkDir::new("./src") {
        println!("DD {}", entry?.path().display());
    }
  "/project/src/backend_proto.rs"
  pwd status: exit code: 0
  stdout: /project

  stderr: 
  DD ./src
  DD ./src/.gitignore
  DD ./src/ankidroid.rs
  DD ./src/backend_proto.rs
  DD ./src/dbcommand.rs
  DD ./src/lib.rs
  DD ./src/sqlite.rs

Edit: I think the not found is referring to rustfmt

TarekkMA commented 3 years ago

The issue was because I think cross didn't include cargo bin in docker. and the 2 build.rs needed to execute the rustfmt command.

https://github.com/david-allison-1/anki/blob/c597f2630d397ab441e81ee15895cf1df46fafb8/rslib/build.rs#L214-L218

After I removed the lines for formating. Cross worked with no issue for both Linux and windows.

I tried using Cross.toml to use mount the bin directory but no luck, it doesn't read it at all.

TarekkMA commented 3 years ago

🎆 🎉 ./gradlew clean assembleRelease is now working with no issues at all

and it will be surprisingly easy to set up the environment in the future, I will upload a PR with the changes I made.

Only needed steps are:


Figured out the issue. The feature of assigning volumes is not yet published.

So I pulled cross from git directly, and it does work not for --out argument of cargo

cargo install cross --git https://github.com/rust-embedded/cross/

The current implementation of cross does not allow the change of the volume name like src:dest it will be src:src. But this won't be an issue for --out argument of cargo

 "-v" "/Users/tarekkma/Developer/Projects/Anki-Android-Backend/rsdroid-testing/assets:/Users/tarekkma/Developer/Projects/Anki-Android-Backend/rsdroid-testing/assets"

I might be able to make a PR to cross to enable selecting the mounting destination, would be a cool first rust PR 😃 Edit: https://github.com/rust-embedded/cross/pull/540 Hope to be merged soon.

TarekkMA commented 3 years ago

I have added steps to get the environment ready. Please let me know if we need to change anything.

https://github.com/TarekkMA/Anki-Android-Backend/blob/ce6aa4f35b2ff1168d19ed43ba73b63d9bd514aa/docs/ENVIROMENT.md

david-allison commented 3 years ago

I have added steps to get the environment ready. Please let me know if we need to change anything.

https://github.com/TarekkMA/Anki-Android-Backend/blob/ce6aa4f35b2ff1168d19ed43ba73b63d9bd514aa/docs/ENVIROMENT.md

Looks great! Will need to get a VM out and test that I can do this.

TarekkMA commented 3 years ago

BackendProto.Backend is about 100K lines of code and the IDE seems to ignore it and not index it. Will that be a problem?

Edit: adding this line to the IDE config should fix this issue, but I don't know if AnkiDroid devs will also have to edit this value or not.

idea.max.intellisense.filesize=999999

https://df.tips/t/topic/826

david-allison commented 3 years ago

BackendProto.Backend is about 100K lines of code and the IDE seems to ignore it and not index it. Will that be a problem?

It's in /build/generated anyway, there's very little reason to view the file.

RustBackendImpl is the one which may be viewed, and that's only 1.4k