Skip to content

Commit c014239

Browse files
jvmvikCopilot
andcommitted
Single-source the version from build.zig.zon
The version was declared twice: build.zig.zon, which `rake release` tags from, and src/client.zig, which the `source` telemetry parameter reports to serpapi.com. build.zig now imports the manifest and forwards `.version` through a `build_options` module, so there is one place to bump. A unit test checks the value parses as a semantic version. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9c2a970 commit c014239

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
agents, via the `output=md` format
88
- `serpapi.Error` is exported from the module root
99
(`serpapi.Error.SerpApiError`, previously only `serpapi.client.Error`)
10+
- `serpapi.version` is derived from `build.zig.zon` at build time instead
11+
of being duplicated in `src/client.zig`, so the tag cut by `rake release`
12+
and the version reported to serpapi.com cannot drift apart
1013
- Fix: the `timeout` option is enforced. It was accepted and documented
1114
but never applied, so a stalled connection blocked forever. Each request
1215
now races a timer on the client's `std.Io.Threaded` pool and is canceled

‎README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ zig fetch --save 'https://github.com/serpapi/serpapi-zig/archive/refs/tags/v1.1.
8585

8686
Released versions are listed on the
8787
[releases page](https://github.com/serpapi/serpapi-zig/releases); changes
88-
are recorded in [CHANGELOG.md](CHANGELOG.md).
88+
are recorded in [CHANGELOG.md](CHANGELOG.md). The version number lives in
89+
one place, `build.zig.zon`: `build.zig` forwards it to the library as
90+
`serpapi.version`, which is what the client reports to serpapi.com, and
91+
`rake release` reads it to name the tag.
8992

9093
## Simple Usage
9194

‎build.zig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const std = @import("std");
2+
const manifest = @import("build.zig.zon");
23

34
pub fn build(b: *std.Build) void {
45
const target = b.standardTargetOptions(.{});
@@ -11,6 +12,12 @@ pub fn build(b: *std.Build) void {
1112
.optimize = optimize,
1213
});
1314

15+
// The library version reported to serpapi.com comes straight from the
16+
// package manifest, so `rake release` and the `source` parameter agree.
17+
const build_options = b.addOptions();
18+
build_options.addOption([]const u8, "version", manifest.version);
19+
mod.addOptions("build_options", build_options);
20+
1421
// Unit tests: zig build test
1522
// the name also disambiguates kcov's per-binary report directories
1623
const mod_tests = b.addTest(.{ .name = "unit-tests", .root_module = mod });

‎src/client.zig‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const std = @import("std");
1111
const Allocator = std.mem.Allocator;
1212

1313
/// Library version, reported to the backend through the `source` parameter.
14-
pub const version = "1.1.0";
14+
/// Single-sourced from `build.zig.zon` via `build.zig`.
15+
pub const version: []const u8 = @import("build_options").version;
1516

1617
/// Backend service host.
1718
pub const backend = "serpapi.com";
@@ -574,6 +575,11 @@ pub const Client = struct {
574575

575576
const testing = std.testing;
576577

578+
test "version is the semantic version from build.zig.zon" {
579+
const parsed = try std.SemanticVersion.parse(version);
580+
try testing.expect(parsed.major >= 1);
581+
}
582+
577583
test "constructor defaults" {
578584
var client = try Client.init(testing.allocator, .{});
579585
defer client.deinit();

0 commit comments

Comments
 (0)