KWARC / rust-libxml

Rust wrapper for libxml2
https://crates.io/crates/libxml
MIT License
76 stars 38 forks source link

windows cargo build fails on libxml #81

Closed lepapareil closed 3 years ago

lepapareil commented 3 years ago

Hi,

I try to build my application on windows, and during the compilation the libxml compilation fails:

error: failed to run custom build command for `libxml v0.2.15`

Caused by:
  process didn't exit successfully: `C:\Applications\target\debug\build\libxml-19fee8ddbe173fc8\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'Could not find libxml2.', C:\Users\frxn7205\.cargo\registry\src\github.com-1ecc6299db9ec823\libxml-0.2.15\build.rs:16:3
  stack backtrace:
     0:     0x7ff6a2cf016e - std::backtrace_rs::backtrace::dbghelp::trace
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\..\..\backtrace\src\backtrace\dbghelp.rs:108
     1:     0x7ff6a2cf016e - std::backtrace_rs::backtrace::trace_unsynchronized
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
     2:     0x7ff6a2cf016e - std::sys_common::backtrace::_print_fmt
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\sys_common\backtrace.rs:67
     3:     0x7ff6a2cf016e - std::sys_common::backtrace::_print::{{impl}}::fmt
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\sys_common\backtrace.rs:46
     4:     0x7ff6a2cffc1b - core::fmt::write
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\core\src\fmt\mod.rs:1078
     5:     0x7ff6a2cecdd8 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\io\mod.rs:1518
     6:     0x7ff6a2cf2cfd - std::sys_common::backtrace::_print
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\sys_common\backtrace.rs:49
     7:     0x7ff6a2cf2cfd - std::sys_common::backtrace::print
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\sys_common\backtrace.rs:36
     8:     0x7ff6a2cf2cfd - std::panicking::default_hook::{{closure}}
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\panicking.rs:208
     9:     0x7ff6a2cf28d8 - std::panicking::default_hook
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\panicking.rs:227
    10:     0x7ff6a2cf366f - std::panicking::rust_panic_with_hook
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\panicking.rs:593
    11:     0x7ff6a2c91fa1 - std::panicking::begin_panic::{{closure}}<str*>
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\library\std\src\panicking.rs:522
    12:     0x7ff6a2c9566f - std::sys_common::backtrace::__rust_end_short_backtrace<closure-0,!>
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\library\std\src\sys_common\backtrace.rs:141
    13:     0x7ff6a2c91ed7 - std::panicking::begin_panic<str*>
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\library\std\src\panicking.rs:521
    14:     0x7ff6a2c9102f - build_script_build::main
                                 at C:\Users\frxn7205\.cargo\registry\src\github.com-1ecc6299db9ec823\libxml-0.2.15\build.rs:16
    15:     0x7ff6a2c910fb - core::ops::function::FnOnce::call_once<fn(),tuple<>>
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\library\core\src\ops\function.rs:227
    16:     0x7ff6a2c9109b - std::sys_common::backtrace::__rust_begin_short_backtrace<fn(),tuple<>>
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\library\std\src\sys_common\backtrace.rs:125
    17:     0x7ff6a2c91351 - std::rt::lang_start::{{closure}}<tuple<>>
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\library\std\src\rt.rs:66
    18:     0x7ff6a2cf3873 - core::ops::function::impls::{{impl}}::call_once
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\library\core\src\ops\function.rs:280
    19:     0x7ff6a2cf3873 - std::panicking::try::do_call
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\panicking.rs:381
    20:     0x7ff6a2cf3873 - std::panicking::try
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\panicking.rs:345
    21:     0x7ff6a2cf3873 - std::panic::catch_unwind
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\panic.rs:396
    22:     0x7ff6a2cf3873 - std::rt::lang_start_internal
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\rt.rs:51
    23:     0x7ff6a2c91323 - std::rt::lang_start<tuple<>>
                                 at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\library\std\src\rt.rs:65
    24:     0x7ff6a2c91060 - main
    25:     0x7ff6a2d04010 - invoke_main
                                 at d:\agent\_work\63\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
    26:     0x7ff6a2d04010 - __scrt_common_main_seh
                                 at d:\agent\_work\63\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    27:     0x7ffcbab27974 - BaseThreadInitThunk
    28:     0x7ffcbb79a0b1 - RtlUserThreadStart
warning: build failed, waiting for other jobs to finish...
error: build failed

however I installed gcc and the libxml2 on my windows with win-builds and vcpkg:

$ vpkg list
libxml2:x86-windows                                2.9.10#2         Libxml2 is the XML C parser and toolkit develope...

