commit 4ebbf90
Artur Manuel
·
2026-03-21 15:09:12 +0000 UTC
parent 4304a5c
chore(zig): remove zig the zig version is wildly out of date, and zig 0.16 will change the language again
5 files changed,
+0,
-205
+0,
-3
1@@ -1,3 +0,0 @@
2-.zig-cache/
3-zig-out/
4-*.o
+0,
-75
1@@ -1,75 +0,0 @@
2-const std = @import("std");
3-
4-// Although this function looks imperative, note that its job is to
5-// declaratively construct a build graph that will be executed by an external
6-// runner.
7-pub fn build(b: *std.Build) void {
8- // Standard target options allows the person running `zig build` to choose
9- // what target to build for. Here we do not override the defaults, which
10- // means any target is allowed, and the default is native. Other options
11- // for restricting supported target set are available.
12- const target = b.standardTargetOptions(.{});
13-
14- // Standard optimization options allow the person running `zig build` to select
15- // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
16- // set a preferred release mode, allowing the user to decide how to optimize.
17- const optimize = b.standardOptimizeOption(.{});
18-
19- // We will also create a module for our other entry point, 'main.zig'.
20- const exe_mod = b.createModule(.{
21- // `root_source_file` is the Zig "entry point" of the module. If a module
22- // only contains e.g. external object files, you can make this `null`.
23- // In this case the main source file is merely a path, however, in more
24- // complicated build scripts, this could be a generated file.
25- .root_source_file = b.path("src/main.zig"),
26- .target = target,
27- .optimize = optimize,
28- });
29-
30- // This creates another `std.Build.Step.Compile`, but this one builds an executable
31- // rather than a static library.
32- const exe = b.addExecutable(.{
33- .name = "rosetta_collatz",
34- .root_module = exe_mod,
35- });
36-
37- // This declares intent for the executable to be installed into the
38- // standard location when the user invokes the "install" step (the default
39- // step when running `zig build`).
40- b.installArtifact(exe);
41-
42- // This *creates* a Run step in the build graph, to be executed when another
43- // step is evaluated that depends on it. The next line below will establish
44- // such a dependency.
45- const run_cmd = b.addRunArtifact(exe);
46-
47- // By making the run step depend on the install step, it will be run from the
48- // installation directory rather than directly from within the cache directory.
49- // This is not necessary, however, if the application depends on other installed
50- // files, this ensures they will be present and in the expected location.
51- run_cmd.step.dependOn(b.getInstallStep());
52-
53- // This allows the user to pass arguments to the application in the build
54- // command itself, like this: `zig build run -- arg1 arg2 etc`
55- if (b.args) |args| {
56- run_cmd.addArgs(args);
57- }
58-
59- // This creates a build step. It will be visible in the `zig build --help` menu,
60- // and can be selected like this: `zig build run`
61- // This will evaluate the `run` step rather than the default, which is "install".
62- const run_step = b.step("run", "Run the app");
63- run_step.dependOn(&run_cmd.step);
64-
65- const exe_unit_tests = b.addTest(.{
66- .root_module = exe_mod,
67- });
68-
69- const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
70-
71- // Similar to creating the run step earlier, this exposes a `test` step to
72- // the `zig build --help` menu, providing a way for the user to request
73- // running the unit tests.
74- const test_step = b.step("test", "Run unit tests");
75- test_step.dependOn(&run_exe_unit_tests.step);
76-}
+0,
-86
1@@ -1,86 +0,0 @@
2-.{
3- // This is the default name used by packages depending on this one. For
4- // example, when a user runs `zig fetch --save <url>`, this field is used
5- // as the key in the `dependencies` table. Although the user can choose a
6- // different name, most users will stick with this provided value.
7- //
8- // It is redundant to include "zig" in this name because it is already
9- // within the Zig package namespace.
10- .name = .rosetta_collatz,
11-
12- // This is a [Semantic Version](https://semver.org/).
13- // In a future version of Zig it will be used for package deduplication.
14- .version = "0.0.0",
15-
16- // Together with name, this represents a globally unique package
17- // identifier. This field is generated by the Zig toolchain when the
18- // package is first created, and then *never changes*. This allows
19- // unambiguous detection of one package being an updated version of
20- // another.
21- //
22- // When forking a Zig project, this id should be regenerated (delete the
23- // field and run `zig build`) if the upstream project is still maintained.
24- // Otherwise, the fork is *hostile*, attempting to take control over the
25- // original project's identity. Thus it is recommended to leave the comment
26- // on the following line intact, so that it shows up in code reviews that
27- // modify the field.
28- .fingerprint = 0xbe90948e57b0e2ea, // Changing this has security and trust implications.
29-
30- // Tracks the earliest Zig version that the package considers to be a
31- // supported use case.
32- .minimum_zig_version = "0.14.0",
33-
34- // This field is optional.
35- // Each dependency must either provide a `url` and `hash`, or a `path`.
36- // `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
37- // Once all dependencies are fetched, `zig build` no longer requires
38- // internet connectivity.
39- .dependencies = .{
40- // See `zig fetch --save <url>` for a command-line interface for adding dependencies.
41- //.example = .{
42- // // When updating this field to a new URL, be sure to delete the corresponding
43- // // `hash`, otherwise you are communicating that you expect to find the old hash at
44- // // the new URL. If the contents of a URL change this will result in a hash mismatch
45- // // which will prevent zig from using it.
46- // .url = "https://example.com/foo.tar.gz",
47- //
48- // // This is computed from the file contents of the directory of files that is
49- // // obtained after fetching `url` and applying the inclusion rules given by
50- // // `paths`.
51- // //
52- // // This field is the source of truth; packages do not come from a `url`; they
53- // // come from a `hash`. `url` is just one of many possible mirrors for how to
54- // // obtain a package matching this `hash`.
55- // //
56- // // Uses the [multihash](https://multiformats.io/multihash/) format.
57- // .hash = "...",
58- //
59- // // When this is provided, the package is found in a directory relative to the
60- // // build root. In this case the package's hash is irrelevant and therefore not
61- // // computed. This field and `url` are mutually exclusive.
62- // .path = "foo",
63- //
64- // // When this is set to `true`, a package is declared to be lazily
65- // // fetched. This makes the dependency only get fetched if it is
66- // // actually used.
67- // .lazy = false,
68- //},
69- },
70-
71- // Specifies the set of files and directories that are included in this package.
72- // Only files and directories listed here are included in the `hash` that
73- // is computed for this package. Only files listed here will remain on disk
74- // when using the zig package manager. As a rule of thumb, one should list
75- // files required for compilation plus any license(s).
76- // Paths are relative to the build root. Use the empty string (`""`) to refer to
77- // the build root itself.
78- // A directory listed here means that all files within, recursively, are included.
79- .paths = .{
80- "build.zig",
81- "build.zig.zon",
82- "src",
83- // For example...
84- //"LICENSE",
85- //"README.md",
86- },
87-}
+0,
-41
1@@ -1,41 +0,0 @@
2-const std = @import("std");
3-const testing = std.testing;
4-
5-fn collatz(a: i32) i32 {
6- if (@mod(a, 2) == 0)
7- return @divFloor(a, 2);
8- return 3 * a + 1;
9-}
10-
11-fn collatzSequence(buffer: []u8, a: i32) ![]u8 {
12- var fbs = std.io.fixedBufferStream(buffer);
13- defer fbs.reset();
14- var writer = fbs.writer();
15-
16- try writer.print("{d}: ", .{a});
17- var i = a;
18- while (i >= 1) : (i = collatz(i)) {
19- if (i == 1) {
20- _ = try writer.write("1\n");
21- break;
22- }
23- try writer.print("{d}, ", .{i});
24- }
25-
26- return fbs.getWritten();
27-}
28-
29-pub fn main() !void {
30- var buffer: [8192]u8 = undefined;
31- const stdout = std.io.getStdOut().writer();
32- var i: i32 = 1;
33- while (i <= 10000) : (i += 1) {
34- const message = try collatzSequence(&buffer, i);
35- _ = try stdout.write(message);
36- }
37-}
38-
39-test "collatz conjecture" {
40- try testing.expect(collatz(1) == 4);
41- try testing.expect(collatz(2) == 1);
42-}
+0,
-0