Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
run: echo "LIBXML2=$(pkg-config libxml-2.0 --variable=libdir)/libxml2.so" >> "$GITHUB_ENV"
if: ${{ matrix.with_default_bindings }}
- uses: actions/checkout@v2
with:
submodules: 'true'
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -40,6 +42,8 @@ jobs:
with:
packages: "libpython3-dev"
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: Install libxml ${{ matrix.libxml_version }} by hand
run: |
wget https://download.gnome.org/sources/libxml2/$(echo ${{ matrix.libxml_version }} | sed -e 's/\.[0-9]*$//')/libxml2-${{ matrix.libxml_version }}.tar.xz
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
override: true
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Build Documentation
uses: actions-rs/cargo@v1
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
VCPKG_ROOT: C:\vcpkg
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Setup vcpkg libxml2 Cache
uses: actions/cache@v4
id: vcpkg-cache
Expand All @@ -35,6 +37,8 @@ jobs:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: msys2/setup-msys2@v2
with:
path-type: minimal
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "libxml-sys/libxml2"]
path = libxml-sys/libxml2
url = https://github.com/GNOME/libxml2.git
branch = 2.15
56 changes: 27 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
[package]
name = "libxml"
[workspace]
members = ['.', "libxml-sys"]
[workspace.package]
version = "0.3.8"
edition = "2024"
authors = ["Andreas Franzén <andreas@devil.se>", "Deyan Ginev <deyan.ginev@gmail.com>","Jan Frederik Schaefer <j.schaefer@jacobs-university.de>"]
authors = [
"Andreas Franzén <andreas@devil.se>",
"Deyan Ginev <deyan.ginev@gmail.com>",
"Jan Frederik Schaefer <j.schaefer@jacobs-university.de>",
]
description = "A Rust wrapper for libxml2 - the XML C parser and toolkit developed for the Gnome project"
repository = "https://github.com/KWARC/rust-libxml"
documentation = "https://kwarc.github.io/rust-libxml/libxml/index.html"
readme = "README.md"
license = "MIT"
keywords = ["xml", "libxml","xpath", "parser", "html"]
build = "build.rs"
exclude = [
"scripts/*"
]
keywords = ["xml", "libxml", "xpath", "parser", "html"]

[package]
name = "libxml"
version.workspace = true
edition.workspace = true
authors.workspace = true
description.workspace = true
repository.workspace = true
documentation = "https://kwarc.github.io/rust-libxml/libxml/index.html"
readme.workspace = true
license.workspace = true
keywords.workspace = true
exclude = ["scripts/*"]

[lib]
name = "libxml"

[features]
iconv = ["libxml-sys/iconv"]
zlib = ["libxml-sys/zlib"]

[dependencies]
libc = "0.2"

[target.'cfg(all(target_family = "windows", target_env = "msvc"))'.build-dependencies]
vcpkg = "0.2"

[target.'cfg(all(target_family = "windows", target_env = "gnu"))'.build-dependencies]
pkg-config = "0.3.2"

[target.'cfg(macos)'.build-dependencies]
pkg-config = "0.3.2"

[target.'cfg(unix)'.build-dependencies]
pkg-config = "0.3.2"

[build-dependencies.bindgen]
version = "0.72"
features = [
"runtime",
]
default-features = false

libxml-sys = { path = "libxml-sys" }
[dev-dependencies]
rayon = "1.0.0"
criterion = "0.8.0"
Expand Down
171 changes: 0 additions & 171 deletions build.rs

This file was deleted.

28 changes: 28 additions & 0 deletions libxml-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "libxml-sys"
version.workspace = true
edition.workspace = true
authors.workspace = true
description.workspace = true
repository.workspace = true
readme.workspace = true
license.workspace = true
keywords.workspace = true

[features]
iconv = []
zlib = []

[dependencies]


[build-dependencies]
cmake = "0.1.57"
bindgen = "0.72.1"
regex = "1.12.3"

[package.metadata.cross.target.x86_64-pc-windows-gnu]
pre-build = [
"apt-get update",
"apt-get install -y win-iconv-mingw-w64-dev libz-mingw-w64-dev",
]
1 change: 1 addition & 0 deletions libxml-sys/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Build libxml2 from source
74 changes: 74 additions & 0 deletions libxml-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use std::{env, fs, path::PathBuf};

fn main() {
let out_dir = env::var("OUT_DIR").unwrap();

let iconv = if cfg!(feature = "iconv") { "ON" } else { "OFF" };
let zlib = if cfg!(feature = "zlib") { "ON" } else { "OFF" };

let path = cmake::Config::new("libxml2")
.define("BUILD_SHARED_LIBS", "OFF")
.define("LIBXML2_WITH_ICONV", iconv)
.define("LIBXML2_WITH_ZLIB", zlib)
.define("LIBXML2_WITH_C14N", "ON")
.build();

println!("cargo::rerun-if-changed=libxml2");

let host = env::var("HOST").unwrap();

let mut libs = std::process::Command::new("sh")
.arg(path.join("bin/xml2-config"))
.arg("--libs")
.output()
.map(|output| String::from_utf8_lossy(&output.stdout).to_string());
let mut cflags = std::process::Command::new("sh")
.arg(path.join("bin/xml2-config"))
.arg("--cflags")
.output()
.map(|output| String::from_utf8_lossy(&output.stdout).to_string());

if host.contains("windows") {
let reg = regex::Regex::new("-(.)/(.)/").expect("reg");
libs = libs.map(|v| reg.replace_all(&v, "-$1$2:/").to_string());
cflags = cflags.map(|v| reg.replace_all(&v, "-$1$2:/").to_string());
}
// NOTE: Manually specify
let mut libs = libs.unwrap_or_else(|_| format!("-L{} -lxml2", path.join("lib").display()));
if host.contains("msvc") {
let mut iters = fs::read_dir(path.join("lib"))
.expect("read_dir")
.filter_map(|p| {
p.ok().and_then(|p| {
let metadata = p.metadata().ok()?;
let file_name = p.file_name();
let name = file_name.to_string_lossy();
if metadata.is_file() && name.starts_with("libxml2") && name.ends_with(".lib") {
return Some(
name
.trim_end_matches(".lib")
.to_string(),
);
}
None
})
});
let name = iters.next().expect("xml name");
println!("cargo:rustc-link-lib=bcrypt");
libs = libs.replace("-lxml2", &format!("-l{}", name));
}
println!("cargo::rustc-flags={}", libs);

// Note: Manually specify
let cflags = cflags.unwrap_or_else(|_| format!("-I{}", path.join("include/libxml2").display()));
let bindings_path = PathBuf::from(out_dir).join("bindings.rs");
bindgen::builder()
.opaque_type("max_align_t")
.header("src/wrapper.h")
.clang_args(&["-DLIBXML_C14N_ENABLED", "-DLIBXML_OUTPUT_ENABLED"])
.clang_args(cflags.split_whitespace())
.generate()
.expect("failed to generate bindings with bindgen")
.write_to_file(bindings_path)
.expect("Failed to write bindings.rs");
}
Loading
Loading