소스 검색

init [skip ci]

codecrafters-bot 5 달 전
커밋
ba4b47da36
10개의 변경된 파일235개의 추가작업 그리고 0개의 파일을 삭제
  1. 11
    0
      .codecrafters/compile.sh
  2. 11
    0
      .codecrafters/run.sh
  3. 1
    0
      .gitattributes
  4. 18
    0
      .gitignore
  5. 33
    0
      README.md
  6. 33
    0
      build.zig
  7. 68
    0
      build.zig.zon
  8. 11
    0
      codecrafters.yml
  9. 25
    0
      src/main.zig
  10. 24
    0
      your_program.sh

+ 11
- 0
.codecrafters/compile.sh 파일 보기

@@ -0,0 +1,11 @@
1
+#!/bin/sh
2
+#
3
+# This script is used to compile your program on CodeCrafters
4
+#
5
+# This runs before .codecrafters/run.sh
6
+#
7
+# Learn more: https://codecrafters.io/program-interface
8
+
9
+set -e # Exit on failure
10
+
11
+zig build

+ 11
- 0
.codecrafters/run.sh 파일 보기

@@ -0,0 +1,11 @@
1
+#!/bin/sh
2
+#
3
+# This script is used to run your program on CodeCrafters
4
+#
5
+# This runs after .codecrafters/compile.sh
6
+#
7
+# Learn more: https://codecrafters.io/program-interface
8
+
9
+set -e # Exit on failure
10
+
11
+exec zig-out/bin/main "$@"

+ 1
- 0
.gitattributes 파일 보기

@@ -0,0 +1 @@
1
+* text=auto

+ 18
- 0
.gitignore 파일 보기

@@ -0,0 +1,18 @@
1
+# Zig build artifacts
2
+main
3
+zig-cache/
4
+.zig-cache/
5
+zig-out/
6
+
7
+# Compiled binary output
8
+bin/
9
+!bin/.gitkeep
10
+
11
+# Ignore any .o or .h files generated during build
12
+*.o
13
+*.h
14
+
15
+# Ignore OS and editor specific files
16
+**/.DS_Store
17
+*.swp
18
+*~

+ 33
- 0
README.md 파일 보기

