Skip to content

Commit

Permalink
Build EdgeDB 5.0 and PostgreSQL 16+ bundles with pgvector-0.6 (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
elprans authored Feb 7, 2024
1 parent 10168b2 commit 89cf39f
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 17 deletions.
3 changes: 2 additions & 1 deletion edgedbpkg/edgedb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class EdgeDB(packages.BundledPythonPackage):
">=5.0.dev1": [
"postgresql-edgedb (~= 15.0)",
"python-edgedb (~= 3.11.0)",
"pgext-pgvector",
"pgext-pgvector (~= 0.6.0)",
],
}

Expand All @@ -88,6 +88,7 @@ class EdgeDB(packages.BundledPythonPackage):
python_bundle.Python(version="3.11.3"),
pyentrypoint.PyEntryPoint(version="1.0.0"),
pgvector.PgVector("v0.4.2"),
pgvector.PgVector("v0.6.0"),
]

@classmethod
Expand Down
25 changes: 16 additions & 9 deletions edgedbpkg/pgbundle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class PostgreSQLBundle(packages.BundledPackage):

bundle_deps: list[packages.BundledPackage]

artifact_requirements = {
"<16.0": [
"pgext-pgvector (== 0.4.2)",
],
">=16.0": [
"pgext-pgvector (~= 0.6.0)",
],
}

@classmethod
def resolve(
cls,
Expand All @@ -55,20 +64,18 @@ def resolve(
bundle.bundle_deps = [
postgres,
pgvector.PgVector("v0.4.2"),
pgvector.PgVector("v0.6.0"),
]

return bundle

def get_requirements(self) -> list[poetry_dep.Dependency]:
req_spec = [
f"postgresql-edgedb (== {self.version})",
"pgext-pgvector",
]

reqs = []
for item in req_spec:
reqs.append(poetry_dep.Dependency.create_from_pep_508(item))

reqs = super().get_requirements()
reqs.append(
poetry_dep.Dependency.create_from_pep_508(
f"postgresql-edgedb (== {self.version})"
),
)
return reqs

def get_configure_script(self, build: targets.Build) -> str:
Expand Down
29 changes: 29 additions & 0 deletions edgedbpkg/pgext/pgvector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Any,
)

import re
import shlex

from poetry.core.semver import version as poetry_version
Expand Down Expand Up @@ -104,3 +105,31 @@ def get_make_env(self, build: targets.Build, wd: str) -> str:
linebreaks=False,
force_args_eq=True,
)

def get_make_install_env(self, build: targets.Build, wd: str) -> str:
return build.sh_format_args(
{
"PG_CONFIG": build.sh_get_command("pg_config_install"),
"USE_PGXS": "1",
},
linebreaks=False,
force_args_eq=True,
)

def get_patches(self) -> dict[str, list[tuple[str, str]]]:
v = f"{self.version.major}{self.version.minor}"

patches = dict(super().get_patches())
for pkg, pkg_patches in patches.items():
if pkg == self.name:
filtered = []
for i, (pn, pfile) in enumerate(list(pkg_patches)):
m = re.match(r"^.*-(\d+)$", pn)
if m and m.group(1) != v:
pass
else:
filtered.append((pn, pfile))
patches[pkg] = filtered
break

return patches
1 change: 1 addition & 0 deletions edgedbpkg/pgext/pgvector/ignore.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{includedir}/**/*.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 50e0ecd8509f292dae18a11678548327e70f94b0 Mon Sep 17 00:00:00 2001
From: Elvis Pranskevichus <[email protected]>
Date: Thu, 8 Jun 2023 08:59:48 -0700
Subject: [PATCH] Fix CFLAGS

---
Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 3dc78f8..275acc6 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test --load-extension=$(EXTENSION)

-OPTFLAGS = -march=native
+OPTFLAGS =

# Mac ARM doesn't support -march=native
ifeq ($(shell uname -s), Darwin)
--
2.43.0

33 changes: 33 additions & 0 deletions edgedbpkg/postgresql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def get_build_tools(self, build: targets.Build) -> dict[str, pathlib.Path]:
bindir = build.get_install_path("bin").relative_to("/")
datadir = build.get_install_path("data")
libdir = build.get_install_path("lib")
includedir = build.get_install_path("include")
builddir_hlp = build.get_build_dir(self, relative_to="helpers")

# Since we are using a temporary Postgres installation,
Expand Down Expand Up @@ -207,6 +208,38 @@ def get_build_tools(self, build: targets.Build) -> dict[str, pathlib.Path]:
"pg_config_wrapper.py", wrapper, relative_to="sourceroot"
)

# Same, but for install-time, so includes more paths
wrapper = textwrap.dedent(
f"""\
import pathlib
import subprocess
import sys
path = (
pathlib.Path(__file__).parent / "{builddir_hlp}" / "_install"
).resolve()
pgc = path / "{bindir}" / "pg_config"
proc = subprocess.run(
[pgc] + sys.argv[1:],
check=True, stdout=subprocess.PIPE,
universal_newlines=True)
for line in proc.stdout.split('\\n'):
if ('{datadir}' in line or
'{includedir}' in line or
('{libdir}' in line and 'pgxs' not in line)):
line = line.replace(str(path), '')
print(line)
"""
)

install_wrapper_cmd = build.write_helper(
"pg_config_install_wrapper.py", wrapper, relative_to="sourceroot"
)

return {
"pg_config": wrapper_cmd,
"pg_config_install": install_wrapper_cmd,
}
12 changes: 6 additions & 6 deletions edgedbpkg/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def get_configure_script(self, build: targets.Build) -> str:
)

if platform.system() == "Darwin":
configure_flags[
"--enable-universalsdk"
] = "!$(xcrun --show-sdk-path)"
configure_flags["--enable-universalsdk"] = (
"!$(xcrun --show-sdk-path)"
)
arch = build.target.machine_architecture
if arch == "x86_64":
configure_flags["--with-universal-archs"] = "intel-64"
Expand All @@ -144,9 +144,9 @@ def get_configure_script(self, build: targets.Build) -> str:
)
openssl_path /= build.get_full_install_prefix().relative_to("/")
configure_flags["--with-openssl"] = openssl_path
configure_flags[
"--with-openssl-rpath"
] = openssl_pkg.get_shlib_paths(build)[0]
configure_flags["--with-openssl-rpath"] = (
openssl_pkg.get_shlib_paths(build)[0]
)

self.configure_dependency(build, configure_flags, "uuid", "LIBUUID")
self.configure_dependency(build, configure_flags, "zlib", "ZLIB")
Expand Down
4 changes: 3 additions & 1 deletion server/process_incoming.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ def main(

region = os.environ.get("AWS_REGION", "us-east-2")
session = boto3.session.Session(region_name=region)
s3: mypy_boto3_s3.S3ServiceResource = session.resource("s3") # pyright: ignore
s3: mypy_boto3_s3.S3ServiceResource = session.resource(
"s3"
) # pyright: ignore

for path_str in uploads:
path = pathlib.Path(path_str)
Expand Down

0 comments on commit 89cf39f

Please sign in to comment.