# Copyright 2025-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

POSTGRES_COMPAT=( {16..18} ) # config section below
POSTGRES_USEDEP="server"

CRATES="
	adler2@2.0.1
	aho-corasick@1.1.4
	alloca@0.4.0
	anes@0.1.6
	annotate-snippets@0.11.5
	anstream@0.6.21
	anstyle-parse@0.2.7
	anstyle-query@1.1.5
	anstyle-wincon@3.0.11
	anstyle@1.0.13
	anyhow@1.0.100
	arrayvec@0.7.6
	autocfg@1.5.0
	bindgen@0.71.1
	bitflags@2.10.0
	bitvec@1.0.1
	bumpalo@3.19.1
	cargo_toml@0.22.3
	cast@0.3.0
	cc@1.2.53
	cee-scape@0.2.0
	cexpr@0.6.0
	cfg-if@1.0.4
	ciborium-io@0.2.2
	ciborium-ll@0.2.2
	ciborium@0.2.2
	clang-sys@1.8.1
	clap@4.5.54
	clap_builder@4.5.54
	clap_derive@4.5.49
	clap_lex@0.7.7
	codepage@0.1.2
	colorchoice@1.0.4
	convert_case@0.8.0
	crc32fast@1.5.0
	criterion-plot@0.8.1
	criterion@0.8.1
	crossbeam-channel@0.5.15
	crossbeam-deque@0.8.6
	crossbeam-epoch@0.9.18
	crossbeam-utils@0.8.21
	crunchy@0.2.4
	darling@0.20.11
	darling_core@0.20.11
	darling_macro@0.20.11
	dary_heap@0.3.8
	displaydoc@0.2.5
	either@1.15.0
	encoding_rs@0.8.35
	enum-map-derive@0.17.0
	enum-map@2.7.3
	env_home@0.1.0
	equivalent@1.0.2
	errno@0.3.14
	eyre@0.6.12
	fallible-iterator@0.3.0
	fallible-streaming-iterator@0.1.9
	fastrand@2.3.0
	find-msvc-tools@0.1.8
	fixedbitset@0.5.7
	flate2@1.1.8
	fnv@1.0.7
	foldhash@0.1.5
	foldhash@0.2.0
	form_urlencoded@1.2.2
	funty@2.0.0
	getrandom@0.3.4
	glob@0.3.3
	half@1.8.3
	half@2.7.1
	hashbrown@0.15.5
	hashbrown@0.16.1
	hashlink@0.11.0
	heck@0.5.0
	humansize@2.1.3
	icu_collections@2.1.1
	icu_locale_core@2.1.1
	icu_normalizer@2.1.1
	icu_normalizer_data@2.1.1
	icu_properties@2.1.2
	icu_properties_data@2.1.2
	icu_provider@2.1.1
	ident_case@1.0.1
	idna@1.1.0
	idna_adapter@1.2.1
	indenter@0.3.4
	indexmap@2.13.0
	is_ci@1.2.0
	is_terminal_polyfill@1.70.2
	itertools@0.13.0
	itoa@1.0.17
	js-sys@0.3.85
	libc@0.2.180
	libloading@0.8.9
	libm@0.2.15
	libmimalloc-sys@0.1.44
	libsqlite3-sys@0.36.0
	linux-raw-sys@0.11.0
	litemap@0.8.1
	memchr@2.7.6
	mimalloc@0.1.48
	min-max-heap@1.3.0
	minimal-lexical@0.2.1
	miniz_oxide@0.8.9
	nom@7.1.3
	num-traits@0.2.19
	object@0.38.1
	once_cell@1.21.3
	once_cell_polyfill@1.70.2
	oorandom@11.1.5
	owo-colors@4.2.3
	page_size@0.6.0
	paste@1.0.15
	pathsearch@0.2.0
	percent-encoding@2.3.2
	petgraph@0.8.3
	pgrx-bindgen@0.16.1
	pgrx-catalog@0.3.1
	pgrx-macros@0.16.1
	pgrx-pg-config@0.16.1
	pgrx-pg-sys@0.16.1
	pgrx-sql-entity-graph@0.16.1
	pgrx@0.16.1
	pin-project-internal@1.1.10
	pin-project@1.1.10
	pkg-config@0.3.32
	plotters-backend@0.3.7
	plotters-svg@0.3.7
	plotters@0.3.7
	potential_utf@0.1.4
	ppv-lite86@0.2.21
	proc-macro-error-attr2@2.0.0
	proc-macro-error2@2.0.1
	proc-macro2@1.0.106
	quote@1.0.44
	r-efi@5.3.0
	radium@0.7.0
	rand@0.9.2
	rand_chacha@0.9.0
	rand_core@0.9.5
	rayon-core@1.13.0
	rayon@1.11.0
	regex-automata@0.4.13
	regex-syntax@0.8.8
	regex@1.12.2
	rsqlite-vfs@0.1.0
	rusqlite@0.38.0
	rustc-hash@2.1.1
	rustix@1.1.3
	rustversion@1.0.22
	ruzstd@0.8.2
	same-file@1.0.6
	seahash@4.1.0
	seq-macro@0.3.6
	serde@1.0.228
	serde_cbor@0.11.2
	serde_core@1.0.228
	serde_derive@1.0.228
	serde_json@1.0.149
	serde_spanned@1.0.4
	shlex@1.3.0
	simd-adler32@0.3.8
	smallvec@1.15.1
	sqlite-wasm-rs@0.5.2
	stable_deref_trait@1.2.1
	strsim@0.11.1
	supports-color@3.0.2
	syn@2.0.114
	synstructure@0.13.2
	tap@1.0.1
	target-triple@1.0.0
	tempfile@3.24.0
	thiserror-impl@2.0.18
	thiserror@2.0.18
	tinystr@0.8.2
	tinytemplate@1.2.1
	toml@0.9.11+spec-1.1.0
	toml_datetime@0.7.5+spec-1.1.0
	toml_parser@1.0.6+spec-1.1.0
	toml_writer@1.0.6+spec-1.1.0
	twox-hash@2.1.2
	unescape@0.1.0
	unicode-ident@1.0.22
	unicode-segmentation@1.12.0
	unicode-width@0.2.2
	url@2.5.8
	utf8_iter@1.0.4
	utf8parse@0.2.2
	uuid@1.19.0
	validator@0.20.0
	validator_derive@0.20.0
	vcpkg@0.2.15
	walkdir@2.5.0
	wasip2@1.0.2+wasi-0.2.9
	wasm-bindgen-macro-support@0.2.108
	wasm-bindgen-macro@0.2.108
	wasm-bindgen-shared@0.2.108
	wasm-bindgen@0.2.108
	wasmparser@0.243.0
	web-sys@0.3.85
	which@8.0.0
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-util@0.1.11
	winapi-x86_64-pc-windows-gnu@0.4.0
	winapi@0.3.9
	windows-link@0.2.1
	windows-sys@0.61.2
	winnow@0.7.14
	winsafe@0.0.19
	wit-bindgen@0.51.0
	writeable@0.6.2
	wyhash@0.6.0
	wyz@0.5.1
	yoke-derive@0.8.1
	yoke@0.8.1
	zerocopy-derive@0.8.33
	zerocopy@0.8.33
	zerofrom-derive@0.1.6
	zerofrom@0.1.6
	zerotrie@0.2.3
	zerovec-derive@0.11.2
	zerovec@0.11.5
	zmij@1.0.16
