libxml2 issue with Homebrew on Linux #2627
-
Hi, I'm trying to build a Homebrew formula for Hurl. On macOS, I don't have any problem and my formula is building. My brew formula is: ...
uses_from_macos "libxml2"
def install
system "cargo", "install", *std_cargo_args(path: "packages/hurl")
end If I try to build as it, I've a compilation error (raised by libxml/build.rs, a build script used by cargo):
This build script use the Rust crate pkg_config to find libxml2 build metadata: https://github.com/KWARC/rust-libxml/blob/40020e15b726c27dc4435e9d104a9799f4c77f46/build.rs#L29-L35 #[cfg(any(target_family="unix", target_os="macos"))]
mod pkg_config_dep {
pub fn find() -> bool {
if pkg_config::find_library("libxml-2.0").is_ok() {
return true;
}
false
}
} I struggle to understand why this snippet doesn't seems to work: in the brew log, I can see In the same configuration, if I build my app directly with cargo ( I acknowledge I'm not an expert neither in Homebrew nor Rust, even in Linux stuff so I maybe miss something trivial. Thank you, edit: I've added a kind of minimal setup to reproduce my problem:
src/main.rs: use libxml::tree::Document;
fn main() {
let doc_result = Document::new();
assert!(doc_result.is_ok());
} Cargo.toml [package]
name = "testxml"
version = "0.1.0"
edition = "2021"
[dependencies]
libxml = "0.3.0"
class Testxml < Formula
desc "Test xml"
url "https://github.com/jcamiel/testxml/archive/refs/tags/0.0.1.tar.gz"
sha256 "72c145617d9af341d332c330f164a987a11b6abe590522a8b675ccd8f00edb78"
depends_on "rust" => :build
on_linux do
depends_on "libxml2" => :build
end
def install
system "cargo", "install", *std_cargo_args(path: ".")
end
end
I use this Dockerfile to test a new Linux image: FROM debian:bullseye
RUN apt-get update
RUN apt-get -y install curl \
git \
clang
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
ENV PATH="/home/linuxbrew/.linuxbrew/bin:${PATH}" Then, install the test formula:
Jc |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Two things here that might help:
|
Beta Was this translation helpful? Give feedback.
Two things here that might help:
You probably need to add
pkg-config
as a Linux only dependency. That is how most Rust packages findlibxml2
.You should check if the final binaries you build are dynamically linked to
libxml2
, or if it's just using the headers. You can check what is dynamically linked to your binaries withldd
. Iflibxml2
is in that list, thenlibxml2
needs to be a run time dependency as well on Linux, and you should remove=> :build
after it. Note that becauselibxml2
is provided by macOS but not Linux, we typically useuses_from_macos "libxml2"
(possibly followed by=> :build
) instead, unless the version oflibxml2
provided by macOS is too old.