libxml2-rs
Rust bindings for the libxml2 C library.
Installation
On UNIX based systems such as macOS and Linux, the installation is simple. Assuming that both Cargo and libxml2 is installed. If not, then Cargo can be installed using Rustup.
libxml2 (Linux/macOS)
On Ubuntu/Debian systems:
On macOS:
- Homebrew:
- MacPorts:
- Conda
Build libxml2-rs (Linux/macOS)
To build and test the library, use:
Windows installation
Just using the standard cargo build command on Windows may result in an error, here is a guide on installing libxml2 and libxml2-rs on Windows:
Install libxml2 (vcpkg)
The best way to install libxml2 on Windows is with vcpkg, using:
vcpkg install libxml2
The result of this will provide the path to a toolchain file vcpkg.cmake.
Since libxml2-rs uses CMake to build the C bindings,
it is necessary to pass the toolchain to CMake using an environment variable
$Env:CMAKE_TOOLCHAIN_FILE = "$Env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake"
Include files
Using the above command allows CMake to find libxml2,
but running cargo build fails to find the libxml2 header files.
These can be specified using:
# For Windows (x64)
$Env:LIBXML2_INCLUDE_DIR = "$Env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\include\libxml2\"
This allows cargo build to run correctly.
However, the cargo test command and any executable built with this library will fail.
Linking and running tests
The cargo test command fails since the library file libxml2.lib is not found. The location for this may be specified using:
# x64
$Env:LIBXML2_LIBRARY_DIR = "$Env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\lib\"
Building the test executables then succeeds, but the tests may still fail if the vcpkg binary directory is not in your PATH variable, e.g.
# x64
$Env:PATH = "$Env:PATH;$Env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\bin\;"
Assuming that these variables are set correctly, building and testing should work.