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

# Autogenerated by pycargoebuild 0.6.2

# OVERLAY NOTE -- WHY THIS MIRRORS ::gentoo AND HOW IT DIFFERS.
#
# ::gentoo builds this package from a single consolidated crate tarball
# published at github.com/gentoo-crate-dist/coreutils, normally within minutes
# of an upstream tag.  That tarball did not exist for 0.10.0 when this ebuild
# was written, so the crates are listed inline instead and fetched straight
# from crates.io; nothing has to be self-hosted.  The only other change from
# the ::gentoo 0.9.0 ebuild is the aggregated crate LICENSE list, which gained
# MPL-2.0 and lost Boost-1.0 in this release.
#
# DROP THIS EBUILD once ::gentoo ships 0.10.0 or newer -- it exists only to
# avoid waiting on that tarball, not to diverge from upstream Gentoo.
#
# Regenerate the CRATES block on a bump:
#   pycargoebuild -d /var/cache/distfiles -o out.ebuild <unpacked source>
# (crates.io rejects wget's default User-Agent; export a WGETRC that sets a
# browser one first.)

EAPI=8

CRATES="
	adler2@2.0.1
	aho-corasick@1.1.4
	allocator-api2@0.2.21
	android_system_properties@0.1.5
	ansi-width@0.1.0
	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.102
	approx@0.5.1
	arrayref@0.3.9
	arrayvec@0.7.6
	autocfg@1.5.0
	base64-simd@0.8.0
	bigdecimal@0.4.10
	binary-heap-plus@0.5.0
	bindgen@0.72.1
	bitflags@1.3.2
	bitflags@2.11.1
	bitvec@1.0.1
	blake2b_simd@1.0.4
	blake3@1.8.5
	block-buffer@0.12.0
	block2@0.6.2
	bstr@1.13.0
	bumpalo@3.20.2
	bytecount@0.6.9
	byteorder@1.5.0
	calendrical_calculations@0.2.4
	cc@1.2.59
	cexpr@0.6.0
	cfg-if@1.0.4
	cfg_aliases@0.2.2
	chacha20@0.10.0
	chrono@0.4.44
	clang-sys@1.8.1
	clap@4.6.5
	clap_builder@4.6.5
	clap_complete@4.6.8
	clap_lex@1.1.0
	clap_mangen@0.3.0
	codspeed-divan-compat-macros@5.0.1
	codspeed-divan-compat-walltime@5.0.1
	codspeed-divan-compat@5.0.1
	codspeed@5.0.1
	colorchoice@1.0.5
	colored@3.1.1
	compare@0.1.0
	condtype@1.3.0
	console@0.16.4
	const-oid@0.10.2
	const-random-macro@0.1.16
	const-random@0.1.18
	constant_time_eq@0.4.2
	core-foundation-sys@0.8.7
	core_maths@0.1.1
	cpufeatures@0.3.0
	crc-catalog@2.5.0
	crc-fast@1.9.0
	crc32fast@1.5.0
	crc@3.3.0
	crossbeam-deque@0.8.6
	crossbeam-epoch@0.9.20
	crossbeam-utils@0.8.21
	crossterm@0.29.0
	crossterm_winapi@0.9.1
	crunchy@0.2.4
	crypto-common@0.1.7
	crypto-common@0.2.1
	ctor@1.0.12
	ctrlc@3.5.2
	data-encoding-macro-internal@0.1.19
	data-encoding-macro@0.1.21
	data-encoding@2.11.1
	defmt-macros@1.1.1
	defmt-parser@1.0.0
	defmt@1.1.1
	deranged@0.5.8
	diff@0.1.13
	digest@0.10.7
	digest@0.11.3
	dispatch2@0.3.1
	displaydoc@0.2.7
	divan-macros@0.1.17
	dlv-list@0.5.2
	dns-lookup@3.0.1
	document-features@0.2.12
	dunce@1.0.5
	either@1.15.0
	encode_unicode@1.0.0
	equivalent@1.0.2
	errno@0.3.14
	fastrand@2.4.1
	file_diff@1.0.0
	filedescriptor@0.8.3
	filetime@0.2.29
	find-msvc-tools@0.1.9
	fixed_decimal@0.7.2
	flate2@1.1.9
	fluent-bundle@0.16.0
	fluent-langneg@0.13.1
	fluent-syntax@0.12.0
	fluent@0.17.0
	foldhash@0.2.0
	foreign-types-shared@0.1.1
	foreign-types@0.3.2
	fs_extra@1.3.0
	fsevent-sys@4.1.0
	fts-sys@0.2.17
	funty@2.0.0
	futures-core@0.3.32
	futures-macro@0.3.32
	futures-task@0.3.32
	futures-timer@3.0.3
	futures-util@0.3.32
	gcd@2.3.0
	generic-array@0.14.7
	getrandom@0.2.17
	getrandom@0.4.3
	glob@0.3.4
	half@2.7.1
	hashbrown@0.14.5
	hashbrown@0.16.1
	hex-literal@1.1.0
	hex@0.4.3
	hostname@0.4.2
	hybrid-array@0.4.10
	iana-time-zone-haiku@0.1.2
	iana-time-zone@0.1.65
	icu_calendar@2.2.1
	icu_calendar_data@2.2.0
	icu_collator@2.2.1
	icu_collator_data@2.2.0
	icu_collections@2.2.0
	icu_datetime@2.2.0
	icu_datetime_data@2.2.0
	icu_decimal@2.2.0
	icu_decimal_data@2.2.0
	icu_locale@2.2.0
	icu_locale_core@2.2.0
	icu_locale_data@2.2.0
	icu_normalizer@2.2.0
	icu_normalizer_data@2.2.0
	icu_pattern@0.4.2
	icu_plurals@2.2.0
	icu_plurals_data@2.2.0
	icu_properties@2.2.0
	icu_properties_data@2.2.0
	icu_provider@2.2.0
	icu_time@2.2.0
	icu_time_data@2.2.0
	indexmap@2.13.1
	indicatif@0.18.6
	inotify-sys@0.1.5
	inotify@0.11.1
	intl-memoizer@0.5.3
	intl_pluralrules@7.0.2
	is_terminal_polyfill@1.70.2
	itertools@0.13.0
	itertools@0.14.0
	itertools@0.15.0
	itoa@1.0.18
	jiff-core@0.1.0
	jiff-icu@0.2.2
	jiff-static@0.2.35
	jiff-tzdb-platform@0.1.3
	jiff-tzdb@0.1.8
	jiff@0.2.35
	js-sys@0.3.94
	keccak@0.2.0
	kqueue-sys@1.1.0
	kqueue@1.1.1
	libc@0.2.189
	libloading@0.8.9
	libm@0.2.16
	link-section@0.19.2
	linktime-proc-macro@0.2.2
	linux-raw-sys@0.12.1
	litemap@0.8.2
	litrs@1.0.0
	lock_api@0.4.14
	log@0.4.29
	lru@0.16.3
	lscolors@0.21.0
	md-5@0.11.0
	memchr@2.8.3
	memmap2@0.9.11
	memoffset@0.9.1
	minimal-lexical@0.2.1
	miniz_oxide@0.8.9
	mio@1.1.1
	nix@0.31.3
	nom@7.1.3
	nom@8.0.0
	notify-types@2.1.0
	notify@8.2.0
	nu-ansi-term@0.50.3
	num-bigint@0.4.8
	num-conv@0.2.2
	num-integer@0.1.46
	num-modular@0.6.1
	num-prime@0.5.0
	num-traits@0.2.19
	num_threads@0.1.7
	objc2-encode@4.1.0
	objc2@0.6.4
	once_cell@1.21.4
	once_cell_polyfill@1.70.2
	onig@6.5.3
	onig_sys@69.9.3
	openssl-macros@0.1.1
	openssl-src@300.5.5+3.5.5
	openssl-sys@0.9.117
	openssl@0.10.81
	ordered-multimap@0.7.3
	os_display@0.1.4
	outref@0.5.2
	parking_lot@0.12.5
	parking_lot_core@0.9.12
	parse_datetime@0.15.0
	phf@0.14.0
	phf_codegen@0.14.0
	phf_generator@0.14.0
	phf_shared@0.14.0
	pin-project-lite@0.2.17
	pkg-config@0.3.32
	platform-info@2.1.0
	portable-atomic-util@0.2.6
	portable-atomic@1.13.1
	potential_utf@0.1.5
	powerfmt@0.2.0
	ppv-lite86@0.2.21
	pretty_assertions@1.4.1
	prettyplease@0.2.37
	proc-macro-crate@3.5.0
	proc-macro2@1.0.107
	procfs-core@0.18.0
	procfs@0.18.0
	quote@1.0.47
	r-efi@6.0.0
	radium@0.7.0
	rand@0.10.2
	rand@0.8.6
	rand_chacha@0.10.0
	rand_chacha@0.3.1
	rand_core@0.10.0
	rand_core@0.6.4
	rayon-core@1.13.0
	rayon@1.12.0
	redox_syscall@0.5.18
	regex-automata@0.4.16
	regex-lite@0.1.9
	regex-syntax@0.8.11
	regex@1.13.1
	relative-path@1.9.3
	rlimit@0.11.0
	roff@1.1.1
	rstest@0.26.1
	rstest_macros@0.26.1
	rstest_reuse@0.7.0
	rust-ini@0.21.3
	rustc-hash@2.1.3
	rustc_version@0.4.1
	rustix@1.1.4
	rustversion@1.0.22
	same-file@1.0.6
	scopeguard@1.2.0
	self_cell@1.3.0
	selinux-sys@0.7.0
	selinux@0.6.3
	semver@1.0.28
	serde@1.0.228
	serde_core@1.0.228
	serde_derive@1.0.228
	serde_json@1.0.149
	sha1@0.11.0
	sha2@0.11.0
	sha3@0.12.0
	shake@0.1.0
	shlex@1.3.0
	signal-hook-mio@0.2.5
	signal-hook-registry@1.4.8
	signal-hook@0.3.18
	simd-adler32@0.3.9
	siphasher@1.0.2
	slab@0.4.12
	sm3@0.5.0
	smallvec@1.15.1
	smawk@0.3.2
	socket2@0.6.5
	spin@0.10.1
	sponge-cursor@0.1.0
	stable_deref_trait@1.2.1
	statrs@0.18.0
	string-interner@0.20.0
	strsim@0.11.1
	syn@2.0.117
	syn@3.0.2
	synstructure@0.13.2
	tap@1.0.1
	tempfile@3.27.0
	terminal_size@0.4.4
	textwrap@0.16.2
	thiserror-impl@1.0.69
	thiserror-impl@2.0.19
	thiserror@1.0.69
	thiserror@2.0.19
	time-core@0.1.9
	time-macros@0.2.32
	time@0.3.55
	tiny-keccak@2.0.2
	tinystr@0.8.3
	toml_datetime@1.1.1+spec-1.1.0
	toml_edit@0.25.11+spec-1.1.0
	toml_parser@1.1.2+spec-1.1.0
	type-map@0.5.1
	typed-path@0.12.3
	typenum@1.19.0
	unic-langid-impl@0.9.6
	unic-langid@0.9.6
	unicode-ident@1.0.24
	unicode-linebreak@0.1.5
	unicode-width@0.1.14
	unicode-width@0.2.2
	unindent@0.2.4
	unit-prefix@0.5.2
	utf16_iter@1.0.5
	utf8_iter@1.0.4
	utf8parse@0.2.2
	utmp-classic-raw@0.1.3
	utmp-classic@0.1.6
	uutils_term_grid@0.8.0
	vcpkg@0.2.15
	version_check@0.9.5
	vsimd@0.8.0
	walkdir@2.5.0
	wasi@0.11.1+wasi-snapshot-preview1
	wasm-bindgen-macro-support@0.2.117
	wasm-bindgen-macro@0.2.117
	wasm-bindgen-shared@0.2.117
	wasm-bindgen@0.2.117
	web-time@1.1.0
	wild@2.2.1
	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.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.59.0
	windows-sys@0.60.2
	windows-sys@0.61.2
	windows-targets@0.52.6
	windows-targets@0.53.5
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_gnullvm@0.53.1
	windows_aarch64_msvc@0.52.6
	windows_aarch64_msvc@0.53.1
	windows_i686_gnu@0.52.6
	windows_i686_gnu@0.53.1
	windows_i686_gnullvm@0.52.6
	windows_i686_gnullvm@0.53.1
	windows_i686_msvc@0.52.6
	windows_i686_msvc@0.53.1
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnu@0.53.1
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_gnullvm@0.53.1
	windows_x86_64_msvc@0.52.6
	windows_x86_64_msvc@0.53.1
	winnow@1.0.1
	write16@1.0.0
	writeable@0.6.3
	wyz@0.5.1
	xattr@1.6.1
	yansi@1.0.1
	yoke-derive@0.8.2
	yoke@0.8.2
	z85@3.0.7
	zerocopy-derive@0.7.35
	zerocopy-derive@0.8.55
	zerocopy@0.7.35
	zerocopy@0.8.55
	zerofrom-derive@0.1.7
	zerofrom@0.1.7
	zerotrie@0.2.4
	zerovec-derive@0.11.3
	zerovec@0.11.6
	zip@8.6.0
	zlib-rs@0.6.3
	zmij@1.0.23
	zopfli@0.8.3
