Skip to content

Commit e672758

Browse files
committed
Methods relative to compilation are applied to the module
Update for Zig 0.16, the following methods now apply to the module instead of the compile step: - addCSourceFiles - addIncludePath - linkLibrary
1 parent 6b76652 commit e672758

File tree

4 files changed

+48
-56
lines changed

4 files changed

+48
-56
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,12 @@ jobs:
1818
os: [ubuntu-latest]
1919
build-options: ["-Dssl=None -Ddisable-zlib -Ddisable-zstd", "-Dssl=OpenSSL", "-Dssl=LibreSSL"]
2020
include:
21-
# Test for users that want stability and use older kernel, glibc and zig versions
22-
- zig-version: "0.14.1"
23-
os: ubuntu-22.04 # GLIBC 2.35
24-
build-options: "-Dssl=LibreSSL"
25-
- zig-version: "0.15.2"
26-
os: ubuntu-latest
27-
build-options: "-Dssl=None"
2821
- zig-version: "master"
2922
os: macos-latest # Apple Silicon
3023
build-options: "-Dssl=LibreSSL"
31-
- zig-version: "master"
32-
os: macos-latest-intel
33-
build-options: "-Dssl=LibreSSL"
24+
# - zig-version: "master"
25+
# os: macos-latest-intel
26+
# build-options: "-Dssl=LibreSSL"
3427

3528
runs-on: ${{ matrix.os }}
3629

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ Provides a package to be used by the zig package manager for C programs.
1111

1212
| Refname | PostgreSQL version | Zig `0.16.x` | Zig `0.15.x` | Zig `0.14.x` | Zig `0.13.x` |
1313
|------------|--------------------|--------------|--------------|--------------|--------------|
14-
| `5.18.1` | `REL_18_1` || | ||
15-
| `5.16.4+5` | `REL_16_4` | ||||
16-
| `5.16.4+3` | `REL_16_4` || |||
14+
| `master` | `REL_18_1` || | ||
15+
| `5.18.1+1` | `REL_18_1` | ||||
16+
| `5.16.4+5` | `REL_16_4` || |||
1717
| `5.16.4+2` | `REL_16_4` |||||
1818

19-
2019
## Use
2120

22-
Add the dependency in your `build.zig.zon` by running the following command:
21+
Add the dependency to your `build.zig.zon` by running the following command:
2322
```zig
2423
zig fetch --save git+https://github.com/allyourcodebase/libpq#master
2524
```