$ where gcc.exe
C:\Applications\winbuilds\bin\gcc.exe

Can you help me with this? Is it even possible to compile under windows with the use of libxml ?

thks :)

dginev commented 3 years ago

We had a PR about Windows support so those builds were supposed to have been enabled recently: https://github.com/KWARC/rust-libxml/pull/77

I don't usually develop on Windows so it may take me a bit of time before I diagnose - need to figure out if the crate build regressed, or some other detail is off.

ghost commented 3 years ago

Did you run vcpkg integrate install and set env VCPKGRS_DYNAMIC to 1 before?

lepapareil commented 3 years ago

Did you run vcpkg integrate install and set env VCPKGRS_DYNAMIC to 1 before?

I've just tried it but I have the same result using x86_x64 cross tools command prompt for VS 2019 or cmd :

>vcpkg integrate install
Applied user-wide integration for this vcpkg root.

All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.

CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/Applications/vcpkg/scripts/buildsystems/vcpkg.cmake"
>set VCPKGRS_DYNAMIC=1
>echo %VCPKGRS_DYNAMIC%
1

>cargo clean
>del cargo.lock
>set RUST_BACKTRACE=1
>cargo check --verbose
........
error: failed to run custom build command for `libxml v0.2.15`

Caused by:
  process didn't exit successfully: `C:\Applications\hurl\target\debug\build\libxml-19fee8ddbe173fc8\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'Could not find libxml2.', C:\Users\frxn7205\.cargo\registry\src\github.com-1ecc6299db9ec823\libxml-0.2.15\build.rs:16:3
  stack backtrace:
     0: std::panicking::begin_panic<str*>
               at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\library\std\src\panicking.rs:521
     1: build_script_build::main
               at .\build.rs:16
     2: core::ops::function::FnOnce::call_once<fn(),tuple<>>
               at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\library\core\src\ops\function.rs:227
  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
lepapareil commented 3 years ago

We had a PR about Windows support so those builds were supposed to have been enabled recently:

77

I don't usually develop on Windows so it may take me a bit of time before I diagnose - need to figure out if the crate build regressed, or some other detail is off.

Me neither, my only goal is to get a windows version of my application. I tried cross platform compilation from linux without success. So I have to do it on a windows directly :)

ghost commented 3 years ago

You are using x86_64 msvc abi, so you need specify vcpkg's target architecture (default is x86-windows).

vcpkg install libxml2:x64-windows

dginev commented 3 years ago

Thanks for helping out here @oiatz , really appreciated! If either of you wants to write a small snippet about windows installation (or link to existing vcpkg docs that explain this), I will be happy to add it to the repo README. Not crucial for me though, I'm mostly happy @lepapareil may have a path to a working installation here.

lepapareil commented 3 years ago

You are the best @oiatz @dginev ! Finally the libxml compilation works :) Thank you very much for your help, I would never have finished without your answers :)

I have other little problems but I should be able to do it this time :) Thank you again for the speed of your answers :)

dginev commented 3 years ago

Excellent! I will close the issue here then. But my offer to add the installation fine-print to the README stands, it's just that I can't write it myself since I haven't done the Windows install - if anyone feels like it, a comment or a PR are welcome any time.

lepapareil commented 3 years ago

Excellent! I will close the issue here then. But my offer to add the installation fine-print to the README stands, it's just that I can't write it myself since I haven't done the Windows install - if anyone feels like it, a comment or a PR are welcome any time.

I will re-test the whole procedure and the software to be installed to ensure that the compilation is fully functional under windows. Then I will let you know to integrate it in your doc. :)

lepapareil commented 3 years ago

Hi @dginev, finally I have finished all my win64 build tests for hurl project. Here are all the steps required to build windows 64bit rust exe that use libxml:

C:\> choco install -y curl git unxUtils winlibs-llvm-free
C:\> refreshenv
C:\> %ChocolateyInstall%\bin\curl --output "c:\rustup-init.exe" "https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe"
C:\> c:\rustup-init.exe -y --default-toolchain stable-x86_64-pc-windows-msvc
C:\> git clone https://github.com/microsoft/vcpkg
C:\> .\vcpkg\bootstrap-vcpkg.bat
C:\> setx /M PATH "%PATH%;c:\vcpkg" && setx VCPKGRS_DYNAMIC "1" /M
C:\> refreshenv
C:\> vcpkg install libxml2:x64-windows
C:\> vcpkg integrate install
C:\> git clone <projectGitUrl>
C:\> cd <projectDir>
C:\> cargo build

enjoy 😄