"

RUST_MIN_VER="1.88.0"
LLVM_COMPAT=( {17..22} )
inherit cargo flag-o-matic llvm-r2 multiprocessing

DESCRIPTION="GNU coreutils rewritten in Rust"
HOMEPAGE="https://uutils.github.io/coreutils/ https://github.com/uutils/coreutils"

if [[ ${PV} == 9999 ]] ; then
	EGIT_REPO_URI="https://github.com/uutils/coreutils"
	inherit git-r3
elif [[ ${PV} == *_p* ]] ; then
	COREUTILS_COMMIT=""
	SRC_URI="https://github.com/uutils/coreutils/archive/${COREUTILS_COMMIT}.tar.gz -> ${P}.tar.gz"
	S="${WORKDIR}"/coreutils-${COREUTILS_COMMIT}
else
	SRC_URI="https://github.com/uutils/coreutils/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz"
	S="${WORKDIR}"/coreutils-${PV}

	KEYWORDS="~amd64 ~arm64 ~ppc64"
fi

if [[ ${PV} != 9999 ]] ; then
	SRC_URI+=" ${CARGO_CRATE_URIS}"
fi

LICENSE="MIT"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 BSD-2 BSD CC0-1.0 ISC MIT MPL-2.0 Unicode-3.0 ZLIB
"
SLOT="0"
IUSE="debug selinux test"
RESTRICT="!test? ( test )"

