# Copyright 2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Auto-Generated by cargo-ebuild 0.5.4

EAPI=8

CRATES="
	Inflector@0.11.4
	activitypub_federation@0.4.5
	activitystreams-kinds@0.3.0
	actix-codec@0.5.0
	actix-cors@0.6.4
	actix-form-data@0.7.0-beta.2
	actix-http@3.3.1
	actix-macros@0.2.3
	actix-multipart@0.6.0
	actix-router@0.5.1
	actix-rt@2.8.0
	actix-server@2.1.1
	actix-service@2.0.2
	actix-tls@3.0.3
	actix-utils@3.0.1
	actix-web-codegen@4.2.0
	actix-web-prom@0.6.0
	actix-web@4.3.1
	addr2line@0.19.0
	adler@1.0.2
	ahash@0.7.6
	ahash@0.8.3
	aho-corasick@1.0.2
	alloc-no-stdlib@2.0.4
	alloc-stdlib@0.2.2
	android-tzdata@0.1.1
	android_system_properties@0.1.5
	anyhow@1.0.71
	argparse@0.2.2
	arrayvec@0.5.2
	assert-json-diff@2.0.2
	async-io@1.13.0
	async-lock@2.7.0
	async-stream-impl@0.3.3
	async-stream@0.3.3
	async-trait@0.1.71
	atom_syndication@0.12.1
	autocfg@1.1.0
	awc@3.0.1
	axum-core@0.2.9
	axum-core@0.3.4
	axum@0.5.17
	axum@0.6.18
	backtrace@0.3.67
	base32@0.4.0
	base64@0.13.1
	base64@0.21.2
	bcrypt@0.15.0
	bincode@1.3.3
	bit-set@0.5.3
	bit-vec@0.6.3
	bitflags@1.3.2
	bitflags@2.3.1
	bitvec@0.19.6
	block-buffer@0.10.3
	blowfish@0.9.1
	brotli-decompressor@2.3.4
	brotli@3.3.4
	bumpalo@3.11.1
	bytecount@0.6.3
	bytemuck@1.12.1
	byteorder@1.4.3
	bytes@1.4.0
	bytestring@1.1.0
	camino@1.1.4
	captcha@0.0.9
	cargo-platform@0.1.2
	cargo_metadata@0.14.2
	cc@1.0.73
	cesu8@1.1.0
	cfg-if@1.0.0
	chrono@0.4.26
	cipher@0.4.3
	clap@4.0.32
	clap_derive@4.0.21
	clap_lex@0.3.0
	clokwerk@0.4.0
	codespan-reporting@0.11.1
	color-eyre@0.6.2
	color-spantrace@0.2.0
	color_quant@1.1.0
	combine@4.6.6
	concurrent-queue@2.2.0
	config@0.13.3
	console-api@0.5.0
	console-subscriber@0.1.10
	const_format@0.2.31
	const_format_proc_macros@0.2.31
	constant_time_eq@0.2.4
	convert_case@0.4.0
	cookie@0.16.2
	core-foundation-sys@0.8.3
	core-foundation@0.9.3
	cpufeatures@0.2.5
	crc32fast@1.3.2
	crossbeam-channel@0.5.8
	crossbeam-epoch@0.9.13
	crossbeam-utils@0.8.12
	crypto-common@0.1.6
	cxx-build@1.0.80
	cxx@1.0.80
	cxxbridge-flags@1.0.80
	cxxbridge-macro@1.0.80
	darling@0.13.4
	darling@0.14.1
	darling@0.20.1
	darling_core@0.13.4
	darling_core@0.14.1
	darling_core@0.20.1
	darling_macro@0.13.4
	darling_macro@0.14.1
	darling_macro@0.20.1
	dashmap@5.4.0
	deadpool-runtime@0.1.2
	deadpool@0.9.5
	derivative@2.2.0
	derive_builder@0.12.0
	derive_builder_core@0.12.0
	derive_builder_macro@0.12.0
	derive_more@0.99.17
	deser-hjson@1.2.0
	diesel-async@0.3.1
	diesel-derive-enum@2.1.0
	diesel-derive-newtype@2.1.0
	diesel@2.1.0
	diesel_derives@2.1.0
	diesel_ltree@0.3.0
	diesel_migrations@2.1.0
	diesel_table_macro_syntax@0.1.0
	digest@0.10.7
	diligent-date-parser@0.1.3
	displaydoc@0.2.4
	dlv-list@0.3.0
	doku-derive@0.21.1
	doku@0.21.1
	downcast-rs@1.2.0
	dyn-clone@1.0.11
	either@1.8.0
	email-encoding@0.2.0
	email_address@0.2.3
	encoding-index-japanese@1.20141219.5
	encoding-index-korean@1.20141219.5
	encoding-index-simpchinese@1.20141219.5
	encoding-index-singlebyte@1.20141219.5
	encoding-index-tradchinese@1.20141219.5
	encoding@0.2.33
	encoding_index_tests@0.1.4
	encoding_rs@0.8.31
	entities@1.0.1
	enum-map-derive@0.12.0
	enum-map@2.6.0
	enum_delegate@0.2.0
	enum_delegate_lib@0.2.0
	equivalent@1.0.0
	errno-dragonfly@0.1.2
	errno@0.2.8
	errno@0.3.1
	error-chain@0.12.4
	event-listener@2.5.3
	eyre@0.6.8
	fallible-iterator@0.2.0
	fallible_collections@0.4.5
	fancy-regex@0.7.1
	fastrand@1.8.0
	flate2@1.0.24
	fnv@1.0.7
	foreign-types-shared@0.1.1
	foreign-types@0.3.2
	form_urlencoded@1.2.0
	fs2@0.4.3
	funty@1.1.0
	futf@0.1.5
	futures-channel@0.3.28
	futures-core@0.3.28
	futures-executor@0.3.28
	futures-io@0.3.28
	futures-lite@1.13.0
	futures-macro@0.3.28
	futures-sink@0.3.28
	futures-task@0.3.28
	futures-util@0.3.28
	futures@0.3.28
	fxhash@0.2.1
	generic-array@0.14.6
	getrandom@0.1.16
	getrandom@0.2.8
	gimli@0.27.0
	glob@0.3.1
	h2@0.3.14
	half@1.8.2
	hashbrown@0.12.3
	hashbrown@0.14.0
	hdrhistogram@7.5.2
	heck@0.4.1
	hermit-abi@0.1.19
	hermit-abi@0.2.6
	hermit-abi@0.3.2
	hex@0.4.3
	hmac@0.12.1
	hostname@0.3.1
	hound@3.5.0
	html-escape@0.2.13
	html2md@0.2.14
	html2text@0.6.0
	html5ever@0.25.2
	html5ever@0.26.0
	http-body@0.4.5
	http-range-header@0.3.0
	http-signature-normalization-reqwest@0.8.0
	http-signature-normalization@0.7.0
	http@0.2.9
	httparse@1.8.0
	httpdate@1.0.2
	humantime@2.1.0
	hyper-timeout@0.4.1
	hyper-tls@0.5.0
	hyper@0.14.25
	iana-time-zone-haiku@0.1.1
	iana-time-zone@0.1.51
	ident_case@1.0.1
	idna@0.2.3
	idna@0.3.0
	idna@0.4.0
	image@0.24.4
	indenter@0.3.3
	indexmap@1.9.1
	indexmap@2.0.0
	inout@0.1.3
	instant@0.1.12
	io-lifetimes@1.0.11
	ipnet@2.5.0
	is-terminal@0.4.2
	itertools@0.10.5
	itertools@0.11.0
	itoa@1.0.6
	jni-sys@0.3.0
	jni@0.19.0
	jobserver@0.1.26
	js-sys@0.3.60
	json5@0.4.1
	jsonwebtoken@8.3.0
	language-tags@0.3.2
	lazy_static@1.4.0
	lettre@0.10.4
	lexical-core@0.7.6
	libc@0.2.146
	line-wrap@0.1.1
	link-cplusplus@1.0.7
	linked-hash-map@0.5.6
	linkify@0.9.0
	linux-raw-sys@0.1.4
	linux-raw-sys@0.3.8
	local-channel@0.1.3
	local-waker@0.1.3
	lock_api@0.4.9
	lodepng@3.7.2
	log@0.4.17
	mac@0.1.1
	mach2@0.4.1
	markdown-it@0.5.1
	markup5ever@0.10.1
	markup5ever@0.11.0
	markup5ever_rcdom@0.1.0
	markup5ever_rcdom@0.2.0
	match_cfg@0.1.0
	matchers@0.1.0
	matches@0.1.9
	matchit@0.5.0
	matchit@0.7.0
	md-5@0.10.5
	mdurl@0.3.1
	memchr@2.5.0
	memoffset@0.7.1
	migrations_internals@2.1.0
	migrations_macros@2.1.0
	mime@0.3.16
	mime_guess@2.0.4
	minimal-lexical@0.2.1
	miniz_oxide@0.5.4
	miniz_oxide@0.6.2
	mio@0.8.8
	moka@0.11.2
	native-tls@0.2.10
	never@0.1.0
	new_debug_unreachable@1.0.4
	nom@6.1.2
	nom@7.1.1
	nu-ansi-term@0.46.0
	num-bigint@0.4.3
	num-integer@0.1.45
	num-rational@0.4.1
	num-traits@0.2.15
	num_cpus@1.13.1
	num_threads@0.1.6
	object@0.30.0
	once_cell@1.18.0
	openssl-macros@0.1.0
	openssl-probe@0.1.5
	openssl-sys@0.9.90
	openssl@0.10.55
	opentelemetry-otlp@0.12.0
	opentelemetry-proto@0.2.0
	opentelemetry@0.16.0
	opentelemetry@0.19.0
	opentelemetry_api@0.19.0
	opentelemetry_sdk@0.19.0
	ordered-multimap@0.4.3
	os_str_bytes@6.4.1
	overload@0.1.1
	owo-colors@3.5.0
	parking@2.1.0
	parking_lot@0.11.2
	parking_lot@0.12.1
	parking_lot_core@0.8.6
	parking_lot_core@0.9.4
	paste@1.0.9
	pathdiff@0.2.1
	pem@1.1.0
	percent-encoding@2.3.0
	pest@2.4.0
	pest_derive@2.4.0
	pest_generator@2.4.0
	pest_meta@2.4.0
	phf@0.10.1
	phf@0.11.1
	phf@0.8.0
	phf_codegen@0.10.0
	phf_codegen@0.8.0
	phf_generator@0.10.0
	phf_generator@0.8.0
	phf_shared@0.10.0
	phf_shared@0.11.1
	phf_shared@0.8.0
	pict-rs@0.4.0
	pin-project-internal@1.0.12
	pin-project-lite@0.2.9
	pin-project@1.0.12
	pin-utils@0.1.0
	pkg-config@0.3.25
	plist@1.4.3
	png@0.17.6
	polling@2.8.0
	postgres-protocol@0.6.5
	postgres-types@0.2.4
	ppv-lite86@0.2.16
	pq-sys@0.4.7
	precomputed-hash@0.1.1
	proc-macro-error-attr@1.0.4
	proc-macro-error@1.0.4
	proc-macro2@1.0.64
	procfs@0.14.2
	prometheus@0.13.3
	prost-derive@0.11.0
	prost-types@0.11.1
	prost@0.11.0
	protobuf@2.28.0
	psm@0.1.21
	pulldown-cmark@0.9.3
	quanta@0.11.1
	quick-xml@0.27.1
	quick-xml@0.28.2
	quick-xml@0.29.0
	quote@1.0.29
	quoted_printable@0.4.8
	radium@0.5.3
	rand@0.7.3
	rand@0.8.5
	rand_chacha@0.2.2
	rand_chacha@0.3.1
	rand_core@0.5.1
	rand_core@0.6.4
	rand_hc@0.2.0
	rand_pcg@0.2.1
	raw-cpuid@10.7.0
	readonly@0.2.8
	redox_syscall@0.2.16
	regex-automata@0.1.10
	regex-automata@0.3.2
	regex-syntax@0.6.27
	regex-syntax@0.7.3
	regex@1.9.1
	remove_dir_all@0.5.3
	reqwest-middleware@0.2.2
	reqwest-tracing@0.4.5
	reqwest@0.11.18
	retain_mut@0.1.9
	rgb@0.8.34
	riff@1.0.1
	ring@0.16.20
	ron@0.7.1
	rosetta-build@0.1.3
	rosetta-i18n@0.1.3
	rss@2.0.4
	rust-ini@0.18.0
	rustc-demangle@0.1.21
	rustc_version@0.4.0
	rustix@0.36.5
	rustix@0.37.22
	rustls-webpki@0.101.1
	rustls@0.20.7
	rustls@0.21.3
	rustversion@1.0.9
	rusty-s3@0.4.1
	ryu@1.0.11
	safemem@0.3.3
	same-file@1.0.6
	schannel@0.1.20
	scheduled-thread-pool@0.2.7
	scoped-futures@0.1.3
	scopeguard@1.1.0
	scratch@1.0.2
	sct@0.7.0
	security-framework-sys@2.6.1
	security-framework@2.7.0
	select@0.5.0
	semver@1.0.14
	serde@1.0.171
	serde_cbor@0.11.2
	serde_derive@1.0.171
	serde_json@1.0.100
	serde_plain@1.0.1
	serde_spanned@0.6.2
	serde_urlencoded@0.7.1
	serde_with@3.0.0
	serde_with_macros@3.0.0
	serial_test@2.0.0
	serial_test_derive@2.0.0
	sha1@0.10.5
	sha2@0.10.7
	sharded-slab@0.1.4
	signal-hook-registry@1.4.0
	simple_asn1@0.6.2
	siphasher@0.3.10
	skeptic@0.13.7
	slab@0.4.7
	sled@0.34.7
	smallvec@1.10.0
	smart-default@0.7.1
	socket2@0.4.9
	socket2@0.5.3
	spin@0.5.2
	stacker@0.1.15
	static_assertions@1.1.0
	storage-path-generator@0.1.1
	string_cache@0.8.4
	string_cache_codegen@0.5.2
	stringprep@0.1.2
	strsim@0.10.0
	strum@0.25.0
	strum_macros@0.25.1
	subtle@2.4.1
	syn@1.0.103
	syn@2.0.25
	sync_wrapper@0.1.1
	syntect@5.0.0
	tagptr@0.2.0
	tap@1.0.1
	task-local-extensions@0.1.4
	tempfile@3.3.0
	tendril@0.4.3
	termcolor@1.1.3
	thiserror-impl@1.0.40
	thiserror@1.0.40
	thread_local@1.1.4
	time-macros@0.2.4
	time@0.1.44
	time@0.3.15
	tinyjson@2.5.0
	tinyvec@1.6.0
	tinyvec_macros@0.1.0
	tokio-io-timeout@1.2.0
	tokio-macros@2.1.0
	tokio-native-tls@0.3.0
	tokio-postgres-rustls@0.10.0
	tokio-postgres@0.7.8
	tokio-rustls@0.23.4
	tokio-rustls@0.24.1
	tokio-stream@0.1.11
	tokio-util@0.7.4
	tokio@1.29.1
	toml@0.5.9
	toml@0.7.4
	toml_datetime@0.6.2
	toml_edit@0.19.10
	tonic@0.8.2
	tonic@0.9.2
	totp-rs@5.0.2
	tower-http@0.3.4
	tower-layer@0.3.2
	tower-service@0.3.2
	tower@0.4.13
	tracing-actix-web@0.7.5
	tracing-attributes@0.1.23
	tracing-awc@0.1.7
	tracing-core@0.1.30
	tracing-error@0.2.0
	tracing-futures@0.2.5
	tracing-log@0.1.3
	tracing-opentelemetry@0.16.0
	tracing-opentelemetry@0.19.0
	tracing-serde@0.1.3
	tracing-subscriber@0.3.17
	tracing@0.1.37
	triomphe@0.1.8
	try-lock@0.2.3
	ts-rs-macros@6.2.0
	ts-rs@6.2.1
	typed-builder-macro@0.15.0
	typed-builder@0.15.0
	typenum@1.15.0
	ucd-trie@0.1.5
	unicase@2.6.0
	unicode-bidi@0.3.13
	unicode-general-category@0.6.0
	unicode-ident@1.0.5
	unicode-normalization@0.1.22
	unicode-width@0.1.10
	unicode-xid@0.2.4
	untrusted@0.7.1
	url@2.4.0
	urlencoding@2.1.2
	utf-8@0.7.6
	utf8-width@0.1.6
	uuid@1.4.0
	valuable@0.1.0
	vcpkg@0.2.15
	version_check@0.9.4
	waker-fn@1.1.0
	walkdir@2.3.2
	want@0.3.0
	wasi@0.10.0+wasi-snapshot-preview1
	wasi@0.11.0+wasi-snapshot-preview1
	wasi@0.9.0+wasi-snapshot-preview1
	wasm-bindgen-backend@0.2.83
	wasm-bindgen-futures@0.4.33
	wasm-bindgen-macro-support@0.2.83
	wasm-bindgen-macro@0.2.83
	wasm-bindgen-shared@0.2.83
	wasm-bindgen@0.2.83
	wasm-streams@0.2.3
	wav@1.0.0
	web-sys@0.3.60
	webmention@0.4.0
	webpage@1.6.0
	webpki-roots@0.22.5
	webpki@0.22.0
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-util@0.1.5
	winapi-x86_64-pc-windows-gnu@0.4.0
	winapi@0.3.9
	windows-sys@0.36.1
	windows-sys@0.42.0
	windows-sys@0.48.0
	windows-targets@0.48.0
	windows_aarch64_gnullvm@0.42.2
	windows_aarch64_gnullvm@0.48.0
	windows_aarch64_msvc@0.36.1
	windows_aarch64_msvc@0.42.2
	windows_aarch64_msvc@0.48.0
	windows_i686_gnu@0.36.1
	windows_i686_gnu@0.42.2
	windows_i686_gnu@0.48.0
	windows_i686_msvc@0.36.1
	windows_i686_msvc@0.42.2
	windows_i686_msvc@0.48.0
	windows_x86_64_gnu@0.36.1
	windows_x86_64_gnu@0.42.2
	windows_x86_64_gnu@0.48.0
	windows_x86_64_gnullvm@0.42.2
	windows_x86_64_gnullvm@0.48.0
	windows_x86_64_msvc@0.36.1
	windows_x86_64_msvc@0.42.2
	windows_x86_64_msvc@0.48.0
	winnow@0.4.6
	winreg@0.10.1
	wyz@0.2.0
	xml5ever@0.16.2
	xml5ever@0.17.0
	yaml-rust@0.4.5
	zeroize@1.5.7
	zstd-safe@6.0.5+zstd.1.5.4
	zstd-sys@2.0.8+zstd.1.5.5
	zstd@0.12.3+zstd.1.5.2
