Skip to content

Commit 63f79fb

Browse files
authored
Add Zig zap framework (#8791)
* Zig zap framework * Zig zap framework db and fortune tests * Zig zap framework fortunes
1 parent a49db36 commit 63f79fb

File tree

11 files changed

+854
-0
lines changed

11 files changed

+854
-0
lines changed

frameworks/Zig/zap/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
zig-cache/**/*',
2+
zig-out: 'zig-out/**/*',

frameworks/Zig/zap/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# [Zap](https://github.com/zigzap/zap) - Blazingly fast backends in zig
3+
4+
## Description
5+
6+
Zap is the zig microframework for web applications.
7+
8+
## Test URLs
9+
10+
### Test 1: JSON Encoding
11+
12+
http://localhost:3000/json
13+
14+
### Test 2: Plaintext
15+
16+
http://localhost:3000/plaintext
17+
18+
### Test 2: Single Row Query
19+
20+
http://localhost:3000/db
21+
22+
### Test 4: Fortunes (Template rendering)
23+
24+
http://localhost:3000/fortunes
25+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"framework": "zap",
3+
"tests": [{
4+
"default": {
5+
"json_url": "/json",
6+
"db_url": "/db",
7+
"fortune_url": "/fortunes",
8+
"plaintext_url": "/plaintext",
9+
"port": 3000,
10+
"approach": "Realistic",
11+
"classification": "Fullstack",
12+
"database": "Postgres",
13+
"framework": "Zap",
14+
"language": "Zig",
15+
"flavor": "None",
16+
"orm": "Full",
17+
"platform": "None",
18+
"webserver": "None",
19+
"os": "Linux",
20+
"database_os": "Linux",
21+
"display_name": "Zap (Zig)",
22+
"notes": "",
23+
"versus": ""
24+
}
25+
}]
26+
}

frameworks/Zig/zap/build.zig

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
const std = @import("std");
2+
3+
// Although this function looks imperative, note that its job is to
4+
// declaratively construct a build graph that will be executed by an external
5+
// runner.
6+
pub fn build(b: *std.Build) void {
7+
// Standard target options allows the person running `zig build` to choose
8+
// what target to build for. Here we do not override the defaults, which
9+
// means any target is allowed, and the default is native. Other options
10+
// for restricting supported target set are available.
11+
const target = b.standardTargetOptions(.{});
12+
13+
// Standard optimization options allow the person running `zig build` to select
14+
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do nots
15+
// set a preferred release mode, allowing the user to decide how to optimize.
16+
const optimize = b.standardOptimizeOption(.{});
17+
18+
const exe = b.addExecutable(.{
19+
.name = "zap",
20+
// In this case the main source file is merely a path, however, in more
21+
// complicated build scripts, this could be a generated file.
22+
.root_source_file = .{ .path = "src/main.zig" },
23+
.target = target,
24+
.optimize = optimize,
25+
});
26+
27+
//exe.addPackagePath("random", "src/random.zig");
28+
29+
const zap = b.dependency("zap", .{
30+
.target = target,
31+
.optimize = optimize,
32+
.openssl = false, // set to true to enable TLS support
33+
});
34+
exe.addModule("zap", zap.module("zap"));
35+
36+
const pg = b.dependency("pg", .{
37+
.target = target,
38+
.optimize = optimize,
39+
});
40+
exe.addModule("pg", pg.module("pg"));
41+
42+
const dig = b.dependency("dig", .{
43+
.target = target,
44+
.optimize = optimize,
45+
});
46+
exe.addModule("dns", dig.module("dns"));
47+
48+
// const mustache = b.dependency("mustache", .{
49+
// .target = target,
50+
// .optimize = optimize,
51+
// });
52+
// exe.addModule("mustache", mustache.module("mustache"));
53+
54+
exe.linkLibrary(zap.artifact("facil.io"));
55+
56+
// This declares intent for the executable to be installed into the
57+
// standard location when the user invokes the "install" step (the default
58+
// step when running `zig build`).
59+
b.installArtifact(exe);
60+
61+
// This *creates* a Run step in the build graph, to be executed when another
62+
// step is evaluated that depends on it. The next line below will establish
63+
// such a dependency.
64+
const run_cmd = b.addRunArtifact(exe);
65+
66+
// By making the run step depend on the install step, it will be run from the
67+
// installation directory rather than directly from within the cache directory.
68+
// This is not necessary, however, if the application depends on other installed
69+
// files, this ensures they will be present and in the expected location.
70+
run_cmd.step.dependOn(b.getInstallStep());
71+
72+
// This allows the user to pass arguments to the application in the build
73+
// command itself, like this: `zig build run -- arg1 arg2 etc`
74+
if (b.args) |args| {
75+
run_cmd.addArgs(args);
76+
}
77+
78+
// This creates a build step. It will be visible in the `zig build --help` menu,
79+
// and can be selected like this: `zig build run`
80+
// This will evaluate the `run` step rather than the default, which is "install".
81+
const run_step = b.step("run", "Run the app");
82+
run_step.dependOn(&run_cmd.step);
83+
84+
// Creates a step for unit testing. This only builds the test executable
85+
// but does not run it.
86+
const unit_tests = b.addTest(.{
87+
.root_source_file = .{ .path = "src/main.zig" },
88+
.target = target,
89+
.optimize = optimize,
90+
});
91+
92+
const run_unit_tests = b.addRunArtifact(unit_tests);
93+
94+
// Similar to creating the run step earlier, this exposes a `test` step to
95+
// the `zig build --help` menu, providing a way for the user to request
96+
// running the unit tests.
97+
const test_step = b.step("test", "Run unit tests");
98+
test_step.dependOn(&run_unit_tests.step);
99+
}

frameworks/Zig/zap/build.zig.zon

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.{
2+
.name = "Zap testing",
3+
.version = "0.1.0",
4+
5+
.dependencies = .{
6+
// zap v0.5.1
7+
.zap = .{
8+
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.5.1.tar.gz",
9+
.hash = "1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4",
10+
},
11+
.pg = .{
12+
.url = "https://github.com/karlseguin/pg.zig/archive/f3f4a0b3b9996bfb1bf9bd0bdd0d73b36e915a86.tar.gz",
13+
.hash = "1220337202642ee66408a35f254549f22cf3a096c6fa6c28e6f87a0161d5a6c0f4ab"
14+
},
15+
.dig = .{
16+
.url = "https://github.com/lun-4/zigdig/archive/2ec407ec3c7f347e747717977958e9ba339eb82f.tar.gz",
17+
.hash = "1220dfdb3089dfe9a4e4bc1226fcff08d91d0c0853f287d98d8b81270da251790331"
18+
},
19+
20+
}
21+
}

frameworks/Zig/zap/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
echo "Waiting for ZAP to start..."
2+
3+
zap

0 commit comments

Comments
 (0)