lzanini / mdbook-katex

A preprocessor for mdBook, rendering LaTex equations to HTML at build time.
MIT License
205 stars 34 forks source link

cargo install fails because of libquickjs-sys patch #15

Closed nickdanis closed 1 year ago

nickdanis commented 3 years ago

Running cargo install mdbook-katex using cargo 1.53.0 on Windows 10 seems to work until eventually the build fails with this error:

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

Caused by:
  process didn't exit successfully: `C:\Users\(user)\AppData\Local\Temp\cargo-installwvCHAe\release\build\libquickjs-sys-f1a22357f8cab028\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\(user)\.cargo\registry\src\github.com-1ecc6299db9ec823\libquickjs-sys-0.9.0\build.rs:136:9

Even though it seems to be an issue with libquickjs-sys v0.9.0 I wonder if there's a workaround to still get mdbook-katex installed. (I'm new to the rust/cargo ecosystem.)

Treeniks commented 3 years ago

There is actually a way to install mdbook-katex on windows. All you need to do is install the MinGW toolchain with MSYS2 and then install for the x86_64-pc-windows-gnu target.

First install MSYS2, e.g. with scoop:

scoop install msys2

Once installed, run MSYS2 once for the first-time setup. Inside the msys2 shell, install the base-devel and mingw-w64-x86_64-toolchain packages, as documented on the MSYS2 website:

pacman -Syu
# it seems one cannot upgrade msys2 and install packages at the same time
# because it will want to restart the shell after upgrading
pacman -Sy base-devel mingw-w64-x86_64-toolchain

Then, you will also need to add the mingw bin directory to your path, as well as the msys2 usr/bin directory. This depends on the installation, for scoop the directories are %USERPROFILE%\scoop\apps\msys2\current\mingw64\bin and %USERPROFILE%\scoop\apps\msys2\current\usr\bin (don't forget to restart your shell after).

When using the installers from the MinGW or MSYS2 websites, the procedure might be slightly different.

Lastly, add the required target with rustup:

rustup target add x86_64-pc-windows-gnu

Then, to install mdbook-katex, simply specify the target for the install:

cargo install mdbook-katex --target=x86_64-pc-windows-gnu
SichangHe commented 1 year ago

It should build now since I changed the Windows build to with duktype. Please open another issue if you have other issues.