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

EAPI=8

RUST_MIN_VER="1.89.0"
CRATES="
	adler2@2.0.1
	aho-corasick@1.1.4
	alloc-no-stdlib@2.0.4
	alloc-stdlib@0.2.2
	android_system_properties@0.1.5
	anyhow@1.0.104
	arbitrary@1.4.2
	arboard@3.6.1
	async-broadcast@0.7.2
	async-channel@2.5.0
	async-executor@1.14.0
	async-io@2.6.0
	async-lock@3.4.2
	async-process@2.5.0
	async-recursion@1.1.1
	async-signal@0.2.13
	async-task@4.7.1
	async-trait@0.1.89
	atk-sys@0.18.2
	atk@0.18.2
	atomic-waker@1.1.2
	auto-launch@0.5.0
	autocfg@1.5.0
	aws-lc-rs@1.17.3
	aws-lc-sys@0.43.0
	base64@0.21.7
	base64@0.22.1
	base64@0.23.1
	bit-set@0.8.0
	bit-vec@0.8.0
	bitflags@1.3.2
	bitflags@2.11.0
	block-buffer@0.10.4
	block-buffer@0.12.1
	block2@0.6.2
	blocking@1.6.2
	brotli-decompressor@5.0.0
	brotli@8.0.2
	bumpalo@3.20.2
	bytemuck@1.25.0
	byteorder-lite@0.1.0
	byteorder@1.5.0
	bytes@1.11.1
	cairo-rs@0.18.5
	cairo-sys-rs@0.18.2
	camino@1.2.2
	cargo-platform@0.1.9
	cargo_metadata@0.19.2
	cargo_toml@0.22.3
	cc@1.2.57
	cesu8@1.1.0
	cfb@0.7.3
	cfg-expr@0.15.8
	cfg-if@1.0.4
	cfg_aliases@0.2.1
	chacha20@0.10.0
	chrono@0.4.44
	clipboard-win@5.4.1
	cmake@0.1.58
	cmov@0.5.4
	combine@4.6.7
	concurrent-queue@2.5.0
	const-oid@0.10.2
	const-random-macro@0.1.16
	const-random@0.1.18
	convert_case@0.4.0
	cookie@0.18.1
	core-foundation-sys@0.8.7
	core-foundation@0.10.1
	core-foundation@0.9.4
	core-graphics-types@0.2.0
	core-graphics@0.25.0
	cpufeatures@0.2.17
	cpufeatures@0.3.0
	crc32fast@1.5.0
	crossbeam-channel@0.5.15
	crossbeam-utils@0.8.21
	crunchy@0.2.4
	crypto-common@0.1.7
	crypto-common@0.2.2
	cssparser-macros@0.6.1
	cssparser@0.29.6
	cssparser@0.36.0
	ctor-proc-macro@0.0.7
	ctor@0.8.0
	ctutils@0.4.2
	darling@0.23.0
	darling_core@0.23.0
	darling_macro@0.23.0
	dbus@0.9.11
	deranged@0.5.8
	derive_arbitrary@1.4.2
	derive_more-impl@2.1.1
	derive_more@0.99.20
	derive_more@2.1.1
	digest@0.10.7
	digest@0.11.3
	dirs-sys@0.3.7
	dirs-sys@0.5.0
	dirs@4.0.0
	dirs@6.0.0
	dispatch2@0.3.1
	displaydoc@0.2.5
	dlopen2@0.8.2
	dlopen2_derive@0.4.3
	dlv-list@0.5.2
	dom_query@0.27.0
	downcast-rs@1.2.1
	dpi@0.1.2
	dtoa-short@0.3.5
	dtoa@1.0.11
	dtor-proc-macro@0.0.6
	dtor@0.3.0
	dunce@1.0.5
	dyn-clone@1.0.20
	elevated-command@1.1.3
	embed-resource@3.0.7
	embed_plist@1.2.2
	encoding_rs@0.8.35
	endi@1.1.1
	enumflags2@0.7.12
	enumflags2_derive@0.7.12
	equivalent@1.0.2
	erased-serde@0.4.10
	errno@0.3.14
	error-code@3.3.2
	event-listener-strategy@0.5.4
	event-listener@5.4.2
	fastrand@2.3.0
	fax@0.2.7
	fdeflate@0.3.7
	field-offset@0.3.6
	filetime@0.2.27
	find-msvc-tools@0.1.9
	fixedbitset@0.5.7
	flate2@1.1.9
	fnv@1.0.7
	foldhash@0.1.5
	foldhash@0.2.0
	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
	futf@0.1.5
	futures-channel@0.3.32
	futures-core@0.3.32
	futures-executor@0.3.32
	futures-io@0.3.32
	futures-lite@2.6.1
	futures-macro@0.3.32
	futures-sink@0.3.32
	futures-task@0.3.32
	futures-util@0.3.32
	fxhash@0.2.1
	gdk-pixbuf-sys@0.18.0
	gdk-pixbuf@0.18.5
	gdk-sys@0.18.2
	gdk@0.18.2
	gdkwayland-sys@0.18.2
	gdkx11-sys@0.18.2
	gdkx11@0.18.2
	generic-array@0.14.7
	gethostname@1.1.0
	getrandom@0.1.16
	getrandom@0.2.17
	getrandom@0.3.4
	getrandom@0.4.2
	gio-sys@0.18.1
	gio@0.18.4
	glib-macros@0.18.5
	glib-sys@0.18.1
	glib@0.18.5
	glob@0.3.3
	gobject-sys@0.18.0
	gtk-sys@0.18.2
	gtk3-macros@0.18.2
	gtk@0.18.2
	h2@0.4.13
	half@2.7.1
	hashbrown@0.12.3
	hashbrown@0.14.5
	hashbrown@0.15.5
	hashbrown@0.16.1
	heck@0.4.1
	heck@0.5.0
	hermit-abi@0.5.2
	hex@0.4.3
	hmac@0.13.0
	home@0.5.12
	html5ever@0.29.1
	html5ever@0.38.0
	http-body-util@0.1.3
	http-body@1.0.1
	http@1.4.0
	httparse@1.10.1
	hybrid-array@0.4.12
	hyper-rustls@0.27.7
	hyper-util@0.1.20
	hyper@1.8.1
	iana-time-zone-haiku@0.1.2
	iana-time-zone@0.1.65
	ico@0.5.0
	icu_collections@2.1.1
	icu_locale_core@2.1.1
	icu_normalizer@2.1.1
	icu_normalizer_data@2.1.1
	icu_properties@2.1.2
	icu_properties_data@2.1.2
	icu_provider@2.1.1
	id-arena@2.3.0
	ident_case@1.0.1
	idna@1.1.0
	idna_adapter@1.2.1
	image@0.25.10
	indexmap@1.9.3
	indexmap@2.13.0
	infer@0.19.0
	ipnet@2.12.0
	iri-string@0.7.10
	is-docker@0.2.0
	is-wsl@0.4.0
	itoa@1.0.18
	javascriptcore-rs-sys@1.1.1
	javascriptcore-rs@1.1.2
	jni-sys-macros@0.4.1
	jni-sys@0.3.1
	jni-sys@0.4.1
	jni@0.21.1
	jobserver@0.1.35
	js-sys@0.3.91
	json-patch@3.0.1
	jsonptr@0.6.3
	keyboard-types@0.7.0
	kuchikiki@0.8.8-speedreader
	leb128fmt@0.1.0
	libappindicator-sys@0.9.0
	libappindicator@0.9.0
	libc@0.2.189
	libdbus-sys@0.2.7
	libloading@0.7.4
	libredox@0.1.14
	linux-raw-sys@0.12.1
	litemap@0.8.1
	lock_api@0.4.14
	log@0.4.34
	lru-slab@0.1.2
	mac-notification-sys@0.6.12
	mac@0.1.1
	markup5ever@0.14.1
	markup5ever@0.38.0
	match_token@0.1.0
	matches@0.1.10
	memchr@2.8.0
	memoffset@0.9.1
	mime@0.3.17
	minisign-verify@0.2.5
	miniz_oxide@0.8.9
	mio@1.2.1
	moxcms@0.8.1
	muda@0.19.2
	ndk-sys@0.6.0+11769913
	ndk@0.9.0
	new_debug_unreachable@1.0.6
	nix@0.31.2
	nodrop@0.1.14
	nom@8.0.0
	notify-rust@4.16.1
	num-conv@0.2.2
	num-traits@0.2.19
	num_enum@0.7.6
	num_enum_derive@0.7.6
	num_threads@0.1.7
	objc2-app-kit@0.3.2
	objc2-cloud-kit@0.3.2
	objc2-core-data@0.3.2
	objc2-core-foundation@0.3.2
	objc2-core-graphics@0.3.2
	objc2-core-image@0.3.2
	objc2-core-location@0.3.2
	objc2-core-text@0.3.2
	objc2-encode@4.1.0
	objc2-exception-helper@0.1.1
	objc2-foundation@0.3.2
	objc2-io-surface@0.3.2
	objc2-osa-kit@0.3.2
	objc2-quartz-core@0.3.2
	objc2-ui-kit@0.3.2
	objc2-user-notifications@0.3.2
	objc2-web-kit@0.3.2
	objc2@0.6.4
	once_cell@1.21.4
	open@5.4.1
	openssl-probe@0.2.1
	option-ext@0.2.0
	ordered-multimap@0.7.3
	ordered-stream@0.2.0
	os_pipe@1.2.3
	osakit@0.3.1
	pango-sys@0.18.0
	pango@0.18.3
	parking@2.2.1
	parking_lot@0.12.5
	parking_lot_core@0.9.12
	percent-encoding@2.3.2
	petgraph@0.8.3
	phf@0.10.1
	phf@0.11.3
	phf@0.13.1
	phf@0.8.0
	phf_codegen@0.11.3
	phf_codegen@0.13.1
	phf_codegen@0.8.0
	phf_generator@0.10.0
	phf_generator@0.11.3
	phf_generator@0.13.1
	phf_generator@0.8.0
	phf_macros@0.10.0
	phf_macros@0.13.1
	phf_shared@0.10.0
	phf_shared@0.11.3
	phf_shared@0.13.1
	phf_shared@0.8.0
	pin-project-lite@0.2.17
	pin-utils@0.1.0
	piper@0.2.5
	pkg-config@0.3.32
	plain@0.2.3
	plist@1.8.0
	png@0.17.16
	png@0.18.1
	polling@3.11.0
	potential_utf@0.1.4
	powerfmt@0.2.0
	ppv-lite86@0.2.21
	precomputed-hash@0.1.1
	prettyplease@0.2.37
	proc-macro-crate@1.3.1
	proc-macro-crate@2.0.2
	proc-macro-crate@3.5.0
	proc-macro-error-attr@1.0.4
	proc-macro-error@1.0.4
	proc-macro-hack@0.5.20+deprecated
	proc-macro2@1.0.106
	process-wrap@9.1.0
	pxfm@0.1.29
	quick-error@2.0.1
	quick-xml@0.37.5
	quick-xml@0.38.4
	quick-xml@0.39.2
	quinn-proto@0.11.16
	quinn-udp@0.5.15
	quinn@0.11.11
	quote@1.0.45
	r-efi@5.3.0
	r-efi@6.0.0
	rand@0.10.2
	rand@0.7.3
	rand@0.8.6
	rand@0.9.4
	rand_chacha@0.2.2
	rand_chacha@0.3.1
	rand_chacha@0.9.0
	rand_core@0.10.0
	rand_core@0.5.1
	rand_core@0.6.4
	rand_core@0.9.5
	rand_hc@0.2.0
	rand_pcg@0.10.2
	rand_pcg@0.2.1
	raw-window-handle@0.6.2
	redox_syscall@0.5.18
	redox_syscall@0.7.3
	redox_users@0.4.6
	redox_users@0.5.2
	ref-cast-impl@1.0.25
	ref-cast@1.0.25
	regex-automata@0.4.18
	regex-syntax@0.8.11
	regex@1.13.1
	reqwest@0.13.4
	rfd@0.16.0
	ring@0.17.14
	rust-ini@0.21.3
	rustc-hash@2.1.1
	rustc_version@0.4.1
	rustix@1.1.4
	rustls-native-certs@0.8.3
	rustls-pki-types@1.14.0
	rustls-platform-verifier-android@0.1.1
	rustls-platform-verifier@0.6.2
	rustls-webpki@0.103.13
	rustls@0.23.37
	rustversion@1.0.22
	same-file@1.0.6
	schannel@0.1.29
	schemars@0.8.22
	schemars@0.9.0
	schemars@1.2.1
	schemars_derive@0.8.22
	scopeguard@1.2.0
	security-framework-sys@2.17.0
	security-framework@3.7.0
	selectors@0.24.0
	selectors@0.36.1
	semver@1.0.27
	serde-untagged@0.1.9
	serde@1.0.229
	serde_core@1.0.229
	serde_derive@1.0.229
	serde_derive_internals@0.29.1
	serde_json@1.0.151
	serde_repr@0.1.20
	serde_spanned@0.6.9
	serde_spanned@1.1.1
	serde_with@3.18.0
	serde_with_macros@3.18.0
	serialize-to-javascript-impl@0.1.2
	serialize-to-javascript@0.1.2
	servo_arc@0.2.0
	servo_arc@0.4.3
	sha2@0.10.9
	sha2@0.11.0
	shlex@1.3.0
	signal-hook-registry@1.4.8
	signal-hook@0.4.4
	simd-adler32@0.3.8
	simplelog@0.12.2
	siphasher@0.3.11
	siphasher@1.0.2
	slab@0.4.12
	smallvec@1.15.1
	socket2@0.6.3
	softbuffer@0.4.8
	soup3-sys@0.5.0
	soup3@0.5.0
	stable_deref_trait@1.2.1
	string_cache@0.8.9
	string_cache@0.9.0
	string_cache_codegen@0.5.4
	string_cache_codegen@0.6.1
	strip-ansi-escapes@0.2.1
	strsim@0.11.1
	subtle@2.6.1
	swift-rs@1.0.7
	syn@1.0.109
	syn@2.0.117
	syn@3.0.3
	sync_wrapper@1.0.2
	synstructure@0.13.2
	system-configuration-sys@0.6.0
	system-configuration@0.7.0
	system-deps@6.2.2
	tao-macros@0.1.3
	tao@0.35.3
	tar@0.4.46
	target-lexicon@0.12.16
	tauri-build@2.6.3
	tauri-codegen@2.6.3
	tauri-macros@2.6.3
	tauri-plugin-autostart@2.5.1
	tauri-plugin-clipboard-manager@2.3.2
	tauri-plugin-deep-link@2.4.9
	tauri-plugin-dialog@2.7.2
	tauri-plugin-fs@2.5.1
	tauri-plugin-notification@2.3.3
	tauri-plugin-opener@2.5.4
	tauri-plugin-process@2.3.1
	tauri-plugin-single-instance@2.4.3
	tauri-plugin-updater@2.10.1
	tauri-plugin-window-state@2.4.1
	tauri-plugin@2.5.4
	tauri-runtime-wry@2.11.4
	tauri-runtime@2.11.3
	tauri-utils@2.9.3
	tauri-winres@0.3.5
	tauri-winrt-notification@0.7.2
	tauri@2.11.5
	tempfile@3.27.0
	tendril@0.4.3
	tendril@0.5.0
	termcolor@1.4.1
	thiserror-impl@1.0.69
	thiserror-impl@2.0.18
	thiserror@1.0.69
	thiserror@2.0.18
	tiff@0.11.3
	time-core@0.1.9
	time-macros@0.2.32
	time@0.3.55
	tiny-keccak@2.0.2
	tinystr@0.8.2
	tinyvec@1.12.0
	tinyvec_macros@0.1.1
	tokio-macros@2.7.0
	tokio-rustls@0.26.4
	tokio-util@0.7.18
	tokio@1.53.1
	toml@0.8.2
	toml@0.9.12+spec-1.1.0
	toml@1.1.2+spec-1.1.0
	toml_datetime@0.6.3
	toml_datetime@0.7.5+spec-1.1.0
	toml_datetime@1.1.1+spec-1.1.0
	toml_edit@0.19.15
	toml_edit@0.20.2
	toml_edit@0.25.5+spec-1.1.0
	toml_parser@1.1.2+spec-1.1.0
	toml_writer@1.1.1+spec-1.1.0
	tower-http@0.6.8
	tower-layer@0.3.3
	tower-service@0.3.3
	tower@0.5.3
	tracing-attributes@0.1.31
	tracing-core@0.1.36
	tracing@0.1.44
	tray-icon@0.24.2
	tree_magic_mini@3.2.2
	try-lock@0.2.5
	typeid@1.0.3
	typenum@1.20.1
	uds_windows@1.2.1
	unic-char-property@0.9.0
	unic-char-range@0.9.0
	unic-common@0.9.0
	unic-ucd-ident@0.9.0
	unic-ucd-version@0.9.0
	unicode-ident@1.0.24
	unicode-segmentation@1.12.0
	unicode-xid@0.2.6
	untrusted@0.9.0
	url@2.5.8
	urlpattern@0.3.0
	utf-8@0.7.6
	utf8_iter@1.0.4
	uuid@1.22.0
	version-compare@0.2.1
	version_check@0.9.5
	vswhom-sys@0.1.3
	vswhom@0.1.0
	vte@0.14.1
	walkdir@2.5.0
	want@0.3.1
	wasi@0.11.1+wasi-snapshot-preview1
	wasi@0.9.0+wasi-snapshot-preview1
	wasip2@1.0.2+wasi-0.2.9
	wasip3@0.4.0+wasi-0.3.0-rc-2026-01-06
	wasm-bindgen-futures@0.4.64
	wasm-bindgen-macro-support@0.2.114
	wasm-bindgen-macro@0.2.114
	wasm-bindgen-shared@0.2.114
	wasm-bindgen@0.2.114
	wasm-encoder@0.244.0
	wasm-metadata@0.244.0
	wasm-streams@0.5.0
	wasmparser@0.244.0
	wayland-backend@0.3.15
	wayland-client@0.31.14
	wayland-protocols-wlr@0.3.12
	wayland-protocols@0.32.12
	wayland-scanner@0.31.10
	wayland-sys@0.31.11
	web-sys@0.3.91
	web-time@1.1.0
	web_atoms@0.2.3
	webkit2gtk-sys@2.0.2
	webkit2gtk@2.0.2
	webpki-root-certs@1.0.6
	webview2-com-macros@0.8.1
	webview2-com-sys@0.38.2
	webview2-com@0.38.2
	weezl@0.1.12
	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
	window-vibrancy@0.6.0
	windows-collections@0.2.0
	windows-collections@0.3.2
	windows-core@0.52.0
	windows-core@0.61.2
	windows-core@0.62.2
	windows-future@0.2.1
	windows-future@0.3.2
	windows-implement@0.60.2
	windows-interface@0.59.3
	windows-link@0.1.3
	windows-link@0.2.1
	windows-numerics@0.2.0
	windows-numerics@0.3.1
	windows-registry@0.5.3
	windows-result@0.3.4
	windows-result@0.4.1
	windows-strings@0.4.2
	windows-strings@0.5.1
	windows-sys@0.45.0
	windows-sys@0.52.0
	windows-sys@0.59.0
	windows-sys@0.60.2
	windows-sys@0.61.2
	windows-targets@0.42.2
	windows-targets@0.52.6
	windows-targets@0.53.5
	windows-threading@0.1.0
	windows-threading@0.2.1
	windows-version@0.1.7
	windows@0.52.0
	windows@0.61.3
	windows@0.62.2
	windows_aarch64_gnullvm@0.42.2
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_gnullvm@0.53.1
	windows_aarch64_msvc@0.42.2
	windows_aarch64_msvc@0.52.6
	windows_aarch64_msvc@0.53.1
	windows_i686_gnu@0.42.2
	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.42.2
	windows_i686_msvc@0.52.6
	windows_i686_msvc@0.53.1
	windows_x86_64_gnu@0.42.2
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnu@0.53.1
	windows_x86_64_gnullvm@0.42.2
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_gnullvm@0.53.1
	windows_x86_64_msvc@0.42.2
	windows_x86_64_msvc@0.52.6
	windows_x86_64_msvc@0.53.1
	winnow@0.5.40
	winnow@0.7.15
	winnow@1.0.0
	winreg@0.10.1
	winreg@0.55.0
	wit-bindgen-core@0.51.0
	wit-bindgen-rust-macro@0.51.0
	wit-bindgen-rust@0.51.0
	wit-bindgen@0.51.0
	wit-component@0.244.0
	wit-parser@0.244.0
	wl-clipboard-rs@0.9.3
	writeable@0.6.2
	wry@0.55.1
	x11-dl@2.21.0
	x11@2.21.0
	x11rb-protocol@0.13.2
	x11rb@0.13.2
	xattr@1.6.1
	yoke-derive@0.8.1
	yoke@0.8.1
	zbus@5.14.0
	zbus_macros@5.14.0
	zbus_names@4.3.1
	zerocopy-derive@0.8.47
	zerocopy@0.8.47
	zerofrom-derive@0.1.6
	zerofrom@0.1.6
	zeroize@1.8.2
	zerotrie@0.2.3
	zerovec-derive@0.11.2
	zerovec@0.11.5
	zip@4.6.1
	zmij@1.0.21
	zune-core@0.5.1
	zune-jpeg@0.5.15
	zvariant@5.10.0
	zvariant_derive@5.10.0
	zvariant_utils@3.3.0
