Update Zig toolchain#105
Conversation
|
Hi, thank you for giving this a try. The removal of usingnamespace is quite unfortunate and we essentially end up with The project also uses nix to provide a stable development environment. See |
|
@urso thanks for your feedback, I will try it out. |
urso
left a comment
There was a problem hiding this comment.
Nice. The move to TranslateC is a great improvement. There are still a few things we can improve on, though. I still wonder if we can reduce the amount of breaking code.
| // Export common set of postgres headers. | ||
| pub const c = @import("pgzx_pgsys"); // keep for backwards compatibility | ||
| pub const pg = c; | ||
| pub const pg = @import("pgzx_pgsys"); |
There was a problem hiding this comment.
I was wondering if it is possible to use pg = @import("c_translated") here. the pgzx_pgsys module basically was c.zig that is now replaced by headers.h. The goal of pgzx_pgsys was to have a base-module just doing the C header translation.
|
The Zig changes look good, but something seems to be wrong with the nix setup :( Will take me some time to figure this out, unless you want to give that a go as well. |
| }; | ||
| zls = { | ||
| url = "github:zigtools/zls"; | ||
| url = "github:zigtools/zls/0.15.0"; |
There was a problem hiding this comment.
Oh, I see. ZLS normally follow the development version. This bit me as well a few times in the past. Normally I'm updating the dependency like so:
nix flake update zls --override-input github:zigtools/zls/0.15.0
With ZLS I kinda agree updating the URL here. It is quite clear what to update when upgrading to new zig version. Let's leave it here as is.
I wonder about the pre-commit-hooks-nix dependency though. Why did we need to pin it? A breaking change? For that dependency I would prefer to pin it in the flake.lock file only via --override-input. If there is a breaking change we eventually have to address that in the future.
Edit: good news, CI now succeeds
There was a problem hiding this comment.
Without the pin, it throws this error:
error: evaluation aborted with the following error message:
'lib.customisation.callPackageWith: Function called without required argument "zizmor"
at /nix/store/r1wrhwj8m29ni4j36dxha1pkzpjdg3jy-source/nix/tools.nix:105'
There was a problem hiding this comment.
Should we try to upgrade nixpkgs? (to try to avoid the pinning, but it might be a good idea even for its own sake)
There was a problem hiding this comment.
oh, good point. We still use 2405. Current is already 2511. Yeah, I think we should try to update this instead.
|
Updating nixpkgs also updates the linters who seem to be more strict 🤦 The linters are correct. In The deadnix linter is also correct. in nixpkgs.nix the You can run the linters locally via: |
|
Probably was already considered on your side. I was thinking if the following would be a good idea. Set up a pipeline that runs let's say weekly. Downloads the latest Zig and tries to build the project and the example extensions and other such checks. Fails if there's any issues with that. |
Yeah, we initially considered that. On the other hand Zig language and standard library is still changing quite a bit between releases. Plus some breaking changes only become apparent when functions are actually used to to Zig 'lazy' nature of compiling code. For this reason we decided to pin to a stable release and even keep to a stable release a little longer in case of critical bugs being discovered. It is still a balance. The ZLS dependency is also a pain to track as this project normally builds against main. A few times we got caught up in incompatibilities because Zig and ZLS overlays/releases were not well in sync. I think this level of automation still make sense for patch releases. |
|
Oh no, looks like postgres headers can't be found after updating nixpkgs: |
|
I think it's due to this change: Source: https://nixos.org/manual/nixpkgs/stable/release-notes?#sec-nixpkgs-release-25.05-incompatibilities |
|
I think it is now confused about where to find files due to the presence of both |
|
Good news: tests compile now. See: |
|
Happy new year. This is a lot of back and forth creating a commit for every change. While I appreciate the effort I can imagine this being quite frustrating on your side. If you check the In case you don't have nix installed on your dev machine you can do everything via docker as well. User I hope this helps a little. |
|
Happy new year! With Docker I managed to create a local setup and with the latest commit the |
That's great. But we still have some tests commented out. Can you reenable and see if they run through? |
|
Good catch, if I uncomment the |
|
Still passes here.. one option would be to revert to commit |
|
@urso shall I revert this PR to commit |
|
Hi, Thank you for all the effort you've put into it. I understand it was quite time consuming and maybe a little frustrating at times. The more I appreciate the dedication and time you spend on this PR. I'm sure we're this close to get it merged. |
|
Hi, |
HTab Test Crash - Root Cause FoundHi @mcadariu, I've been investigating the CI failure in this PR and found the root cause of the server crash during unit tests. The ProblemThe crash occurs because Zig's MachO linker uses two-level namespace by default, which binds On macOS (and apparently Linux CI too), the system's libc exports BSD hsearch functions with the same names but different signatures than PostgreSQL's internal functions:
When the extension calls EvidenceIt should show No Zig WorkaroundI tested extensively and Zig's linker doesn't support The only fix is building with clang: SolutionDisable HTab tests until Zig adds support for flat namespace linking. I've documented this and created a draft Zig issue. I'm working on a separate branch with:
Happy to collaborate on getting this merged. Would you like to coordinate? |
Replace the deprecated @cImport approach with build-time translate-c for C header translation. This aligns with Zig's direction of removing @cImport in future versions. Changes: - Add src/pgzx/c/include/headers.h with all PostgreSQL includes - Update build.zig to use addTranslateC() instead of @cImport - Rename module from 'pgzx_pgsys' to 'c_translated' - Update all internal imports to use the new module name - Keep test_filter support for selective test running This change is based on PR xataio#105 by @mcadariu, adapted to work with our existing infrastructure and test framework. Co-authored-by: Marius Cadariu <mcadariu@users.noreply.github.com>
I have to disagree. We should not disable the tests. Due to the zig linker issue it is not safe to use pgzx on macOS in general. Postgres fortunately builds with The issue is known and has reported more than once to the Zig team. For example:
This is why for the local tests we use Docker. We want to run the tests in a linux environment. The tests did fail on our linux runners, not macOS (although it will fail on macOS for sure). If you want to work on macOS, a good compromise would be to use a comp-time conditional to not include the test for darwin targets. |
Yes, disabling the test was to verify that everything else works. |
|
I did push my work in #106 trying to combine your work mcadariu and my ideas. |
PR to close #104