add library for stuff

This commit is contained in:
Emil Lerch 2023-05-07 16:12:33 -07:00
parent 110e306e05
commit 08dec6a978
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 37 additions and 12 deletions

View File

@ -24,11 +24,25 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});
const lib = b.addSharedLibrary(.{
.name = "faas-proxy-sample-lib",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/main-lib.zig" },
.target = target,
.optimize = optimize,
});
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
b.installArtifact(exe);
// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
b.installArtifact(lib);
// This *creates* a RunStep in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
// such a dependency.
@ -46,25 +60,26 @@ pub fn build(b: *std.Build) void {
run_cmd.addArgs(args);
}
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const lib_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main-lib.zig" },
.target = target,
.optimize = optimize,
});
const run_unit_tests = b.addRunArtifact(unit_tests);
const run_main_tests = b.addRunArtifact(main_tests);
const run_lib_tests = b.addRunArtifact(lib_tests);
// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build test`
// This will evaluate the `test` step rather than the default, which is "install".
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
test_step.dependOn(&run_main_tests.step);
test_step.dependOn(&run_lib_tests.step);
}

10
src/main-lib.zig Normal file
View File

@ -0,0 +1,10 @@
const std = @import("std");
const testing = std.testing;
export fn add(a: i32, b: i32) i32 {
return a + b;
}
test "basic add functionality" {
try testing.expect(add(3, 7) == 10);
}