"
MYPV="${PV/_rc/-rc.}"
MYPN="lemmy"
S="${WORKDIR}/${MYPN}-${MYPV}"
KEYWORDS="~amd64 ~arm64"

if [ "${PV}" == "9999" ] || [ "$(ver_cut 3)" == "9999" ]; then
	unset CRATES S KEYWORDS
	EGIT_REPO_URI="https://github.com/LemmyNet/lemmy"
	inherit git-r3
fi
inherit cargo systemd flag-o-matic
DESCRIPTION="A link aggregator for the fediverse"
# Double check the homepage as the cargo_metadata crate
# does not provide this value so instead repository is used
HOMEPAGE="https://github.com/LemmyNet/lemmy"

if [ "${PV}" != "9999" ] && [ "$(ver_cut 3)" != "9999" ]; then
	SRC_URI="${CARGO_CRATE_URIS}
	https://github.com/LemmyNet/lemmy/archive/refs/tags/${MYPV}.tar.gz -> ${P}.tar.gz
	https://drive.google.com/uc?export=download&id=1fHlHWN-SUTv4-dINLgh9v0pq7tai6Hyv -> lemmy-translations-0.18.2.tar.xz"
fi

# License set may be more restrictive as OR is not respected
# use cargo@license for a more accurate license picture
LICENSE="0BSD AGPL-3 Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD BSD-2 Boost-1.0 CC0-1.0 GPL-3 GPL-3+ ISC MIT MIT-0 MPL-2.0 Unicode-DFS-2016 Unlicense ZLIB"
SLOT="0"

