# Template file for 'scx'
pkgname=scx
version=1.1.1
revision=1
archs="x86_64* aarch64*"
build_style=cargo
# test_thread_operations: tries to read procfs dynamically
# cpuset tests are odd on my system, I'm planning to investigate them later
# with bwrap containment even more fail
_skip_tests="test_thread_operations
 test_borrowable_cpumasks_respects_cpuset
 test_cpuset_parsing_from_file
 test_deficit_all_cells_exceed_target
 test_symmetric_pairwise_overlap_produces_equal_cells
 test_to_cpulist_roundtrip"
make_check_args="-- --skip ${_skip_tests// / --skip }"
hostmakedepends="clang pkg-config elfutils-devel libseccomp-devel"
makedepends="libbpf-devel zlib-devel libzstd-devel libseccomp-devel"
short_desc="Sched_ext schedulers and tools"
maintainer="Chloé Vulquin <code@toast.bunkerlabs.net>"
license="GPL-2.0-only"
homepage="https://github.com/sched-ext/scx"
distfiles="https://github.com/sched-ext/scx/archive/refs/tags/v${version}.tar.gz"
checksum=1b162f0a198e379fc1f7016505b78c236acb63d1b8f22d66a4b6fd762ec592fb

pre_build() {
	# workaround the cc-rs mixing CFLAGS for host and target.
	# https://github.com/rust-lang/cc-rs/issues/1469
	export CFLAGS_${RUST_BUILD//-/_}="${CFLAGS_host}" \
		   CXXFLAGS_${RUST_BUILD//-/_}="${CXXFLAGS_host}" \
		   LDFLAGS_${RUST_BUILD//-/_}="${LDFLAGS_host}" \
		   CFLAGS_${RUST_TARGET//-/_}="${CFLAGS}" \
		   CXXFLAGS_${RUST_TARGET//-/_}="${CXXFLAGS}" \
		   LDFLAGS_${RUST_TARGET//-/_}="${LDFLAGS}" \
		   CFLAGS="" CXXFLAGS="" LDFLAGS=""
}

# cargo install does not support workspaces
# alternative: specify the wanted packages only
# requires setting do_* manually, but avoids useless build time
do_install() {
	# POSIX for find … -maxdepth 1 -executable
	find target/"$RUST_TARGET"/release \
		! -path target/"$RUST_TARGET"/release -prune \
		-type f -perm -0100 -name 'scx*' \
		! -name scx_arena_selftests \
		-exec install -Dm755 -t "$PKGDESTDIR"/usr/bin '{}' \+
}

post_install() {
	vinstall "${FILESDIR}"/00-pseudofs-scx.sh 644 /etc/runit/core-services
}