@@ -0,0 +1,33 @@
1
+[![progress-banner](https://backend.codecrafters.io/progress/redis/21973efa-5a41-4f55-8f51-9f73f9135a15)](https://app.codecrafters.io/users/codecrafters-bot?r=2qF)
2
+
3
+This is a starting point for Zig solutions to the
4
+["Build Your Own Redis" Challenge](https://codecrafters.io/challenges/redis).
5
+
6
+In this challenge, you'll build a toy Redis clone that's capable of handling
7
+basic commands like `PING`, `SET` and `GET`. Along the way we'll learn about
8
+event loops, the Redis protocol and more.
9
+
10
+**Note**: If you're viewing this repo on GitHub, head over to
11
+[codecrafters.io](https://codecrafters.io) to try the challenge.
12
+
13
+# Passing the first stage
14
+
15
+The entry point for your Redis implementation is in `src/main.zig`. Study and
16
+uncomment the relevant code, and push your changes to pass the first stage:
17
+
18
+```sh
19
+git commit -am "pass 1st stage" # any msg
20
+git push origin master
21
+```
22
+
23
+That's all!
24
+
25
+# Stage 2 & beyond
26
+
27
+Note: This section is for stages 2 and beyond.
28
+
29
+1. Ensure you have `zig (0.13+)` installed locally
30
+1. Run `./your_program.sh` to run your Redis server, which is implemented in
31
+   `src/main.zig`.
32
+1. Commit your changes and run `git push origin master` to submit your solution
33
+   to CodeCrafters. Test output will be streamed to your terminal.

+ 33
- 0
build.zig 파일 보기

@@ -0,0 +1,33 @@
1
+const std = @import("std");
2
+
3
+// Learn more about this file here: https://ziglang.org/learn/build-system
4
+pub fn build(b: *std.Build) void {
5
+    const exe = b.addExecutable(.{
6
+        .name = "main",
7
+        .root_source_file = b.path("src/main.zig"),
8
+        .target = b.standardTargetOptions(.{}),
9
+        .optimize = b.standardOptimizeOption(.{}),
10
+    });
11
+
12
+    // This declares intent for the executable to be installed into the
13
+    // standard location when the user invokes the "install" step (the default
14
+    // step when running `zig build`).
15
+    b.installArtifact(exe);
16
+
17
+    // This *creates* a Run step in the build graph, to be executed when another
18
+    // step is evaluated that depends on it. The next line below will establish
19
+    // such a dependency.
20
+    const run_cmd = b.addRunArtifact(exe);
21
+
22
+    // This creates a build step. It will be visible in the `zig build --help` menu,
23
+    // and can be selected like this: `zig build run`
24
+    // This will evaluate the `run` step rather than the default, which is "install".
25
+    const run_step = b.step("run", "Run the app");
26
+    run_step.dependOn(&run_cmd.step);
27
+
28
+    // This allows the user to pass arguments to the application in the build
29
+    // command itself, like this: `zig build run -- arg1 arg2 etc`
30
+    if (b.args) |args| {
31
+        run_cmd.addArgs(args);
32
+    }
33
+}

+ 68
- 0
build.zig.zon 파일 보기

@@ -0,0 +1,68 @@
1
+.{
2
+    .name = "codecrafters-redis",
3
+
4
+    // This is a [Semantic Version](https://semver.org/).
5
+    // In a future version of Zig it will be used for package deduplication.
6
+    .version = "0.0.0",
7
+
8
+    // This field is optional.
9
+    // This is currently advisory only; Zig does not yet do anything
10
+    // with this value.
11
+    //.minimum_zig_version = "0.11.0",
12
+
13
+    // This field is optional.
14
+    // Each dependency must either provide a `url` and `hash`, or a `path`.
15
+    // `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
16
+    // Once all dependencies are fetched, `zig build` no longer requires
17
+    // internet connectivity.
18
+    .dependencies = .{
19
+        // See `zig fetch --save <url>` for a command-line interface for adding dependencies.
20
+        //.example = .{
21
+        //    // When updating this field to a new URL, be sure to delete the corresponding
22
+        //    // `hash`, otherwise you are communicating that you expect to find the old hash at
23
+        //    // the new URL.
24
+        //    .url = "https://example.com/foo.tar.gz",
25
+        //
26
+        //    // This is computed from the file contents of the directory of files that is
27
+        //    // obtained after fetching `url` and applying the inclusion rules given by
28
+        //    // `paths`.
29
+        //    //
30
+        //    // This field is the source of truth; packages do not come from a `url`; they
31
+        //    // come from a `hash`. `url` is just one of many possible mirrors for how to
32
+        //    // obtain a package matching this `hash`.
33
+        //    //
34
+        //    // Uses the [multihash](https://multiformats.io/multihash/) format.
35
+        //    .hash = "...",
36
+        //
37
+        //    // When this is provided, the package is found in a directory relative to the
38
+        //    // build root. In this case the package's hash is irrelevant and therefore not
39
+        //    // computed. This field and `url` are mutually exclusive.
40
+        //    .path = "foo",
41
+
42
+        //    // When this is set to `true`, a package is declared to be lazily
43
+        //    // fetched. This makes the dependency only get fetched if it is
44
+        //    // actually used.
45
+        //    .lazy = false,
46
+        //},
47
+    },
48
+
49
+    // Specifies the set of files and directories that are included in this package.
50
+    // Only files and directories listed here are included in the `hash` that
51
+    // is computed for this package.
52
+    // Paths are relative to the build root. Use the empty string (`""`) to refer to
53
+    // the build root itself.
54
+    // A directory listed here means that all files within, recursively, are included.
55
+    .paths = .{
56
+        // This makes *all* files, recursively, included in this package. It is generally
57
+        // better to explicitly list the files and directories instead, to insure that
58
+        // fetching from tarballs, file system paths, and version control all result
59
+        // in the same contents hash.
60
+        "",
61
+        // For example...
62
+        //"build.zig",
63
+        //"build.zig.zon",
64
+        //"src",
65
+        //"LICENSE",
66
+        //"README.md",
67
+    },
68
+}

+ 11
- 0
codecrafters.yml 파일 보기

@@ -0,0 +1,11 @@
1
+# Set this to true if you want debug logs.
2
+#
3
+# These can be VERY verbose, so we suggest turning them off
4
+# unless you really need them.
5
+debug: false
6
+
7
+# Use this to change the Zig version used to run your code
8
+# on Codecrafters.
9
+#
10
+# Available versions: zig-0.13
11
+language_pack: zig-0.13

+ 25
- 0
src/main.zig 파일 보기

@@ -0,0 +1,25 @@
1
+const std = @import("std");
2
+const net = std.net;
3
+
4
+pub fn main() !void {
5
+    const stdout = std.io.getStdOut().writer();
6
+
7
+    // You can use print statements as follows for debugging, they'll be visible when running tests.
8
+    try stdout.print("Logs from your program will appear here!", .{});
9
+
10
+    // Uncomment this block to pass the first stage
11
+    //
12
+    // const address = try net.Address.resolveIp("127.0.0.1", 6379);
13
+    //
14
+    // var listener = try address.listen(.{
15
+    //     .reuse_address = true,
16
+    // });
17
+    // defer listener.deinit();
18
+    //
19
+    // while (true) {
20
+    //     const connection = try listener.accept();
21
+    //
22
+    //     try stdout.print("accepted new connection", .{});
23
+    //     connection.stream.close();
24
+    // }
25
+}

+ 24
- 0
your_program.sh 파일 보기

@@ -0,0 +1,24 @@
1
+#!/bin/sh
2
+#
3
+# Use this script to run your program LOCALLY.
4
+#
5
+# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6
+#
7
+# Learn more: https://codecrafters.io/program-interface
8
+
9
+set -e # Exit early if any commands fail
10
+
11
+# Copied from .codecrafters/compile.sh
12
+#
13
+# - Edit this to change how your program compiles locally
14
+# - Edit .codecrafters/compile.sh to change how your program compiles remotely
15
+(
16
+  cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17
+  zig build
18
+)
19
+
20
+# Copied from .codecrafters/run.sh
21
+#
22
+# - Edit this to change how your program runs locally
23
+# - Edit .codecrafters/run.sh to change how your program runs remotely
24
+exec zig-out/bin/main "$@"