update build options module name and readme
All checks were successful
AWS-Zig Build / build-zig-0.11.0-amd64-host (push) Successful in 1m28s

This commit is contained in:
Emil Lerch 2023-10-28 15:51:41 -07:00
parent 0736660669
commit e5a1099f74
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
4 changed files with 20 additions and 13 deletions

View File

@ -28,8 +28,8 @@ Create a `build.zig.zon` with the following contents:
.dependencies = .{
.universal_lambda_build = .{
.url = "https://git.lerch.org/lobo/universal-lambda-zig/archive/70b0fda03b9c54a6eda8d61cb8ab8b9d9f29b2ef.tar.gz",
.hash = "122004f2a4ad253be9b8d7989ca6508af1483d8a593ca7fee93627444b2b37d170d2",
.url = "https://git.lerch.org/lobo/universal-lambda-zig/archive/07366606696081f324591b66ab7a9a176a38424c.tar.gz",
.hash = "122049daa19f61d778a79ffb82c64775ca5132ee5c4797d7f7d76667ab82593917cd",
},
.flexilib = .{
.url = "https://git.lerch.org/lobo/flexilib/archive/c44ad2ba84df735421bef23a2ad612968fb50f06.tar.gz",
@ -50,7 +50,7 @@ and/or changes to this library.
* Add an import at the top:
```zig
const configureUniversalLambdaBuild = @import("universal_lambda_build").configureBuild;
const universal_lambda = @import("universal_lambda_build");
```
* Set the return of the build function to return `!void` rather than `void`
@ -58,7 +58,7 @@ const configureUniversalLambdaBuild = @import("universal_lambda_build").configur
after adding the exe is fine:
```zig
try configureUniversalLambdaBuild(b, exe);
try universal_lambda.configureBuild(b, exe);
```
This will provide most of the magic functionality of the package, including
@ -85,6 +85,9 @@ const universal_lambda = @import("universal_lambda_handler");
const universal_lambda_interface = @import("universal_lambda_interface");
```
Another module `universal_lambda_build_options` is available if access to the
environment is needed. The build type is stored under a `build_type` variable.
Add a handler to be executed. The handler must follow this signature:
```zig
@ -144,3 +147,7 @@ Limitations include standalone web server port customization and linux/aws cli r
Also, within the context, AWS Lambda is unable to provide proper method, target,
and headers for the request. This may be important for routing purposes. Suggestion
here is to use API Gateway and pass these parameters through the event_data content.
Lastly, support for specifying multiple targets in the downstream (your) application
is somewhat spotty. For example, `zig build standalone_server run` works fine.
However, `zig build test flexilib` is broken.

View File

@ -3,9 +3,6 @@ const builtin = @import("builtin");
/// flexilib will create a dynamic library for use with flexilib.
/// Flexilib will need to get the exe compiled as a library
/// For flexilib, we will need the main file to have a pub fn named
/// "handler". If it is not called that, a pub const handler = ... can be
/// used instead
pub fn configureBuild(b: *std.build.Builder, cs: *std.Build.Step.Compile, build_root_src: []const u8) !void {
const package_step = b.step("flexilib", "Create a flexilib dynamic library");
@ -29,6 +26,9 @@ pub fn configureBuild(b: *std.build.Builder, cs: *std.Build.Step.Compile, build_
};
lib.addModule(entry.key_ptr.*, entry.value_ptr.*);
}
// Add the downstream root source file back into the build as a module
// that our new root source file can import
lib.addAnonymousModule("flexilib_handler", .{
// Source file can be anywhere on disk, does not need to be a subdirectory
.source_file = cs.root_src.?,

View File

@ -1,5 +1,5 @@
const std = @import("std");
const build_options = @import("build_options");
const build_options = @import("universal_lambda_build_options");
const flexilib = @import("flexilib-interface");
const interface = @import("universal_lambda_interface");

View File

@ -30,7 +30,7 @@ pub fn configureBuild(b: *std.Build, cs: *std.Build.Step.Compile) !void {
///
/// We will create the following modules for downstream consumption:
///
/// * build_options
/// * universal_lambda_build_options
/// * flexilib-interface
/// * universal_lambda_handler
pub fn addModules(b: *std.Build, cs: *std.Build.Step.Compile) ![]const u8 {
@ -65,7 +65,7 @@ pub fn addModules(b: *std.Build, cs: *std.Build.Step.Compile) ![]const u8 {
// Add options module so we can let our universal_lambda know what
// type of interface is necessary
.{
.name = "build_options",
.name = "universal_lambda_build_options",
.module = options_module,
},
.{
@ -139,7 +139,7 @@ fn findFileLocation(b: *std.Build) ![]const u8 {
return b.pathJoin(&[_][]const u8{ ulb_root, "src" });
}
/// Make our target platform visible to runtime through an import
/// called "build_options". This will also be available to the consuming
/// called "universal_lambda_build_options". This will also be available to the consuming
/// executable if needed
pub fn createOptionsModule(b: *std.Build, cs: *std.Build.Step.Compile) !*std.Build.Module {
// We need to go through the command line args, look for argument(s)
@ -152,8 +152,8 @@ pub fn createOptionsModule(b: *std.Build, cs: *std.Build.Step.Compile) !*std.Bui
defer b.allocator.free(args);
const options = b.addOptions();
options.addOption(BuildType, "build_type", findBuildType(args) orelse .exe_run);
cs.addOptions("build_options", options);
return cs.modules.get("build_options").?;
cs.addOptions("universal_lambda_build_options", options);
return cs.modules.get("universal_lambda_build_options").?;
}
fn findBuildType(build_args: [][:0]u8) ?BuildType {