# Maintainer: Eloy Degen <git@eloydegen.com>
pkgname=lldap
pkgver=0.6.1
pkgrel=0
pkgdesc="Light LDAP implementation for authentication"
url="https://github.com/lldap/lldap"
arch="x86_64 aarch64" # due to different issues (missing packages, upstream bugs), only 2 archs build
license="GPL-3.0-only"
makedepends="cargo cargo-auditable wasm-pack wasm-bindgen rust-wasm"
source="
	$pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz
	config-template.patch
	"
options="net" # fetch dependencies

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release -p lldap -p lldap_migration_tool -p lldap_set_password

	# frontend
	# RUSTFLAGS needs to be unset as a temporary workaround to make sure wasm-ld is able to link
	(
	cd app
	unset RUSTFLAGS
	wasm-pack build --target web --release
	gzip -9 -k -f pkg/lldap_app_bg.wasm
	)
}

check() {
	cargo test --frozen
}

package() {
	install -D -m755 target/release/lldap* -t "$pkgdir"/usr/bin/

	# frontend, path needs to be specified as lldap command arg
	install -D -m755 app/index.html -t "$pkgdir"/usr/lib/"$pkgname"/app/
	install -D -m755 app/static/fonts.css -t "$pkgdir"/usr/lib/"$pkgname"/app/static/
	install -D -m755 app/static/libraries.txt -t "$pkgdir"/usr/lib/"$pkgname"/app/static/
	install -D -m755 app/static/main.js -t "$pkgdir"/usr/lib/"$pkgname"/app/static/
	install -D -m755 app/static/spinner.gif -t "$pkgdir"/usr/lib/"$pkgname"/app/static/
	install -D -m755 app/static/style.css -t "$pkgdir"/usr/lib/"$pkgname"/app/static/
	install -D -m755 app/pkg/* -t "$pkgdir"/usr/lib/"$pkgname"/app/pkg/

	# install default config file with correct filepath to SQLite db and other things
	install -D -m755 lldap_config.docker_template.toml "$pkgdir"/etc/"$pkgname".toml

	# TODO fonts, could be an Alpine package too, but app works fine without them
}

sha512sums="
35a7abd18167453e79cf8abe62dc4440afe1ef7ccb6d7880380d4fca0f3d6f314ec090d82ad36941c466a154e9921be8be0da8fc728f90720391e2c421bc41e7  lldap-0.6.1.tar.gz
cddaa73949cccc0ac238863ddaf3ab946b883fcb34f4129937a995c04410460c4a2ef331f2ecfa930c57cbd0a28349baf0a35f72733ce5d53c58211be813197f  config-template.patch
"
