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
38 changes: 8 additions & 30 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ pub fn build(b: *std.Build) !void {
"Filter tests to run",
) orelse &.{};

const trace = b.option(bool, "trace", "enable tracy tracing") orelse false;

const coverage = b.option(
bool,
"coverage",
Expand All @@ -21,15 +19,14 @@ pub fn build(b: *std.Build) !void {
"version",
try getVersionString(b, coreutils_version, b.build_root.path.?),
);
options.addOption(bool, "trace", trace);
const options_module = options.createModule();

// exe
{
const target = b.standardTargetOptions(.{});

const coreutils_target = CoreutilsTarget.fromOsTag(target.result.os.tag) orelse {
std.debug.panic("unsupported target OS {s}", .{@tagName(target.result.os.tag)});
std.debug.panic("unsupported target OS {t}", .{target.result.os.tag});
};

const coreutils_exe = b.addExecutable(.{
Expand All @@ -38,7 +35,6 @@ pub fn build(b: *std.Build) !void {
b,
target,
optimize,
trace,
coreutils_target,
options_module,
),
Expand Down Expand Up @@ -79,7 +75,6 @@ pub fn build(b: *std.Build) !void {
b,
target,
optimize,
trace,
coreutils_target,
options_module,
target.result.os.tag == builtin.os.tag,
Expand All @@ -97,29 +92,16 @@ fn createRootModule(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
trace: bool,
coreutils_target: CoreutilsTarget,
options_module: *std.Build.Module,
) *std.Build.Module {
const tracy_dep = b.dependency("tracy", .{
.target = target,
.optimize = optimize,
});

const coreutils_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});

coreutils_module.addImport("options", options_module);
coreutils_module.addImport("tracy", tracy_dep.module("tracy"));

if (trace) {
coreutils_module.addImport("tracy_impl", tracy_dep.module("tracy_impl_enabled"));
} else {
coreutils_module.addImport("tracy_impl", tracy_dep.module("tracy_impl_disabled"));
}

const target_options = b.addOptions();
target_options.addOption(CoreutilsTarget, "target_os", coreutils_target);
Expand All @@ -132,7 +114,6 @@ fn createTestAndCheckSteps(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
trace: bool,
coreutils_target: CoreutilsTarget,
options_module: *std.Build.Module,
is_native_target: bool,
Expand All @@ -146,13 +127,12 @@ fn createTestAndCheckSteps(
b,
target,
optimize,
trace,
coreutils_target,
options_module,
);

const coreutils_test = b.addTest(.{
.name = b.fmt("test_zig-coreutils-{s}", .{@tagName(target.result.os.tag)}),
.name = b.fmt("test_zig-coreutils-{t}", .{target.result.os.tag}),
.root_module = module,
.filters = test_filters,
});
Expand All @@ -178,8 +158,8 @@ fn createTestAndCheckSteps(
}

const target_test_step = b.step(
b.fmt("test_{s}", .{@tagName(target.result.os.tag)}),
b.fmt("Run the tests for {s}", .{@tagName(target.result.os.tag)}),
b.fmt("test_{t}", .{target.result.os.tag}),
b.fmt("Run the tests for {t}", .{target.result.os.tag}),
);

if (is_native_target or run_non_native_tests) {
Expand All @@ -197,7 +177,7 @@ fn createTestAndCheckSteps(
}

const build_exe = b.addExecutable(.{
.name = b.fmt("build_zig-coreutils-{s}", .{@tagName(target.result.os.tag)}),
.name = b.fmt("build_zig-coreutils-{t}", .{target.result.os.tag}),
.root_module = module,
});
target_test_step.dependOn(&build_exe.step);
Expand All @@ -206,23 +186,21 @@ fn createTestAndCheckSteps(

{
const coreutils_exe_check = b.addExecutable(.{
.name = b.fmt("check_zig-coreutils-{s}", .{@tagName(target.result.os.tag)}),
.name = b.fmt("check_zig-coreutils-{t}", .{target.result.os.tag}),
.root_module = createRootModule(
b,
target,
optimize,
trace,
coreutils_target,
options_module,
),
});
const coreutils_test_check = b.addTest(.{
.name = b.fmt("check_test_zig-coreutils-{s}", .{@tagName(target.result.os.tag)}),
.name = b.fmt("check_test_zig-coreutils-{t}", .{target.result.os.tag}),
.root_module = createRootModule(
b,
target,
optimize,
trace,
coreutils_target,
options_module,
),
Expand Down Expand Up @@ -304,7 +282,7 @@ fn getVersionString(b: *std.Build, base_semantic_version: std.SemanticVersion, r
const ancestor_version = try std.SemanticVersion.parse(tagged_ancestor_version_string);
if (base_semantic_version.order(ancestor_version) != .gt) {
std.debug.print(
"version '{}' must be greater than tagged ancestor '{}'\n",
"version '{f}' must be greater than tagged ancestor '{f}'\n",
.{ base_semantic_version, ancestor_version },
);
std.process.exit(1);
Expand Down
9 changes: 1 addition & 8 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@

.version = "0.3.0",

.minimum_zig_version = "0.15.0-dev.784+4a02e080d",
.minimum_zig_version = "0.15.0-dev.1149+4e6a04929",

.paths = .{
"build.zig",
"build.zig.zon",
"src",
},

.dependencies = .{
.tracy = .{
.url = "git+https://github.com/Games-by-Mason/tracy_zig.git?ref=main#0cad4646be2791982f692a7a47716ec92b62eb2e",
.hash = "tracy-0.0.0-R7l8BdlCAQBFp6uysnan3Alaxap65HBF1mzGdabdKe8z",
},
},

.fingerprint = 0x3bcfe8c5bc4f06d3,
}
13 changes: 0 additions & 13 deletions src/Arg.zig
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,20 @@ pub const Iterator = union(enum) {
},

pub fn nextRaw(self: *Iterator) ?[]const u8 {
const z: tracy.Zone = .begin(.{ .src = @src(), .name = "raw next arg" });
defer z.end();

if (self.dispatchNext()) |arg| {
@branchHint(.likely);
z.text(arg);
return arg;
}

return null;
}

pub fn next(self: *Iterator) ?Arg {
const z: tracy.Zone = .begin(.{ .src = @src(), .name = "next arg" });
defer z.end();

const current_arg = self.dispatchNext() orelse {
@branchHint(.unlikely);
return null;
};

z.text(current_arg);

// the length checks in the below ifs allow '-' and '--' to fall through as positional arguments
if (current_arg.len > 1 and current_arg[0] == '-') longhand_shorthand_blk: {
if (current_arg.len > 2 and current_arg[1] == '-') {
Expand Down Expand Up @@ -125,9 +116,6 @@ pub const Iterator = union(enum) {
self: *Iterator,
comptime include_shorthand: bool,
) error{ ShortHelp, FullHelp, Version }!?Arg {
const z: tracy.Zone = .begin(.{ .src = @src(), .name = "next arg with help/version" });
defer z.end();

var arg = self.next() orelse return null;

switch (arg.arg_type) {
Expand Down Expand Up @@ -174,4 +162,3 @@ const log = std.log.scoped(.arg);

const builtin = @import("builtin");
const std = @import("std");
const tracy = @import("tracy");
Loading