initial commit

This commit is contained in:
Jeffrey C. Ollie 2024-12-30 22:51:22 -06:00
commit 3f66332a05
Signed by: jeff
GPG key ID: 6F86035A6D97044E
7 changed files with 231 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/zig-out
/.zig-cache

78
build.zig Normal file
View file

@ -0,0 +1,78 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const upstream = b.dependency("zork", .{});
const exe = b.addExecutable(.{
.name = "zig-zork",
.target = target,
.optimize = optimize,
});
const textfile_flag = std.fmt.allocPrint(b.allocator, "-DTEXTFILE=\"{s}/share/zork/dtextc.dat\"", .{b.install_path}) catch unreachable;
defer b.allocator.free(textfile_flag);
exe.addCSourceFiles(.{
.root = upstream.path("."),
.files = &.{
"actors.c",
"ballop.c",
"clockr.c",
"demons.c",
"dgame.c",
"dinit.c",
"dmain.c",
"dso1.c",
"dso2.c",
"dso3.c",
"dso4.c",
"dso5.c",
"dso6.c",
"dso7.c",
"dsub.c",
"dverb1.c",
"dverb2.c",
"gdt.c",
"lightp.c",
"local.c",
"nobjs.c",
"np.c",
"np1.c",
"np2.c",
"np3.c",
"nrooms.c",
"objcts.c",
"rooms.c",
"sobjs.c",
"supp.c",
"sverbs.c",
"verbs.c",
"villns.c",
},
.flags = &.{
textfile_flag,
},
});
exe.linkSystemLibrary2("termcap", .{});
exe.linkLibC();
b.installArtifact(exe);
const data = b.addInstallFile(upstream.path("dtextc.dat"), "share/zork/dtextc.dat");
b.getInstallStep().dependOn(&data.step);
const run_cmd = b.addRunArtifact(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);
}

18
build.zig.zon Normal file
View file

@ -0,0 +1,18 @@
.{
.name = "zig-zork",
.version = "1.0.3",
.minimum_zig_version = "0.13.0",
.dependencies = .{
.zork = .{
.url = "git+https://github.com/devshane/zork?ref=v1.0.3#c44f046a1279c2d29ef3e46ec2e35d7aaecb580f",
.hash = "12200afb837aa4eb3e0136539997b7da6af19aa3a29b6de9b4aec0e1d3476278e06c",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
}

60
flake.lock generated Normal file
View file

@ -0,0 +1,60 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1735471104,
"narHash": "sha256-0q9NGQySwDQc7RhAV2ukfnu7Gxa5/ybJ2ANT8DQrQrs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "88195a94f390381c6afcdaa933c2f6ff93959cb4",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

38
flake.nix Normal file
View file

@ -0,0 +1,38 @@
{
description = "zig-zork";
inputs = {
nixpkgs = {
url = "nixpkgs/nixos-unstable";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
};
outputs =
{
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
devShells.default = pkgs.mkShell {
name = "zig-zork";
nativeBuildInputs = [
pkgs.zig_0_13
];
buildInputs = [
pkgs.termcap
];
};
}
);
}

24
src/main.zig Normal file
View file

@ -0,0 +1,24 @@
const std = @import("std");
pub fn main() !void {
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
// stdout is for the actual output of your application, for example if you
// are implementing gzip, then only the compressed bytes should be sent to
// stdout, not any debugging messages.
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
try stdout.print("Run `zig build test` to run the tests.\n", .{});
try bw.flush(); // don't forget to flush!
}
test "simple test" {
var list = std.ArrayList(i32).init(std.testing.allocator);
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
try list.append(42);
try std.testing.expectEqual(@as(i32, 42), list.pop());
}

10
src/root.zig Normal file
View file

@ -0,0 +1,10 @@
const std = @import("std");
const testing = std.testing;
export fn add(a: i32, b: i32) i32 {
return a + b;
}
test "basic add functionality" {
try testing.expect(add(3, 7) == 10);
}