blob: e893d86252b1ef29e7225bf006f295eed5b9a160 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# Copyright 2022-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: shards.eclass
# @MAINTAINER:
# Anna <cyber+gentoo@sysrq.in>
# @AUTHOR:
# Anna <cyber+gentoo@sysrq.in>
# @SUPPORTED_EAPIS: 8 9
# @PROVIDES: crystal-utils
# @BLURB: eclass to build Crystal packages using Shards
# @DESCRIPTION:
# This eclass contains the default phase function for packages which use Crystal
# Shards as a build system.
#
# If the package has no shard.yml(5) file, use crystal-utils.eclass(5) instead.
# @EXAMPLE:
# Typical ebuild for a Crystal application:
#
# @CODE@
# EAPI=9
#
# inherit shards
#
# ...
#
# DEPEND="dev-crystal/foo"
#
# CRYSTAL_DEFINES=( -Denable_cli )
#
# src_install() {
# dobin hello-world
# einstalldocs
# }
# @CODE@
#
#
# Typical ebuild for a Crystal library:
#
# @CODE@
# EAPI=9
#
# inherit shards
#
# ...
#
# RDEPEND="
# dev-crystal/bar
# dev-crystal/baz
# "
# @CODE@
#
#
# Typical ebuild for a hybrid Crystal library/applicaton:
#
# @CODE@
# EAPI=9
#
# inherit shards
#
# ...
#
# DEPEND="
# dev-crystal/bar
# dev-crystal/baz
# "
# RDEPEND="${DEPEND}"
#
# src_install() {
# dobin helper-util
# shards_src_install # install library sources
# }
# @CODE@
case ${EAPI} in
8|9) ;;
*) die "${ECLASS}: EAPI ${EAPI} unsupported."
esac
if [[ ! ${_SHARDS_ECLASS} ]]; then
_SHARDS_ECLASS=1
inherit crystal-utils toolchain-funcs
BDEPEND="
${CRYSTAL_DEPS}
${SHARDS_DEPS}
>=dev-util/gshards-0.2
"
IUSE="debug doc"
if [[ ${CATEGORY} == dev-crystal ]]; then
# To build a correct dependency graph, add Crystal version
# restrictions to runtime dependencies of Crystal libraries.
RDEPEND="${CRYSTAL_DEPS}"
else
# Add a buildtime dependency on the Crystal standard library.
DEPEND="${CRYSTAL_DEPS}"
fi
# Crystal packages do not use CFLAGS
QA_FLAGS_IGNORED='.*'
# @FUNCTION: shards_get_libdir
# @RETURN: the library path for Crystal packages
shards_get_libdir() {
echo /usr/lib/shards
}
# @FUNCTION: shards_get_pkgname
# @RETURN: the package name as specified in shard.yml
shards_get_pkgname() {
debug-print-function ${FUNCNAME} "${@}"
gshards-get-pkgname || die "Parsing package name failed"
}
# @FUNCTION: shards_src_configure
# @DESCRIPTION:
# Function for configuring Crystal to match user settings.
shards_src_configure() {
debug-print-function ${FUNCNAME} "${@}"
crystal_configure
debug-print "CRYSTAL_OPTS='${CRYSTAL_OPTS}'"
export SHARDS_INSTALL_PATH="${BROOT}$(shards_get_libdir)"
export CRYSTAL_PATH="${SHARDS_INSTALL_PATH}:$(crystal env CRYSTAL_PATH || die "'crystal env' failed")"
debug-print "CRYSTAL_PATH='${CRYSTAL_PATH}'"
tc-export CC
}
# @FUNCTION: shards_src_compile
# @DESCRIPTION:
# Function for building the package's executables and documentation.
shards_src_compile() {
debug-print-function ${FUNCNAME} "${@}"
local args
gshards-print-targets | while read -r args; do
crystal_build "${@}" ${args}
done
if use doc; then
ecrystal docs "${CRYSTAL_DEFINES[@]}"
HTML_DOCS=( docs/. )
fi
return 0
}
# @FUNCTION: shards_src_test
# @USAGE: [<args>...]
# @DESCRIPTION:
# Function for testing the package.
shards_src_test() {
debug-print-function ${FUNCNAME} "${@}"
if [[ -d "spec" ]]; then
crystal_spec "${@}"
fi
return 0
}
# @FUNCTION: shards_src_install
# @DESCRIPTION:
# Function for installing the package's source.
shards_src_install() {
debug-print-function ${FUNCNAME} "${@}"
if [[ -d "src" ]]; then
insinto $(shards_get_libdir)/$(shards_get_pkgname)
doins -r src
doins shard.yml
fi
einstalldocs
}
fi
EXPORT_FUNCTIONS src_configure src_compile src_test src_install
|