From bbad849f074103e1b806f1b80c324d66956b55ab Mon Sep 17 00:00:00 2001 From: Antoine Date: Sat, 28 Sep 2024 15:29:09 +0200 Subject: [PATCH 1/2] Merge all 3 libraries in one --- README.md | 4 --- build.zig | 81 +++++++++++++++++++++++-------------------------------- 2 files changed, 33 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index def475b..0f5e3b3 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,7 @@ Then, in your `build.zig`: ```zig const postgres = b.dependency("libpq", { .target = target, .optimize = optimize }); const libpq = postgres.artifact("pq"); -const libpgcommon = postgres.artifact("pgcommon"); -const libpgport = postgres.artifact("pgport"); // wherever needed: exe.linkLibrary(libpq); -exe.linkLibrary(libpgcommon); -exe.linkLibrary(libpgport); ``` diff --git a/build.zig b/build.zig index f661749..2b94fd4 100644 --- a/build.zig +++ b/build.zig @@ -37,53 +37,45 @@ pub fn build(b: *std.Build) !void { default_paths, ); - const libpq = b.addStaticLibrary(.{ .name = "pq", .target = target, .optimize = optimize }); - const libport = b.addStaticLibrary(.{ .name = "pgport", .target = target, .optimize = optimize }); - const common = b.addStaticLibrary(.{ .name = "pgcommon", .target = target, .optimize = optimize }); + const lib = b.addStaticLibrary(.{ .name = "pq", .target = target, .optimize = optimize }); - libpq.addCSourceFiles(.{ + lib.addCSourceFiles(.{ .root = upstream.path(libpq_path), .files = &libpq_sources, .flags = &CFLAGS, }); - libport.addCSourceFiles(.{ + lib.addCSourceFiles(.{ .root = upstream.path("src/port"), .files = &libport_sources, .flags = &CFLAGS, }); - common.addCSourceFiles(.{ + lib.addCSourceFiles(.{ .root = upstream.path("src/common"), .files = &common_sources, .flags = &CFLAGS, }); const config_headers = [_]*std.Build.Step.ConfigHeader{ config_ext, pg_config, config_os }; - const libs = [_]*std.Build.Step.Compile{ libpq, libport, common }; - - for (libs) |lib| { - lib.addIncludePath(upstream.path("src/include")); - lib.addIncludePath(b.path("include")); - lib.addConfigHeader(config_path); - lib.root_module.addCMacro("_GNU_SOURCE", "1"); - lib.root_module.addCMacro("FRONTEND", "1"); - lib.linkLibC(); - b.installArtifact(lib); - } + + lib.addIncludePath(upstream.path("src/include")); + lib.addIncludePath(b.path("include")); + lib.addConfigHeader(config_path); + lib.root_module.addCMacro("_GNU_SOURCE", "1"); + lib.root_module.addCMacro("FRONTEND", "1"); + lib.linkLibC(); + b.installArtifact(lib); + for (config_headers) |header| { - for (libs) |lib| { - lib.addConfigHeader(header); - } - common.installConfigHeader(header); + lib.addConfigHeader(header); + lib.installConfigHeader(header); } if (!disable_ssl) { if (b.lazyDependency("openssl", .{ .target = target, .optimize = optimize })) |openssl_dep| { const openssl = openssl_dep.artifact("openssl"); - for (libs) |lib| { - lib.linkLibrary(openssl); - } + lib.linkLibrary(openssl); } - libpq.addCSourceFiles(.{ + lib.addCSourceFiles(.{ .root = upstream.path(libpq_path), .files = &.{ "fe-secure-common.c", @@ -91,7 +83,7 @@ pub fn build(b: *std.Build) !void { }, .flags = &CFLAGS, }); - common.addCSourceFiles(.{ + lib.addCSourceFiles(.{ .root = upstream.path("src/common"), .files = &.{ "cryptohash_openssl.c", @@ -101,7 +93,7 @@ pub fn build(b: *std.Build) !void { .flags = &CFLAGS, }); } else { - common.addCSourceFiles(.{ + lib.addCSourceFiles(.{ .root = upstream.path("src/common"), .files = &.{ "cryptohash.c", @@ -132,10 +124,7 @@ pub fn build(b: *std.Build) !void { if (!disable_zlib) { if (b.lazyDependency("zlib", .{ .target = target, .optimize = optimize })) |zlib_dep| { - const zlib = zlib_dep.artifact("z"); - for (libs) |lib| { - lib.linkLibrary(zlib); - } + lib.linkLibrary(zlib_dep.artifact("z")); } } const use_z: ?u8 = if (disable_zlib) null else 1; @@ -143,10 +132,7 @@ pub fn build(b: *std.Build) !void { if (!disable_zstd) { if (b.lazyDependency("zstd", .{ .target = target, .optimize = optimize })) |zstd_dep| { - const zstd = zstd_dep.artifact("zstd"); - for (libs) |lib| { - lib.linkLibrary(zstd); - } + lib.linkLibrary(zstd_dep.artifact("zstd")); } } const use_zstd: ?u8 = if (disable_zstd) null else 1; @@ -157,7 +143,7 @@ pub fn build(b: *std.Build) !void { const have_strlcat: bool = target.result.os.tag == .macos; // or linux with glibc >= 2.38, how can I test that ? if (!have_strlcat) { - libport.addCSourceFiles(.{ + lib.addCSourceFiles(.{ .root = upstream.path("src/port"), .files = &.{ "strlcat.c", @@ -201,14 +187,14 @@ pub fn build(b: *std.Build) !void { .HAVE_MEMSET_S = 1, .HAVE_SYS_UCRED_H = 1, }); - libport.addCSourceFile(.{ + lib.addCSourceFile(.{ .file = upstream.path("src/port/explicit_bzero.c"), .flags = &CFLAGS, }); } else return error.ConfigUnknown; // Export public headers - libpq.installHeadersDirectory( + lib.installHeadersDirectory( upstream.path(libpq_path), "", .{ .include_extensions = &.{ @@ -216,7 +202,7 @@ pub fn build(b: *std.Build) !void { "libpq-events.h", } }, ); - libpq.installHeadersDirectory( + lib.installHeadersDirectory( upstream.path(libpq_path), "postgresql/internal", .{ .include_extensions = &.{ @@ -225,13 +211,13 @@ pub fn build(b: *std.Build) !void { "pqexpbuffer.h", } }, ); - libpq.installHeader(upstream.path("src/include/libpq/libpq-fs.h"), "libpq/libpq-fs.h"); - libpq.installHeader(upstream.path("src/include/libpq/pqcomm.h"), "postgresql/internal/libpq/pqcomm.h"); - common.installHeader(upstream.path("src/include/pg_config_manual.h"), "pg_config_manual.h"); - common.installHeader(upstream.path("src/include/postgres_ext.h"), "postgres_ext.h"); - common.installHeader(upstream.path("src/include/postgres_fe.h"), "postgresql/internal/postgres_fe.h"); - libport.installHeader(upstream.path("src/include/c.h"), "postgresql/internal/c.h"); - libport.installHeader(upstream.path("src/include/port.h"), "postgresql/internal/port.h"); + lib.installHeader(upstream.path("src/include/libpq/libpq-fs.h"), "libpq/libpq-fs.h"); + lib.installHeader(upstream.path("src/include/libpq/pqcomm.h"), "postgresql/internal/libpq/pqcomm.h"); + lib.installHeader(upstream.path("src/include/pg_config_manual.h"), "pg_config_manual.h"); + lib.installHeader(upstream.path("src/include/postgres_ext.h"), "postgres_ext.h"); + lib.installHeader(upstream.path("src/include/postgres_fe.h"), "postgresql/internal/postgres_fe.h"); + lib.installHeader(upstream.path("src/include/c.h"), "postgresql/internal/c.h"); + lib.installHeader(upstream.path("src/include/port.h"), "postgresql/internal/port.h"); // Build executables to ensure no symbols are left undefined const test_step = b.step("examples", "Build example programs"); @@ -251,8 +237,7 @@ pub fn build(b: *std.Build) !void { const tests = [_]*std.Build.Step.Compile{ test1, test2, test3, test4, test5 }; for (tests) |t| { t.linkLibC(); - for (libs) |lib| - t.linkLibrary(lib); + t.linkLibrary(lib); const install_test = b.addInstallArtifact(t, .{}); test_step.dependOn(&install_test.step); } From 2de7eec6d885830ec36c00016f432a9e2d0967bf Mon Sep 17 00:00:00 2001 From: Antoine Date: Sat, 28 Sep 2024 15:35:30 +0200 Subject: [PATCH 2/2] Run CI on intel macos --- .github/workflows/ci.yml | 7 +++++-- README.md | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ae698e..0933d8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,9 +21,12 @@ jobs: - zig-version: "master" os: ubuntu-latest build-options: "" + #- zig-version: "master" + # os: macos-latest # Apple Silicon (M1) + # build-options: "-Ddisable-ssl" - zig-version: "master" - os: macos-latest - build-options: "-Ddisable-ssl -Ddisable-zstd" + os: macos-13 # Intel macOS + build-options: "-Ddisable-ssl" runs-on: ${{ matrix.os }} diff --git a/README.md b/README.md index 0f5e3b3..3398eed 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ Provides a package to be used by the zig package manager for C programs. | Architecture \ OS | Linux | MacOS | |:------------------|:------|-------------------| -| x86_64 | ✅ | ? | -| arm 64 | ❌ | ☑️ `-Ddisable-ssl` | +| x86_64 | ✅ | ☑️ `-Ddisable-ssl` | +| arm 64 | __?__ | ☑️ `-Ddisable-ssl` | Optional dependencies used by default: - openssl