Skip to content

Commit 8421fd9

Browse files
committed
merge pr #6 allowing dependency on service model
2 parents 9e8b3a6 + 220d45a commit 8421fd9

File tree

3 files changed

+68
-54
lines changed

3 files changed

+68
-54
lines changed

build.zig

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@ pub fn build(b: *Builder) !void {
6767
const smithy_module = smithy_dep.module("smithy");
6868
exe.root_module.addImport("smithy", smithy_module); // not sure this should be here...
6969

70-
// Expose module to others
71-
_ = b.addModule("aws", .{
72-
.root_source_file = b.path("src/aws.zig"),
73-
.imports = &.{.{ .name = "smithy", .module = smithy_module }},
74-
});
75-
76-
// Expose module to others
77-
_ = b.addModule("aws-signing", .{
78-
.root_source_file = b.path("src/aws_signing.zig"),
79-
.imports = &.{.{ .name = "smithy", .module = smithy_module }},
80-
});
8170
// TODO: This does not work correctly due to https://github.com/ziglang/zig/issues/16354
8271
//
8372
// We are working here with kind of a weird dependency though. So we can do this
@@ -100,51 +89,73 @@ pub fn build(b: *Builder) !void {
10089
const run_step = b.step("run", "Run the app");
10190
run_step.dependOn(&run_cmd.step);
10291

103-
const gen_step = blk: {
104-
const cg = b.step("gen", "Generate zig service code from smithy models");
92+
const cg = b.step("gen", "Generate zig service code from smithy models");
10593

106-
const cg_exe = b.addExecutable(.{
107-
.name = "codegen",
108-
.root_source_file = b.path("codegen/src/main.zig"),
109-
// We need this generated for the host, not the real target
110-
.target = b.graph.host,
111-
.optimize = if (b.verbose) .Debug else .ReleaseSafe,
112-
});
113-
cg_exe.use_llvm = !no_llvm;
114-
cg_exe.root_module.addImport("smithy", smithy_dep.module("smithy"));
115-
var cg_cmd = b.addRunArtifact(cg_exe);
116-
cg_cmd.addArg("--models");
117-
cg_cmd.addArg(try std.fs.path.join(
94+
const cg_exe = b.addExecutable(.{
95+
.name = "codegen",
96+
.root_source_file = b.path("codegen/src/main.zig"),
97+
// We need this generated for the host, not the real target
98+
.target = b.graph.host,
99+
.optimize = if (b.verbose) .Debug else .ReleaseSafe,
100+
});
101+
cg_exe.root_module.addImport("smithy", smithy_module);
102+
var cg_cmd = b.addRunArtifact(cg_exe);
103+
cg_cmd.addArg("--models");
104+
cg_cmd.addArg(try std.fs.path.join(
118105
b.allocator,
119106
&[_][]const u8{
120107
try b.dependency("models", .{}).path("").getPath3(b, null).toString(b.allocator),
121108
models_subdir,
122109
},
123110
));
124-
cg_cmd.addArg("--output");
125-
cg_cmd.addDirectoryArg(b.path("src/models"));
126-
if (b.verbose)
127-
cg_cmd.addArg("--verbose");
128-
// cg_cmd.step.dependOn(&fetch_step.step);
129-
// TODO: this should use zig_exe from std.Build
130-
// codegen should store a hash in a comment
131-
// this would be hash of the exe that created the file
132-
// concatenated with hash of input json. this would
133-
// allow skipping generated files. May not include hash
134-
// of contents of output file as maybe we want to tweak
135-
// manually??
136-
//
137-
// All the hashes can be in service_manifest.zig, which
138-
// could be fun to just parse and go nuts. Top of
139-
// file, generator exe hash. Each import has comment
140-
// with both input and output hash and we can decide
141-
// later about warning on manual changes...
142-
143-
cg.dependOn(&cg_cmd.step);
144-
break :blk cg;
145-
};
146-
147-
exe.step.dependOn(gen_step);
111+
cg_cmd.addArg("--output");
112+
const cg_output_dir = cg_cmd.addOutputDirectoryArg("src/models");
113+
if (b.verbose)
114+
cg_cmd.addArg("--verbose");
115+
// cg_cmd.step.dependOn(&fetch_step.step);
116+
// TODO: this should use zig_exe from std.Build
117+
// codegen should store a hash in a comment
118+
// this would be hash of the exe that created the file
119+
// concatenated with hash of input json. this would
120+
// allow skipping generated files. May not include hash
121+
// of contents of output file as maybe we want to tweak
122+
// manually??
123+
//
124+
// All the hashes can be in service_manifest.zig, which
125+
// could be fun to just parse and go nuts. Top of
126+
// file, generator exe hash. Each import has comment
127+
// with both input and output hash and we can decide
128+
// later about warning on manual changes...
129+
130+
cg.dependOn(&cg_cmd.step);
131+
132+
exe.step.dependOn(cg);
133+
134+
// This allows us to have each module depend on the
135+
// generated service manifest.
136+
const service_manifest_module = b.createModule(.{
137+
.root_source_file = cg_output_dir.path(b, "service_manifest.zig"),
138+
.target = target,
139+
.optimize = optimize,
140+
});
141+
service_manifest_module.addImport("smithy", smithy_module);
142+
143+
exe.root_module.addImport("service_manifest", service_manifest_module);
144+
145+
// Expose module to others
146+
_ = b.addModule("aws", .{
147+
.root_source_file = b.path("src/aws.zig"),
148+
.imports = &.{
149+
.{ .name = "smithy", .module = smithy_module },
150+
.{ .name = "service_manifest", .module = service_manifest_module },
151+
},
152+
});
153+
154+
// Expose module to others
155+
_ = b.addModule("aws-signing", .{
156+
.root_source_file = b.path("src/aws_signing.zig"),
157+
.imports = &.{.{ .name = "smithy", .module = smithy_module }},
158+
});
148159

149160
// Similar to creating the run step earlier, this exposes a `test` step to
150161
// the `zig build --help` menu, providing a way for the user to request
@@ -174,8 +185,9 @@ pub fn build(b: *Builder) !void {
174185
.target = b.resolveTargetQuery(t),
175186
.optimize = optimize,
176187
});
177-
unit_tests.root_module.addImport("smithy", smithy_dep.module("smithy"));
178-
unit_tests.step.dependOn(gen_step);
188+
unit_tests.root_module.addImport("smithy", smithy_module);
189+
unit_tests.root_module.addImport("service_manifest", service_manifest_module);
190+
unit_tests.step.dependOn(cg);
179191
unit_tests.use_llvm = !no_llvm;
180192

181193
const run_unit_tests = b.addRunArtifact(unit_tests);
@@ -199,8 +211,9 @@ pub fn build(b: *Builder) !void {
199211
.optimize = optimize,
200212
});
201213
smoke_test.use_llvm = !no_llvm;
202-
smoke_test.root_module.addImport("smithy", smithy_dep.module("smithy"));
203-
smoke_test.step.dependOn(gen_step);
214+
smoke_test.root_module.addImport("smithy", smithy_module);
215+
smoke_test.root_module.addImport("service_manifest", service_manifest_module);
216+
smoke_test.step.dependOn(cg);
204217

205218
const run_smoke_test = b.addRunArtifact(smoke_test);
206219

build.zig.zon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"build.zig",
77
"build.zig.zon",
88
"src",
9+
"codegen",
910
"README.md",
1011
"LICENSE",
1112
},

src/servicemodel.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const std = @import("std");
2-
const service_list = @import("models/service_manifest.zig");
2+
const service_list = @import("service_manifest");
33
const expectEqualStrings = std.testing.expectEqualStrings;
44

55
pub fn Services(comptime service_imports: anytype) type {

0 commit comments

Comments
 (0)