Skip to content

Commit d6a3f15

Browse files
committed
fix(build): update Zig version to 0.12.0 and improve build command syntax
1 parent 59408e9 commit d6a3f15

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

.github/workflows/make-plugin-arm.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,19 @@ jobs:
3535
- name: Setup Zig
3636
run: |
3737
mkdir -p $HOME/.local/bin $HOME/.local/zig
38-
curl 'https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz' | tar xJ --strip-components=1 --directory=$HOME/.local/zig
39-
ln -s $HOME/.local/zig/zig $HOME/.local/bin/zig
38+
curl -L 'https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz' | tar xJ --strip-components=1 --directory=$HOME/.local/zig
39+
ln -sf $HOME/.local/zig/zig $HOME/.local/bin/zig
4040
echo "PATH=$PATH:$HOME/.local/bin" >> $GITHUB_ENV
4141
- name: Build plugin
42-
env:
43-
VERSION: ${{ env.VERSION_NUMBER }}
4442
run: |
4543
cd javascript/net/grpc/web/generator
46-
zig build --release-fast
44+
VERSION="$VERSION_NUMBER" zig build -Doptimize=ReleaseFast
4745
- name: gen and verify sha256
4846
run: |
4947
cd javascript/net/grpc/web/generator/zig-out/bin
50-
for exe in $(ls)
51-
do
52-
openssl dgst -sha256 -r -out $exe'.sha256' $exe
53-
sha256sum -c $exe'.sha256'
48+
for exe in $(ls); do
49+
openssl dgst -sha256 -r -out "${exe}.sha256" "$exe"
50+
sha256sum -c "${exe}.sha256"
5451
done
5552
- name: Upload artifacts
5653
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ target
1313
.settings
1414
zig-out
1515
zig-cache
16+
.zig-cache

javascript/net/grpc/web/generator/build.zig

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)