DEPEND="
	dev-libs/oniguruma:=
	selinux? ( sys-libs/libselinux )
"
RDEPEND="${DEPEND}"
BDEPEND="
	test? ( dev-util/cargo-nextest )
	selinux? (
		$(llvm_gen_dep '
			llvm-core/clang:${LLVM_SLOT}
		')
	)
"
QA_FLAGS_IGNORED=".*"

pkg_setup() {
	llvm-r2_pkg_setup
	rust_pkg_setup
}

src_unpack() {
	if [[ ${PV} == 9999 ]] ; then
		git-r3_src_unpack
		cargo_live_src_unpack
	else
		cargo_src_unpack
	fi
}

src_prepare() {
	default
	# This is should be a set of env vars in upstream CI
	rm -f "${S}/.cargo/config.toml"

	# Upstream convention for bash-completions clashes with our own
	sed -i -e 's:\.bash::' "${S}/GNUmakefile" || die
}

src_compile() {
	# normally cargo_src_compile sets this for us, but we don't use it
	filter-lto

	# By default, the crate uses a system version if it can. This just guarantees
	# that it will error out instead of building a vendored copy.
	export RUSTONIG_SYSTEM_LIBONIG=1

	makeargs=(
		# Disable output synchronisation as make calls cargo
		-Onone

		V=1

		PROFILE=$(usex debug debug release)

		PREFIX="${EPREFIX}/usr"
		PROG_PREFIX="uu-"
		MULTICALL=y
		MANDIR="/share/man/man1"

		SELINUX_ENABLED=$(usex selinux 1 0)

		# pinky, uptime, users, and who require utmpx (not available on musl)
		# bug #832868
		SKIP_UTILS="$(usev elibc_musl "pinky uptime users who")"

		# bug #963516
		LIBSTDBUF_DIR="${EPREFIX}/usr/libexec/${PN}"
	)

	emake "${makeargs[@]}"
}

src_test() {
	local -x RUST_BACKTRACE=full
	local -x NEXTEST_TEST_THREADS="$(makeopts_jobs)"

	# Nicer output for nextest vs test
	emake "${makeargs[@]}" \
		CARGOFLAGS="${CARGOFLAGS} $(usev !debug --release)" \
		TEST_NO_FAIL_FAST="--no-fail-fast" \
		nextest
}

src_install() {
	emake "${makeargs[@]}" DESTDIR="${D}" install
}