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

Add installation instructions #9

Closed
david-allison opened this issue Dec 29, 2020 · 25 comments · Fixed by #246
Closed

Add installation instructions #9

david-allison opened this issue Dec 29, 2020 · 25 comments · Fixed by #246
Labels
documentation Improvements or additions to documentation

Comments

@david-allison
Copy link
Member

david-allison commented Dec 29, 2020

Consider a doctor.sh script

  • Java
  • NDK
  • Python
    • and google protobuf compiler
  • Rust
    • 4 Android targets
    • no spaces in NDK path (Windows)
    • 2/3 targets for testing & warn on macOS
    • windows compiler for testing
    • Nightly for testing
@david-allison david-allison added the documentation Improvements or additions to documentation label Jan 16, 2021
@TarekkMA
Copy link
Contributor

Do you mean to make a script which:

  • Check if Java, NDK, Python (protobuf lib) are installed

What does these steps mean:

  • 4 Android targets
  • 2/3 targets for testing & warn on macOS
  • Nightly for testing
  • And should we check a c compiler on widows?

@david-allison
Copy link
Member Author

david-allison commented Mar 19, 2021

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

  • we build the .so for 4 different Android architectures:

/~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
Copy link
Contributor

TarekkMA commented Mar 19, 2021

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
Copy link
Member Author

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
Copy link
Contributor

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

@mikehardy
Copy link
Member

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
Copy link
Contributor

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
Copy link
Member Author

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
Copy link
Contributor

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

@TarekkMA
Copy link
Contributor

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

I had issues with error: could not compile cfg-if`` and can'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
Copy link
Contributor

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
Copy link
Member Author

david-allison commented Mar 20, 2021

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
Copy link
Contributor

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
Copy link
Member

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
Copy link
Contributor

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
Copy link
Contributor

TarekkMA commented Mar 20, 2021

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
Copy link
Contributor

TarekkMA commented Mar 20, 2021

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<T,E>::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
Copy link
Member Author

david-allison commented Mar 21, 2021

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
Copy link
Contributor

TarekkMA commented Mar 21, 2021

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
Copy link
Contributor

TarekkMA commented Mar 21, 2021

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
Copy link
Contributor

TarekkMA commented Mar 21, 2021

🎆 🎉 ./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:

  • Android NDK
    • Android Rust Targets
  • Rust
  • Cross
  • Python 3.7 (macOS)

Without adding compilers/linkers or anything else

The only trade off we did is not using rustfmt, but I guess it can be fixed.


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: cross-rs/cross#540 Hope to be merged soon.

@TarekkMA
Copy link
Contributor

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
Copy link
Member Author

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.

  • Link rsdroid.gradle to the file
  • Install Python - would be great to get a venv working if we can, but understandable otherwise - either way, let's get some more issues into the project for specific TODOs which won't initially be handled.

@TarekkMA
Copy link
Contributor

TarekkMA commented Mar 22, 2021

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
Copy link
Member Author

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

dae added a commit to ankitects/Anki-Android-Backend that referenced this issue Nov 29, 2022
The 2.1.55 desktop release switched away from Bazel to a new build system,
which required some changes to this repo. Making the changes was a bit complicated
due to the complexity of the current build system, and I ended up shaving some yaks
to make things simpler while I was working on the changes.

Changes:

- Building for the current architecture instead of all architectures is now the
default, so getting started is easier, and a build in Android Studio no longer
requires special flags.
- The build-current.sh script has been split into build-aar and build-robo
for the Android and Robolectric parts, and can be used for both single-arch
and multi-arch builds.
- On arm64 Macs, the build scripts now create arm binaries
- In a multi-arch build, both x86 and arm64 Mac libs are built, and they're
merged into a single library. This can be done in CI, so there is no manual step
required for M1 machines anymore.
- The build now uses protobuf and python binaries/libs that the desktop build
downloads, so they don't need to be installed separately.
- The pinned Rust version and Rust targets are automatically installed as
required.
- The per-platform CI builds now build in debug mode and are faster.
- Updated the docs to explain how the NDK can be installed via Android Studio,
instead of via separate command-line tools.
- The cross/docker stuff has been stripped out, as it's of limited use as it
can't target macOS legally. Easier to use GH actions for the multi-arch
builds, and keep things simple for local development.
- Fix lint not being run in CI; caught an API 23 reference.

Bumps ankidroid#179 (builds on M1 already work, so this may be simpler than expected?)
Bumps ankidroid#174 (a bunch of the doctor stuff is obsolete; updated HOWTO.md and GH actions should be consulted)
Bumps ankidroid#27 (I recommend closing this; single-platform is the default for local builds, and
CI runners don't have any extra compute available)

Tentatively closes ankidroid#109 (didn't see the flake when I was updating the actions)

Closes ankidroid#235 (translation submodules now automatically synced with anki submodule)
Closes ankidroid#213 (path based on script now)
Closes ankidroid#211 (builds for Arm Mac on Arm Macs)
Closes ankidroid#197 (single arch is the default)
Closes ankidroid#196 (desktop venv is used)
Closes ankidroid#195 (can be done via the GUI, and does not require separate cli download)
Closes ankidroid#168 (latest Rust; easier changing via rust-toolchain.toml)
Closes ankidroid#164 (universal dylib)
Closes ankidroid#127 (no docker)
Closes ankidroid#106 (most of those scripts obsolete; some commands moved into build scripts)
Closes ankidroid#99 (no docker)
Closes ankidroid#98 (no docker)
Closes ankidroid#97 (submodule automatically updated)
Closes ankidroid#96 (build will fail if commit unavailable)
Closes ankidroid#53 (no docker)
Closes ankidroid#40 (DEBUG=1 option documented)
Closes ankidroid#9 (simpler OOTB experience, and updated docs)
dae added a commit to ankitects/Anki-Android-Backend that referenced this issue Nov 29, 2022
The 2.1.55 desktop release switched away from Bazel to a new build system,
which required some changes to this repo. Making the changes was a bit complicated
due to the complexity of the current build system, and I ended up shaving some yaks
to make things simpler while I was working on the changes.