DEPEND="media-libs/gexiv2
	dev-db/postgresql:15=
	dev-libs/openssl:=
"

RDEPEND="${DEPEND}
media-gfx/imagemagick
media-video/ffmpeg
perl-gcpan/Image-ExifTool
acct-user/lemmy
acct-group/lemmy
"

BDEPEND="virtual/pkgconfig
	>=virtual/rust-1.70.0[rustfmt]" #todo test if rustfmt still needed, shouldnt be for 0.18.3+

# rust does not use *FLAGS from make.conf, silence portage warning
# update with proper path to binaries this crate installs, omit leading /
QA_FLAGS_IGNORED="usr/bin/lemmy_server"

IUSE="+embed-pictrs opentelemetry-console json-log"

src_unpack() {
	if [ "${PV}" == "9999" ]; then
		git-r3_src_unpack
		cargo_live_src_unpack
		default
	elif [ "$(ver_cut 3)" == "9999" ]; then
		EGIT_BRANCH="release/v$(ver_cut 1-2)"
		git-r3_src_unpack
		cargo_live_src_unpack
	else
	cargo_src_unpack
	fi
}
src_prepare() {
	default
	if [ "${PV}" != "9999" ] && [ $(ver_cut 3) != "9999" ]; then
		echo "pub const VERSION: &str = \"${MYPV}\";" > "crates/utils/src/version.rs"
	else
		echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs"
	fi
}