build.zig

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,41 +34,41 @@ pub fn build(b: *std.Build) !void {
3434
.{ .style = .blank, .include_path = "pg_config_paths.h" },
3535
default_paths,
3636
);
37-
38-
const lib = b.addLibrary(.{
39-
.name = "pq",
40-
.root_module = b.createModule(.{ .target = target, .optimize = optimize }),
37+
const mod = b.createModule(.{
38+
.target = target,
39+
.optimize = optimize,
40+
.link_libc = true,
4141
});
42+
const lib = b.addLibrary(.{ .name = "pq", .root_module = mod });
4243

43-
lib.addCSourceFiles(.{
44+
mod.addCSourceFiles(.{
4445
.root = upstream.path(libpq_path),
4546
.files = &libpq_sources,
4647
.flags = &CFLAGS,
4748
});
48-
lib.addCSourceFiles(.{
49+
mod.addCSourceFiles(.{
4950
.root = upstream.path("src/port"),
5051
.files = &libport_sources,
5152
.flags = &CFLAGS,
5253
});
53-
lib.addCSourceFiles(.{
54+
mod.addCSourceFiles(.{
5455
.root = upstream.path("src/common"),
5556
.files = &common_sources,
5657
.flags = &CFLAGS,
5758
});
5859

5960
const config_headers = [_]*std.Build.Step.ConfigHeader{ pg_config, config_os };
6061

61-
lib.addIncludePath(upstream.path("src/include"));
62-
lib.addIncludePath(b.path("include"));
63-
lib.addIncludePath(upstream.path(libpq_path));
64-
lib.addConfigHeader(config_path);
65-
lib.root_module.addCMacro("FRONTEND", "1");
66-
lib.root_module.addCMacro("JSONAPI_USE_PQEXPBUFFER", "1");
67-
lib.linkLibC();
62+
mod.addIncludePath(upstream.path("src/include"));
63+
mod.addIncludePath(b.path("include"));
64+
mod.addIncludePath(upstream.path(libpq_path));
65+
mod.addConfigHeader(config_path);
66+
mod.addCMacro("FRONTEND", "1");
67+
mod.addCMacro("JSONAPI_USE_PQEXPBUFFER", "1");
6868
b.installArtifact(lib);
6969

7070
for (config_headers) |header| {
71-
lib.addConfigHeader(header);
71+
mod.addConfigHeader(header);
7272
lib.installConfigHeader(header);
7373
}
7474

@@ -81,14 +81,14 @@ pub fn build(b: *std.Build) !void {
8181
use_openssl = 1;
8282
if (b.lazyDependency("openssl", .{ .target = target, .optimize = optimize })) |openssl_dep| {
8383
const openssl = openssl_dep.artifact("openssl");
84-
lib.linkLibrary(openssl);
84+
mod.linkLibrary(openssl);
8585
}
8686
},
8787
.LibreSSL => {
8888
use_ssl = 1;
8989
if (b.lazyDependency("libressl", .{ .target = target, .optimize = optimize })) |libressl_dep| {
9090
const libressl = libressl_dep.artifact("ssl");
91-
lib.linkLibrary(libressl);
91+
mod.linkLibrary(libressl);
9292
}
9393
},
9494
.None => {},
@@ -105,15 +105,15 @@ pub fn build(b: *std.Build) !void {
105105
});
106106

107107
if (ssl_option != .None) {
108-
lib.addCSourceFiles(.{
108+
mod.addCSourceFiles(.{
109109
.root = upstream.path(libpq_path),
110110
.files = &.{
111111
"fe-secure-common.c",
112112
"fe-secure-openssl.c",
113113
},
114114
.flags = &CFLAGS,
115115
});
116-
lib.addCSourceFiles(.{
116+
mod.addCSourceFiles(.{
117117
.root = upstream.path("src/common"),
118118
.files = &.{
119119
"cryptohash_openssl.c",
@@ -122,7 +122,7 @@ pub fn build(b: *std.Build) !void {
122122
.flags = &CFLAGS,
123123
});
124124
} else {
125-
lib.addCSourceFiles(.{
125+
mod.addCSourceFiles(.{
126126
.root = upstream.path("src/common"),
127127
.files = &.{
128128
"cryptohash.c",
@@ -137,15 +137,15 @@ pub fn build(b: *std.Build) !void {
137137

138138
if (!disable_zlib) {
139139
if (b.lazyDependency("zlib", .{ .target = target, .optimize = optimize })) |zlib_dep| {
140-
lib.linkLibrary(zlib_dep.artifact("z"));
140+
mod.linkLibrary(zlib_dep.artifact("z"));
141141
}
142142
}
143143
const use_z: ?u8 = if (disable_zlib) null else 1;
144144
pg_config.addValues(.{ .HAVE_LIBZ = use_z });
145145

146146
if (!disable_zstd) {
147147
if (b.lazyDependency("zstd", .{ .target = target, .optimize = optimize })) |zstd_dep| {
148-
lib.linkLibrary(zstd_dep.artifact("zstd"));
148+
mod.linkLibrary(zstd_dep.artifact("zstd"));
149149
}
150150
}
151151
const use_zstd: ?u8 = if (disable_zstd) null else 1;
@@ -156,7 +156,7 @@ pub fn build(b: *std.Build) !void {
156156

157157
const have_strlcat: bool = target.result.os.tag == .macos or (target.result.os.tag == .linux and target.result.os.versionRange().gnuLibCVersion().?.order(.{ .major = 2, .minor = 38, .patch = 0 }) == .gt);
158158
if (!have_strlcat) {
159-
lib.addCSourceFiles(.{
159+
mod.addCSourceFiles(.{
160160
.root = upstream.path("src/port"),
161161
.files = &.{
162162
"strlcat.c",
@@ -183,7 +183,7 @@ pub fn build(b: *std.Build) !void {
183183
const is_gnu: ?u8 = if (target.result.isGnuLibC()) 1 else null;
184184
const not_gnu: ?u8 = if (is_gnu == null) 1 else null;
185185
// While building with musl, defining _GNU_SOURCE makes musl declare extra things (e.g. struct ucred)
186-
lib.root_module.addCMacro("_GNU_SOURCE", "1");
186+
mod.addCMacro("_GNU_SOURCE", "1");
187187

188188
pg_config.addValues(.{
189189
.HAVE_SYNC_FILE_RANGE = is_gnu,
@@ -215,7 +215,7 @@ pub fn build(b: *std.Build) !void {
215215
.HAVE_SYNCFS = null,
216216
.HAVE_XLOCALE_H = 1,
217217
});
218-
lib.addCSourceFile(.{
218+
mod.addCSourceFile(.{
219219
.file = upstream.path("src/port/explicit_bzero.c"),
220220
.flags = &CFLAGS,
221221
});
@@ -284,17 +284,17 @@ pub fn build(b: *std.Build) !void {
284284
const test5 = b.addExecutable(.{ .name = "testlo", .root_module = b.createModule(.{ .target = target, .optimize = optimize }) });
285285
const test6 = b.addExecutable(.{ .name = "testlo64", .root_module = b.createModule(.{ .target = target, .optimize = optimize }) });
286286

287-
test1.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlibpq.c"} });
288-
test2.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlibpq2.c"} });
289-
test3.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlibpq3.c"} });
290-
test4.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlibpq4.c"} });
291-
test5.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlo.c"} });
292-
test6.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlo64.c"} });
287+
test1.root_module.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlibpq.c"} });
288+
test2.root_module.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlibpq2.c"} });
289+
test3.root_module.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlibpq3.c"} });
290+
test4.root_module.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlibpq4.c"} });
291+
test5.root_module.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlo.c"} });
292+
test6.root_module.addCSourceFiles(.{ .root = upstream.path("src/test/examples"), .files = &.{"testlo64.c"} });
293293

294294
const tests = [_]*std.Build.Step.Compile{ test1, test2, test3, test4, test5, test6 };
295295
for (tests) |t| {
296-
t.linkLibC();
297-
t.linkLibrary(lib);
296+
t.root_module.link_libc = true;
297+
t.root_module.linkLibrary(lib);
298298
const install_test = b.addInstallArtifact(t, .{});
299299
test_step.dependOn(&install_test.step);
300300
}

build.zig.zon

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
.hash = "N-V-__8AAFtMXAi66ac6zMPeIBt5tVnTQSyckKgjCq_nZvZo",
1010
},
1111
.openssl = .{
12-
.url = "git+https://github.com/allyourcodebase/openssl?ref=main#7d4b2590b3b05fbc0e5cc20e2704a968e63503b1",
13-
.hash = "openssl-3.3.2-TC9C3Vy3ZABkts70T3a6QfLYghNUy0tI42ksiW7jRmvd",
12+
.url = "git+https://github.com/allyourcodebase/openssl?ref=main#0ac677650d43eadf669067d050992118b13338d2",
13+
.hash = "openssl-3.3.2-TC9C3Ze3ZABaKR5hc8KRnRPhTClKrKQKqTnXTUYkvmSR",
1414
.lazy = true,
1515
},
1616
.libressl = .{
17-
.url = "git+https://github.com/allyourcodebase/libressl?ref=master#43595de12da7fe58e4209560558bddfb0f195d0e",
18-
.hash = "libressl-4.0.0--kqV4OjTAADhw9rD-tZaxFy2KPrSU4Bt9FOi9UZe-Zjl",
17+
.url = "git+https://github.com/allyourcodebase/libressl?ref=zig-0.16#e8f79856c79117d3f90fb9466f07fe40326dc5ea",
18+
.hash = "libressl-4.0.0--kqV4CnYAACipI0uyGhRMjpZU1JlcIrtPslSCMO0nLsj",
1919
.lazy = true,
2020
},
2121
.zlib = .{
22-
.url = "git+https://github.com/allyourcodebase/zlib?ref=main#c2585c096171b8fbc8e5f78ab6c91b39e3573e15",
23-
.hash = "zlib-1.3.1-ZZQ7lcMNAABPzkWdm_9y0tjlN17kF7czIiTVQ7h10rMR",
22+
.url = "git+https://github.com/allyourcodebase/zlib?ref=main#3599c16d41dbe749ae51b0ff7ab864c61adc779a",
23+
.hash = "zlib-1.3.1-ZZQ7lc8NAABUbHzDe_cSWboCqMbrLkVwvFkKnojgeiT2",
2424
.lazy = true,
2525
},
2626
.zstd = .{
27-
.url = "git+https://github.com/allyourcodebase/zstd?ref=master#01327d49cbc56dc24c20a167bb0055d7fc23de84",
28-
.hash = "zstd-1.5.7-KEItkJ8vAAC5_rRlKmLflYQ-eKXbAIQBWZNmmJtS18q0",
27+
.url = "git+https://github.com/allyourcodebase/zstd?ref=1.5.7-1#e1a501be57f42c541e8a5597e4b59a074dfd09a3",
28+
.hash = "zstd-1.5.7-1-KEItkAMwAAD6OKY3m0OOmXG7aL-aLUfrDqbP5J5oYapU",
2929
.lazy = true,
3030
},
3131
},

0 commit comments

Comments
 (0)