-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
82 lines (72 loc) · 2.2 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const std = @import("std");
const Build = std.Build;
const Options = struct {
target: Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const smithy = b.dependency("smithy", .{
.target = target,
.optimize = optimize,
}).module("runtime");
const aws_runtime = b.dependency("aws", .{
.target = target,
.optimize = optimize,
}).module("runtime");
//
// SDK
//
b.modules.put("aws", aws_runtime) catch {};
const sdk_path = "sdk";
var sdk_dir = std.fs.openDirAbsolute(b.path(sdk_path).getPath(b), .{ .iterate = true }) catch {
@panic("Open dir error");
};
defer sdk_dir.close();
// Services
var it = sdk_dir.iterateAssumeFirstIteration();
while (it.next() catch @panic("Dir iterator error")) |entry| {
if (entry.kind != .directory) continue;
addSdkClient(b, .{
.target = target,
.optimize = optimize,
}, sdk_path, entry.name, smithy, aws_runtime);
}
}
fn addSdkClient(
b: *std.Build,
options: Options,
dir: []const u8,
name: []const u8,
smithy: *Build.Module,
runtime: *Build.Module,
) void {
// Client
const path = b.path(b.fmt("{s}/{s}/client.zig", .{ dir, name }));
_ = b.addModule(
b.fmt("sdk/{s}", .{name}),
.{
.target = options.target,
.optimize = options.optimize,
.root_source_file = path,
.imports = &.{
.{ .name = "smithy", .module = smithy },
.{ .name = "aws-runtime", .module = runtime },
},
},
);
// Tests
const test_step = b.step(
b.fmt("test:sdk-{s}", .{name}),
b.fmt("Run `{s}` SDK unit tests", .{name}),
);
const unit_tests = b.addTest(.{
.target = options.target,
.optimize = options.optimize,
.root_source_file = path,
});
unit_tests.root_module.addImport("smithy", smithy);
unit_tests.root_module.addImport("aws-runtime", runtime);
test_step.dependOn(&b.addRunArtifact(unit_tests).step);
}