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
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
A `wc` like program written by `C++` but built by `Zig`.
# Coreutils Implementation

A project to implement GNU coreutils utilities in `C++` and `Zig`. This is an ongoing effort to recreate the essential Unix/Linux command-line tools.

## Implemented Utilities

- `wc`: Word, line, and byte counting utility

## Planned Utilities

The project aims to implement all core utilities, including but not limited to:
- File Management: `ls`, `cp`, `mv`, `rm`, `mkdir`, `cat`, etc.
- Text Processing: `head`, `tail`, `sort`, `uniq`, etc.
- System Information: `pwd`, `whoami`, `uname`, etc.
- And many more...

## Installation

Expand All @@ -16,11 +30,11 @@ cd wc
zig build
```

The executable will be available at `zig-out/bin/wc`.
The executables will be available in `zig-out/bin/`.

## Usage

### Examples
### wc Examples

Count lines, words, and characters in a file:
```bash
Expand All @@ -37,6 +51,14 @@ Count words from standard input:
cat file.txt | wc -w
```

## Contributing

Contributions are welcome! Feel free to:
- Implement new utilities
- Improve existing implementations
- Report bugs
- Suggest enhancements

## License

Licensed under Apache-2.0 license ([LICENSE](LICENSE) or http://opensource.org/licenses/Apache-2.0)
30 changes: 15 additions & 15 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
const std = @import("std");
const zcc = @import("compile_commands");

const executable_name = "wc";

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var targets = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
defer targets.deinit();

const exe = b.addExecutable(.{
.name = executable_name,
const wc_exe = b.addExecutable(.{
.name = "wc",
.target = target,
.optimize = optimize,
});
targets.append(exe) catch @panic("OOM");
targets.append(wc_exe) catch @panic("OOM");

const cpp_sources = [_][]const u8{
"src/main.cpp",
"src/wc.cpp",
"src/options.cpp",
"src/params.cpp",
"src/wc/main.cpp",
"src/wc/wc.cpp",
"src/wc/options.cpp",
"src/wc/params.cpp",
};

for (cpp_sources) |source| {
exe.addCSourceFile(.{
wc_exe.addCSourceFile(.{
.file = b.path(source),
.flags = &[_][]const u8{"-std=c++20"},
});
}

exe.linkLibCpp();
exe.addIncludePath(b.path("src"));
wc_exe.linkLibCpp();
wc_exe.addIncludePath(b.path("src/wc"));

b.installArtifact(wc_exe);

b.installArtifact(exe);
const run_step = b.step("run-wc", "Run the wc app");

const run_cmd = b.addRunArtifact(exe);
const run_cmd = b.addRunArtifact(wc_exe);
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);
zcc.createStep(b, "cdb", targets.toOwnedSlice() catch @panic("OOM"));
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.