Changes:

- Building for the current architecture instead of all architectures is now the
default, so getting started is easier, and a build in Android Studio no longer
requires special flags.
- The build-current.sh script has been split into build-aar and build-robo
for the Android and Robolectric parts, and can be used for both single-arch
and multi-arch builds.
- On arm64 Macs, the build scripts now create arm binaries
- In a multi-arch build, both x86 and arm64 Mac libs are built, and they're
merged into a single library. This can be done in CI, so there is no manual step
required for M1 machines anymore.
- The build now uses protobuf and python binaries/libs that the desktop build
downloads, so they don't need to be installed separately.
- The pinned Rust version and Rust targets are automatically installed as
required.
- The per-platform CI builds now build in debug mode and are faster.
- Updated the docs to explain how the NDK can be installed via Android Studio,
instead of via separate command-line tools.
- The cross/docker stuff has been stripped out, as it's of limited use as it
can't target macOS legally. Easier to use GH actions for the multi-arch
builds, and keep things simple for local development.
- Fix lint not being run in CI; caught an API 23 reference.

Bumps ankidroid#179 (builds on M1 already work, so this may be simpler than expected?)
Bumps ankidroid#174 (a bunch of the doctor stuff is obsolete; updated HOWTO.md and GH actions should be consulted)
Bumps ankidroid#27 (I recommend closing this; single-platform is the default for local builds, and
CI runners don't have any extra compute available)

Tentatively closes ankidroid#109 (didn't see the flake when I was updating the actions)

Closes ankidroid#235 (translation submodules now automatically synced with anki submodule)
Closes ankidroid#213 (path based on script now)
Closes ankidroid#211 (builds for Arm Mac on Arm Macs)
Closes ankidroid#197 (single arch is the default)
Closes ankidroid#196 (desktop venv is used)
Closes ankidroid#195 (can be done via the GUI, and does not require separate cli download)
Closes ankidroid#168 (latest Rust; easier changing via rust-toolchain.toml)
Closes ankidroid#164 (universal dylib)
Closes ankidroid#127 (no docker)
Closes ankidroid#106 (most of those scripts obsolete; some commands moved into build scripts)
Closes ankidroid#99 (no docker)
Closes ankidroid#98 (no docker)
Closes ankidroid#97 (submodule automatically updated)
Closes ankidroid#96 (build will fail if commit unavailable)
Closes ankidroid#53 (no docker)
Closes ankidroid#40 (DEBUG=1 option documented)
Closes ankidroid#9 (simpler OOTB experience, and updated docs)
dae added a commit to ankitects/Anki-Android-Backend that referenced this issue Nov 29, 2022
The 2.1.55 desktop release switched away from Bazel to a new build system,
which required some changes to this repo. Making the changes was a bit complicated
due to the complexity of the current build system, and I ended up shaving some yaks
to make things simpler while I was working on the changes.

Changes:

- Building for the current architecture instead of all architectures is now the
default, so getting started is easier, and a build in Android Studio no longer
requires special flags.
- The build-current.sh script has been split into build-aar and build-robo
for the Android and Robolectric parts, and can be used for both single-arch
and multi-arch builds.
- On arm64 Macs, the build scripts now create arm binaries
- In a multi-arch build, both x86 and arm64 Mac libs are built, and they're
merged into a single library. This can be done in CI, so there is no manual step
required for M1 machines anymore.
- The build now uses protobuf and python binaries/libs that the desktop build
downloads, so they don't need to be installed separately.
- The pinned Rust version and Rust targets are automatically installed as
required.
- The per-platform CI builds now build in debug mode and are faster.
- Updated the docs to explain how the NDK can be installed via Android Studio,
instead of via separate command-line tools.
- The cross/docker stuff has been stripped out, as it's of limited use as it
can't target macOS legally. Easier to use GH actions for the multi-arch
builds, and keep things simple for local development.
- Fix lint not being run in CI; caught an API 23 reference.

Bumps ankidroid#179 (builds on M1 already work, so this may be simpler than expected?)
Bumps ankidroid#174 (a bunch of the doctor stuff is obsolete; updated HOWTO.md and GH actions should be consulted)
Bumps ankidroid#27 (I recommend closing this; single-platform is the default for local builds, and
CI runners don't have any extra compute available)

Tentatively closes ankidroid#109 (didn't see the flake when I was updating the actions)

Closes ankidroid#235 (translation submodules now automatically synced with anki submodule)
Closes ankidroid#213 (path based on script now)
Closes ankidroid#211 (builds for Arm Mac on Arm Macs)
Closes ankidroid#197 (single arch is the default)
Closes ankidroid#196 (desktop venv is used)
Closes ankidroid#195 (can be done via the GUI, and does not require separate cli download)
Closes ankidroid#168 (latest Rust; easier changing via rust-toolchain.toml)
Closes ankidroid#164 (universal dylib)
Closes ankidroid#127 (no docker)
Closes ankidroid#106 (most of those scripts obsolete; some commands moved into build scripts)
Closes ankidroid#99 (no docker)
Closes ankidroid#98 (no docker)
Closes ankidroid#97 (submodule automatically updated)
Closes ankidroid#96 (build will fail if commit unavailable)
Closes ankidroid#53 (no docker)
Closes ankidroid#40 (DEBUG=1 option documented)
Closes ankidroid#9 (simpler OOTB experience, and updated docs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants