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

# Autogenerated by pycargoebuild 0.13.1
# path: rust/bridge/ffi

EAPI=8

CRATES="
	addr2line@0.24.2
	adler2@2.0.1
	aead@0.5.2
	aes-gcm-siv@0.11.1
	aes-gcm@0.10.3
	aes@0.8.4
	aho-corasick@1.1.3
	android_system_properties@0.1.5
	anes@0.1.6
	anstream@0.6.20
	anstyle-parse@0.2.7
	anstyle-query@1.1.4
	anstyle-wincon@3.0.10
	anstyle@1.0.11
	anyhow@1.0.99
	argon2@0.5.3
	arrayvec@0.7.6
	asn1@0.21.3
	asn1_derive@0.21.3
	assert_cmd@2.0.17
	assert_matches@1.5.0
	async-compression@0.4.30
	async-trait@0.1.89
	atomic-take@1.1.0
	atomic-waker@1.1.2
	auto_enums@0.8.7
	autocfg@1.5.0
	backtrace@0.3.75
	base64@0.22.1
	base64ct@1.8.0
	bincode@1.3.3
	bindgen@0.72.1
	bit-set@0.8.0
	bit-vec@0.8.0
	bitflags@2.9.4
	bitstream-io@1.10.0
	blake2@0.10.6
	block-buffer@0.10.4
	block-padding@0.3.3
	breakpad-symbols@0.22.2
	bstr@1.12.0
	bumpalo@3.19.0
	bytes@1.10.1
	cachemap2@0.3.0
	cast@0.3.0
	cbc@0.1.2
	cc@1.2.37
	cesu8@1.1.0
	cexpr@0.6.0
	cfg-if@1.0.3
	chacha20@0.9.1
	chacha20poly1305@0.10.1
	chrono@0.4.42
	ciborium-io@0.2.2
	ciborium-ll@0.2.2
	ciborium@0.2.2
	cipher@0.4.4
	circular@0.3.0
	clang-sys@1.8.1
	clap-stdin@0.6.0
	clap@4.5.47
	clap_builder@4.5.47
	clap_derive@4.5.47
	clap_lex@0.7.5
	cmake@0.1.48
	colorchoice@1.0.4
	combine@4.6.7
	compression-codecs@0.4.30
	compression-core@0.4.29
	const-oid@0.9.6
	const-str@0.6.4
	convert_case@0.4.0
	core-foundation-sys@0.8.7
	core-foundation@0.10.1
	core-models@0.0.4
	cpufeatures@0.2.17
	crc32fast@1.5.0
	criterion-plot@0.5.0
	criterion@0.5.1
	crossbeam-deque@0.8.6
	crossbeam-epoch@0.9.18
	crossbeam-utils@0.8.21
	crunchy@0.2.4
	crypto-common@0.1.6
	ctr@0.9.2
	darling@0.20.11
	darling_core@0.20.11
	darling_macro@0.20.11
	data-encoding-macro-internal@0.1.16
	data-encoding-macro@0.1.18
	data-encoding@2.9.0
	debugid@0.8.0
	der@0.7.10
	deranged@0.5.3
	derive-where@1.6.0
	derive_builder@0.20.2
	derive_builder_core@0.20.2
	derive_builder_macro@0.20.2
	derive_more-impl@2.0.1
	derive_more@0.99.20
	derive_more@2.0.1
	derive_utils@0.15.0
	diff@0.1.13
	difflib@0.4.0
	digest@0.10.7
	dir-test-macros@0.4.1
	dir-test@0.4.1
	displaydoc@0.2.5
	doc-comment@0.3.3
	downcast-rs@1.2.1
	dyn-clonable-impl@0.9.2
	dyn-clonable@0.9.2
	dyn-clone@1.0.20
	ed25519-dalek@2.2.0
	ed25519@2.2.3
	either@1.15.0
	encoding_rs@0.8.35
	enum-as-inner@0.6.1
	env_filter@0.1.3
	env_logger@0.11.8
	equivalent@1.0.2
	errno@0.3.14
	fastrand@2.3.0
	fiat-crypto@0.2.9
	find-msvc-tools@0.1.1
	fixedbitset@0.5.7
	flate2@1.1.2
	fnv@1.0.7
	foreign-types-macros@0.2.3
	foreign-types-shared@0.3.1
	foreign-types@0.5.0
	form_urlencoded@1.2.2
	fs_extra@1.3.0
	fslock@0.2.1
	futures-channel@0.3.31
	futures-core@0.3.31
	futures-executor@0.3.31
	futures-io@0.3.31
	futures-macro@0.3.31
	futures-sink@0.3.31
	futures-task@0.3.31
	futures-util@0.3.31
	futures@0.3.31
	generic-array@0.14.7
	getrandom@0.2.16
	getrandom@0.3.3
	ghash@0.5.1
	gimli@0.31.1
	glob@0.3.3
	h2@0.4.12
	half@2.6.0
	hashbrown@0.12.3
	hashbrown@0.15.5
	hax-lib-macros-types@0.3.5
	hax-lib-macros@0.3.5
	hax-lib@0.3.5
	headers-core@0.3.0
	headers@0.4.1
	heck@0.5.0
	hermit-abi@0.5.2
	hex@0.4.3
	hickory-proto@0.24.4
	hkdf@0.12.4
	hmac@0.12.1
	home@0.5.11
	hpke-rs-crypto@0.3.0
	hpke-rs@0.4.0
	http-body-util@0.1.3
	http-body@1.0.1
	http@1.3.1
	httparse@1.10.1
	httpdate@1.0.3
	hyper-util@0.1.17
	hyper@1.7.0
	iana-time-zone-haiku@0.1.2
	iana-time-zone@0.1.64
	icu_collections@2.0.0
	icu_locale_core@2.0.0
	icu_normalizer@2.0.0
	icu_normalizer_data@2.0.0
	icu_properties@2.0.1
	icu_properties_data@2.0.1
	icu_provider@2.0.0
	ident_case@1.0.1
	idna@1.1.0
	idna_adapter@1.2.1
	indexmap@1.9.3
	indexmap@2.11.3
	inout@0.1.4
	intmap@3.1.2
	io-uring@0.7.10
	ipnet@2.11.0
	is-terminal@0.4.16
	is_terminal_polyfill@1.70.1
	itertools@0.10.5
	itertools@0.13.0
	itertools@0.14.0
	itoa@1.0.15
	jiff-static@0.2.15
	jiff@0.2.15
	jni-sys@0.3.0
	jni@0.21.1
	js-sys@0.3.80
	lazy_static@1.5.0
	libc@0.2.175
	libcrux-hacl-rs@0.0.4
	libcrux-hmac@0.0.4
	libcrux-intrinsics@0.0.4
	libcrux-macros@0.0.3
	libcrux-ml-kem@0.0.4
	libcrux-platform@0.0.2
	libcrux-secrets@0.0.4
	libcrux-sha2@0.0.4
	libcrux-sha3@0.0.4
	libcrux-traits@0.0.4
	libloading@0.8.8
	libz-sys@1.1.22
	linkme-impl@0.3.33
	linkme@0.3.33
	linux-raw-sys@0.11.0
	linux-raw-sys@0.4.15
	litemap@0.8.0
	log-panics@2.1.0
	log@0.4.28
	macro_rules_attribute-proc_macro@0.2.2
	macro_rules_attribute@0.2.2
	matchers@0.2.0
	mediasan-common@0.5.3
	memchr@2.7.5
	memmap2@0.9.8
	mime@0.3.17
	mime_guess@2.0.5
	minidump-common@0.22.2
	minidump-processor@0.22.1
	minidump-unwind@0.22.2
	minidump@0.22.2
	minimal-lexical@0.2.1
	miniz_oxide@0.8.9
	mio@1.0.4
	mp4san-derive@0.5.3
	mp4san@0.5.3
	multimap@0.10.1
	neon-macros@1.1.1
	neon@1.1.1
	nom-derive-impl@0.10.1
	nom-derive@0.10.1
	nom@7.1.3
	nonzero_ext@0.3.0
	nu-ansi-term@0.50.1
	num-bigint@0.4.6
	num-conv@0.1.0
	num-derive@0.4.2
	num-integer@0.1.46
	num-traits@0.2.19
	num_enum@0.7.4
	num_enum_derive@0.7.4
	object@0.36.7
	once_cell@1.21.3
	once_cell_polyfill@1.70.1
	oorandom@11.1.5
	opaque-debug@0.3.1
	openssl-macros@0.1.1
	openssl-probe@0.1.6
	partial-default-derive@0.1.0
	partial-default@0.1.0
	password-hash@0.5.0
	paste@1.0.15
	pastey@0.1.1
	pem@3.0.5
	percent-encoding@2.3.2
	pest@2.8.2
	pest_derive@2.8.2
	pest_generator@2.8.2
	pest_meta@2.8.2
	petgraph@0.7.1
	phf@0.11.3
	phf_codegen@0.11.3
	phf_generator@0.11.3
	phf_shared@0.11.3
	pin-project-internal@1.1.10
	pin-project-lite@0.2.16
	pin-project@1.1.10
	pin-utils@0.1.0
	pkcs8@0.10.2
	pkg-config@0.3.32
	plotters-backend@0.3.7
	plotters-svg@0.3.7
	plotters@0.3.7
	poly1305@0.8.0
	polyval@0.6.2
	portable-atomic-util@0.2.4
	portable-atomic@1.11.1
	potential_utf@0.1.3
	powerfmt@0.2.0
	ppv-lite86@0.2.21
	predicates-core@1.0.9
	predicates-tree@1.0.12
	predicates@3.1.3
	pretty_assertions@1.4.1
	prettyplease@0.2.37
	proc-macro-crate@3.4.0
	proc-macro-error-attr2@2.0.0
	proc-macro-error2@2.0.1
	proc-macro2@1.0.101
	procfs-core@0.17.0
	proptest@1.7.0
	prost-build@0.14.1
	prost-derive@0.14.1
	prost-types@0.14.1
	prost@0.14.1
	protobuf-codegen@3.7.2
	protobuf-json-mapping@3.7.2
	protobuf-parse@3.7.2
	protobuf-support@3.7.2
	protobuf@3.7.2
	pulldown-cmark-to-cmark@21.1.0
	pulldown-cmark@0.13.0
	quick-error@1.2.3
	quote@1.0.40
	r-efi@5.3.0
	rand@0.8.5
	rand@0.9.2
	rand_chacha@0.3.1
	rand_chacha@0.9.0
	rand_core@0.6.4
	rand_core@0.9.3
	rand_xorshift@0.4.0
	range-map@0.2.0
	rangemap@1.6.0
	rayon-core@1.13.0
	rayon@1.11.0
	rcgen@0.13.2
	ref-cast-impl@1.0.24
	ref-cast@1.0.24
	regex-automata@0.4.10
	regex-syntax@0.8.6
	regex@1.11.2
	ring@0.17.14
	rustc-demangle@0.1.26
	rustc-hash@2.1.1
	rustc_version@0.4.1
	rusticata-macros@4.1.0
	rustix@0.38.44
	rustix@1.1.2
	rustls-native-certs@0.8.1
	rustls-pki-types@1.12.0
	rustls-platform-verifier-android@0.1.1
	rustls-platform-verifier@0.5.3
	rustls-webpki@0.103.6
	rustls@0.23.31
	rustversion@1.0.22
	rusty-fork@0.3.0
	ryu@1.0.20
	same-file@1.0.6
	schannel@0.1.28
	schemars@0.9.0
	schemars@1.0.4
	scoped-tls@1.0.1
	scopeguard@1.2.0
	scroll@0.12.0
	scroll_derive@0.12.1
	security-framework-sys@2.15.0
	security-framework@3.4.0
	semver@1.0.27
	send_wrapper@0.6.0
	serde@1.0.225
	serde_core@1.0.225
	serde_derive@1.0.225
	serde_json5@0.2.1
	serde_json@1.0.145
	serde_urlencoded@0.7.1
	serde_with@3.14.0
	serde_with_macros@3.14.0
	sha1@0.10.6
	sha1_smol@1.0.1
	sha2-asm@0.6.4
	sha2@0.10.9
	sharded-slab@0.1.7
	shlex@1.3.0
	signature@2.2.0
	siphasher@1.0.1
	slab@0.4.11
	smallvec@1.15.1
	smart-default@0.7.1
	snow@0.10.0
	socket2@0.6.0
	socks5-proto@0.4.1
	socks5-server@0.10.1
	sorted-vec@0.8.10
	spki@0.7.3
	stable_deref_trait@1.2.0
	static_assertions@1.1.0
	strsim@0.11.1
	strum@0.27.2
	strum_macros@0.27.2
	subtle@2.6.1
	syn-mid@0.6.0
	syn@1.0.109
	syn@2.0.106
	sync_wrapper@1.0.2
	synstructure@0.13.2
	tempfile@3.22.0
	termtree@0.5.1
	test-case-core@3.3.1
	test-case-macros@3.3.1
	test-case@3.3.1
	test-log-macros@0.2.18
	test-log@0.2.18
	testing_logger@0.1.1
	thiserror-impl@1.0.69
	thiserror-impl@2.0.16
	thiserror@1.0.69
	thiserror@2.0.16
	thread_local@1.1.9
	time-core@0.1.6
	time-macros@0.2.24
	time@0.3.43
	tinystr@0.8.1
	tinytemplate@1.2.1
	tinyvec@1.10.0
	tinyvec_macros@0.1.1
	tls-parser@0.12.2
	tokio-macros@2.5.0
	tokio-socks@0.5.2
	tokio-stream@0.1.17
	tokio-tungstenite@0.27.0
	tokio-util@0.7.16
	tokio@1.47.1
	toml_datetime@0.7.1
	toml_edit@0.23.5
	toml_parser@1.0.2
	tonic-build@0.14.2
	tonic-prost-build@0.14.2
	tonic-prost@0.14.2
	tonic@0.14.2
	tower-layer@0.3.3
	tower-service@0.3.3
	tracing-attributes@0.1.30
	tracing-core@0.1.34
	tracing-log@0.2.0
	tracing-subscriber@0.3.20
	tracing@0.1.41
	try-lock@0.2.5
	tungstenite@0.27.0
	typenum@1.18.0
	ucd-trie@0.1.7
	unarray@0.1.4
	unicase@2.8.1
	unicode-ident@1.0.19
	unicode-segmentation@1.12.0
	unicode-xid@0.2.6
	universal-hash@0.5.1
	untrusted@0.9.0
	url@2.5.7
	utf-8@0.7.6
	utf8_iter@1.0.4
	utf8parse@0.2.2
	uuid@1.18.1
	valuable@0.1.1
	vcpkg@0.2.15
	version_check@0.9.5
	visibility@0.1.1
	wait-timeout@0.2.1
	walkdir@2.5.0
	want@0.3.1
	warp@0.4.2
	wasi@0.11.1+wasi-snapshot-preview1
	wasi@0.14.7+wasi-0.2.4
	wasip2@1.0.1+wasi-0.2.4
	wasm-bindgen-backend@0.2.103
	wasm-bindgen-macro-support@0.2.103
	wasm-bindgen-macro@0.2.103
	wasm-bindgen-shared@0.2.103
	wasm-bindgen@0.2.103
	web-sys@0.3.80
	webpki-root-certs@0.26.11
	webpki-root-certs@1.0.2
	webpsan@0.5.3
	which@4.4.2
	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-core@0.62.0
	windows-implement@0.60.0
	windows-interface@0.59.1
	windows-link@0.1.3
	windows-link@0.2.0
	windows-result@0.4.0
	windows-strings@0.5.0
	windows-sys@0.45.0
	windows-sys@0.52.0
	windows-sys@0.59.0
	windows-sys@0.60.2
	windows-sys@0.61.0
	windows-targets@0.42.2
	windows-targets@0.52.6
	windows-targets@0.53.3
	windows_aarch64_gnullvm@0.42.2
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_gnullvm@0.53.0
	windows_aarch64_msvc@0.42.2
	windows_aarch64_msvc@0.52.6
	windows_aarch64_msvc@0.53.0
	windows_i686_gnu@0.42.2
	windows_i686_gnu@0.52.6
	windows_i686_gnu@0.53.0
	windows_i686_gnullvm@0.52.6
	windows_i686_gnullvm@0.53.0
	windows_i686_msvc@0.42.2
	windows_i686_msvc@0.52.6
	windows_i686_msvc@0.53.0
	windows_x86_64_gnu@0.42.2
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnu@0.53.0
	windows_x86_64_gnullvm@0.42.2
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_gnullvm@0.53.0
	windows_x86_64_msvc@0.42.2
	windows_x86_64_msvc@0.52.6
	windows_x86_64_msvc@0.53.0
	winnow@0.7.13
	wit-bindgen@0.46.0
	writeable@0.6.1
	x25519-dalek@2.0.1
	yansi@1.0.1
	yasna@0.5.2
	yoke-derive@0.8.0
	yoke@0.8.0
	zerocopy-derive@0.8.27
	zerocopy@0.8.27
	zerofrom-derive@0.1.6
	zerofrom@0.1.6
	zeroize@1.8.1
	zeroize_derive@1.4.2
	zerotrie@0.2.2
	zerovec-derive@0.11.1
	zerovec@0.11.4
"

declare -A GIT_CRATES=(
	[boring-sys]='https://github.com/signalapp/boring;81d4aa19ac6c5af99238ff0bf9328b381ccebcdd;boring-%commit%/boring-sys'
	[boring]='https://github.com/signalapp/boring;81d4aa19ac6c5af99238ff0bf9328b381ccebcdd;boring-%commit%/boring'
	[curve25519-dalek-derive]='https://github.com/signalapp/curve25519-dalek;7c6d34756355a3566a704da84dce7b1c039a6572;curve25519-dalek-%commit%/curve25519-dalek-derive'
	[curve25519-dalek]='https://github.com/signalapp/curve25519-dalek;7c6d34756355a3566a704da84dce7b1c039a6572;curve25519-dalek-%commit%/curve25519-dalek'
	[spqr]='https://github.com/signalapp/SparsePostQuantumRatchet;46e387458d438b81a3485e26bf6bb44595e52073;SparsePostQuantumRatchet-%commit%'
	[tokio-boring]='https://github.com/signalapp/boring;81d4aa19ac6c5af99238ff0bf9328b381ccebcdd;boring-%commit%/tokio-boring'
)

LLVM_COMPAT=( {18..20} )
RUST_MIN_VER="1.85.0"

inherit cargo llvm-r2

BSSL_COMMIT="44b3df6f03d85c901767250329c571db405122d5"
DESCRIPTION="C ABI library which exposes Signal protocol logic"
HOMEPAGE="https://github.com/signalapp/libsignal"
SRC_URI="
	https://github.com/signalapp/libsignal/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
	https://github.com/google/boringssl/archive/${BSSL_COMMIT}.tar.gz -> boringssl-${BSSL_COMMIT:0:7}.tar.gz
	${CARGO_CRATE_URIS}
"
S="${WORKDIR}/libsignal-${PV}/rust/bridge/ffi"

LICENSE="AGPL-3"
# Dependent crate licenses
LICENSE+="
	AGPL-3 Apache-2.0 BSD CDLA-Permissive-2.0 GPL-3+ ISC MIT MPL-2.0
	Unicode-3.0
"
SLOT="0"
KEYWORDS="~amd64"

# https://bugs.gentoo.org/927382
BDEPEND="
	dev-build/cmake
	dev-libs/protobuf
	$(llvm_gen_dep 'llvm-core/clang:${LLVM_SLOT}')
"

pkg_setup() {
	llvm-r2_pkg_setup
	rust_pkg_setup
}

src_unpack() {
	cargo_src_unpack

	local bssl_submodule=( "${WORKDIR}"/boring-*/boring-sys/deps/boringssl )
	rmdir "${bssl_submodule[@]}" || die
	mv "${WORKDIR}/boringssl-${BSSL_COMMIT}" "${bssl_submodule[@]}" || die

	# borrowed from net-im/gurk-rs
	local crate_patches crate crate_uri commit crate_dir host
	for crate in curve25519-dalek boring{,-sys}; do
		IFS=';' read -r crate_uri commit crate_dir host \
			<<< "${GIT_CRATES["${crate}"]}"

		: "${crate_dir:=${crate}-%commit%}"
		crate_patches+="${crate} = { path = \"${WORKDIR}/${crate_dir//%commit%/${commit}}\" };;"
	done

	printf -- "[patch.crates-io]\\n%s" "${crate_patches//;;/$'\n'}" \
		>> "${CARGO_HOME}/config.toml" || die
}

src_install() {
	dolib.a "${WORKDIR}"/libsignal-${PV}/$(cargo_target_dir)/libsignal_ffi.a
	einstalldocs
}
