|
| 1 | +const std = @import("std"); |
| 2 | +const Builder = std.build.Builder; |
| 3 | +const Pkg = std.build.Pkg; |
| 4 | +const Step = std.build.Step; |
| 5 | +const debug = std.debug; |
| 6 | + |
| 7 | + |
| 8 | +pub fn build(b: *std.build.Builder) void { |
| 9 | + b.installFile("external/WinDivert-2.2.0-A/x64/WinDivert.dll", "bin/WinDivert.dll"); |
| 10 | + b.installFile("external/WinDivert-2.2.0-A/x64/WinDivert64.sys", "bin/WinDivert64.sys"); |
| 11 | + |
| 12 | + const exe = b.addExecutable("clumsy", null); |
| 13 | + |
| 14 | + // switch to rc.exe?? at least it's not so fucking stupid |
| 15 | + // const abs_rc = std.fs.cwd().realpathAlloc(b.allocator); |
| 16 | + |
| 17 | + |
| 18 | + // TODO setup candidate for windres/rc.exe from a few places |
| 19 | + // windres need to be working in its directory |
| 20 | + // TODO mkdir p |
| 21 | + // const cmd = b.addSystemCommand(&[_][]const u8{ |
| 22 | + // "C:/msys64/mingw64/bin/llvm-windres.exe", |
| 23 | + // "etc/clumsy.rc", |
| 24 | + // "-O", |
| 25 | + // "coff", |
| 26 | + // "-o", |
| 27 | + // "tmp/x64/release/clumsy_res_x64.obj", |
| 28 | + // "-DNDEBUG", |
| 29 | + // "-DX64", |
| 30 | + // }); |
| 31 | + // cmd.cwd = "C:/msys64/mingw64/bin"; |
| 32 | + |
| 33 | + const cmd = b.addSystemCommand(&[_][]const u8{ |
| 34 | + "rc", |
| 35 | + "/nologo", |
| 36 | + "/d", |
| 37 | + "NDEBUG", |
| 38 | + "/d", |
| 39 | + "X64", |
| 40 | + "/r", |
| 41 | + "/fo", |
| 42 | + "tmp/x64/release/clumsy_res_x64.obj", |
| 43 | + "etc/clumsy.rc", |
| 44 | + }); |
| 45 | + |
| 46 | + exe.step.dependOn(&cmd.step); |
| 47 | + |
| 48 | + exe.addObjectFile("tmp/x64/release/clumsy_res_x64.obj"); |
| 49 | + |
| 50 | + exe.addCSourceFile("src/bandwidth.c", &[_][]const u8{""}); |
| 51 | + exe.addCSourceFile("src/divert.c", &[_][]const u8{""}); |
| 52 | + exe.addCSourceFile("src/drop.c", &[_][]const u8{""}); |
| 53 | + exe.addCSourceFile("src/duplicate.c", &[_][]const u8{""}); |
| 54 | + exe.addCSourceFile("src/elevate.c", &[_][]const u8{""}); |
| 55 | + exe.addCSourceFile("src/lag.c", &[_][]const u8{""}); |
| 56 | + exe.addCSourceFile("src/main.c", &[_][]const u8{""}); |
| 57 | + exe.addCSourceFile("src/ood.c", &[_][]const u8{""}); |
| 58 | + exe.addCSourceFile("src/packet.c", &[_][]const u8{""}); |
| 59 | + exe.addCSourceFile("src/reset.c", &[_][]const u8{""}); |
| 60 | + exe.addCSourceFile("src/tamper.c", &[_][]const u8{""}); |
| 61 | + exe.addCSourceFile("src/throttle.c", &[_][]const u8{""}); |
| 62 | + exe.addCSourceFile("src/utils.c", &[_][]const u8{""}); |
| 63 | + |
| 64 | + exe.setBuildMode(b.standardReleaseOptions()); |
| 65 | + exe.setTarget(b.standardTargetOptions(.{})); |
| 66 | + |
| 67 | + exe.addIncludeDir("external/WinDivert-2.2.0-A/include"); |
| 68 | + exe.addIncludeDir("external/iup-3.30_Win64_mingw6_lib/include"); |
| 69 | + |
| 70 | + exe.addCSourceFile("external/iup-3.30_Win64_mingw6_lib/libiup.a", &[_][]const u8{""}); |
| 71 | + |
| 72 | + exe.linkLibC(); |
| 73 | + exe.addLibPath("external/WinDivert-2.2.0-A/x64"); |
| 74 | + exe.linkSystemLibrary("WinDivert"); |
| 75 | + exe.linkSystemLibrary("comctl32"); |
| 76 | + exe.linkSystemLibrary("Winmm"); |
| 77 | + exe.linkSystemLibrary("ws2_32"); |
| 78 | + exe.linkSystemLibrary("kernel32"); |
| 79 | + exe.linkSystemLibrary("gdi32"); |
| 80 | + exe.linkSystemLibrary("comdlg32"); |
| 81 | + exe.linkSystemLibrary("uuid"); |
| 82 | + exe.linkSystemLibrary("ole32"); |
| 83 | + exe.install(); |
| 84 | + |
| 85 | + const run_cmd = exe.run(); |
| 86 | + run_cmd.step.dependOn(b.getInstallStep()); |
| 87 | + |
| 88 | + // `b.step` creates a new top level step |
| 89 | + // then it depends on exe.run,so running hello would trigger run |
| 90 | + const hello_step = b.step("hello", "this is a hello step"); |
| 91 | + hello_step.dependOn(&run_cmd.step); |
| 92 | + |
| 93 | + const clumsy_step = ClumsyStep.create(b, "wow"); |
| 94 | + hello_step.dependOn(&clumsy_step.step); |
| 95 | + |
| 96 | + debug.print("builder args: {s}\n", .{b.args}); |
| 97 | +} |
| 98 | + |
| 99 | +pub const ClumsyStep = struct { |
| 100 | + step: Step, |
| 101 | + builder: *Builder, |
| 102 | + |
| 103 | + pub fn create(builder: *Builder, data: []const u8) *@This() { |
| 104 | + const self = builder.allocator.create(@This()) catch unreachable; |
| 105 | + self.* = . { |
| 106 | + .step = Step.init(.custom, builder.fmt("clumsyStep {s}", .{data}), builder.allocator, make), |
| 107 | + .builder = builder, |
| 108 | + }; |
| 109 | + return self; |
| 110 | + } |
| 111 | + |
| 112 | + fn make(_: *Step) anyerror!void { |
| 113 | + debug.print("{s}", .{"hello clumsyStep"}); |
| 114 | + } |
| 115 | +}; |
0 commit comments