Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ multiple threads, fcvvdp is over 221% faster than the reference implementation.

Compilation requires:

- [Zig](https://ziglang.org/) 0.16.x
- [Zig](https://ziglang.org/) 0.17.x
- macOS, Linux, or Unix-like operating system

### Binary

0. Ensure all dependencies are installed
1. Run `zig build --release=fast` (add `-Dflto=true` for FLTO)
1. Run `zig build --release=fast` (add `-Dflto=true` for FLTO on ELF targets)
2. Your `fcvvdp` binary will be in `zig-out/bin/`

```sh
Expand Down Expand Up @@ -84,7 +84,7 @@ sRGB PNG, PNM/PAM, QOI, or Y4M input expected
### Library

0. Ensure all dependencies are installed
1. Run `zig build --release=fast` (add `-Dflto=true` for FLTO)
1. Run `zig build --release=fast` (add `-Dflto=true` for FLTO on ELF targets)
2. The `libcvvdp` library will be in `zig-out/lib/`, alongside `cvvdp.h` in
`zig-out/include/`.

Expand Down
50 changes: 29 additions & 21 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
// Copyright © 2026, Halide Compression, LLC.
// All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
const std = @import("std");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const strip = b.option(bool, "strip", "strip symbols from the binary, defaults to false") orelse false;
const flto = b.option(bool, "flto", "enable Link Time Optimization, defaults to false") orelse false;
const flto = b.option(bool, "flto", "enable Link Time Optimization on ELF targets, defaults to false") orelse false;
if (flto and target.result.ofmt != .elf) {
const unsupported = b.addFail("Zig 0.17 supports this project's LTO build only on ELF targets; omit -Dflto=true for macOS");
b.default_step.dependOn(&unsupported.step);
return;
}
const options = b.addOptions();

// simpleimgio
const simpleimgio_dep = b.dependency("simpleimgio", .{
.target = target,
.optimize = optimize,
});
const simpleimgio = simpleimgio_dep.module("simpleimgio");

// libspng
const spng_dep = b.dependency("spng", .{
.target = target,
.optimize = optimize,
Expand All @@ -45,9 +34,9 @@ pub fn build(b: *std.Build) void {
translate_c.addIncludePath(spng.getEmittedIncludeTree());
const c_module = translate_c.createModule();

// 'libcvvdp.a' static lib
const cvvdp = b.addLibrary(.{
.name = "cvvdp",
.use_lld = if (flto) true else null,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
Expand All @@ -74,10 +63,29 @@ pub fn build(b: *std.Build) void {
});

if (target_result.cpu.arch == .x86_64) {
cvvdp.root_module.addCSourceFile(.{
var avx2_query = target.query;
avx2_query.cpu_features_sub.removeFeature(@backingInt(std.Target.x86.Feature.avx2));
avx2_query.cpu_features_sub.removeFeature(@backingInt(std.Target.x86.Feature.fma));
avx2_query.cpu_features_add.addFeature(@backingInt(std.Target.x86.Feature.avx2));
avx2_query.cpu_features_add.addFeature(@backingInt(std.Target.x86.Feature.fma));
const avx2_module = b.createModule(.{
.target = b.resolveTargetQuery(avx2_query),
.optimize = optimize,
.link_libc = true,
.strip = strip,
});
avx2_module.addIncludePath(b.path("."));
avx2_module.addCSourceFile(.{
.file = b.path("src/cvvdp_avx2.c"),
.flags = &cvvdp_flags,
});
const avx2 = b.addObject(.{
.name = "cvvdp-avx2",
.root_module = avx2_module,
.use_lld = if (flto) true else null,
});
avx2.lto = if (flto) .full else null;
cvvdp.root_module.addObject(avx2);
} else if (target_result.cpu.arch == .aarch64) {
cvvdp.root_module.addCSourceFile(.{
.file = b.path("src/cvvdp_neon.c"),
Expand All @@ -88,10 +96,8 @@ pub fn build(b: *std.Build) void {
cvvdp.lto = if (flto) .full else null;
b.installArtifact(cvvdp);

// cvvdp.h
cvvdp.installHeader(b.path("src/cvvdp.h"), "cvvdp.h");

// 'fcvvdp' executable
const cvvdpenc = b.addExecutable(.{
.name = "fcvvdp",
.root_module = b.createModule(.{
Expand All @@ -102,12 +108,14 @@ pub fn build(b: *std.Build) void {
.strip = strip,
}),
.use_llvm = true,
.use_lld = if (flto) true else null,
});
cvvdpenc.root_module.addOptions("build_opts", options);
cvvdpenc.root_module.addImport("c", c_module);
cvvdpenc.root_module.addImport("simpleimgio", simpleimgio);
cvvdpenc.root_module.addIncludePath(b.path("."));
cvvdpenc.root_module.linkLibrary(cvvdp);
cvvdpenc.root_module.linkLibrary(spng);
cvvdpenc.lto = if (flto) .full else null;
b.installArtifact(cvvdpenc);
}
14 changes: 7 additions & 7 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
.{
.name = .fcvvdp,
.version = "0.4.0",
.version = "0.4.1",
.dependencies = .{
.spng = .{
.url = "git+https://github.com/allyourcodebase/libspng.git#8858232bde47083739c3e25f676093423610ec5e",
.hash = "spng-0.0.1-T166cP8UAABcBGTOPKx7kUUyHEcu0eDvN8LnSIj3S_cW",
.url = "git+https://github.com/gianni-rosato/libspng.git#c459a577fe818f4dfdb3ceaea46b702bd8c9d118",
.hash = "spng-0.0.2-T166cHISAADR33WgZ6IfHBVOPj0gwjyqnxYxc-XTWF8Z",
},
.simpleimgio = .{
.url = "git+https://github.com/gianni-rosato/simpleimgio.git#98031ca5c7487fdc9d57f97184f3bd6044b3ab07",
.hash = "simpleimgio-0.0.1-oHTuOdP9AADRXI8TEcZr6hNxRYS-OH3ZoYMAS-jxxe5H",
.url = "git+https://github.com/gianni-rosato/simpleimgio.git#98473d19f243eefd4ef29a2149af47bc072c2484",
.hash = "simpleimgio-0.0.1-oHTuOfMbAQBWcIe2wQBOoIIrItr8a-kBVowFbAaZkwXy",
},
},
.fingerprint = 0xfe41744458a5e60e,
.minimum_zig_version = "0.16.0",
.minimum_zig_version = "0.17.0",
.paths = .{
"build.zig",
"build.zig.zon",
"c_imports.h",
"src",
"third-party",
"LICENSE",
"README.md",
},
Expand Down
2 changes: 1 addition & 1 deletion src/cvvdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {
#endif

/* Version */
static const char* CVVDP_VERSION = "0.4.0";
static const char* CVVDP_VERSION = "0.4.1";

/* Error codes */
typedef enum FcvvdpError {
Expand Down