"add omt building to build.zig and link with exe"
This commit is contained in:
94
build.zig
94
build.zig
@@ -4,92 +4,70 @@ pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
// const mod = b.addModule("omtoy", .{
|
||||
// .root_source_file = b.path("src/root.zig"),
|
||||
// .target = target,
|
||||
// });
|
||||
const triple = target.result;
|
||||
if (triple.os.tag != .linux or triple.cpu.arch != .x86_64) {
|
||||
std.log.warn("The build file only supports Linux x86-64 right now.\n", .{});
|
||||
std.log.warn("You can extend the build.zig to call the appropriate platform scripts in 3rd/libomtnet/build/ and 3rd/libomt/build.\n", .{});
|
||||
}
|
||||
|
||||
// Build libomtnet
|
||||
const libomtnet_build = b.addSystemCommand(&.{
|
||||
"bash",
|
||||
"buildall.sh",
|
||||
});
|
||||
libomtnet_build.cwd = b.path("3rd/libomtnet/build");
|
||||
|
||||
// Build libomt
|
||||
const libomt_build = b.addSystemCommand(&.{
|
||||
"bash",
|
||||
"buildlinuxx64.sh",
|
||||
});
|
||||
libomt_build.cwd = b.path("3rd/libomt/build");
|
||||
libomt_build.step.dependOn(&libomtnet_build.step);
|
||||
|
||||
// Define executable
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "omtoy",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
|
||||
// .imports = &.{
|
||||
// .{ .name = "omtoy", .module = mod },
|
||||
// },
|
||||
}),
|
||||
});
|
||||
|
||||
// This declares intent for the executable to be installed into the
|
||||
// install prefix when running `zig build` (i.e. when executing the default
|
||||
// step). By default the install prefix is `zig-out/` but can be overridden
|
||||
// by passing `--prefix` or `-p`.
|
||||
// Link libomt with the build
|
||||
{
|
||||
const omt_output_dir = b.path("3rd/libomt/bin/Release/net8.0/linux-x64/publish");
|
||||
exe.step.dependOn(&libomt_build.step);
|
||||
exe.addIncludePath(omt_output_dir);
|
||||
exe.addLibraryPath(omt_output_dir);
|
||||
exe.linkSystemLibrary("omt");
|
||||
exe.linkLibC();
|
||||
}
|
||||
|
||||
b.installArtifact(exe);
|
||||
|
||||
// This creates a top level step. Top level steps have a name and can be
|
||||
// invoked by name when running `zig build` (e.g. `zig build run`).
|
||||
// This will evaluate the `run` step rather than the default step.
|
||||
// For a top level step to actually do something, it must depend on other
|
||||
// steps (e.g. a Run step, as we will see in a moment).
|
||||
const run_step = b.step("run", "Run the app");
|
||||
// Manual build step for libomt dependencies
|
||||
const build_omt_step = b.step("build-omt", "Build libomt and libomtnet");
|
||||
build_omt_step.dependOn(&libomt_build.step);
|
||||
|
||||
// This creates a RunArtifact step in the build graph. A RunArtifact step
|
||||
// invokes an executable compiled by Zig. Steps will only be executed by the
|
||||
// runner if invoked directly by the user (in the case of top level steps)
|
||||
// or if another step depends on it, so it's up to you to define when and
|
||||
// how this Run step will be executed. In our case we want to run it when
|
||||
// the user runs `zig build run`, so we create a dependency link.
|
||||
// Add run step
|
||||
const run_step = b.step("run", "Run the app");
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
|
||||
// By making the run step depend on the default step, it will be run from the
|
||||
// installation directory rather than directly from within the cache directory.
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
|
||||
// This allows the user to pass arguments to the application in the build
|
||||
// command itself, like this: `zig build run -- arg1 arg2 etc`
|
||||
if (b.args) |args| {
|
||||
run_cmd.addArgs(args);
|
||||
}
|
||||
|
||||
// Creates an executable that will run `test` blocks from the provided module.
|
||||
// Here `mod` needs to define a target, which is why earlier we made sure to
|
||||
// set the releative field.
|
||||
// const mod_tests = b.addTest(.{
|
||||
// .root_module = mod,
|
||||
// });
|
||||
|
||||
// A run step that will run the test executable.
|
||||
// const run_mod_tests = b.addRunArtifact(mod_tests);
|
||||
|
||||
// Creates an executable that will run `test` blocks from the executable's
|
||||
// root module. Note that test executables only test one module at a time,
|
||||
// hence why we have to create two separate ones.
|
||||
const exe_tests = b.addTest(.{
|
||||
.root_module = exe.root_module,
|
||||
});
|
||||
|
||||
// A run step that will run the second test executable.
|
||||
const run_exe_tests = b.addRunArtifact(exe_tests);
|
||||
|
||||
// A top level step for running all tests. dependOn can be called multiple
|
||||
// times and since the two run steps do not depend on one another, this will
|
||||
// make the two of them run in parallel.
|
||||
const test_step = b.step("test", "Run tests");
|
||||
// test_step.dependOn(&run_mod_tests.step);
|
||||
test_step.dependOn(&run_exe_tests.step);
|
||||
|
||||
// Just like flags, top level steps are also listed in the `--help` menu.
|
||||
//
|
||||
// The Zig build system is entirely implemented in userland, which means
|
||||
// that it cannot hook into private compiler APIs. All compilation work
|
||||
// orchestrated by the build system will result in other Zig compiler
|
||||
// subcommands being invoked with the right flags defined. You can observe
|
||||
// these invocations when one fails (or you pass a flag to increase
|
||||
// verbosity) to validate assumptions and diagnose problems.
|
||||
//
|
||||
// Lastly, the Zig build system is relatively simple and self-contained,
|
||||
// and reading its source code will allow you to master it.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user