Skip to content

Commit

Permalink
zig update 0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marler8997 authored and ikskuh committed Jul 11, 2024
1 parent 17894e7 commit d103ec3
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 178 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
submodules: 'recursive'

- name: Install Zig
uses: goto-bus-stop/setup-zig@v2
uses: mlugg/setup-zig@v1
with:
version: v0.11.0
version: 0.13.0

- name: Install dotnet sdk
uses: actions/setup-dotnet@v4
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
zig-cache/
.zig-cache/
zig-out/
dev-thingies/
kcov-output/
Expand Down
88 changes: 47 additions & 41 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");

fn initNativeLibrary(lib: *std.build.CompileStep, tvg: *std.Build.Module) void {
lib.addModule("tvg", tvg);
lib.addIncludePath(.{ .path = "src/binding/include" });
fn initNativeLibrary(lib: *std.Build.Step.Compile, tvg: *std.Build.Module) void {
lib.root_module.addImport("tvg", tvg);
lib.addIncludePath(lib.step.owner.path("src/binding/include"));
lib.bundle_compiler_rt = true;
}

Expand All @@ -12,13 +12,13 @@ pub fn build(b: *std.Build) !void {

// TinyVG package
const tvg = b.addModule("tvg", .{
.source_file = .{ .path = "src/lib/tinyvg.zig" },
.dependencies = &.{.{ .name = "ptk", .module = ptk }},
.root_source_file = b.path("src/lib/tinyvg.zig"),
.imports = &.{ .{ .name = "ptk", .module = ptk }},
});

const args_dep = b.dependency("args", .{});
const args = args_dep.module("args");
const www_folder = std.build.InstallDir{ .custom = "www" };
const www_folder = std.Build.InstallDir{ .custom = "www" };

const install_include = b.option(bool, "install-include", "Installs the include directory") orelse true;
const install_www = b.option(bool, "install-www", "Installs the www directory (polyfill)") orelse true;
Expand All @@ -30,7 +30,7 @@ pub fn build(b: *std.Build) !void {

const static_native_lib = b.addStaticLibrary(.{
.name = "tinyvg",
.root_source_file = .{ .path = "src/binding/binding.zig" },
.root_source_file = b.path("src/binding/binding.zig"),
.target = target,
.optimize = optimize,
});
Expand All @@ -39,14 +39,14 @@ pub fn build(b: *std.Build) !void {
b.installArtifact(static_native_lib);
}

const dynamic_lib_name = if (target.isWindows())
const dynamic_lib_name = if (target.result.os.tag == .windows)
"tinyvg.dll"
else
"tinyvg";

const dynamic_native_lib = b.addSharedLibrary(.{
.name = dynamic_lib_name,
.root_source_file = .{ .path = "src/binding/binding.zig" },
.root_source_file = b.path("src/binding/binding.zig"),
.target = target,
.optimize = optimize,
});
Expand All @@ -56,47 +56,47 @@ pub fn build(b: *std.Build) !void {
}

if (install_include) {
const install_header = b.addInstallFileWithDir(.{ .path = "src/binding/include/tinyvg.h" }, .header, "tinyvg.h");
const install_header = b.addInstallFileWithDir(b.path("src/binding/include/tinyvg.h"), .header, "tinyvg.h");
b.getInstallStep().dependOn(&install_header.step);
}

const render = b.addExecutable(.{
.name = "tvg-render",
.root_source_file = .{ .path = "src/tools/render.zig" },
.root_source_file = b.path("src/tools/render.zig"),
.target = target,
.optimize = optimize,
});
render.addModule("tvg", tvg);
render.addModule("args", args);
render.root_module.addImport("tvg", tvg);
render.root_module.addImport("args", args);
if (install_bin) {
b.installArtifact(render);
}

const text = b.addExecutable(.{
.name = "tvg-text",
.root_source_file = .{ .path = "src/tools/text.zig" },
.root_source_file = b.path("src/tools/text.zig"),
.target = target,
.optimize = optimize,
});
text.addModule("tvg", tvg);
text.addModule("args", args);
text.addModule("ptk", ptk);
text.root_module.addImport("tvg", tvg);
text.root_module.addImport("args", args);
text.root_module.addImport("ptk", ptk);
if (install_bin) {
b.installArtifact(text);
}

const ground_truth_generator = b.addExecutable(.{
.name = "ground-truth-generator",
.root_source_file = .{ .path = "src/lib/data/ground-truth.zig" },
.main_pkg_path = .{ .path = "src/lib" },
.root_source_file = b.path("src/lib/ground-truth.zig"),
.target = b.host,
.optimize = optimize,
});
for (tvg.dependencies.keys(), tvg.dependencies.values()) |name, mod| {
ground_truth_generator.addModule(name, mod);
for (tvg.import_table.keys(), tvg.import_table.values()) |name, mod| {
ground_truth_generator.root_module.addImport(name, mod);
}

const generate_ground_truth = b.addRunArtifact(ground_truth_generator);
generate_ground_truth.cwd = b.cache_root.path;
generate_ground_truth.cwd = .{ .cwd_relative = b.cache_root.path.? };

const gen_gt_step = b.step("generate", "Regenerates the ground truth data.");

Expand All @@ -111,14 +111,14 @@ pub fn build(b: *std.Build) !void {
tvg_conversion.addArg("2");
tvg_conversion.addArg("--output");
tvg_conversion.addArg(file[0 .. file.len - 3] ++ "tga");
tvg_conversion.cwd = b.cache_root.path;
tvg_conversion.cwd = .{ .cwd_relative = b.cache_root.path.? };
tvg_conversion.step.dependOn(&generate_ground_truth.step);

const tvgt_conversion = b.addRunArtifact(text);
tvgt_conversion.addArg(file);
tvgt_conversion.addArg("--output");
tvgt_conversion.addArg(file[0 .. file.len - 3] ++ "tvgt");
tvgt_conversion.cwd = b.cache_root.path;
tvgt_conversion.cwd = .{ .cwd_relative = b.cache_root.path.? };
tvgt_conversion.step.dependOn(&generate_ground_truth.step);

gen_gt_step.dependOn(&tvgt_conversion.step);
Expand All @@ -127,64 +127,70 @@ pub fn build(b: *std.Build) !void {

{
const tvg_tests = b.addTest(.{
.root_source_file = tvg.source_file,
.root_source_file = tvg.root_source_file.?,
.optimize = optimize,
.main_pkg_path = .{ .path = "src" },
});
for (tvg.dependencies.keys(), tvg.dependencies.values()) |name, mod| {
tvg_tests.addModule(name, mod);
for (tvg.import_table.keys(), tvg.import_table.values()) |name, mod| {
tvg_tests.root_module.addImport(name, mod);
}

const static_binding_test = b.addExecutable(.{
.name = "static-native-binding",
.target = target,
.optimize = optimize,
});
static_binding_test.linkLibC();
static_binding_test.addIncludePath(.{ .path = "src/binding/include" });
static_binding_test.addCSourceFile(.{ .file = .{ .path = "examples/usage.c" }, .flags = &[_][]const u8{ "-Wall", "-Wextra", "-pedantic", "-std=c99" } });
static_binding_test.addIncludePath(b.path("src/binding/include"));
static_binding_test.addCSourceFile(.{
.file = b.path("examples/usage.c"),
.flags = &[_][]const u8{ "-Wall", "-Wextra", "-pedantic", "-std=c99" },
});
static_binding_test.linkLibrary(static_native_lib);

const dynamic_binding_test = b.addExecutable(.{
.name = "dynamic-native-binding",
.optimize = optimize,
.target = target,
});
dynamic_binding_test.linkLibC();
dynamic_binding_test.addIncludePath(.{ .path = "src/binding/include" });
dynamic_binding_test.addCSourceFile(.{ .file = .{ .path = "examples/usage.c" }, .flags = &[_][]const u8{ "-Wall", "-Wextra", "-pedantic", "-std=c99" } });
dynamic_binding_test.addIncludePath(b.path("src/binding/include"));
dynamic_binding_test.addCSourceFile(.{ .file = b.path("examples/usage.c"), .flags = &[_][]const u8{ "-Wall", "-Wextra", "-pedantic", "-std=c99" } });
dynamic_binding_test.linkLibrary(dynamic_native_lib);

const static_binding_test_run = b.addRunArtifact(static_binding_test);
static_binding_test_run.cwd = b.cache_root.path;
static_binding_test_run.cwd = .{ .cwd_relative = b.cache_root.path.? };

const dynamic_binding_test_run = b.addRunArtifact(dynamic_binding_test);
dynamic_binding_test_run.cwd = b.cache_root.path;
dynamic_binding_test_run.cwd = .{ .cwd_relative = b.cache_root.path.? };

const test_step = b.step("test", "Runs all tests");
test_step.dependOn(&b.addRunArtifact(tvg_tests).step);
test_step.dependOn(&static_binding_test_run.step);
test_step.dependOn(&dynamic_binding_test_run.step);
}

const polyfill = b.addSharedLibrary(.{
const polyfill = b.addExecutable(.{
.name = "tinyvg",
.root_source_file = .{ .path = "src/polyfill/tinyvg.zig" },
.target = .{
.root_source_file = b.path("src/polyfill/tinyvg.zig"),
.target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.cpu_model = .baseline,
.os_tag = .freestanding,
},
}),
.optimize = optimize,
});
polyfill.strip = (optimize != .Debug);
polyfill.addModule("tvg", tvg);
polyfill.entry = .disabled;
polyfill.root_module.export_symbol_names = &.{ "convertToSvg" };
polyfill.root_module.strip = (optimize != .Debug);
polyfill.root_module.addImport("tvg", tvg);

if (install_www) {
var artifact_install = b.addInstallArtifact(polyfill, .{});
artifact_install.dest_dir = www_folder;
b.getInstallStep().dependOn(&artifact_install.step);
}

const copy_stuff = b.addInstallFileWithDir(.{ .path = "src/polyfill/tinyvg.js" }, www_folder, "tinyvg.js");
const copy_stuff = b.addInstallFileWithDir(b.path("src/polyfill/tinyvg.js"), www_folder, "tinyvg.js");

if (install_www) {
b.getInstallStep().dependOn(&copy_stuff.step);
Expand Down
17 changes: 13 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
.version = "0.0.1",
.dependencies = .{
.args = .{
.url = "https://github.com/MasterQ32/zig-args/archive/91d1e89fb89a4d01dec7c9aec95b0a324080ebcc.tar.gz",
.hash = "12203d04cafc97f952d74cdb077e74c0ab3414f9f6b5fbd159112c62bfa584a0dbed",
.url = "https://github.com/ikskuh/zig-args/archive/03af1b6c5bfda9646a562c861055024daed5b238.tar.gz",
.hash = "1220904d2fdcd970dd0d216211d092eb3ef6da01117163cc9393ab845a1d66c029d9",
},
.ptk = .{
.url = "https://github.com/MasterQ32/parser-toolkit/archive/6238b7c6893582fb56f39676a090b1af1226fe1a.tar.gz",
.hash = "1220cf55c10add71a9cd2591dbe118ffa9a9198e21069e440fae1f6e3eef6f274733",
.url = "https://github.com/ikskuh/parser-toolkit/archive/9349d087a3216ebea27cc99b5b4bd8affe234816.tar.gz",
.hash = "12206f0ade18be8db985f6a688ca7ec9ffdbb95f033c8db91760b0d13cfe27618b61",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"docs",
"examples",
"LICENSE",
"README.md",
"src",
},
}
4 changes: 2 additions & 2 deletions src/binding/binding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ fn renderBitmap(data: []const u8, src_anti_alias: c.tinyvg_AntiAlias, width: u32
var temp_mem = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer temp_mem.deinit();

var size_hint: tvg.rendering.SizeHint = if (width == 0 and height == 0)
const size_hint: tvg.rendering.SizeHint = if (width == 0 and height == 0)
.inherit
else if (width == 0)
tvg.rendering.SizeHint{ .height = height }
else if (height == 0)
tvg.rendering.SizeHint{ .width = width }
else
tvg.rendering.SizeHint{ .size = .{ .width = width, .height = height } };
var anti_alias: tvg.rendering.AntiAliasing = @enumFromInt(src_anti_alias);
const anti_alias: tvg.rendering.AntiAliasing = @enumFromInt(src_anti_alias);

var image = try tvg.rendering.renderBuffer(
temp_mem.allocator(),
Expand Down
40 changes: 20 additions & 20 deletions src/lib/builder.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ pub fn Builder(comptime Writer: type) type {
const rwidth = mapSizeToType(u8, width) catch return error.OutOfRange;
const rheight = mapSizeToType(u8, height) catch return error.OutOfRange;

try self.writer.writeIntLittle(u8, rwidth);
try self.writer.writeIntLittle(u8, rheight);
try self.writer.writeInt(u8, rwidth, .little);
try self.writer.writeInt(u8, rheight, .little);
},

.default => {
const rwidth = mapSizeToType(u16, width) catch return error.OutOfRange;
const rheight = mapSizeToType(u16, height) catch return error.OutOfRange;

try self.writer.writeIntLittle(u16, rwidth);
try self.writer.writeIntLittle(u16, rheight);
try self.writer.writeInt(u16, rwidth, .little);
try self.writer.writeInt(u16, rheight, .little);
},

.enhanced => {
try self.writer.writeIntLittle(u32, width);
try self.writer.writeIntLittle(u32, height);
try self.writer.writeInt(u32, width, .little);
try self.writer.writeInt(u32, height, .little);
},
}

Expand All @@ -93,21 +93,21 @@ pub fn Builder(comptime Writer: type) type {
(@as(u16, ((rgb8[1] >> 2) & 0x2F)) << 5) |
(@as(u16, ((rgb8[2] >> 3) & 0x1F)) << 11);

try self.writer.writeIntLittle(u16, value);
try self.writer.writeInt(u16, value, .little);
},

.u8888 => for (colors) |c| {
var rgba = c.toRgba8();
try self.writer.writeIntLittle(u8, rgba[0]);
try self.writer.writeIntLittle(u8, rgba[1]);
try self.writer.writeIntLittle(u8, rgba[2]);
try self.writer.writeIntLittle(u8, rgba[3]);
const rgba = c.toRgba8();
try self.writer.writeInt(u8, rgba[0], .little);
try self.writer.writeInt(u8, rgba[1], .little);
try self.writer.writeInt(u8, rgba[2], .little);
try self.writer.writeInt(u8, rgba[3], .little);
},
.f32 => for (colors) |c| {
try self.writer.writeIntLittle(u32, @as(u32, @bitCast(c.r)));
try self.writer.writeIntLittle(u32, @as(u32, @bitCast(c.g)));
try self.writer.writeIntLittle(u32, @as(u32, @bitCast(c.b)));
try self.writer.writeIntLittle(u32, @as(u32, @bitCast(c.a)));
try self.writer.writeInt(u32, @as(u32, @bitCast(c.r)), .little);
try self.writer.writeInt(u32, @as(u32, @bitCast(c.g)), .little);
try self.writer.writeInt(u32, @as(u32, @bitCast(c.b)), .little);
try self.writer.writeInt(u32, @as(u32, @bitCast(c.a)), .little);
},

.custom => return error.UnsupportedColorEncoding,
Expand Down Expand Up @@ -357,14 +357,14 @@ pub fn Builder(comptime Writer: type) type {
switch (self.range) {
.reduced => {
const reduced_val = std.math.cast(i8, val) orelse return error.OutOfRange;
try self.writer.writeIntLittle(i8, reduced_val);
try self.writer.writeInt(i8, reduced_val, .little);
},
.default => {
const reduced_val = std.math.cast(i16, val) orelse return error.OutOfRange;
try self.writer.writeIntLittle(i16, reduced_val);
try self.writer.writeInt(i16, reduced_val, .little);
},
.enhanced => {
try self.writer.writeIntLittle(i32, val);
try self.writer.writeInt(i32, val, .little);
},
}
}
Expand Down Expand Up @@ -405,7 +405,7 @@ const ReducedCount = enum(u6) {
_,
};

const ground_truth = @import("data/ground-truth.zig");
const ground_truth = @import("ground-truth.zig");

test "encode shield (default range, scale 1/256)" {
var buffer: [1024]u8 = undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/data/ground-truth.zig → src/lib/ground-truth.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const tvg = @import("../tinyvg.zig");
const tvg = @import("tinyvg.zig");

// pub const everything_16 = blk: {
// @setEvalBranchQuota(100_000);
Expand Down Expand Up @@ -241,7 +241,7 @@ pub fn writeEverything(src_writer: anytype, range: tvg.Range) !void {
Emitter.emitOutlineFillPath,
};

var style_base = [_]tvg.Style{
const style_base = [_]tvg.Style{
tvg.Style{ .flat = 0 },
tvg.Style{ .linear = .{
.point_0 = tvg.point(0, 0),
Expand Down
Loading

0 comments on commit d103ec3

Please sign in to comment.