Files
eric dc75722f6f feat(plugins): add the SOCKS5 plugin in C and in Zig
The ABI's claim is that a plugin needs a C compiler and nothing else. These
two are the evidence: the same SOCKS5 stream engine written twice, once in
plain C11 against leaf_plugin_abi.h and once in Zig importing that same
header, with no SDK, no runtime and no dependency beyond libc between them.

Both are state machines over the greeting, the method reply, the request and
the reply, so neither ever blocks or holds a thread. Each carries its own
tests -- socks5_test.c runs the engine against truncated and malformed
replies, and the Zig build runs its tests through `zig build test`.
2026-12-03 19:31:53 +08:00

36 lines
1.3 KiB
Zig

//! Standalone build for the SOCKS5 Zig plugin.
//!
//! `zig build` produces the shared library under `zig-out`, and `zig build
//! test` runs the unit tests in `src/main.zig`. leaf's own end-to-end harness
//! calls `zig build-lib` directly instead, because it needs to name the output
//! path; this file is here so the plugin can be built and tested on its own,
//! the way a third-party plugin would be.
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
// libc for the allocator and for the C ABI header.
.link_libc = true,
});
module.addIncludePath(b.path("../../leaf-plugin-abi/include"));
const library = b.addLibrary(.{
.name = "socks5_cabi_zig",
.root_module = module,
.linkage = .dynamic,
});
b.installArtifact(library);
const unit_tests = b.addTest(.{ .root_module = module });
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run the plugin's unit tests");
test_step.dependOn(&run_unit_tests.step);
}