@@ -6,14 +6,16 @@ const BinaryTarget = struct {
66 arch : []const u8 ,
77};
88
9- pub fn build (b : * std.build.Builder ) void {
9+ pub fn build (b : * std.Build ) void {
1010 // Standard release options allow the person running `zig build` to select
1111 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
1212 const optimize = b .standardOptimizeOption (.{});
1313
14- var version = if (std .os .getenv ("VERSION" )) | v | v else "unknown" ;
14+ var env = std .process .getEnvMap (b .allocator ) catch unreachable ;
15+ defer env .deinit ();
16+ const version = env .get ("VERSION" ) orelse "unknown" ;
1517
16- var targets = [_ ]BinaryTarget {
18+ const targets = [_ ]BinaryTarget {
1719 // for now, let's only build aarch64 binaries
1820 // .{ .name = b.fmt("protoc-gen-grpc-web-{s}-linux-x86_64", .{version}), .arch = "x86_64-linux" },
1921 // .{ .name = b.fmt("protoc-gen-grpc-web-{s}-darwin-x86_64", .{version}), .arch = "x86_64-macos" },
@@ -30,9 +32,12 @@ pub fn build(b: *std.build.Builder) void {
3032 const protobuf_src_dir = std .fs .path .join (b .allocator , &.{ protobuf_dir , "src" }) catch unreachable ;
3133
3234 for (targets ) | target | {
35+ const resolved_target = b .resolveTargetQuery (CrossTarget .parse (.{ .arch_os_abi = target .arch }) catch unreachable );
3336 const exe = b .addExecutable (.{
3437 .name = target .name ,
3538 .root_source_file = .{ .path = "grpc_generator.cc" },
39+ .target = resolved_target ,
40+ .optimize = optimize ,
3641 });
3742 exe .linkLibCpp ();
3843 exe .linkSystemLibrary ("pthread" );
@@ -212,12 +217,11 @@ pub fn build(b: *std.build.Builder) void {
212217 "src/google/protobuf/compiler/subprocess.cc" ,
213218 "src/google/protobuf/compiler/zip_writer.cc" ,
214219 },
215- .relative_to = protobuf_dir ,
220+ .root = .{ . path = protobuf_dir } ,
216221 });
217222
218- exe .setTarget (CrossTarget .parse (.{ .arch_os_abi = target .arch }) catch unreachable );
219- exe .setOptimize (optimize );
220- exe .strip = true ;
223+ // Target and optimize configured at creation time above.
224+ // Install the built artifact (Zig 0.12 API).
221225 b .installArtifact (exe );
222226 }
223- }
227+ }
0 commit comments