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; // =========================================== // Dependencies // =========================================== const zcatttf_dep = b.dependency("zcatttf", .{ .target = target, .optimize = optimize, }); const zcatttf_mod = zcatttf_dep.module("zcatttf"); // =========================================== // Main library module // =========================================== const zcatgui_mod = b.createModule(.{ .root_source_file = b.path("src/zcatgui.zig"), .target = target, .optimize = optimize, .link_libc = !is_wasm, .imports = &.{ .{ .name = "zcatttf", .module = zcatttf_mod }, }, }); // 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, .imports = &.{ .{ .name = "zcatttf", .module = zcatttf_mod }, }, }), }); 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); // =========================================== // WASM Build // =========================================== // WASM-specific module (no SDL2, no libc) const wasm_target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding, }); // zcatttf for WASM const zcatttf_wasm_dep = b.dependency("zcatttf", .{ .target = wasm_target, .optimize = .ReleaseSmall, }); const zcatttf_wasm_mod = zcatttf_wasm_dep.module("zcatttf"); const zcatgui_wasm_mod = b.createModule(.{ .root_source_file = b.path("src/zcatgui.zig"), .target = wasm_target, .optimize = .ReleaseSmall, .imports = &.{ .{ .name = "zcatttf", .module = zcatttf_wasm_mod }, }, }); // 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, }); // zcatttf for Android ARM64 const zcatttf_android_dep = b.dependency("zcatttf", .{ .target = android_target, .optimize = .ReleaseSafe, }); const zcatttf_android_mod = zcatttf_android_dep.module("zcatttf"); const zcatgui_android_mod = b.createModule(.{ .root_source_file = b.path("src/zcatgui.zig"), .target = android_target, .optimize = .ReleaseSafe, .link_libc = true, .imports = &.{ .{ .name = "zcatttf", .module = zcatttf_android_mod }, }, }); // 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, }); // zcatttf for Android x86_64 const zcatttf_android_x86_dep = b.dependency("zcatttf", .{ .target = android_x86_target, .optimize = .ReleaseSafe, }); const zcatttf_android_x86_mod = zcatttf_android_x86_dep.module("zcatttf"); const zcatgui_android_x86_mod = b.createModule(.{ .root_source_file = b.path("src/zcatgui.zig"), .target = android_x86_target, .optimize = .ReleaseSafe, .link_libc = true, .imports = &.{ .{ .name = "zcatttf", .module = zcatttf_android_x86_mod }, }, }); 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, }); // zcatttf for iOS const zcatttf_ios_dep = b.dependency("zcatttf", .{ .target = ios_target, .optimize = .ReleaseSafe, }); const zcatttf_ios_mod = zcatttf_ios_dep.module("zcatttf"); const zcatgui_ios_mod = b.createModule(.{ .root_source_file = b.path("src/zcatgui.zig"), .target = ios_target, .optimize = .ReleaseSafe, .link_libc = true, .imports = &.{ .{ .name = "zcatttf", .module = zcatttf_ios_mod }, }, }); // 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, }); // zcatttf for iOS Simulator const zcatttf_ios_sim_dep = b.dependency("zcatttf", .{ .target = ios_sim_target, .optimize = .ReleaseSafe, }); const zcatttf_ios_sim_mod = zcatttf_ios_sim_dep.module("zcatttf"); const zcatgui_ios_sim_mod = b.createModule(.{ .root_source_file = b.path("src/zcatgui.zig"), .target = ios_sim_target, .optimize = .ReleaseSafe, .link_libc = true, .imports = &.{ .{ .name = "zcatttf", .module = zcatttf_ios_sim_mod }, }, }); 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); }