summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 969b7b532ec3168315049e17bb097932506d0dc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Maintainer: pikl <me@pikl.uk>

_pgver=16  # postgresql version
_pkgbase=pgvecto.rs
pkgname=${_pkgbase}
pkgver=0.2.0
pkgrel=5
pkgdesc="Postgres extension that provides vector similarity search functions. It is written in Rust and based on pgrx."
arch=(x86_64)
url="https://github.com/tensorchord/pgvecto.rs"
license=('Apache-2.0')
# make deps determined from here - https://docs.pgvecto.rs/developers/development.html
makedepends=('rustup' 'bison' 'ccache' 'flex' 'gcc' 'git' 'gnupg' 'readline' 'libxml2' 'libxslt' 'lsb-release' 'pkgconf' 'tzdata' 'zlib' "postgresql>=${_pgver}" 'clang>=16' 'rustup')
# build fails with LTO enabled
options=('!lto')
provides=("pgvecto.rs=$pkgver")
conflicts=('pgvecto.rs')
source=(
    "${_pkgbase}-${pkgver}.tar.gz::https://github.com/tensorchord/pgvecto.rs/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('671bfe39a3b87d5dfa5229ab0beffff1bd09686b53779dc511248e79aa4b2646')

_gettcstr() {
    cd ${srcdir}/${_pkgbase}-${pkgver}
    _toolchain=$(cat rust-toolchain.toml | grep ^channel | cut -d" " -f 3 | tr -d '"')
    echo "$_toolchain-$CARCH-unknown-linux-gnu"
}

prepare() {

    # https://docs.pgvecto.rs/developers/development.html

    cd ${srcdir}/${_pkgbase}-${pkgver}

    # workaround to 0.0.0 version number in Cargo.toml
    # TODO report to upstream
    sed -i -e "s/version = \"0.0.0\"/version = \"${pkgver}\"/" Cargo.toml

    # determine required version of cargo-pgrx
    _pgrxver=$(grep 'pgrx = {' Cargo.toml | cut -d '"' -f 2)
    
    # specifying toolchain version is not strictly necessary since cargo will do it automatically
    # although can bt overwritten easily with environment variables, e.g. RUSTUP_TOOLCHAIN=stable
    # so most probably best to install is explicitly with this command
    rustup toolchain install "$(_gettcstr)"
    
    # an alternative method for installing cargo-pgrx for debug is to clone the repo direct using
    # sources, however:
    #    * ensure https://github.com/tensorchord/pgrx.git fork is cloned
    #    * often the version number is not tagged, so use the commit hash to checkout the correct version
    #    * only build the cargo-pgrx sub-module using `cargo build --release --locked -p cargo-pgrx`
    cargo install --locked --version ${_pgrxver} cargo-pgrx
}

build() {

    # https://docs.pgvecto.rs/developers/development.html
    # https://docs.pgvecto.rs/getting-started/installation.html

    rustup toolchain install "$(_gettcstr)"
    cd ${srcdir}/${_pkgbase}-${pkgver}

    # workaround problem in pgrx.git cargo-pgrx/src/command/schema.rs:531 where an empty argument
    # to the rustc compiler command is generated if RUSTFLAGS environment variable is defined but
    # empty - as is typical in arch build environment
    # TODO report upstream
    unset RUSTFLAGS

    # desired postgresql version only
    cargo pgrx init --pg16=/usr/bin/pg_config
    
    # equivalent to `cargo pgrx install --release` without installing
    cargo pgrx package
}

package() {
    cd "${srcdir}/${_pkgbase}-${pkgver}/target/release/vectors-pg${_pgver}"
    install -Dm0755 usr/lib/postgresql/vectors.so "${pkgdir}/usr/lib/postgresql/vectors.so"
    install -Dm0644 usr/share/postgresql/extension/vectors--0.2.0.sql "${pkgdir}/usr/share/postgresql/extension/vectors--0.2.0.sql"
    install -Dm0644 usr/share/postgresql/extension/vectors.control "${pkgdir}/usr/share/postgresql/extension/vectors.control"

    cd "${srcdir}/${_pkgbase}-${pkgver}/sql/upgrade"
    # upgrade scripts
    cp -r vectors--*.sql "${pkgdir}/usr/share/postgresql/extension"
}