use newer libxml2 package (#109)

wch-ch32v003
Matt Knight 1 year ago
parent ab8fda1814
commit 7ba67916af

@ -4,106 +4,41 @@ const LibExeObjStep = std.build.LibExeObjStep;
const Step = std.build.Step;
const GeneratedFile = std.build.GeneratedFile;
const libxml2 = @import("deps/zig-libxml2/libxml2.zig");
fn root() []const u8 {
return comptime (std.fs.path.dirname(@src().file) orelse unreachable) ++ "/";
}
pub const Regz = struct {
builder: *Builder,
exe: *LibExeObjStep,
build_options: *std.build.OptionsStep,
xml: libxml2.Library,
pub const Options = struct {
target: ?std.zig.CrossTarget = null,
optimize: ?std.builtin.OptimizeMode = null,
};
pub fn create(builder: *Builder, opts: Options) *Regz {
const target = opts.target orelse std.zig.CrossTarget{};
const optimize = opts.optimize orelse .Debug;
const xml = libxml2.create(builder, target, optimize, .{
.iconv = false,
.lzma = false,
.zlib = false,
}) catch unreachable;
builder.installArtifact(xml.step);
const commit_result = std.ChildProcess.exec(.{
.allocator = builder.allocator,
.argv = &.{ "git", "rev-parse", "HEAD" },
.cwd = comptime root(),
}) catch unreachable;
const build_options = builder.addOptions();
build_options.addOption([]const u8, "commit", commit_result.stdout);
const clap_dep = builder.dependency("clap", .{});
pub fn build(b: *std.build.Builder) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{
.preferred_optimize_mode = .ReleaseSafe,
});
const exe = builder.addExecutable(.{
.name = "regz",
.root_source_file = .{ .path = comptime root() ++ "src/main.zig" },
const libxml2_dep = b.dependency("libxml2", .{
.target = target,
.optimize = optimize,
.iconv = false,
});
exe.addOptions("build_options", build_options);
exe.addModule("clap", clap_dep.module("clap"));
xml.link(exe);
var regz = builder.allocator.create(Regz) catch unreachable;
regz.* = Regz{
.builder = builder,
.exe = exe,
.build_options = build_options,
.xml = xml,
};
return regz;
}
pub fn addGeneratedChipFile(regz: *Regz, schema_path: []const u8) GeneratedFile {
// generate path where the schema will go
// TODO: improve collision resistance
const basename = std.fs.path.basename(schema_path);
const extension = std.fs.path.extension(basename);
const destination_path = regz.builder.cache_root.join(regz.builder.allocator, &.{
"regz",
std.mem.join(regz.builder.allocator, "", &.{
basename[0 .. basename.len - extension.len],
".zig",
}) catch unreachable,
}) catch unreachable;
const run_step = regz.builder.addRunArtifact(regz.exe);
run_step.addArgs(&.{
schema_path,
"-o",
destination_path,
const clap_dep = b.dependency("clap", .{
.target = target,
.optimize = optimize,
});
return GeneratedFile{
.step = &run_step.step,
.path = destination_path,
};
}
};
const rev_parse = b.addSystemCommand(&.{ "git", "rev-parse", "HEAD" });
const commit = rev_parse.captureStdOut();
pub fn build(b: *std.build.Builder) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{
.preferred_optimize_mode = .ReleaseSafe,
});
const build_options = b.addOptions();
build_options.addOptionPath("commit", commit);
const regz = Regz.create(b, .{
const regz = b.addExecutable(.{
.name = "regz",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(regz.exe);
regz.addOptions("build_options", build_options);
regz.addModule("clap", clap_dep.module("clap"));
regz.linkLibrary(libxml2_dep.artifact("xml2"));
b.installArtifact(regz);
const run_cmd = b.addRunArtifact(regz.exe);
const run_cmd = b.addRunArtifact(regz);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
@ -118,13 +53,11 @@ pub fn build(b: *std.build.Builder) !void {
.path = "src/contextualize-fields.zig",
},
});
regz.xml.link(contextualize_fields);
contextualize_fields.linkLibrary(libxml2_dep.artifact("xml2"));
const contextualize_fields_run = b.addRunArtifact(contextualize_fields);
if (b.args) |args| {
contextualize_fields_run.addArgs(args);
}
const contextualize_fields_step = b.step("contextualize-fields", "Create ndjson of all the fields with the context of parent fields");
contextualize_fields_step.dependOn(&contextualize_fields_run.step);
@ -134,15 +67,11 @@ pub fn build(b: *std.build.Builder) !void {
.path = "src/characterize.zig",
},
});
regz.xml.link(characterize);
characterize.linkLibrary(libxml2_dep.artifact("xml2"));
const characterize_run = b.addRunArtifact(characterize);
const characterize_step = b.step("characterize", "Characterize a number of xml files whose paths are piped into stdin, results are ndjson");
characterize_step.dependOn(&characterize_run.step);
const test_chip_file = regz.addGeneratedChipFile("tests/svd/cmsis-example.svd");
_ = test_chip_file;
const tests = b.addTest(.{
.root_source_file = .{
.path = "src/Database.zig",
@ -150,12 +79,8 @@ pub fn build(b: *std.build.Builder) !void {
.target = target,
.optimize = optimize,
});
tests.addOptions("build_options", regz.build_options);
//tests.addPackagePath("xml", "src/xml.zig");
//tests.addPackagePath("Database", "src/Database.zig");
regz.xml.link(tests);
tests.addOptions("build_options", build_options);
tests.linkLibrary(libxml2_dep.artifact("xml2"));
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&tests.step);
}

@ -2,6 +2,10 @@
.name = "regz",
.version = "0.0.0",
.dependencies = .{
.libxml2 = .{
.url = "https://github.com/mitchellh/zig-build-libxml2/archive/4e80a167d6e13e09e0da77457310401084e758cc.tar.gz",
.hash = "1220000fd2a0f192b1aab0c12be0080748e774044399d69a852ffa38a58f2b1dcc09",
},
.clap = .{
.url = "https://github.com/Hejsil/zig-clap/archive/f49b94700e0761b7514abdca0e4f0e7f3f938a93.tar.gz",
.hash = "1220f48518ce22882e102255ed3bcdb7aeeb4891f50b2cdd3bd74b5b2e24d3149ba2",

@ -977,17 +977,14 @@ fn stringify_test(comptime init: DbInitFn, expected: []const u8) !void {
defer buffer.deinit();
const test_stringify_opts = .{
.whitespace = .{
.indent_level = 0,
.indent = .{ .space = 2 },
},
.whitespace = .indent_2,
};
try db.json_stringify(test_stringify_opts, buffer.writer());
try expectEqualStrings(expected, buffer.items);
}
fn empty_db(allocator: Allocator) !Database {
fn empty_db(allocator: Allocator) error{OutOfMemory}!Database {
return Database.init(allocator);
}

Loading…
Cancel
Save