xu-cheng / katex-rs

Rust bindings to KaTeX
https://docs.rs/katex
Apache License 2.0
110 stars 11 forks source link

Testing katex in Windows CI failed though testing quick-js alone succeeded #10

Closed SichangHe closed 1 year ago

SichangHe commented 1 year ago

Testing katex in Windows CI failed though testing quick-js alone succeeded.

I am trying to fix the CI test of mdbook-katex.

Below is the log from testing a dummy crate with only katex as its dependency:

error: failed to run custom build command for `libquickjs-sys v0.9.0`

Caused by:
  process didn't exit successfully: `D:\a\mdbook-katex2\mdbook-katex2\target\debug\build\libquickjs-sys-3bf002dc4bca0895\build-script-build` (exit code: 101)
  --- stdout
  patching file libbf.c

  --- stderr
  Applying patches...
  Applying "js-tobigint64-overflow.patch"...
  Assertation failed!

  Program: C:\Strawberry\c\bin\patch.exe
  File: .\src\patch\2.5.9\patch-2.5.9-src\patch.c, Line 354

  Expression: hunk
  thread 'main' panicked at 'Patch command returned non-zero exit code', C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\libquickjs-sys-0.9.0\build.rs:136:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
Error: Process completed with exit code 1.

Since testing the dummy crate with only quick-js and libquickjs-sys succeeded, the above failure must have something to do with katex. I cannot figure out what made the difference though.

SichangHe commented 1 year ago

To be specific, I am trying to solve this issue from mdbook-katex.

xu-cheng commented 1 year ago

Since quickjs crate only supports Windows when using MinGW/MSYS2, it is recommended to use duktape backend on Windows. For example, you can follow the below example in Cargo.toml.

https://github.com/xu-cheng/pandoc-katex/blob/417b9e37cb11338f775c03eeda746f2f71e5ac0d/Cargo.toml#L21-L25

To use quickjs backend on Windows, it is actually easier to build it on Linux with cross-compilation. That is also another reason why it is better to use duktape backend on Windows. For your problem specifically, I think it may be due to incompatible patch program. Can you try to install gnu patch?

SichangHe commented 1 year ago

Thank you for your early response.

I am not familiar with Windows build support, nor do I have a Windows machine to test on. Could you provide more information on using GNA Patch in Windows CIs?

Meanwhile, I will try the first approach you provide.

Steven Hé (Sīchàng)

xu-cheng commented 1 year ago

If you use CI and want to use quickjs, I suggest to use cross-compilation. You can use the following as an example:

https://github.com/xu-cheng/pandoc-katex/blob/75d9677cf863c2913f2b24ca0aea877aea59d67a/.github/workflows/build.yml

Again, I suggest to use duktape, which is much easier.

SichangHe commented 1 year ago

It seem like duktape did not work. This is the commit. Did I do anything wrong?

xu-cheng commented 1 year ago

You need to remove "Setup msys64 and mingw64" step as well as --target x86_64-pc-windows-gnu in cargo build.