"

declare -A GIT_CRATES=(
	[fix-path-env]='https://github.com/tauri-apps/fix-path-env-rs;c4c45d503ea115a839aae718d02f79e7c7f0f673;fix-path-env-rs-%commit%'
)

inherit cargo desktop xdg

DESCRIPTION="Tauri desktop UI to run and train AI models locally with Unsloth"
HOMEPAGE="
	https://unsloth.ai/docs/desktop
	https://github.com/unslothai/unsloth
"
SRC_URI="
	https://github.com/unslothai/unsloth/archive/refs/tags/v${PV/_beta/-beta}.tar.gz -> ${P}.gh.tar.gz
	${CARGO_CRATE_URIS}
"
S="${WORKDIR}/unsloth-${PV/_beta/-beta}"

PATCHES=( "${FILESDIR}/${P}-system-backend.patch" )

# The GitHub-generated archive is not immutable. Its Manifest digest pins the
# current bytes and must be deliberately re-pinned if GitHub rehashes it.
# studio/LICENSE.AGPL-3.0 is SPDX AGPL-3.0-only; Gentoo's license name is
# AGPL-3.
# AGPL-3: the studio UI. OFL-1.1: the bundled Figtree/Inter/Space-Grotesk web
# fonts (the proprietary Hellix font is stripped in src_compile).
LICENSE="AGPL-3 OFL-1.1"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD Boost-1.0 CC0-1.0
	CDLA-Permissive-2.0 ISC MIT MPL-2.0 Unicode-3.0 ZLIB
