# Copyright 2023-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MY_PV="$(ver_rs 3 - 4 .)" # 0.8.0_beta15 -> 0.8.0-beta.15
# gdc currently fails due to a bug in mir-cpuid, see: https://github.com/libmir/mir-cpuid/pull/46
DLANG_COMPAT=( dmd-2_{106..111} ldc2-1_{35..40} )
DUB_DEPENDENCIES=(
"serve-d@${MY_PV}"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]+3.0.8"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
)
inherit check-reqs dlang-single dub multiprocessing
DUB_TEST_DEP="[email protected]"
DESCRIPTION="Microsoft language server protocol implementation for D"
HOMEPAGE="https://github.com/Pure-D/serve-d"
SRC_URI="
${DUB_DEPENDENCIES_URIS}
test? ( $(dub_dependencies_uris "${DUB_TEST_DEP}") )
"
S="${WORKDIR}/${PN}-${MY_PV}"
LICENSE="MIT BSD"
LICENSE+=" Apache-2.0 Boost-1.0 BSD GPL-3 LGPL-3 MIT openssl public-domain Unlicense"
LICENSE+=" test? ( ISC public-domain )" # test dependencies. These do _not_ map to test? () in SRC_URI
SLOT="0"
KEYWORDS="~amd64"
IUSE="test"
RESTRICT="!test? ( test )"
CHECKREQS_MEMORY="10G" # mir is a chonker
# Lower versions of dcd won't immediately fail but they won't work as
# intended (no autocompletion for example).
COMMON_DEPEND=">=dev-util/dcd-0.15.2"
RDEPEND+=" ${COMMON_DEPEND}"
BDEPEND+=" test? ( ${COMMON_DEPEND} )"
src_unpack() {
dub_src_unpack
use test && dub_copy_dependencies_locally "${DUB_TEST_DEP}"
}
src_prepare() {
# Tries to update dependencies timing out for each one which sums up
# to about 4 minutes of doing nothing. There is no direct way to
# configure the code not to contact https://code.dlang.org
rm -r test/tc_dub || die
# Uses basename to run compiler binaries which happens to work since
# dlang-utils.eclass creates symlinks for them. Like tc_dub spends
# ~40 seconds waiting for code.dlang.org
rm -r test/tc_dub_empty || die
default
}
src_configure() {
# There's an issue with ldc that when -mcpu=native is specified you
# get an llvm stack trace. It seems to be related to the use of
# certain intrinsics that depend on the target cpu.
if [[ ${EDC} == ldc2* && ${DCFLAGS} == *-mcpu=native* ]]; then
ewarn "-mcpu=native causes issues with ldc2 so it will be removed"
ewarn "from your flags."
ewarn "See: https://github.com/libmir/mir-ion/pull/46"
fi
dlang-filter-dflags "ldc2*" "-mcpu=native"
# See https://issues.dlang.org/show_bug.cgi?id=24406 and
# https://github.com/Pure-D/serve-d/issues/360
# In short, we have to remove -O from DCFLAGS for dmd.
if [[ ${EDC} == dmd* && ${DCFLAGS} == *-O* ]]; then
ewarn "Optimizations will be turned off for this build with dmd"
ewarn "See: https://github.com/Pure-D/serve-d/issues/360"
fi
dlang-filter-dflags "dmd*" "-O*"
}
src_test() {
# Tests all submodules in dub.json.
local subpkg
for subpkg in ":http" ":protocol" ":lsp" ":serverbase" ":dcd" ":workspace-d" ""; do
edub test ${subpkg} --build=unittest -- --threads="$(makeopts_jobs)"
done
edub build --root=null_server
edub run --root=null_server_test
# A simplified version for ${S}/test/runtests.sh
pushd test > /dev/null || die
local testcase
for testcase in tc*; do
pushd "${testcase}" > /dev/null || die
einfo "Running testcase ${testcase}"
edub run
popd > /dev/null || die
done
popd > /dev/null || die
}
src_install() {
dobin "${S}/serve-d"
dodoc README.md editor-*.md
}
pkg_postinst() {
elog "You will need to configure your editor to use serve-d."
elog "For instructions check out the README and editor-* files in"
elog " ${EROOT}/usr/share/doc/${PF}"
}