From 0596cd07d35ea3a51124946dc88dd1c320eaa210 Mon Sep 17 00:00:00 2001 From: David Allemang Date: Mon, 4 Aug 2025 22:18:32 -0400 Subject: [PATCH] Unknown state [2025-08-04] --- zelio/.gitignore | 9 ++++++ zelio/.tool-versions | 2 ++ zelio/build.zig | 63 ++++++++++++++++++++++++++++++++++++ zelio/build.zig.zon | 47 +++++++++++++++++++++++++++ zelio/datagen/hipparcos.py | 14 ++++++++ zelio/datagen/pyproject.toml | 6 ++++ zelio/src/main.zig | 24 ++++++++++++++ zelio/src/root.zig | 10 ++++++ 8 files changed, 175 insertions(+) create mode 100644 zelio/.gitignore create mode 100644 zelio/.tool-versions create mode 100644 zelio/build.zig create mode 100644 zelio/build.zig.zon create mode 100644 zelio/datagen/hipparcos.py create mode 100644 zelio/datagen/pyproject.toml create mode 100644 zelio/src/main.zig create mode 100644 zelio/src/root.zig diff --git a/zelio/.gitignore b/zelio/.gitignore new file mode 100644 index 0000000..a8cb256 --- /dev/null +++ b/zelio/.gitignore @@ -0,0 +1,9 @@ +.zig-cache/ +zig-out/ + +/.venv/ +*.egg-info/ +__pycache__/ +*.py[cd] + +/.idea/ diff --git a/zelio/.tool-versions b/zelio/.tool-versions new file mode 100644 index 0000000..430b9ef --- /dev/null +++ b/zelio/.tool-versions @@ -0,0 +1,2 @@ +zig 0.13.0 +python 3.12.4 diff --git a/zelio/build.zig b/zelio/build.zig new file mode 100644 index 0000000..02a4493 --- /dev/null +++ b/zelio/build.zig @@ -0,0 +1,63 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const hip_cmd = b.addSystemCommand(&.{"python"}); + hip_cmd.addFileArg(b.path("datagen/hipparcos.py")); + const result = hip_cmd.addOutputFileArg("result.zig"); + + const lib = b.addStaticLibrary(.{ + .name = "gen", + .root_source_file = b.path("src/root.zig"), + .target = target, + .optimize = optimize, + }); + + b.installArtifact(lib); + + const exe = b.addExecutable(.{ + .name = "gen", + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + exe.root_module.addAnonymousImport("hipparcos", .{ + .root_source_file = result, + }); + + b.installArtifact(exe); + + 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); + + const lib_unit_tests = b.addTest(.{ + .root_source_file = b.path("src/root.zig"), + .target = target, + + .optimize = optimize, + }); + + const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); + + const exe_unit_tests = b.addTest(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + + const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); + + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_lib_unit_tests.step); + test_step.dependOn(&run_exe_unit_tests.step); +} diff --git a/zelio/build.zig.zon b/zelio/build.zig.zon new file mode 100644 index 0000000..233990b --- /dev/null +++ b/zelio/build.zig.zon @@ -0,0 +1,47 @@ +.{ + .name = "gen", + + .version = "0.0.0", + + // 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 = .{ + // See `zig fetch --save ` for a command-line interface for adding dependencies. + //.example = .{ + // // When updating this field to a new URL, be sure to delete the corresponding + // // `hash`, otherwise you are communicating that you expect to find the old hash at + // // the new URL. + // .url = "https://example.com/foo.tar.gz", + // + // // This is computed from the file contents of the directory of files that is + // // obtained after fetching `url` and applying the inclusion rules given by + // // `paths`. + // // + // // This field is the source of truth; packages do not come from a `url`; they + // // come from a `hash`. `url` is just one of many possible mirrors for how to + // // obtain a package matching this `hash`. + // // + // // Uses the [multihash](https://multiformats.io/multihash/) format. + // .hash = "...", + // + // // When this is provided, the package is found in a directory relative to the + // // build root. In this case the package's hash is irrelevant and therefore not + // // computed. This field and `url` are mutually exclusive. + // .path = "foo", + + // // When this is set to `true`, a package is declared to be lazily + // // fetched. This makes the dependency only get fetched if it is + // // actually used. + // .lazy = false, + //}, + }, + + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + }, +} diff --git a/zelio/datagen/hipparcos.py b/zelio/datagen/hipparcos.py new file mode 100644 index 0000000..eca4992 --- /dev/null +++ b/zelio/datagen/hipparcos.py @@ -0,0 +1,14 @@ +import sys +import numpy + + +def main(): + print("hello world!") + print(sys.argv) + _, out = sys.argv + with open(out, 'w') as f: + pass + + +if __name__ == '__main__': + main() diff --git a/zelio/datagen/pyproject.toml b/zelio/datagen/pyproject.toml new file mode 100644 index 0000000..46d9cd5 --- /dev/null +++ b/zelio/datagen/pyproject.toml @@ -0,0 +1,6 @@ +[project] +name = "zelio-datagen" +version = "0.0.0" +dependencies = [ + "numpy" +] diff --git a/zelio/src/main.zig b/zelio/src/main.zig new file mode 100644 index 0000000..c8a3f67 --- /dev/null +++ b/zelio/src/main.zig @@ -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()); +} diff --git a/zelio/src/root.zig b/zelio/src/root.zig new file mode 100644 index 0000000..ecfeade --- /dev/null +++ b/zelio/src/root.zig @@ -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); +}