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

# Autogenerated by pycargoebuild 0.17.1

EAPI=8

RUST_MIN_VER="1.85.0"

CRATES="
	adler2@2.0.1
	android_system_properties@0.1.6
	anstream@1.0.0
	anstyle-parse@1.0.0
	anstyle-query@1.1.5
	anstyle-wincon@3.0.11
	anstyle@1.0.14
	anyhow@1.0.104
	autocfg@1.5.1
	bitflags@2.13.1
	blazesym@0.2.3
	bumpalo@3.20.3
	camino@1.2.5
	cargo-platform@0.1.9
	cargo_metadata@0.19.2
	cc@1.4.4
	cfg-if@1.0.4
	cfg_aliases@0.2.2
	chrono@0.4.45
	clap@4.6.6
	clap_builder@4.6.6
	clap_derive@4.6.4
	clap_lex@1.1.0
	colorchoice@1.0.5
	core-foundation-sys@0.8.7
	cpp_demangle@0.5.1
	equivalent@1.0.2
	errno@0.3.14
	fallible-iterator@0.3.0
	fastrand@2.5.0
	find-msvc-tools@0.1.11
	futures-core@0.3.34
	futures-task@0.3.34
	futures-util@0.3.34
	getrandom@0.4.3
	gimli@0.32.3
	hashbrown@0.17.1
	heck@0.5.0
	iana-time-zone-haiku@0.1.2
	iana-time-zone@0.1.65
	indexmap@2.14.0
	is_terminal_polyfill@1.70.2
	itoa@1.0.18
	js-sys@0.3.104
	lazy_static@1.5.0
	libbpf-cargo@0.27.0
	libbpf-rs@0.27.0
	libbpf-sys@1.7.0+v1.7.0
	libc@0.2.189
	linux-raw-sys@0.12.1
	log@0.4.34
	memchr@2.8.3
	memmap2@0.9.11
	miniz_oxide@0.9.1
	nix@0.31.3
	nu-ansi-term@0.50.3
	num-traits@0.2.19
	once_cell@1.21.4
	once_cell_polyfill@1.70.2
	pin-project-lite@0.2.17
	pkg-config@0.3.34
	proc-macro2@1.0.107
	quote@1.0.47
	r-efi@6.0.0
	rustc-demangle@0.1.28
	rustix@1.1.4
	rustversion@1.0.23
	semver@1.0.28
	serde@1.0.229
	serde_core@1.0.229
	serde_derive@1.0.229
	serde_json@1.0.151
	sharded-slab@0.1.7
	shlex@2.0.1
	signal-hook-registry@1.4.8
	signal-hook@0.3.18
	simd-adler32@0.3.10
	slab@0.4.12
	stable_deref_trait@1.2.1
	strsim@0.11.1
	syn@2.0.119
	syn@3.0.4
	tempfile@3.27.0
	thiserror-impl@2.0.20
	thiserror@2.0.20
	thread_local@1.1.10
	tracing-core@0.1.36
	tracing-subscriber@0.3.23
	tracing@0.1.44
	unicode-ident@1.0.24
	utf8parse@0.2.2
	vsprintf@2.0.0
	wasm-bindgen-macro-support@0.2.127
	wasm-bindgen-macro@0.2.127
	wasm-bindgen-shared@0.2.127
	wasm-bindgen@0.2.127
	windows-core@0.62.2
	windows-implement@0.60.2
	windows-interface@0.59.3
	windows-link@0.2.1
	windows-result@0.4.1
	windows-strings@0.5.1
	windows-sys@0.61.2
	zmij@1.0.23
"

inherit cargo

MY_PN="ProcDump-Linux"

DESCRIPTION="Linux port of the Sysinternals ProcDump tool"
HOMEPAGE="https://github.com/microsoft/ProcDump-Linux"
SRC_URI="https://github.com/microsoft/${MY_PN}/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz
	${CARGO_CRATE_URIS}"
S="${WORKDIR}/${MY_PN}-${PV}"

LICENSE="MIT"
# Dependent crate licenses
LICENSE+=" BSD-2 BSD MIT Unicode-3.0"
SLOT="0"
KEYWORDS="~amd64"

RDEPEND="dev-libs/elfutils
	virtual/zlib:="
DEPEND="${RDEPEND}"
# clang compiles the eBPF program.
BDEPEND="llvm-core/clang
	virtual/pkgconfig"

src_prepare() {
	default
	# Newer Clang turns the eBPF program's byte-zeroing loop into a memset() call, which BPF
	# cannot link.
	sed -e 's/^\(\s*\)"-Wno-unknown-warning-option".into(),$/&\n\1"-fno-builtin-memset".into(),/' \
		-i crates/procdump/build.rs || die
	grep -q 'fno-builtin-memset' crates/procdump/build.rs || die "failed to patch build.rs"
}

src_compile() {
	# The embedded .NET profiler uses MSVC extensions that only Clang accepts; upstream's build
	# script falls back to clang++ when CXX is unset.
	local -x CXX="${CHOST}-clang++"
	cargo_src_compile --package procdump-cli --bin procdump
}

src_install() {
	dobin "$(cargo_target_dir)/procdump"
	doman procdump.1
	einstalldocs
}