feat: update build.zig
zba-gdbstub now supports being used as a library
This commit is contained in:
parent
d64b35fdf3
commit
2cb5c93eca
63
build.zig
63
build.zig
|
@ -1,20 +1,50 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn build(b: *std.build.Builder) void {
|
fn path(comptime suffix: []const u8) []const u8 {
|
||||||
// Standard target options allows the person running `zig build` to choose
|
if (suffix[0] == '/') @compileError("expected a relative path");
|
||||||
// what target to build for. Here we do not override the defaults, which
|
return comptime (std.fs.path.dirname(@src().file) orelse ".") ++ std.fs.path.sep_str ++ suffix;
|
||||||
// means any target is allowed, and the default is native. Other options
|
}
|
||||||
// for restricting supported target set are available.
|
|
||||||
const target = b.standardTargetOptions(.{});
|
|
||||||
|
|
||||||
// Standard release options allow the person running `zig build` to select
|
const pkgs = struct {
|
||||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
const Pkg = std.build.Pkg;
|
||||||
const mode = b.standardReleaseOptions();
|
|
||||||
|
|
||||||
const exe = b.addExecutable("zba-gdbstub", "src/main.zig");
|
pub const gdbstub: Pkg = .{
|
||||||
|
.name = "gdbstub",
|
||||||
|
.source = .{ .path = path("src/lib.zig") },
|
||||||
|
.dependencies = &[_]Pkg{network},
|
||||||
|
};
|
||||||
|
|
||||||
// https://github.com/MasterQ32/zig-network
|
// https://github.com/MasterQ32/zig-network
|
||||||
exe.addPackagePath("network", "lib/zig-network/network.zig");
|
pub const network: Pkg = .{
|
||||||
|
.name = "network",
|
||||||
|
.source = .{ .path = path("lib/zig-network/network.zig") },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn link(exe: *std.build.LibExeObjStep) void {
|
||||||
|
exe.addPackage(pkgs.gdbstub);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build(b: *std.build.Builder) void {
|
||||||
|
const target = b.standardTargetOptions(.{});
|
||||||
|
const mode = b.standardReleaseOptions();
|
||||||
|
|
||||||
|
// -- library --
|
||||||
|
const lib = b.addStaticLibrary("gdbstub", "src/lib.zig");
|
||||||
|
lib.addPackage(pkgs.network);
|
||||||
|
|
||||||
|
lib.setBuildMode(mode);
|
||||||
|
lib.install();
|
||||||
|
|
||||||
|
const lib_tests = b.addTest("src/lib.zig");
|
||||||
|
lib_tests.setBuildMode(mode);
|
||||||
|
|
||||||
|
const test_step = b.step("lib-test", "Run Library Tests");
|
||||||
|
test_step.dependOn(&lib_tests.step);
|
||||||
|
|
||||||
|
// -- Executable --
|
||||||
|
const exe = b.addExecutable("gdbserver", "src/main.zig");
|
||||||
|
link(exe);
|
||||||
|
|
||||||
exe.setTarget(target);
|
exe.setTarget(target);
|
||||||
exe.setBuildMode(mode);
|
exe.setBuildMode(mode);
|
||||||
|
@ -22,17 +52,8 @@ pub fn build(b: *std.build.Builder) void {
|
||||||
|
|
||||||
const run_cmd = exe.run();
|
const run_cmd = exe.run();
|
||||||
run_cmd.step.dependOn(b.getInstallStep());
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
if (b.args) |args| {
|
if (b.args) |args| run_cmd.addArgs(args);
|
||||||
run_cmd.addArgs(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
|
||||||
const exe_tests = b.addTest("src/main.zig");
|
|
||||||
exe_tests.setTarget(target);
|
|
||||||
exe_tests.setBuildMode(mode);
|
|
||||||
|
|
||||||
const test_step = b.step("test", "Run unit tests");
|
|
||||||
test_step.dependOn(&exe_tests.step);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const network = @import("network");
|
const Server = @import("gdbstub").Server;
|
||||||
const Server = @import("Server.zig");
|
|
||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
|
||||||
const Socket = network.Socket;
|
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
const log = std.log.scoped(.Main);
|
const log = std.log.scoped(.Main);
|
||||||
|
|
Loading…
Reference in New Issue