Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mitchellh/zig-libxml2
libxml2 built using Zig build system
https://github.com/mitchellh/zig-libxml2
Last synced: about 1 month ago
JSON representation
libxml2 built using Zig build system
- Host: GitHub
- URL: https://github.com/mitchellh/zig-libxml2
- Owner: mitchellh
- License: mit
- Created: 2022-01-12T20:38:39.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-02T21:39:07.000Z (over 1 year ago)
- Last Synced: 2024-10-24T16:10:28.984Z (about 2 months ago)
- Language: Zig
- Homepage:
- Size: 55.7 KB
- Stars: 78
- Watchers: 6
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - mitchellh/zig-libxml2
- awesome-zig - zig-libxml2ποΈlibxml2 built using Zig build system
README
# 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](https://kristoff.it/blog/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](https://github.com/ziglang/zig/issues/943),
the recommended way to use this is via git submodules or just embedding
this into your repository.```zig
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:```zig
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](https://github.com/mattnite/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.