"

RUST_REQ_USE="rustfmt"
RUST_MIN_VER="1.91.0"

inherit postgres-multi autotools cargo

DESCRIPTION="Scalable, fast, and disk-friendly vector search in Postgres, the successor of pgvecto.rs"
HOMEPAGE="
	https://docs.vectorchord.ai/vectorchord/getting-started/overview.html
	https://github.com/tensorchord/VectorChord
"
SRC_URI="
	https://github.com/tensorchord/VectorChord/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz
	${CARGO_CRATE_URIS}
"

LICENSE="AGPL-3"
# Dependent crate licenses
LICENSE+=" Apache-2.0 BSD ISC MIT Unicode-3.0 ZLIB"

RDEPEND="
	${POSTGRES_DEP}
	dev-db/pgvector
"

BDEPEND="
	dev-util/cargo-pgrx
"

DEPEND="
	${BDEPEND}
	${RDEPEND}
"

SLOT="0"
KEYWORDS="~amd64"

S=${WORKDIR}/VectorChord-${PV}
export PGRX_HOME=${WORKDIR}/pgrx_home

pkg_setup() {
	postgres-multi_pkg_setup
	rust_pkg_setup
	use postgres_targets_postgres16 && ( cargo pgrx init --pg16=/usr/bin/pg_config || die )
	use postgres_targets_postgres17 && ( cargo pgrx init --pg17=/usr/bin/pg_config || die )
	use postgres_targets_postgres18 && ( cargo pgrx init --pg18=/usr/bin/pg_config || die )
}

src_configure() {
        local myfeatures=(
                $(usev postgres_targets_postgres16 pg16)
                $(usev postgres_targets_postgres17 pg17)
                $(usev postgres_targets_postgres18 pg18)
        )
        cargo_src_configure
}

src_compile() {
	make build
}

src_install() {
	default
	DESTDIR=${T} make install
}