Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/zig-cache/
.zig-cache/
zig-out/*
50 changes: 41 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
const test_targets = [_]std.Target.Query{
.{}, // native
.{
.cpu_arch = .x86_64,
.os_tag = .linux,
},
.{
.cpu_arch = .aarch64,
.os_tag = .macos,
},
};

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

_ = b.addModule("getopt", .{
.source_file = .{
.path = "getopt.zig",
},
const getopt_lib_mod = b.createModule(.{
.root_source_file = b.path("getopt.zig"),
.target = target,
.optimize = optimize,
});

const tests = b.addTest(.{
.root_source_file = .{ .path = "getopt.zig" },
const getopt_example_exe_mod = b.createModule(.{
.root_source_file = b.path("example.zig"),
.target = target,
.optimize = optimize,
});
const run_tests = b.addRunArtifact(tests);

const lib = b.addLibrary(.{
.linkage = .static,
.name = "getopt",
.root_module = getopt_lib_mod,
});
b.installArtifact(lib);

const exe = b.addExecutable(.{
.name = "example",
.root_module = getopt_example_exe_mod,
});
b.installArtifact(exe);

const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_tests.step);
for (test_targets) |test_target| {
const unit_tests = b.addTest(.{
.root_module = getopt_lib_mod,
.target = b.resolveTargetQuery(test_target),
});

const run_unit_tests = b.addRunArtifact(unit_tests);
test_step.dependOn(&run_unit_tests.step);
}
}
50 changes: 50 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.{
// This is the default name used by packages depending on this one. For
// example, when a user runs `zig fetch --save <url>`, this field is used
// as the key in the `dependencies` table. Although the user can choose a
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = .getopt,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",

// Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the
// package is first created, and then *never changes*. This allows
// unambiguous detection of one package being an updated version of
// another.
//
// When forking a Zig project, this id should be regenerated (delete the
// field and run `zig build`) if the upstream project is still maintained.
// Otherwise, the fork is *hostile*, attempting to take control over the
// original project's identity. Thus it is recommended to leave the comment
// on the following line intact, so that it shows up in code reviews that
// modify the field.
.fingerprint = 0x2a601179af5673be,

// Tracks the earliest Zig version that the package considers to be a
// supported use case.
.minimum_zig_version = "0.14.1",

// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{},
.paths = .{
"build.zig",
"build.zig.zon",
"example.zig",
"LICENSE",
"README.md",
"getopt.zig",
// For example...
//"LICENSE",
//"README.md",
},
}
2 changes: 1 addition & 1 deletion getopt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const mem = std.mem;
const os = std.os;
const expect = std.testing.expect;

/// Parsed option struct.
/// Parsed option struct.
pub const Option = struct {
/// Option character.
opt: u8,
Expand Down