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

run fails on Windows due to latest rust_rules #2100

Closed
RumovZ opened this issue Oct 1, 2022 · 7 comments
Closed

run fails on Windows due to latest rust_rules #2100

RumovZ opened this issue Oct 1, 2022 · 7 comments

Comments

@RumovZ
Copy link
Collaborator

RumovZ commented Oct 1, 2022

Since a39a3b4 I can't .\run Anki anymore:

INFO: Invocation ID: b2647e0c-c0dc-4711-86f5-a7f860e81a22
INFO: Build option --compilation_mode has changed, discarding analysis cache.
INFO: Analyzed target //qt:runanki (0 packages loaded, 33463 targets configured).
INFO: Found 1 target...
ERROR: C:/bazel/anki/c5pd2hpw/external/raze__zstd_sys__2_0_1_zstd_1_5_2/BUILD.bazel:40:19: Running Cargo build script zstd_sys failed: (Exit 101): cargo_build_script_runner.exe failed: error executing command bazel-out\x64_windows-opt-exec-2B5CBBC6\bin\external\rules_rust\cargo\cargo_build_script_runner\cargo_build_script_runner.exe ... (remaining 10 arguments skipped)
thread 'main' panicked at 'Cannot read line: Error { kind: InvalidData, message: "stream did not contain valid UTF-8" }', external/rules_rust/cargo/cargo_build_script_runner/lib.rs:107:43
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Target //qt:runanki failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 8.858s, Critical Path: 4.06s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

Clearing out old artifacts did not help. Curiously, .\tools\runopt continues to work.

@dae
Copy link
Member

dae commented Oct 3, 2022

I suspect the build script is writing some localized text in utf16, when the runner expects utf8. You could try:

    # native.local_repository(
    #     name = "rules_rust",
    #     path = "../rules_rust",
    # )

then edit rules_rust/cargo/cargo_build_script_runner/lib.rs

Then the read_line().expect() call can be replaced with read_until() to get bytes, which can then be manually converted to utf8 using lossy conversion. If that fixes it, we can submit a patch upstream.

@RumovZ
Copy link
Collaborator Author

RumovZ commented Oct 3, 2022

Thanks a lot, it works! Will you take care of the upstream patch?

@dae
Copy link
Member

dae commented Oct 3, 2022

If you can paste your patch, I'll report it upstream

@RumovZ
Copy link
Collaborator Author

RumovZ commented Oct 3, 2022

diff --git a/cargo/cargo_build_script_runner/lib.rs b/cargo/cargo_build_script_runner/lib.rs
index b1aa7932..809253bc 100644
--- a/cargo/cargo_build_script_runner/lib.rs
+++ b/cargo/cargo_build_script_runner/lib.rs
@@ -103,12 +103,17 @@ impl BuildScriptOutput {
     /// Converts a [BufReader] into a vector of [BuildScriptOutput] enums.
     fn outputs_from_reader<T: Read>(mut reader: BufReader<T>) -> Vec<BuildScriptOutput> {
         let mut result = Vec::<BuildScriptOutput>::new();
-        let mut line = String::new();
-        while reader.read_line(&mut line).expect("Cannot read line") != 0 {
-            if let Some(bso) = BuildScriptOutput::new(&line) {
+        let mut buf = Vec::new();
+        while reader
+            .read_until(b'\n', &mut buf)
+            .expect("Cannot read line")
+            != 0
+        {
+            let line = &String::from_utf8_lossy(&buf);
+            if let Some(bso) = BuildScriptOutput::new(line) {
                 result.push(bso);
             }
-            line.clear();
+            buf.clear();
         }
         result
     }

@RumovZ RumovZ changed the title Can't build Anki anymore run fails on Windows due to latest rust_rules Oct 3, 2022
@dae
Copy link
Member

dae commented Oct 4, 2022

Thanks, reported on bazelbuild/rules_rust#1583

@siegieda53a
Copy link

Hi, I am new in Anki. According to documentation I try to download the project. Unfortunately, I have the same bug. There is nothing in documentation where I find rules_rust in my project nor how to use it. Could you tell me how to fix it?

@RumovZ
Copy link
Collaborator Author

RumovZ commented Oct 6, 2022

rules_rust is a separate project. As you are new to Anki, I recommend not trying to fix this on your end and waiting on an upstream fix. In the meantime and depending on your intention, you can make do with runopt or work on a snapshot before the problematic commit.

@dae dae closed this as completed in 2f67738 Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants