@@ -34,12 +34,12 @@ pub fn build(b: *Builder) !void {
3434 "no-llvm" ,
3535 "Disable LLVM" ,
3636 ) orelse false ;
37-
3837 const broken_windows = b .option (
3938 bool ,
4039 "broken-windows" ,
4140 "Windows is broken in this environment (do not run Windows tests)" ,
4241 ) orelse false ;
42+ const no_bin = b .option (bool , "no-bin" , "skip emitting binary" ) orelse false ;
4343 // TODO: Embed the current git version in the code. We can do this
4444 // by looking for .git/HEAD (if it exists, follow the ref to /ref/heads/whatevs,
4545 // grab that commit, and use b.addOptions/exe.addOptions to generate the
@@ -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 (
118- b .allocator ,
119- &[_ ][]const u8 {
120- try b .dependency ("models" , .{}).path ("" ).getPath3 (b , null ).toString (b .allocator ),
121- models_subdir ,
122- },
123- ));
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 );
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 (
105+ b .allocator ,
106+ &[_ ][]const u8 {
107+ try b .dependency ("models" , .{}).path ("" ).getPath3 (b , null ).toString (b .allocator ),
108+ models_subdir ,
109+ },
110+ ));
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,11 +211,16 @@ 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
207220 smoke_test_step .dependOn (& run_smoke_test .step );
208- b .installArtifact (exe );
221+ if (no_bin ) {
222+ b .getInstallStep ().dependOn (& exe .step );
223+ } else {
224+ b .installArtifact (exe );
225+ }
209226}
0 commit comments