refactor build process
This commit is contained in:
parent
49c6326086
commit
a9b1873109
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
lib/zlib
|
lib/zlib
|
||||||
.zig-cache
|
.zig-cache
|
||||||
|
.env
|
||||||
|
@ -4,13 +4,9 @@
|
|||||||
wget https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz
|
wget https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.gz
|
||||||
tar xvf zlib-1.2.13.tar.gz
|
tar xvf zlib-1.2.13.tar.gz
|
||||||
rm zlib-1.2.13.tar.gz
|
rm zlib-1.2.13.tar.gz
|
||||||
mv zlib-1.2.13 zlib
|
mv zlib-1.2.13 lib/zlib
|
||||||
mv zlib lib/zlib
|
|
||||||
git clone https://github.com/yuzudev/websocket.zig.git ./lib/websocket.zig/
|
|
||||||
git clone https://github.com/yuzudev/zig-tls12 ./lib/zig-tls12/
|
|
||||||
git clone https://github.com/jetzig-framework/zmpl.git ./lib/zmpl/
|
|
||||||
```
|
```
|
||||||
or simply run ./install.sh
|
or simply run ./install-zlib.sh
|
||||||
|
|
||||||
# features
|
# features
|
||||||
* supports sharding for large bots
|
* supports sharding for large bots
|
||||||
|
66
build.zig
66
build.zig
@ -10,32 +10,17 @@ pub fn build(b: *std.Build) void {
|
|||||||
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
|
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
|
||||||
|
|
||||||
// this is your own program
|
// this is your own program
|
||||||
const exe = b.addExecutable(.{
|
const dzig = b.addModule("discord.zig", .{
|
||||||
// the name of your project
|
.root_source_file = b.path("src/discord.zig"),
|
||||||
.name = "oculus-2",
|
|
||||||
// your main function
|
|
||||||
.root_source_file = b.path("src/main.zig"),
|
|
||||||
// references the ones you declared above
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
.link_libc = true,
|
.link_libc = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const test_comp = b.addTest(.{
|
const websocket = b.dependency("websocket", .{
|
||||||
.root_source_file = b.path("src/test.zig"),
|
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
||||||
const websocket = b.createModule(.{
|
const zig_tls = b.dependency("zig-tls", .{
|
||||||
.root_source_file = b.path("lib/websocket.zig/src/websocket.zig"),
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
.link_libc = true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const zig_tls = b.createModule(.{
|
|
||||||
.root_source_file = b.path("lib/zig-tls12/src/entry.zig"),
|
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
@ -48,11 +33,9 @@ pub fn build(b: *std.Build) void {
|
|||||||
.link_libc = true,
|
.link_libc = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const zmpl = b.createModule(.{
|
const zmpl = b.dependency("zmpl", .{
|
||||||
//.name = "zlib",
|
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.root_source_file = b.path("lib/zmpl/src/zmpl.zig"),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const deque = b.dependency("zig-deque", .{
|
const deque = b.dependency("zig-deque", .{
|
||||||
@ -60,6 +43,14 @@ pub fn build(b: *std.Build) void {
|
|||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const marin = b.addExecutable(.{
|
||||||
|
.name = "marin",
|
||||||
|
.root_source_file = b.path("src/test.zig"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
.link_libc = true,
|
||||||
|
});
|
||||||
|
|
||||||
const srcs = &.{
|
const srcs = &.{
|
||||||
"lib/zlib/adler32.c",
|
"lib/zlib/adler32.c",
|
||||||
"lib/zlib/compress.c",
|
"lib/zlib/compress.c",
|
||||||
@ -83,28 +74,23 @@ pub fn build(b: *std.Build) void {
|
|||||||
zlib_zig.addCSourceFiles(.{ .files = srcs, .flags = &.{"-std=c89"} });
|
zlib_zig.addCSourceFiles(.{ .files = srcs, .flags = &.{"-std=c89"} });
|
||||||
zlib_zig.addIncludePath(b.path("lib/zlib/"));
|
zlib_zig.addIncludePath(b.path("lib/zlib/"));
|
||||||
|
|
||||||
websocket.addImport("zlib", zlib_zig);
|
|
||||||
websocket.addImport("tls12", zig_tls);
|
|
||||||
|
|
||||||
// now install your own executable after it's built correctly
|
// now install your own executable after it's built correctly
|
||||||
|
|
||||||
exe.root_module.addImport("ws", websocket);
|
dzig.addImport("ws", websocket.module("websocket"));
|
||||||
exe.root_module.addImport("tls12", zig_tls);
|
dzig.addImport("tls12", zig_tls.module("zig-tls12"));
|
||||||
exe.root_module.addImport("zlib", zlib_zig);
|
dzig.addImport("zlib", zlib_zig);
|
||||||
exe.root_module.addImport("zmpl", zmpl);
|
dzig.addImport("zmpl", zmpl.module("zmpl"));
|
||||||
exe.root_module.addImport("deque", deque.module("zig-deque"));
|
dzig.addImport("deque", deque.module("zig-deque"));
|
||||||
|
|
||||||
|
marin.root_module.addImport("discord.zig", dzig);
|
||||||
|
marin.root_module.addImport("ws", websocket.module("websocket"));
|
||||||
|
marin.root_module.addImport("tls12", zig_tls.module("zig-tls12"));
|
||||||
|
marin.root_module.addImport("zlib", zlib_zig);
|
||||||
|
marin.root_module.addImport("zmpl", zmpl.module("zmpl"));
|
||||||
|
marin.root_module.addImport("deque", deque.module("zig-deque"));
|
||||||
|
|
||||||
// test
|
// test
|
||||||
test_comp.root_module.addImport("ws", websocket);
|
const run_cmd = b.addRunArtifact(marin);
|
||||||
test_comp.root_module.addImport("tls12", zig_tls);
|
|
||||||
test_comp.root_module.addImport("zlib", zlib_zig);
|
|
||||||
|
|
||||||
const run_test_comp = b.addRunArtifact(test_comp);
|
|
||||||
const test_step = b.step("test", "Run unit tests");
|
|
||||||
test_step.dependOn(&test_comp.step);
|
|
||||||
test_step.dependOn(&run_test_comp.step);
|
|
||||||
|
|
||||||
const run_cmd = b.addRunArtifact(exe);
|
|
||||||
run_cmd.step.dependOn(b.getInstallStep());
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
|
||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
|
@ -27,6 +27,18 @@
|
|||||||
.url = "https://github.com/magurotuna/zig-deque/archive/refs/heads/main.zip",
|
.url = "https://github.com/magurotuna/zig-deque/archive/refs/heads/main.zip",
|
||||||
.hash = "1220d1bedf7d5cfc7475842b3d4e8f03f1308be2e724a036677cceb5c4db13c3da3d",
|
.hash = "1220d1bedf7d5cfc7475842b3d4e8f03f1308be2e724a036677cceb5c4db13c3da3d",
|
||||||
},
|
},
|
||||||
|
.zmpl = .{
|
||||||
|
.url = "https://github.com/jetzig-framework/zmpl/archive/refs/heads/main.zip",
|
||||||
|
.hash = "1220d279461176a5554da195c19e025110096819004c6de86a6bb2e186ac13b63f85",
|
||||||
|
},
|
||||||
|
.@"zig-tls" = .{
|
||||||
|
.url = "https://github.com/yuzudev/zig-tls12/archive/refs/heads/main.zip",
|
||||||
|
.hash = "122079aad9eebc5945e207715c50722bbeca34e7b7a5876b3a322fad6468b28f2ed3",
|
||||||
|
},
|
||||||
|
.websocket = .{
|
||||||
|
.url = "https://github.com/yuzudev/websocket.zig/archive/refs/heads/master.zip",
|
||||||
|
.hash = "122062d9dda015ba25780d00697e0e2c1cbc3ffa5b5eae55c9ea28b39b6d99ef1d85",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
git clone https://github.com/yuzudev/websocket.zig.git ./lib/websocket.zig/
|
|
||||||
git clone https://github.com/yuzudev/zig-tls12 ./lib/zig-tls12/
|
|
||||||
git clone https://github.com/jetzig-framework/zmpl.git ./lib/zmpl/
|
|
||||||
./install-zlib.sh
|
|
@ -1 +0,0 @@
|
|||||||
Subproject commit e93fa527f1d4deaeda5f74f51efaf7ec60cab396
|
|
@ -1 +0,0 @@
|
|||||||
Subproject commit 56153d0f9f4551c7031b3b536845e90d23250d01
|
|
1
lib/zmpl
1
lib/zmpl
@ -1 +0,0 @@
|
|||||||
Subproject commit a128d0a9c9cd70ca9f007405ae3d17e3a074ab34
|
|
@ -1,9 +1,8 @@
|
|||||||
const Session = @import("shard.zig");
|
const Shard = @import("discord.zig").Shard;
|
||||||
const Discord = @import("types.zig");
|
const Discord = @import("discord.zig").Discord;
|
||||||
const Intents = Discord.Intents;
|
const Intents = Discord.Intents;
|
||||||
const std = @import("std");
|
|
||||||
const Thread = std.Thread;
|
const Thread = std.Thread;
|
||||||
const token = "Bot MTI5ODgzOTgzMDY3OTEzMDE4OA.GNojts.iyblGKK0xTWU57QCG5n3hr2Be1whyylTGr44P0";
|
const std = @import("std");
|
||||||
|
|
||||||
fn ready(payload: Discord.Ready) void {
|
fn ready(payload: Discord.Ready) void {
|
||||||
std.debug.print("logged in as {s}\n", .{payload.user.username});
|
std.debug.print("logged in as {s}\n", .{payload.user.username});
|
||||||
@ -18,10 +17,12 @@ pub fn main() !void {
|
|||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
const allocator = arena.allocator();
|
const allocator = arena.allocator();
|
||||||
|
|
||||||
var handler = try Session.init(allocator, .{
|
const token = std.posix.getenv("TOKEN") orelse unreachable;
|
||||||
|
|
||||||
|
var handler = try Shard.init(allocator, .{
|
||||||
.token = token,
|
.token = token,
|
||||||
.intents = Intents.fromRaw(37379),
|
.intents = Intents.fromRaw(37379),
|
||||||
.run = Session.GatewayDispatchEvent{
|
.run = Shard.GatewayDispatchEvent{
|
||||||
.message_create = &message_create,
|
.message_create = &message_create,
|
||||||
.ready = &ready,
|
.ready = &ready,
|
||||||
},
|
},
|
||||||
@ -29,6 +30,6 @@ pub fn main() !void {
|
|||||||
});
|
});
|
||||||
errdefer handler.deinit();
|
errdefer handler.deinit();
|
||||||
|
|
||||||
const t = try Thread.spawn(.{}, Session.readMessage, .{ &handler, null });
|
const t = try Thread.spawn(.{}, Shard.readMessage, .{ &handler, null });
|
||||||
defer t.join();
|
defer t.join();
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user