You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Matt Knight f42d279890 Fix build api breaks and morale (#85)
* fix build api breaks

* fix ci

* zig parser api update
7 months ago
..
.github/workflows Fix build api breaks and morale (#85) 7 months ago
libxml2 Fix build api breaks and morale (#85) 7 months ago
nix Fix build api breaks and morale (#85) 7 months ago
override Fix build api breaks and morale (#85) 7 months ago
test Fix build api breaks and morale (#85) 7 months ago
.envrc Fix build api breaks and morale (#85) 7 months ago
.gitignore Fix build api breaks and morale (#85) 7 months ago
.gitmodules Fix build api breaks and morale (#85) 7 months ago
LICENSE Fix build api breaks and morale (#85) 7 months ago
README.md Fix build api breaks and morale (#85) 7 months ago
build.zig Fix build api breaks and morale (#85) 7 months ago
flake.lock Fix build api breaks and morale (#85) 7 months ago
flake.nix Fix build api breaks and morale (#85) 7 months ago
gyro.zzz Fix build api breaks and morale (#85) 7 months ago
libxml2.zig Fix build api breaks and morale (#85) 7 months ago
shell.nix Fix build api breaks and morale (#85) 7 months ago

README.md

libxml2 Built with Zig

This repository contains Zig code for building libxml2 using Zig. This allows other projects that use the Zig build system to easily consume this library, cross-compile it, etc.

Why? Using the Zig build system makes it much easier to cross-compile a library, even if you aren't using the Zig programming language. See Maintain it with Zig for some more information.

This library currently hardcodes the libxml2 version (latest as of writing this but unlikely to remain that way for long). In the future, I'd like to allow users to pass in a custom libxml2 directory, and it'd be really cool to setup some sort of Github Action to check for new versions and try to pull it in. Maybe one day.

Usage

While we all eagerly await the Zig Package Manager, the recommended way to use this is via git submodules or just embedding this into your repository.

const libxml2 = @import("path/to/libxml2.zig");

pub fn build(b: *std.build.Builder) !void {
    // ...

    const lib = try libxml2.create(b, target, mode, .{
        // These are the minimal options to NOT depend on any other libraries.
        // If you ave these libraries, just set these to true.
        .iconv = false,
        .lzma = false,
        .zlib = false,
    });

    const exe = b.addExecutable("my-program", "src/main.zig");
    lib.link(exe);
}

This package does not provide any Zig-native APIs to access the underlying C library. This is by design, the focus of this repository is only to enable building the underlying library using the Zig build system. Therefore, to use the library, import the headers and use the C API:

const c = @cImport({
    @cInclude("libxml/xmlreader.h");
});

// ... do stuff with `c`

Other Dependencies

Some features require other libraries. In the example above, we disabled those features. For example, if you set .zlib = true, then zlib must be available.

In this scenario, you can find and use a zlib build such as zig-zlib as normal. When that library is also added to the project, it adds its include paths and linking information to the build, so libxml2 can be built with zlib support.