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");
|
||||
|
||||
pub fn build(b: *std.build.Builder) void {
|
||||
// Standard target options allows the person running `zig build` to choose
|
||||
// what target to build for. Here we do not override the defaults, which
|
||||
// means any target is allowed, and the default is native. Other options
|
||||
// for restricting supported target set are available.
|
||||
const target = b.standardTargetOptions(.{});
|
||||
fn path(comptime suffix: []const u8) []const u8 {
|
||||
if (suffix[0] == '/') @compileError("expected a relative path");
|
||||
return comptime (std.fs.path.dirname(@src().file) orelse ".") ++ std.fs.path.sep_str ++ suffix;
|
||||
}
|
||||
|
||||
// Standard release options allow the person running `zig build` to select
|
||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||
const mode = b.standardReleaseOptions();
|
||||
const pkgs = struct {
|
||||
const Pkg = std.build.Pkg;
|
||||
|
||||
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
|
||||
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.setBuildMode(mode);
|
||||
|
@ -22,17 +52,8 @@ pub fn build(b: *std.build.Builder) void {
|
|||
|
||||
const run_cmd = exe.run();
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
if (b.args) |args| {
|
||||
run_cmd.addArgs(args);
|
||||
}
|
||||
if (b.args) |args| run_cmd.addArgs(args);
|
||||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
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 network = @import("network");
|
||||
const Server = @import("Server.zig");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Socket = network.Socket;
|
||||
const Server = @import("gdbstub").Server;
|
||||
|
||||
pub fn main() !void {
|
||||
const log = std.log.scoped(.Main);
|
||||
|
|
Loading…
Reference in New Issue