2024-04-20 05:49:42 -08:00
|
|
|
// SPDX-FileCopyrightText: Yorhel <projects@yorhel.nl>
|
2021-07-18 01:36:05 -08:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
2021-04-29 02:48:45 -08:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
2023-04-09 07:45:11 -08:00
|
|
|
pub fn build(b: *std.Build) void {
|
2021-04-29 02:48:45 -08:00
|
|
|
const target = b.standardTargetOptions(.{});
|
2024-04-25 04:15:43 -08:00
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
2021-04-29 02:48:45 -08:00
|
|
|
|
2023-04-09 07:41:06 -08:00
|
|
|
const pie = b.option(bool, "pie", "Build with PIE support (by default false)") orelse false;
|
2024-11-16 23:30:40 -09:00
|
|
|
const strip = b.option(bool, "strip", "Strip debugging info (by default false)") orelse false;
|
2023-04-09 07:41:06 -08:00
|
|
|
|
2025-03-05 11:10:55 -09:00
|
|
|
const main_mod = b.createModule(.{
|
2024-04-11 23:52:22 -08:00
|
|
|
.root_source_file = b.path("src/main.zig"),
|
2023-04-09 07:45:11 -08:00
|
|
|
.target = target,
|
|
|
|
|
.optimize = optimize,
|
2024-11-16 23:30:40 -09:00
|
|
|
.strip = strip,
|
2024-01-03 04:35:20 -09:00
|
|
|
.link_libc = true,
|
2023-04-09 07:45:11 -08:00
|
|
|
});
|
2025-03-05 11:10:55 -09:00
|
|
|
main_mod.linkSystemLibrary("ncursesw", .{});
|
|
|
|
|
main_mod.linkSystemLibrary("libzstd", .{});
|
2023-04-09 07:45:11 -08:00
|
|
|
|
2025-03-05 11:10:55 -09:00
|
|
|
const exe = b.addExecutable(.{
|
|
|
|
|
.name = "ncdu",
|
|
|
|
|
.root_module = main_mod,
|
|
|
|
|
});
|
2024-01-03 04:35:20 -09:00
|
|
|
exe.pie = pie;
|
2025-02-20 07:48:05 -09:00
|
|
|
// https://github.com/ziglang/zig/blob/faccd79ca5debbe22fe168193b8de54393257604/build.zig#L745-L748
|
|
|
|
|
if (target.result.os.tag.isDarwin()) {
|
2023-02-21 20:51:08 -09:00
|
|
|
// useful for package maintainers
|
|
|
|
|
exe.headerpad_max_install_names = true;
|
|
|
|
|
}
|
2023-04-09 07:45:11 -08:00
|
|
|
b.installArtifact(exe);
|
2021-04-29 02:48:45 -08:00
|
|
|
|
2023-04-09 07:45:11 -08:00
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
2021-04-29 02:48:45 -08:00
|
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
|
|
|
if (b.args) |args| {
|
|
|
|
|
run_cmd.addArgs(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const run_step = b.step("run", "Run the app");
|
|
|
|
|
run_step.dependOn(&run_cmd.step);
|
2021-05-04 08:01:49 -08:00
|
|
|
|
2023-04-09 07:45:11 -08:00
|
|
|
const unit_tests = b.addTest(.{
|
2025-03-05 11:10:55 -09:00
|
|
|
.root_module = main_mod,
|
2023-04-09 07:45:11 -08:00
|
|
|
});
|
|
|
|
|
unit_tests.pie = pie;
|
|
|
|
|
|
|
|
|
|
const run_unit_tests = b.addRunArtifact(unit_tests);
|
|
|
|
|
|
|
|
|
|
const test_step = b.step("test", "Run unit tests");
|
|
|
|
|
test_step.dependOn(&run_unit_tests.step);
|
|
|
|
|
}
|