Gentoo Archives: gentoo-dev

From: Gerion Entrup <gerion.entrup@×××××.de>
To: "gentoo-dev@l.g.o" <gentoo-dev@l.g.o>
Subject: Re: [gentoo-dev] New eclass: openvdb.eclass
Date: Mon, 15 Jun 2020 15:46:13
Message-Id: 12544687.uLZWGnKmhe@gump
In Reply to: [gentoo-dev] New eclass: openvdb.eclass by Adrian Grigo
1 Friendly ping (or have I missed any discussion channel?).
2 As a user, I'm really looking forward to see blender >=2.80 in the tree.
3 According to https://bugs.gentoo.org/689740 this eclass is the main blocker.
4
5 Gerion
6
7 Am Mittwoch, 27. Mai 2020, 03:40:04 CEST schrieb Adrian Grigo:
8 > Hello, I am a proxied maintainer of blender and openvdb and wish to propose a new eclass and USE_EXPAND variable to ensure the same version of the openvdb abi is used when building the blender, openvdb and openimageio packages.
9 >
10 > The tree currently contains openvdb 4 and 5, and I plan to add 6 and 7 soon to support my new blender PR. Each major release of openvdb has a new ABI, and can also support legacy versions. However only one version can be built at a time, which is passed to cmake through OPENVDB_ABI_VERSION_NUMBER, and produces a library with functions named xxx_7abi5 when building openvdb 7 with support for abi 5. Client packages like blender and openimageio which depend on openvdb and also need to be compiled with the same version number in order to link correctly.
11 >
12 > To enforce this I propose to add a new USE_EXPAND variable called OPENVDB_ABI, which is set to the version number the user wants to use in the system eg 5, which expands to openvdb_abi_5. The packages can then append -DOPENVDB_ABI_VERSION_NUMBER=${OPENVDB_ABI} to ensure they pass the same value to cmake.
13 >
14 > To reduce the boilerplate code required to ensure that only one supported value is set in OPENVDB_ABI and used by all packages, so I propose to add an eclass to maintain this in one place. Similar to PYTHON_COMPAT, each ebuilds set OPENVDB_COMPAT to specify which legacy ABI they can support. The openvdb.eclass uses it to set global variables OPENVDB_REQUIRED_USE and OPENVDB_SINGLE_USEDEP and verify in pkg_prepare that only one of the openvdb_abi_X flags is set.
15 >
16 > Each ebuild sets REQUIRED_USE="${OPENVDB_REQUIRED_USE}" which evaluates to ^^ ( openvdb_abi_3 openvdb_abi_4 ... ) to ensure only one abi is enabled from those it supports.
17 > They set RDEPEND="openvdb? ( media-gfx/openvdb[${OPENVDB_SINGLE_USEDEP}] )" which evaluates to openvdb_abi_3(-)?,openvdb_abi_4(-)?,... to allow portage to enforce the same abi version is built between all packages.
18 >
19 > With a new release of openvdb, I will only need to add it to the openvdb_abi.desc file, to an eclass internal list _OPENVDB_ALL_ABI, and to OPENVDB_COMPAT for each ebuild which supports the new version.
20 >
21 > Please review my proposed eclass below. I have tested it works when OPENVDB_ABI is missing, set to invalid values, or set to values that cannot satisfy all package requirements simultaneously, and that the system recompiles all packages when the ABI is changed. It also works when set to appropriate values.
22 >
23 > I considered other alternatives during development. It is possible to manually add the expanded REQUIRED_USE and RDEPEND strings to each package, but with each new version of openvdb and multiple client packages to maintain this becomes messy and error prone. The user also needs to set the same openvdb_abi_X flag for each package. While currently there are only three packages which need to be synchronised, any other package which depends on openvdb in future will benefit from this infrastructure.
24 >
25 > Also without the USE_EXPAND variable the ebuilds do not have access to the version number to pass to the build system, and need to generate it by testing each USE flag. So I think this is the cleanest solution.
26 >
27 > I also looked into slotting openvdb as then packages could specify the slot/subslot required eg openvdb:7/5 but don't think this is possible. This would be a major undertaking as it has a static as well as dynamic core library, another library for python, and the cmake modules that find openvdb use the output of a binary at /usr/bin/vdb_print to determine which version to link against. It would also not centralise the boilerplate code.
28 >
29 > For further information and my discussion during development see https://github.com/redchillipadi/ebuild-overlay/issues/4
30 >
31 > Please let me know if there is a better solution or improvements are required.
32 >
33 > Kind Regards,
34 > Adrian Grigo
35 >
36 >
37 > # Copyright 1999-2020 Gentoo Authors
38 > # Distributed under the terms of the GNU General Public License v2
39 >
40 > # @ECLASS: openvdb.eclass
41 > # @MAINTAINER:
42 > # Adrian Grigo <agrigo2001@×××××××××.au>
43 > # @ AUTHOR:
44 > # Author: Adrian Grigo <agrigo2001@×××××××××.au>
45 > # Based on work of: Michał Górny <mgorny@g.o> and Krzysztof Pawlik <nelchael@g.o>
46 > # @SUPPORTED_EAPIS: 5 6 7
47 > # @BLURB: An eclass for OpenVDB to control which ABI version is compiled
48 > # @DESCRIPTION:
49 > # The OpenVDB package is a library for sorting and manipulating sparse
50 > # data structures with dynamic topology as required for use in volume
51 > # rendering for computer graphics.
52 > #
53 > # Each major version of OpenVDB provides an updated ABI, as well as
54 > # the ability to compile using a legacy version of the ABI.
55 > # Openvdb 7 can be compiled to support version 5, 6 or 7 of the ABI.
56 > #
57 > # However the user needs to choose at compile time which version to
58 > # build by passing OPENVDB_ABI_VERSION_NUMBER="5" to cmake.
59 > # It is not possible to support multiple versions concurrently
60 > # so OpenVDB and all packages depending upon it must be built for the
61 > # same ABI version. This currently means blender and openvdb, and
62 > # will also include >=openimageio-2.0 once it is updated
63 > #
64 > # The client packages have differing requirements for the ABI support.
65 > # For example,
66 > # Openvdb-7 supports 5-7 (older version provide ABI 3 and 4 support)
67 > # Blender supports ABI 4-7
68 > # Openimageio-2.0 supports ABI 5-7.
69 > #
70 > # To use this eclass, the user should first select which ABI to build
71 > # and set OPENVDB_ABI USE_EXPAND variable in make.conf.
72 > #
73 > # When the client package inherits this eclass, it can use the
74 > # OPENVDB_COMPAT variable in the ebuild to specify which ABI it
75 > # supports, and then use the OPENVDB_SINGLE_USEDEP variable that the
76 > # eclass produces to force the package to link using ABI selected in
77 > # OPENVDB_ABI
78 > # eg. openvdb? ( media-gfx/openvdb[${OPENVDB_SINGLE_USEDEP}] )
79 > # When OPENVDB_COMPAT="X Y" the variable evaluates to
80 > # openvdb_abi_X(-)? openvdb_abi_Y(-)?
81 > #
82 > # The client can pass the ABI version to the build system as follows:
83 > # append-cppflags -DOPENVDB_ABI_VERSION_NUMBER="${OPENVDB_ABI}"
84 > #
85 > # This eclass includes pkg_setup which ensures that the package will
86 > # only compile if only one openvdb_abi_X USE flag is set
87 > #
88 > # @EXAMPLE:
89 > # The user needs to choose which version of the ABI supports all packages
90 > # they plan to install. This is then stored in a variable in make.conf
91 > # eg. OPENVDB_ABI="5" in /etc/portage/make.conf
92 > #
93 > # The client packages need to:
94 > # - inherit this eclass.
95 > # - list the ABI supported by the package in OPENVDB_COMPAT.
96 > # - use OPENVDB_REQUIRED_USE to ensure that only one of the
97 > # compatible ABI can be selected by the ebuild.
98 > # - include OPENVDB_SINGLE_USEDEP in RDEPEND to ensure any
99 > # dependencies build against a similar ABI.
100 > # - pass the OPENVDB_ABI version to the package build system
101 > #
102 > # @CODE
103 > # inherit openvdb
104 > # OPENVDB_COMPAT=( 4 5 6 7 )
105 > # REQUIRED_USE="openvdb? ( ${OPENVDB_REQUIRED_USE} )"
106 > # RDEPEND="openvdb? ( media-gfx/openvdb[${OPENVDB_SINGLE_USEDEP}] )"
107 > #
108 > # src_configure() {
109 > # append-cppflags -DOPENVDB_ABI_VERSION_NUMBER="${OPENVDB_ABI_VERSION}"
110 > # ...
111 > # cmake-utils_src_configure
112 > # }
113 > # @CODE
114 >
115 > case "${EAPI:-0}" in
116 > 0|1|2|3|4)
117 > die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
118 > ;;
119 > 5|6|7)
120 > # EAPI=5 is required for sane USE_EXPAND dependencies
121 > ;;
122 > *)
123 > die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
124 > ;;
125 > esac
126 >
127 > EXPORT_FUNCTIONS pkg_setup
128 >
129 > # @ECLASS-VARIABLE: OPENVDB_COMPAT
130 > # @REQUIRED
131 > # @DESCRIPTION:
132 > # This variable contains a list of OpenVDB ABI the package supports.
133 > # It must be set before the 'inherit' call and has to be an array.
134 > #
135 > # Example use:
136 > # @CODE
137 > # OPENVDB_COMPAT=( 4 5 6 7 )
138 > # @CODE
139 > #
140 >
141 > # @ECLASS-VARIABLE: OPENVDB_SINGLE_USEDEP
142 > # @DESCRIPTION:
143 > # This is an eclass generated USE-dependency flag which can be used by
144 > # any package depending on openvdb to ensure the correct ABI version
145 > # support is built.
146 > #
147 > # Example use:
148 > # @CODE
149 > # RDEPEND="openvdb? ( media-gfx/openvdb[${OPENVDB_SINGLE_USEDEP}] )"
150 > # @CODE
151 > #
152 > # Example value:
153 > # @CODE
154 > # openvdb_abi_3(-)?,openvdb_abi_4(-)?,openvdb_abi_5(-)?...
155 > # @CODE
156 >
157 > # @ECLASS-VARIABLE: OPENVDB_REQUIRED_USE
158 > # @DESCRIPTION:
159 > # This is an eclass-generated required use expression which ensures
160 > # that exactly one openvdb_use_X value has been enabled.
161 > #
162 > # Example use:
163 > # @CODE
164 > # REQUIRED_USE="${OPENVDB_REQUIRED_USE}"
165 > # @CODE
166 > #
167 > # Example value:
168 > # @CODE
169 > # ^^ ( openvdb_abi_3 openvdb_abi_4 openvdb_abi_5 openvdb_abi_6 openvdb_abi_7)
170 > # @CODE
171 >
172 > # @ECLASS-VARIABLE: _OPENVDB_ALL_ABI
173 > # @INTERNAL
174 > # @DESCRIPTION:
175 > # All supported OpenVDB ABI
176 > # Update this with each new major version release of OpenVDB
177 > _OPENVDB_ALL_ABI=(
178 > 3 4 5 6 7
179 > )
180 > readonly _OPENVDB_ALL_ABI
181 >
182 > # @FUNCTION: _openvdb_set_globals
183 > # @INTERNAL
184 > # @DESCRIPTION:
185 > # Ensure that OPENVDB_COMPAT is valid and generate the
186 > # OPENVDB_REQUIRED_USE and OPENVDB_SINGLE_USEDEP global variables for
187 > # use by the inheriting ebuild
188 > _openvdb_set_globals() {
189 > local i
190 >
191 > if ! declare -p OPENVDB_COMPAT &>/dev/null; then
192 > die 'OPENVDB_COMPAT not declared.'
193 > fi
194 >
195 > if [[ $(declare -p OPENVDB_COMPAT) != "declare -a"* ]]; then
196 > die 'OPENVDB_COMPAT must be an array.'
197 > fi
198 >
199 > local flags=()
200 > for i in "${_OPENVDB_ALL_ABI[@]}"; do
201 > if has "${i}" "${OPENVDB_COMPAT[@]}"; then
202 > flags+=( "openvdb_abi_${i}" )
203 > fi
204 > done
205 >
206 > if [[ ${#supp[@]} -eq 1 ]]; then
207 > IUSE="+${flags[0]}"
208 > else
209 > IUSE="${flags[*]}"
210 > fi
211 >
212 > if [[ ! ${#flags[@]} ]]; then
213 > die "No supported OpenVDB ABI in OPENVDB_COMPAT."
214 > fi
215 >
216 > local single_flags="${flags[@]/%/(-)?}"
217 > local single_usedep=${single_flags// /,}
218 >
219 > OPENVDB_REQUIRED_USE="^^ ( ${flags[*]} )"
220 > OPENVDB_SINGLE_USEDEP="${single_usedep}"
221 > readonly OPENVDB_REQUIRED_USE OPENVDB_SINGLE_USEDEP
222 > }
223 > _openvdb_set_globals
224 > unset -f _openvdb_set_globals
225 >
226 > if [[ ! ${_OPENVDB} ]]; then
227 >
228 > # @FUNCTION: openvdb_setup
229 > # @DESCRIPTION
230 > # Ensure one and only one OpenVDB ABI version is selected
231 > openvdb_setup() {
232 > debug-print-function ${FUNCNAME} "${@}"
233 >
234 > local i, version
235 > for i in "${_OPENVDB_ABI[@]}"; do
236 > if use "openvdb_abi_${i}"; then
237 > if [[ ${version} ]]; then
238 > eerror "Your OPENVDB_ABI setting lists more than a single OpenVDB"
239 > eerror "ABI version. Please set it to just one value."
240 > echo
241 > die "More than one ABI in OPENVDB_ABI."
242 > fi
243 > fi
244 >
245 > version="${i}"
246 > echo "Using OpenVDB ABI ${version} to build"
247 > done
248 >
249 > if [[ ! ${version} ]]; then
250 > eerror "No OpenVDB ABI Version selected for the system. Please set"
251 > eerror "the OPENVDB_ABI variable in your make.conf to one"
252 > eerror "of the values contained in all of:"
253 > eerror
254 > eerror "- the entire list of ABI: ${_OPENVDB_ALL_ABI[*]}"
255 > eerror "- the ABI supported by this package: ${OPENVDB_COMPAT}"
256 > eerror "- and the ABI supported by all other packages on your system"
257 > echo
258 > die "No supported OpenVDB ABI version in OPENVDB_ABI."
259 > fi
260 > }
261 >
262 > # @FUNCTION: openvdb_pkg_setup
263 > # @DESCRIPTION:
264 > # Runs openvdb_setup.
265 > openvdb_pkg_setup() {
266 > debug-print-function ${FUNCNAME} "${@}"
267 >
268 > [[ ${MERGE_TYPE} != binary ]] && openvdb_setup
269 > }
270 >
271 > _OPENVDB=1
272 > fi
273 >
274 >
275 >

Attachments

File name MIME type
signature.asc application/pgp-signature