Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgsys module #67

Merged
merged 3 commits into from
Jun 22, 2024
Merged

pgsys module #67

merged 3 commits into from
Jun 22, 2024

Conversation

urso
Copy link
Collaborator

@urso urso commented Jun 21, 2024

Requires: #65

With this change we split the C include and the pgzx into 2 modules:

  • pgzx_pgsys: C includes and some custom C helpers
  • pgzx: High level Zig utilities and abstractions.

The split is to prepare for code generation support. When generating Zig code on the fly the generated code is imported as a module into pgzx, but we also want the generated code to depend on the C includes. By splitting out the C support we can have the generated module import pgsys as a module dependency itself.

The change follows the pattern in https://github.com/ziglang/zig/blob/master/test/standalone/dep_triangle/build.zig

We still re-export pgsys under pgzx.c.

Within pgzx we replace const c = @import(...) with const pg = @import("pgzx_pgsys");. Now Postgres API usage is always prefixed with pg.* instead of c.*, which is also more consistent on how we use the namespaces ourselves and in the example extensions.

Follow ups (not handled in this PR):

  • move C support into separate pgsys folder
  • rename pgzx.c to pgzx.pg

@urso urso marked this pull request as ready for review June 22, 2024 17:33
@urso urso merged commit 466ac4c into xataio:main Jun 22, 2024
1 check passed
@urso urso deleted the pgsys branch June 22, 2024 17:54
urso added a commit that referenced this pull request Jun 23, 2024
Requires #67 

Closes #66 

Postgres sources use tagging and the `Node` (and `NodeTag`) types for
many internal types. Unfortunately the macros did not translate well to
Zig, which makes it annoying to work with the low level types.

We introduce the `pgzx.node` module that provides a list of helper
functions like `pgzx.node.make`, `pgzx.node.create`, `pgzx.node.tag`, or
`pgzx.node.isA`.

We also wrap the constants into our own `pgzx.node.Tag` enum, so you can
use `pgzx.node.isA(node, .Query)` in code.

Postgres uses code generation to collect the node tags and supported
types into `nodetags.h`. We also use code generation to produce the list
of tags and type mappings. The generated module is then imported by
`pgzx.node`.

The `tools/gennodetags` tool imports the `nodes/nodes.h` header file at
compile time and uses comptime to collect all known tags into an
`ArrayList` which is then used to produce the sources for the anonymous
module imported into `pgzx`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants