Skip to content

Commit d90361f

Browse files
committed
dev-util/serve-d: filter faulty user flags
More precisely - remove -O from DMDFLAGS - remove -mcpu=native from LDCFLAGS Bug: Pure-D/serve-d#360 Signed-off-by: Andrei Horodniceanu <[email protected]>
1 parent e1cb0e5 commit d90361f

File tree

1 file changed

+195
-0
lines changed

1 file changed

+195
-0
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Copyright 2023-2024 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
EAPI=8
5+
6+
MY_VER="$(ver_rs 3 - 4 .)" # 0.8.0_beta15 -> 0.8.0-beta.15
7+
8+
DESCRIPTION="Microsoft language server protocol implementation for D"
9+
HOMEPAGE="https://github.com/Pure-D/serve-d"
10+
SRC_URI="https://code.dlang.org/packages/serve-d/${MY_VER}.zip -> ${P}.zip
11+
12+
https://code.dlang.org/packages/automem/0.6.9.zip -> automem-0.6.9.zip
13+
https://code.dlang.org/packages/botan/1.12.19.zip -> botan-1.12.19.zip
14+
https://code.dlang.org/packages/botan-math/1.0.3.zip -> botan-math-1.0.3.zip
15+
https://code.dlang.org/packages/cachetools/0.4.1.zip -> cachetools-0.4.1.zip
16+
https://code.dlang.org/packages/dcd/0.16.0-beta.2.zip -> dcd-0.16.0-beta.2.zip
17+
https://code.dlang.org/packages/dfmt/0.15.0.zip -> dfmt-0.15.0.zip
18+
https://code.dlang.org/packages/diet-complete/0.0.3.zip -> diet-complete-0.0.3.zip
19+
https://code.dlang.org/packages/diet-ng/1.8.1.zip -> diet-ng-1.8.1.zip
20+
https://code.dlang.org/packages/dscanner/0.16.0-beta.2.zip -> dscanner-0.16.0-beta.2.zip
21+
https://code.dlang.org/packages/dub/1.33.1.zip -> dub-1.33.1.zip
22+
https://code.dlang.org/packages/emsi_containers/0.9.0.zip -> emsi_containers-0.9.0.zip
23+
https://code.dlang.org/packages/eventcore/0.9.25.zip -> eventcore-0.9.25.zip
24+
https://code.dlang.org/packages/fuzzymatch/1.0.0.zip -> fuzzymatch-1.0.0.zip
25+
https://code.dlang.org/packages/inifiled/1.3.3.zip -> inifiled-1.3.3.zip
26+
https://code.dlang.org/packages/isfreedesktop/0.1.1.zip -> isfreedesktop-0.1.1.zip
27+
https://code.dlang.org/packages/libasync/0.8.6.zip -> libasync-0.8.6.zip
28+
https://code.dlang.org/packages/libddoc/0.8.0.zip -> libddoc-0.8.0.zip
29+
https://code.dlang.org/packages/libdparse/0.23.2.zip -> libdparse-0.23.2.zip
30+
https://code.dlang.org/packages/memutils/1.0.9.zip -> memutils-1.0.9.zip
31+
https://code.dlang.org/packages/mir-algorithm/3.20.4.zip -> mir-algorithm-3.20.4.zip
32+
https://code.dlang.org/packages/mir-core/1.5.5.zip -> mir-core-1.5.5.zip
33+
https://code.dlang.org/packages/mir-cpuid/1.2.10.zip -> mir-cpuid-1.2.10.zip
34+
https://code.dlang.org/packages/mir-ion/2.1.8.zip -> mir-ion-2.1.8.zip
35+
https://code.dlang.org/packages/mir-linux-kernel/1.0.1.zip -> mir-linux-kernel-1.0.1.zip
36+
https://code.dlang.org/packages/msgpack-d/1.0.4.zip -> msgpack-d-1.0.4.zip
37+
https://code.dlang.org/packages/openssl/3.3.0.zip -> openssl-3.3.0.zip
38+
https://code.dlang.org/packages/openssl-static/1.0.2+3.0.8.zip -> openssl-static-1.0.2+3.0.8.zip
39+
https://code.dlang.org/packages/requests/2.1.1.zip -> requests-2.1.1.zip
40+
https://code.dlang.org/packages/rm-rf/0.1.0.zip -> rm-rf-0.1.0.zip
41+
https://code.dlang.org/packages/sdlfmt/0.1.1.zip -> sdlfmt-0.1.1.zip
42+
https://code.dlang.org/packages/sdlite/1.1.2.zip -> sdlite-1.1.2.zip
43+
https://code.dlang.org/packages/silly/1.1.1.zip -> silly-1.1.1.zip
44+
https://code.dlang.org/packages/standardpaths/0.8.2.zip -> standardpaths-0.8.2.zip
45+
https://code.dlang.org/packages/stdx-allocator/2.77.5.zip -> stdx-allocator-2.77.5.zip
46+
https://code.dlang.org/packages/taggedalgebraic/0.11.22.zip -> taggedalgebraic-0.11.22.zip
47+
https://code.dlang.org/packages/test_allocator/0.3.4.zip -> test_allocator-0.3.4.zip
48+
https://code.dlang.org/packages/unit-threaded/0.10.8.zip -> unit-threaded-0.10.8.zip
49+
https://code.dlang.org/packages/vibe-core/2.2.0.zip -> vibe-core-2.2.0.zip
50+
https://code.dlang.org/packages/vibe-d/0.9.6.zip -> vibe-d-0.9.6.zip
51+
https://code.dlang.org/packages/xdgpaths/0.2.5.zip -> xdgpaths-0.2.5.zip
52+
"
53+
54+
LICENSE="MIT"
55+
LICENSE+=" Apache-2.0 BSD-2 BSD Boost-1.0 GPL-3 ISC LGPL-3 MIT public-domain Unlicense || ( openssl SSLeay )"
56+
S="${WORKDIR}/${PN}-${MY_VER}"
57+
SLOT="0"
58+
KEYWORDS="~amd64"
59+
60+
DLANG_VERSION_RANGE="2.100-2.106"
61+
DLANG_PACKAGE_TYPE="single"
62+
# gdc currently fails due to a bug in mir-cpuid, see: https://github.com/libmir/mir-cpuid/pull/46
63+
DLANG_COMPILER_DISABLED_BACKENDS=(gdc)
64+
65+
CHECKREQS_MEMORY="10G" # mir is a chonker
66+
67+
inherit check-reqs dlang multiprocessing
68+
69+
# Lower versions of dcd won't immediately fail but they won't work as intended (no autocompletion for example)
70+
RDEPEND=">=dev-util/dcd-0.15.2"
71+
BDEPEND="dev-util/dub app-arch/unzip"
72+
73+
src_unpack() {
74+
unpack "${P}.zip"
75+
pushd "${S}" || die
76+
77+
local dep name ver dub_args
78+
dub_args=(
79+
# Don't look up dependencies online or in the system path
80+
--skip-registry=all
81+
# Only look for them in the ${T} directory
82+
--registry=file://"${T}"
83+
# Prefer verbose operation
84+
--verbose
85+
# Unpack dependencies for the local project (put them in ${S}/.dub)
86+
--cache=local
87+
)
88+
for dep in ${A}; do
89+
if [[ ${dep} != ${P}.zip ]]; then
90+
# Due to a bug in dub, we can't have similar looking
91+
# archives in the same directory. Simply put, if we had:
92+
# foo-1.zip and foo-bar-2.zip when trying to fetch foo dub
93+
# will fail because it thinks that foo-bar-2.zip is foo's
94+
# archive. See: https://github.com/dlang/dub/pull/2727
95+
cp "${DISTDIR}/${dep}" "${T}" || die "Could not copy dependency to temporary directory"
96+
97+
# This calculation is faulty, dub allows digits in package names, it will
98+
# probably be needed to save dependencies in a similar to $CRATES variable.
99+
name="${dep%%-[0-9]*}"
100+
version="${dep%.zip}"
101+
version="${version#${name}-}"
102+
103+
/usr/bin/dub "${dub_args[@]}" fetch "${name}@${version}" \
104+
|| die "Could not extract dub dependencies"
105+
106+
rm "${T}/${dep}" || die "Could not remove depedency from temporary directory"
107+
fi
108+
done
109+
popd > /dev/null || die
110+
}
111+
112+
d_src_compile() {
113+
local dub_args=(
114+
# It wouldn't be good if the build became interactive
115+
--non-interactive
116+
# Let user provided $DCFLAGS dictate the build
117+
#--build=realease
118+
# It is good practice to be verbose
119+
--verbose
120+
# Don't touch anything outside the ${S} directory
121+
--skip-registry=all
122+
)
123+
124+
DFLAGS="$(get_dflags)" DUB_HOME="${S}" /usr/bin/dub build "${dub_args[@]}" || die
125+
}
126+
127+
d_src_test() {
128+
local dub_args=(
129+
# It is good practice to be verbose
130+
--verbose
131+
# Don't touch anything outside the ${S} directory
132+
--skip-registry=all
133+
134+
# ${PV} uses silly for testing so it supports jobs
135+
--
136+
--threads="$(makeopts_jobs)"
137+
)
138+
139+
# Tests all submodules in dub.json. :dcd currently fails tests due to a missing dependency and import.
140+
# It's 1 little test though so no biggie.
141+
# See: https://github.com/Pure-D/serve-d/pull/350
142+
local subpkg
143+
# We also have another issue that testing $PV gives linking errors
144+
# when the --build configuration is specified (or if $DFLAGS are specified).
145+
# We can work around it by forcing --build=unittest.
146+
# See: https://github.com/Pure-D/serve-d/issues/351
147+
for subpkg in ":http" ":protocol" ":lsp" ":serverbase" ":workspace-d" ""; do
148+
# Let $subpkg be shell expanded since it can be empty
149+
DUB_HOME="${S}" DFLAGS="$(get_dflags)" /usr/bin/dub test ${subpkg} --build=unittest "${dub_args[@]}" \
150+
|| die "Tests failed"
151+
done
152+
}
153+
154+
d_src_install() {
155+
dobin "${S}/serve-d"
156+
}
157+
158+
get_dflags() {
159+
# See https://issues.dlang.org/show_bug.cgi?id=24406 and
160+
# https://github.com/Pure-D/serve-d/issues/360
161+
# For short, we have to remove -O from DCFLAGS for dmd.
162+
#
163+
# There's also an issue with ldc that when -mcpu=native is specified
164+
# you get an llvm stack trace. I have to investigate it further
165+
# before reporting. -mcpu=<resolve-march-native> works though, idk.
166+
# For now just remove -mcpu=native for ldc2.
167+
case "${DLANG_VENDOR}" in
168+
GNU) echo "${DCFLAGS}" ;;
169+
LDC)
170+
# Use a file since we can't export variables because we're
171+
# called in $().
172+
if [[ ${DCFLAGS} == *-mcpu=native* && ! -e ${T}/ldc2-flags-warned ]]; then
173+
touch "${T}"/ldc2-flags-warned || die
174+
175+
ewarn "-mcpu=native causes issues with ldc2 so it will be removed"
176+
ewarn "from your flags. If you still want to specify it use"
177+
ewarn "app-misc/resolve-march-native to get your actual architecture"
178+
ewarn "and use that with -mcpu, like in -mcpu=znver3."
179+
fi
180+
echo "${DCFLAGS//-mcpu=native/}"
181+
;;
182+
DigitalMars)
183+
if [[ ${DCFLAGS} == *-O* && ! -e ${T}/dmd-flags-warned ]]; then
184+
touch "${T}"/dmd-flags-warned || die
185+
186+
ewarn "Optimizations will be turned off for this build with dmd"
187+
ewarn "See: https://github.com/Pure-D/serve-d/issues/360"
188+
fi
189+
echo "${DCFLAGS//-O/}"
190+
;;
191+
*)
192+
die "Unknown DLANG_VENDOR: ${DLANG_VENDOR}"
193+
;;
194+
esac
195+
}

0 commit comments

Comments
 (0)