zcatgui/build.zig
reugenio 0cdd44b8a0 fix: TTF ABGR format + herramienta diagnóstico cmap
Cambios:
- ttf.zig: Fix formato pixel ABGR (era RGBA invertido)
- cmap_debug.zig: Herramienta diagnóstico tabla cmap
- build.zig: Target cmap-debug para ejecutar diagnóstico
- docs/research/TTF_DEBUG_SESSION: Documentación sesión debug

Nota: El código base TTF funciona (cmap_debug lo confirma).
El bug de rendering sigue sin resolver en integración.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-16 22:00:54 +01:00

346 lines
11 KiB
Zig

const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Check if building for WASM
const is_wasm = target.result.cpu.arch == .wasm32 or target.result.cpu.arch == .wasm64;
// ===========================================
// Main library module
// ===========================================
const zcatgui_mod = b.createModule(.{
.root_source_file = b.path("src/zcatgui.zig"),
.target = target,
.optimize = optimize,
.link_libc = !is_wasm,
});
// Link SDL2 to the module (only for native builds)
if (!is_wasm) {
zcatgui_mod.linkSystemLibrary("SDL2", .{});
}
// ===========================================
// Tests
// ===========================================
const lib_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/zcatgui.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
lib_unit_tests.root_module.linkSystemLibrary("SDL2", .{});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
// ===========================================
// Examples
// ===========================================
// Hello World example
const hello_exe = b.addExecutable(.{
.name = "hello",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/hello.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zcatgui", .module = zcatgui_mod },
},
}),
});
hello_exe.root_module.linkSystemLibrary("SDL2", .{});
b.installArtifact(hello_exe);
const run_hello = b.addRunArtifact(hello_exe);
run_hello.step.dependOn(b.getInstallStep());
const hello_step = b.step("hello", "Run hello world example");
hello_step.dependOn(&run_hello.step);
// Macro demo
const macro_exe = b.addExecutable(.{
.name = "macro-demo",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/macro_demo.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zcatgui", .module = zcatgui_mod },
},
}),
});
macro_exe.root_module.linkSystemLibrary("SDL2", .{});
b.installArtifact(macro_exe);
const run_macro = b.addRunArtifact(macro_exe);
run_macro.step.dependOn(b.getInstallStep());
const macro_step = b.step("macro-demo", "Run macro recording demo");
macro_step.dependOn(&run_macro.step);
// Widgets demo
const widgets_exe = b.addExecutable(.{
.name = "widgets-demo",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/widgets_demo.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zcatgui", .module = zcatgui_mod },
},
}),
});
widgets_exe.root_module.linkSystemLibrary("SDL2", .{});
b.installArtifact(widgets_exe);
const run_widgets = b.addRunArtifact(widgets_exe);
run_widgets.step.dependOn(b.getInstallStep());
const widgets_step = b.step("widgets-demo", "Run widgets demo");
widgets_step.dependOn(&run_widgets.step);
// Table demo
const table_exe = b.addExecutable(.{
.name = "table-demo",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/table_demo.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zcatgui", .module = zcatgui_mod },
},
}),
});
table_exe.root_module.linkSystemLibrary("SDL2", .{});
b.installArtifact(table_exe);
const run_table = b.addRunArtifact(table_exe);
run_table.step.dependOn(b.getInstallStep());
const table_step = b.step("table-demo", "Run table demo with split panels");
table_step.dependOn(&run_table.step);
// ===========================================
// Debug tools
// ===========================================
// cmap debug - TTF font table diagnostics
const cmap_debug_exe = b.addExecutable(.{
.name = "cmap-debug",
.root_module = b.createModule(.{
.root_source_file = b.path("src/render/cmap_debug.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zcatgui", .module = zcatgui_mod },
},
}),
});
cmap_debug_exe.root_module.linkSystemLibrary("SDL2", .{});
b.installArtifact(cmap_debug_exe);
const run_cmap_debug = b.addRunArtifact(cmap_debug_exe);
run_cmap_debug.step.dependOn(b.getInstallStep());
const cmap_debug_step = b.step("cmap-debug", "Run TTF cmap diagnostics");
cmap_debug_step.dependOn(&run_cmap_debug.step);
// ===========================================
// WASM Build
// ===========================================
// WASM-specific module (no SDL2, no libc)
const wasm_target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
});
const zcatgui_wasm_mod = b.createModule(.{
.root_source_file = b.path("src/zcatgui.zig"),
.target = wasm_target,
.optimize = .ReleaseSmall,
});
// WASM demo executable
const wasm_demo = b.addExecutable(.{
.name = "zcatgui-demo",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/wasm_demo.zig"),
.target = wasm_target,
.optimize = .ReleaseSmall,
.imports = &.{
.{ .name = "zcatgui", .module = zcatgui_wasm_mod },
},
}),
});
// Export WASM functions
wasm_demo.entry = .{ .symbol_name = "wasm_main" };
wasm_demo.rdynamic = true;
// Install WASM to web directory
const install_wasm = b.addInstallArtifact(wasm_demo, .{
.dest_dir = .{ .override = .{ .custom = "../web" } },
.dest_sub_path = "zcatgui-demo.wasm",
});
const wasm_step = b.step("wasm", "Build WASM demo");
wasm_step.dependOn(&install_wasm.step);
// ===========================================
// Android Build
// ===========================================
// Android ARM64 target
const android_target = b.resolveTargetQuery(.{
.cpu_arch = .aarch64,
.os_tag = .linux,
.abi = .android,
});
const zcatgui_android_mod = b.createModule(.{
.root_source_file = b.path("src/zcatgui.zig"),
.target = android_target,
.optimize = .ReleaseSafe,
.link_libc = true,
});
// Android demo shared library
const android_demo_mod = b.createModule(.{
.root_source_file = b.path("examples/android_demo.zig"),
.target = android_target,
.optimize = .ReleaseSafe,
.link_libc = true,
.imports = &.{
.{ .name = "zcatgui", .module = zcatgui_android_mod },
},
});
const android_demo = b.addExecutable(.{
.name = "zcatgui",
.root_module = android_demo_mod,
.linkage = .dynamic,
});
// Link Android NDK libraries
android_demo.root_module.linkSystemLibrary("android", .{});
android_demo.root_module.linkSystemLibrary("log", .{});
// Install to android directory
const install_android = b.addInstallArtifact(android_demo, .{
.dest_dir = .{ .override = .{ .custom = "../android/libs/arm64-v8a" } },
.dest_sub_path = "libzcatgui.so",
});
const android_step = b.step("android", "Build Android shared library (ARM64)");
android_step.dependOn(&install_android.step);
// Android x86_64 (for emulator)
const android_x86_target = b.resolveTargetQuery(.{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .android,
});
const zcatgui_android_x86_mod = b.createModule(.{
.root_source_file = b.path("src/zcatgui.zig"),
.target = android_x86_target,
.optimize = .ReleaseSafe,
.link_libc = true,
});
const android_demo_x86_mod = b.createModule(.{
.root_source_file = b.path("examples/android_demo.zig"),
.target = android_x86_target,
.optimize = .ReleaseSafe,
.link_libc = true,
.imports = &.{
.{ .name = "zcatgui", .module = zcatgui_android_x86_mod },
},
});
const android_demo_x86 = b.addExecutable(.{
.name = "zcatgui",
.root_module = android_demo_x86_mod,
.linkage = .dynamic,
});
android_demo_x86.root_module.linkSystemLibrary("android", .{});
android_demo_x86.root_module.linkSystemLibrary("log", .{});
const install_android_x86 = b.addInstallArtifact(android_demo_x86, .{
.dest_dir = .{ .override = .{ .custom = "../android/libs/x86_64" } },
.dest_sub_path = "libzcatgui.so",
});
const android_x86_step = b.step("android-x86", "Build Android shared library (x86_64 for emulator)");
android_x86_step.dependOn(&install_android_x86.step);
// ===========================================
// iOS Build
// ===========================================
// iOS ARM64 target (device)
const ios_target = b.resolveTargetQuery(.{
.cpu_arch = .aarch64,
.os_tag = .ios,
});
const zcatgui_ios_mod = b.createModule(.{
.root_source_file = b.path("src/zcatgui.zig"),
.target = ios_target,
.optimize = .ReleaseSafe,
.link_libc = true,
});
// iOS static library (object file that can be linked into iOS app)
const ios_lib = b.addExecutable(.{
.name = "zcatgui",
.root_module = zcatgui_ios_mod,
.linkage = .static,
});
// Install to ios directory
const install_ios = b.addInstallArtifact(ios_lib, .{
.dest_dir = .{ .override = .{ .custom = "../ios" } },
.dest_sub_path = "libzcatgui.a",
});
const ios_step = b.step("ios", "Build iOS static library (ARM64 device)");
ios_step.dependOn(&install_ios.step);
// iOS Simulator (ARM64 for Apple Silicon Macs)
const ios_sim_target = b.resolveTargetQuery(.{
.cpu_arch = .aarch64,
.os_tag = .ios,
.abi = .simulator,
});
const zcatgui_ios_sim_mod = b.createModule(.{
.root_source_file = b.path("src/zcatgui.zig"),
.target = ios_sim_target,
.optimize = .ReleaseSafe,
.link_libc = true,
});
const ios_sim_lib = b.addExecutable(.{
.name = "zcatgui",
.root_module = zcatgui_ios_sim_mod,
.linkage = .static,
});
const install_ios_sim = b.addInstallArtifact(ios_sim_lib, .{
.dest_dir = .{ .override = .{ .custom = "../ios" } },
.dest_sub_path = "libzcatgui-simulator.a",
});
const ios_sim_step = b.step("ios-sim", "Build iOS static library (ARM64 simulator)");
ios_sim_step.dependOn(&install_ios_sim.step);
}