acheronfail / repgrep

An interactive replacer for ripgrep that makes it easy to find and replace across files on the command line.
Apache License 2.0
267 stars 4 forks source link

`build.rs` can't find asciidoctor on msys2/mingw #101

Closed ognevny closed 9 months ago

ognevny commented 9 months ago

running cargo build at master shows it

$ cat target/debug/build/repgrep-fe233b2d10e66f92/stderr
Could not run 'asciidoctor' binary, skipping man page generation.
Error from running 'asciidoctor': program not found

while actual output from asciidoctor is

```console $ asciidoctor Usage: asciidoctor [OPTION]... FILE... Convert the AsciiDoc input FILE(s) to the backend output format (e.g., HTML 5, DocBook 5, etc.) Unless specified otherwise, the output is written to a file whose name is derived from the input file. Application log messages are printed to STDERR. Example: asciidoctor input.adoc -b, --backend BACKEND set backend output format: [html5, xhtml5, docbook5, manpage] (default: html5) additional backends are supported via extended converters (e.g., pdf, epub3) -d, --doctype DOCTYPE document type to use when converting document: [article, book, manpage, inline] (default: article) -e, --embedded suppress enclosing document structure and output an embedded document (default: false) -o, --out-file FILE output file (default: based on path of input file); use - to output to STDOUT --safe set safe mode level to safe (default: unsafe) enables include directives, but prevents access to ancestor paths of source file provided for compatibility with the asciidoc command -S, --safe-mode SAFE_MODE set safe mode level explicitly: [unsafe, safe, server, secure] (default: unsafe) disables potentially dangerous macros in source files, such as include::[] -s, --no-header-footer suppress enclosing document structure and output an embedded document (default: false) -n, --section-numbers auto-number section titles in the HTML backend; disabled by default --eruby ERUBY specify eRuby implementation to use when rendering custom ERB templates: [erb, erubi, erubis] (default: erb) -a, --attribute name[=value] a document attribute to set in the form of name, name!, or name=value pair this attribute takes precedence over the same attribute defined in the source document unless either the name or value ends in @ (i.e., name@=value or name=value@) -T, --template-dir DIR a directory containing custom converter templates that override the built-in converter (requires tilt gem) may be specified multiple times -E, --template-engine NAME template engine to use for the custom converter templates (loads gem on demand) -B, --base-dir DIR base directory containing the document and resources (default: directory of source file) -R, --source-dir DIR source root directory (used for calculating path in destination directory) -D, --destination-dir DIR destination output directory (default: directory of source file) -I, --load-path DIRECTORY add a directory to the $LOAD_PATH may be specified more than once -r, --require LIBRARY require the specified library before executing the processor (using require) may be specified more than once --failure-level LEVEL set minimum log level that yields a non-zero exit code: [INFO, WARN, ERROR, FATAL] (default: FATAL) -q, --quiet silence application log messages and script warnings (default: false) --trace include backtrace information when reporting errors (default: false) -v, --verbose directs application messages logged at DEBUG or INFO level to STDERR (default: false) -w, --warnings turn on script warnings (default: false) -t, --timings print timings report (default: false) -h, --help [TOPIC] print a help message show this usage if TOPIC is not specified or recognized show an overview of the AsciiDoc syntax if TOPIC is syntax dump the Asciidoctor man page (in troff/groff format) if TOPIC is manpage -V, --version display the version and runtime environment (or -v if no other flags or arguments) ```

toolchain info: (see msys2.org for details) MSYSTEM: CLANG64 asciidoctor -V:

Asciidoctor 2.0.20 [https://asciidoctor.org]
Runtime Environment (ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x64-mingw-ucrt]) (lc:IBM866 fs:UTF-8 in:UTF-8 ex:UTF-8)

cargo -Vv:

cargo 1.75.0
release: 1.75.0
host: x86_64-pc-windows-gnu
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.4.0-DEV (sys:0.4.68+curl-8.4.0 vendored ssl:Schannel)
os: Windows 10.0.22621 (Windows 11 CoreSingleLanguage) [64-bit]

running asciidoctor directly works

$ asciidoctor \
      --doctype manpage \
      --backend manpage \
      --destination-dir dummy \
      doc/rgr.1.template
acheronfail commented 9 months ago

I've done little testing on windows, on even then it was for x86_64-pc-windows-msvc. The build doesn't fail though, right? (In build.rs that error should return Ok(()) and the build should continue).

That said, seems strange that you have it installed, but it can't find it. How did you install asciidoctor? Is it on your PATH?

