Selaa lähdekoodia

init [skip ci]

codecrafters-bot 8 kuukautta sitten
commit
50949936f1
10 muutettua tiedostoa jossa 232 lisäystä ja 0 poistoa
  1. 11
    0
      .codecrafters/compile.sh
  2. 11
    0
      .codecrafters/run.sh
  3. 1
    0
      .gitattributes
  4. 18
    0
      .gitignore
  5. 37
    0
      README.md
  6. 33
    0
      build.zig
  7. 67
    0
      build.zig.zon
  8. 11
    0
      codecrafters.yml
  9. 19
    0
      src/main.zig
  10. 24
    0
      your_program.sh

+ 11
- 0
.codecrafters/compile.sh Näytä tiedosto

@@ -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 Näytä tiedosto

@@ -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/zig "$@"

+ 1
- 0
.gitattributes Näytä tiedosto

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

+ 18
- 0
.gitignore Näytä tiedosto

@@ -0,0 +1,18 @@
1
+# Zig build artifacts
2
+.zig-cache/
3
+zig-cache/
4
+zig-out/
5
+
6
+# Compiled binary output
7
+main
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
+*~

+ 37
- 0
README.md Näytä tiedosto

@@ -0,0 +1,37 @@
1
+[![progress-banner](https://backend.codecrafters.io/progress/http-server/02e6f1b4-ef8b-4bd0-ab1c-a85885d66dec)](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 HTTP server" Challenge](https://app.codecrafters.io/courses/http-server/overview).
5
+
6
+[HTTP](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) is the
7
+protocol that powers the web. In this challenge, you'll build a HTTP/1.1 server
8
+that is capable of serving multiple clients.
9
+
10
+Along the way you'll learn about TCP servers,
11
+[HTTP request syntax](https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html),
12
+and more.
13
+
14
+**Note**: If you're viewing this repo on GitHub, head over to
15
+[codecrafters.io](https://codecrafters.io) to try the challenge.
16
+
17
+# Passing the first stage
18
+
19
+The entry point for your HTTP server implementation is in `src/main.zig`. Study
20
+and uncomment the relevant code, and push your changes to pass the first stage:
21
+
22
+```sh
23
+git commit -am "pass 1st stage" # any msg
24
+git push origin master
25
+```
26
+
27
+Time to move on to the next stage!
28
+
29
+# Stage 2 & beyond
30
+
31
+Note: This section is for stages 2 and beyond.
32
+
33
+1. Ensure you have `zig (0.12)` installed locally
34
+1. Run `./your_program.sh` to run your program, which is implemented in
35
+   `src/main.zig`.
36
+1. Commit your changes and run `git push origin master` to submit your solution
37
+   to CodeCrafters. Test output will be streamed to your terminal.

+ 33
- 0
build.zig Näytä tiedosto

@@ -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 = "zig",
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
+}

+ 67
- 0
build.zig.zon Näytä tiedosto

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

+ 11
- 0
codecrafters.yml Näytä tiedosto

@@ -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.12
11
+language_pack: zig-0.12

+ 19
- 0
src/main.zig Näytä tiedosto

@@ -0,0 +1,19 @@
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!\n", .{});
9
+
10
+    // Uncomment this block to pass the first stage
11
+    // const address = try net.Address.resolveIp("127.0.0.1", 4221);
12
+    // var listener = try address.listen(.{
13
+    //     .reuse_address = true,
14
+    // });
15
+    // defer listener.deinit();
16
+    //
17
+    // _ = try listener.accept();
18
+    // try stdout.print("client connected!", .{});
19
+}

+ 24
- 0
your_program.sh Näytä tiedosto

@@ -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/zig "$@"