"
SLOT="0"
KEYWORDS="-* ~amd64"

PROPERTIES="live"
# cargo.eclass exports src_test (cargo_src_test); the workspace's tests want a
# display/network, so keep them off like the base unsloth and unsloth[studio].
RESTRICT="network-sandbox test"

DEPEND="
	dev-libs/glib:2
	net-libs/libsoup:3.0
	net-libs/webkit-gtk:4.1
	sys-apps/dbus
	x11-libs/cairo
	x11-libs/gdk-pixbuf:2
	x11-libs/gtk+:3
	x11-libs/pango
"
RDEPEND="
	${DEPEND}
	sci-ml/unsloth[studio]
"
BDEPEND="
	dev-build/cmake
	net-libs/nodejs[npm]
	virtual/pkgconfig
"

src_prepare() {
	default

	# Upstream's Cargo.toml/Cargo.lock carry a placeholder version (2026.4.8)
	# that the release CI rewrites to the release before building; do the same
	# so the built app reports the packaged version, not the placeholder.
	local relver="${PV/_beta/-beta}"
	sed -i "s/^version = \"2026\.4\.8\"/version = \"${relver}\"/" \
		studio/src-tauri/Cargo.toml || die
	sed -i "/^name = \"unsloth-studio\"\$/{n;s/^version = \".*\"/version = \"${relver}\"/}" \
		studio/src-tauri/Cargo.lock || die
}