All that build.rs does is Command::new("asciidoctor").output(), so if it's on your PATH it should work (as far as I know - my understanding of the PATH is Unix-based not Windows-based...).

ognevny commented 9 months ago

I've done little testing on windows, on even then it was for x86_64-pc-windows-msvc. The build doesn't fail though, right? (In build.rs that error should return Ok(()) and the build should continue).

it doesn't fail, only asciidoctor isn't found

That said, seems strange that you have it installed, but it can't find it. How did you install asciidoctor? Is it on your PATH?

installed through pacman -S $MINGW_PACKAGE_PREFIX-asciidoctor

All that build.rs does is Command::new("asciidoctor").output(), so if it's on your PATH it should work.

in msys2 PATH is set for certain MSYSTEMs, so /clang64/bin is included

acheronfail commented 9 months ago

Can you point me to any documentation on how you setup pacman with msys2? I've not ever setup a windows machine this way, since it's something I don't know about I'm happy to learn.

If you point me to the website/documentation/etc, I'll try to reproduce this in a VM and see how far I get. 🙂

ognevny commented 9 months ago

Can you point me to any documentation on how you setup pacman with msys2? I've not ever setup a windows machine this way, since it's something I don't know about I'm happy to learn.

If you point me to the website/documentation/etc, I'll try to reproduce this in a VM and see how far I get. 🙂

just visit https://msys2.org/, there is beginners' guide

acheronfail commented 9 months ago

Alrighty, so I installed msys2. Hopefully I set things up right!

This was more or less what I did:

# install asciidoctor and ripgrep
$ pacman -S mingw-w64-clang-x86_64-asciidoctor
$ pacman -S mingw-w64-clang-x86_64-ripgrep

# update path to include installed packages
$ export PATH="/clang64/bin:$PATH"

# install rustup in msys2
$ export RUSTUP_HOME="$HOME/.rustup"
$ export CARGO_HOME="$HOME/.cargo"
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-host=x86_64-pc-windows-gnu

# install git and clone repgrep
$ pacman -S git
$ git clone https://github.com/acheronfail/repgrep

# check asciidoctor
$ which asciidoctor
/clang64/bin/asciidoctor

# run test
$ cd repgrep
$ cargo clean; cargo build -q && cat target/debug/build/repgrep-*/stderr
Could not run 'asciidoctor' binary, skipping manpage generation.
Error from running 'asciidoctor': program not found

It seems you're right - in this msys2 environment things are weird.

I added a line to print the PATH in the build.rs script, and msys2 prints it as this:

"C:\\msys64\\home\\acheronfail\\src\\repgrep\\target\\debug\\deps;C:\\msys64\\home\\acheronfail\\src\\repgrep\\target\\debug;C:\\msys64\\home\\acheronfail\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib;C:/msys64/home/acheronfail/.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\bin;C:\\msys64\\clang64\\bin;C:\\msys64\\home\\acheronfail\\.cargo\\bin;C:\\msys64\\usr\\local\\bin;C:\\msys64\\usr\\bin;C:\\msys64\\usr\\bin;C:\\msys64\\opt\\bin;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\msys64\\usr\\bin\\site_perl;C:\\msys64\\usr\\bin\\vendor_perl;C:\\msys64\\usr\\bin\\core_perl"

It's clear that the /clang64/bin directory is there - I wonder if this is due to some Windows path behaviour? If I echo $PATH in hte msys2 terminal it appears to be a unix-like path, but when printing the path in the Rust build script it's been converted to Windows-style paths... I don't know enough about the msys2 environment, but if asciidoctor can definitely be found on the path, I'm not sure what's going on here... 🤔

ognevny commented 9 months ago

I applied a workaround, see https://github.com/msys2/MINGW-packages/pull/19779

ognevny commented 9 months ago

sorry for late answer, few notes:

  1. we maintain a rust with needed target (pacman -S mingw-w64-clang-x86_64-rust), rustup sometimes shows unwanted behaviour
  2. as msys2 based on cygwin (core things), the path behaviour is copied from there (there is a cygpath util for resolving some things), the default root is a directory of msys2 installation (usually C:\msys64\). also if you use CLANG64 shell, you don't need to add /clang64/bin to PATH.
  3. windows is weird, I used some sh scripts in my code, and I had to write Command::new("sh").arg("script") to make it work. any other ways return os code 3 or os code 193. but when I tried to apply this workaround in build.rs, it didn't work
acheronfail commented 9 months ago

Great that you were able to find a good workaround. I'm still not 100% clear on how msys2 works, having just used WSL myself on Windows platforms myself.

Since you have the workaround, I'm going to close this issue. Thanks for reporting it though!