src_configure() {
	filter-lto  # can conflict with rusts lto setting/cause link issues.
	#gcc's lto causes link issues with undefined symbols that are part of ring
	# clangs untested. rust does enough of its own lto it shouldn't make much difference
	local myfeatures=(
		$(usex opentelemetry-console console "")
		$(usev embed-pictrs)
		$(usev json-log)
	)
	cargo_src_configure --frozen
}
src_install() {
	cargo_src_install
	insinto /etc/lemmy
	doins "${S}/config/config.hjson"
	doins "${S}/config/defaults.hjson"
	doins "${FILESDIR}/config.hjson.example"
	systemd_dounit "${FILESDIR}/lemmy.service"
	keepdir /var/lib/pictrs
	fowners lemmy:lemmy /var/lib/pictrs
}
pkg_preinst() {
	if has_version "${CATEGORY}/${PN}"; then
		export EXISTING_INSTALL=1
	fi
}
pkg_postinst() {
	if [ -z "${EXISTING_INSTALL}" ]; then
		einfo "This is the backend server"
		einfo "You probabily also want the nodejs based frontend"
		einfo "Install it from https://github.com/LemmyNet/lemmy-ui"
		einfo "See https://join-lemmy.org/docs/administration/from_scratch.html for details"
		einfo "Pict-rs storage is currently set to /var/lib/pictrs, adjust lemmy.service to change"
	fi
}