src_compile() {
	pushd studio/frontend >/dev/null || die
	npm ci --no-audit --no-fund || die
	npm run build || die
	# Strip the proprietary Hellix font (copied public/ -> dist/); the UI falls
	# back to a system font for that text. The OFL-1.1 @fontsource fonts stay.
	find dist -iname '*hellix*' -exec rm -rf {} + || die
	popd >/dev/null || die

	pushd studio/src-tauri >/dev/null || die
	cargo_src_compile
	popd >/dev/null || die
}

src_install() {
	newbin studio/src-tauri/target/release/unsloth-studio unsloth-desktop

	cp studio/src-tauri/linux/unsloth.desktop "${T}/unsloth.desktop" || die
	sed -i \
		-e 's/{{categories}}/Science;X-ArtificialIntelligence;/' \
		-e '/{{#if comment}}/,/{{\/if}}/d' \
		-e 's|Exec={{exec}} %u|Exec=unsloth-desktop %u|' \
		-e 's|StartupWMClass={{exec}}|StartupWMClass=unsloth-desktop|' \
		-e 's|Icon={{icon}}|Icon=unsloth|' \
		-e 's|Name={{name}}|Name=Unsloth|' \
		"${T}/unsloth.desktop" || die
	domenu "${T}/unsloth.desktop"

	newicon -s 32 studio/src-tauri/icons/32x32.png unsloth.png
	newicon -s 128 studio/src-tauri/icons/128x128.png unsloth.png
	newicon -s 1024 studio/src-tauri/icons/icon.png unsloth.png
}