Debian Codegraph @

rsvg/meson.build

raw
1 library_sources = files(
2 'Cargo.toml',
3 'build.rs',
4 'src/accept_language.rs',
5 'src/angle.rs',
6 'src/api.rs',
7 'src/aspect_ratio.rs',
8 'src/bbox.rs',
9 'src/cairo_path.rs',
10 'src/color.rs',
11 'src/cond.rs',
12 'src/coord_units.rs',
13 'src/css.rs',
14 'src/dasharray.rs',
15 'src/document.rs',
16 'src/dpi.rs',
17 'src/drawing_ctx.rs',
18 'src/element.rs',
19 'src/error.rs',
20 'src/filter_func.rs',
21 'src/filter.rs',
22 'src/filters/blend.rs',
23 'src/filters/bounds.rs',
24 'src/filters/color_matrix.rs',
25 'src/filters/component_transfer.rs',
26 'src/filters/composite.rs',
27 'src/filters/context.rs',
28 'src/filters/convolve_matrix.rs',
29 'src/filters/displacement_map.rs',
30 'src/filters/error.rs',
31 'src/filters/flood.rs',
32 'src/filters/gaussian_blur.rs',
33 'src/filters/image.rs',
34 'src/filters/lighting.rs',
35 'src/filters/merge.rs',
36 'src/filters/mod.rs',
37 'src/filters/morphology.rs',
38 'src/filters/offset.rs',
39 'src/filters/tile.rs',
40 'src/filters/turbulence.rs',
41 'src/float_eq_cairo.rs',
42 'src/font_props.rs',
43 'src/gradient.rs',
44 'src/href.rs',
45 'src/image.rs',
46 'src/io.rs',
47 'src/iri.rs',
48 'src/layout.rs',
49 'src/length.rs',
50 'src/lib.rs',
51 'src/limits.rs',
52 'src/log.rs',
53 'src/marker.rs',
54 'src/node.rs',
55 'src/paint_server.rs',
56 'src/parsers.rs',
57 'src/path_builder.rs',
58 'src/path_parser.rs',
59 'src/pattern.rs',
60 'src/properties.rs',
61 'src/property_defs.rs',
62 'src/property_macros.rs',
63 'src/rect.rs',
64 'src/shapes.rs',
65 'src/space.rs',
66 'src/structure.rs',
67 'src/style.rs',
68 'src/surface_utils/iterators.rs',
69 'src/surface_utils/mod.rs',
70 'src/surface_utils/shared_surface.rs',
71 'src/surface_utils/srgb.rs',
72 'src/text.rs',
73 'src/transform.rs',
74 'src/ua.css',
75 'src/unit_interval.rs',
76 'src/url_resolver.rs',
77 'src/util.rs',
78 'src/viewbox.rs',
79 'src/ua.css',
80 'src/xml/attributes.rs',
81 'src/xml/mod.rs',
82 'src/xml/xml2_load.rs',
83 'src/xml/xml2.rs',
84 )
85
86 rust_artifacts = custom_target(
87 'librsvg-2',
88 build_by_default: true,
89 output: '@0@rsvg_@1@.@2@'.format(lib_prefix, librsvg_api_major, ext_static),
90 console: true,
91 depend_files: library_sources + librsvg_c_sources,
92 env: extra_env,
93 command: [
94 cargo_wrapper,
95 cargo_wrapper_args,
96 '--command=cbuild',
97 '--current-build-dir', '@OUTDIR@',
98 '--current-source-dir', meson.current_source_dir(),
99 '--packages', 'librsvg-c',
100 '--extension', ext_static,
101 ] + avif_feature_args
102 + pixbuf_feature_args,
103 )
104
105 librsvg_c_lib = rust_artifacts[0]
106
107 makedef_args = [
108 makedef,
109 '--regex',
110 '^rsvg_.',
111 ]
112
113 if host_system in ['darwin', 'ios']
114 makedef_args += ['--os', 'darwin']
115 elif host_system in ['windows', 'cygwin']
116 makedef_args += ['--os', 'win']
117 else
118 makedef_args += ['--os', 'linux']
119 endif
120
121 if cc.symbols_have_underscore_prefix()
122 makedef_args += ['--prefix', '_']
123 else
124 makedef_args += ['--prefix', '']
125 endif
126
127 makedef_tool_args = []
128
129 if is_msvc_style
130 dumpbin = find_program('dumpbin')
131 makedef_tool_args += ['--dumpbin', dumpbin]
132 else
133 nm = find_program('llvm-nm', required: false)
134 if not nm.found()
135 if host_system in ['darwin', 'ios']
136 warning('llvm-nm not found, you may experience problems when creating the shared librsvg.')
137 warning('Please install the llvm-tools component through rustup, or point Meson to an existing LLVM installation.')
138 endif
139 nm = find_program('nm')
140 endif
141 makedef_tool_args += ['--nm', nm]
142 endif
143
144 sym_files = files(
145 '../win32/librsvg.symbols'
146 )
147
148 if pixbuf_dep.found()
149 sym_files += files(
150 '../win32/librsvg-pixbuf.symbols'
151 )
152 endif
153
154 librsvg_def = configure_file(
155 command: [makedef_args, '--list', '@INPUT@'],
156 input: sym_files,
157 output: '@[email protected]'.format(librsvg_pc),
158 capture: true,
159 )
160
161 librsvg_ver = custom_target(
162 '@[email protected]'.format(librsvg_pc),
163 command: [makedef_args, makedef_tool_args, '@INPUT@'],
164 input: librsvg_c_lib,
165 output: '@[email protected]'.format(librsvg_pc),
166 capture: true,
167 )
168
169 version_script = meson.current_build_dir() / '@[email protected]'.format(librsvg_pc)
170
171 if host_system in ['darwin', 'ios']
172 vflag = '-Wl,-exported_symbols_list,@0@'.format(version_script)
173 elif host_system in ['windows', 'cygwin']
174 vflag = []
175 else
176 vflag = '-Wl,--version-script,@0@'.format(version_script)
177 endif
178
179 # This is not strictly needed, but since we are telling Cargo to build a staticlib, it puts in
180 # all of Rust's standard library and code from dependencies even when it is not needed.
181 # With the following, we shrink the final .so size; see issue #965.
182 #
183 # Amyspark: this is still needed after switching to cargo-cbuild, since
184 # GIR requires a shared library under MSVC, and Meson will only accept it
185 # if the library is a Meson generated target.
186 # No further flags are needed under MSVC, because LINK will already strip
187 # the library by default.
188 #
189 # Also check for -Bsymbolic-functions linker flag used to avoid
190 # intra-library PLT jumps, if available.
191 strip_link_args = cc.get_supported_link_arguments(
192 '-Wl,-dead_strip',
193 '-Wl,--gc-sections',
194 '-Wl,-Bsymbolic-functions',
195 )
196
197 # The symbol list argument cannot be tested, as the dummy
198 # executable Meson uses will lack the necessary functions.
199 link_args = strip_link_args + vflag
200
201 # Some systems, reportedly OpenBSD and macOS, refuse
202 # to create libraries without any object files. Compiling
203 # this file, and adding its object file to the library,
204 # will prevent the library from being empty.
205 if cc.has_function_attribute('unused')
206 rsvg_dummy = configure_file(
207 command: [
208 python,
209 '-c',
210 'print("static int __attribute__((unused)) __rsvg_dummy;")'
211 ],
212 capture: true,
213 output: '_rsvg_dummy.c'
214 )
215 else
216 rsvg_dummy = configure_file(
217 command: [
218 python,
219 '-c',
220 'print("static int __rsvg_dummy; int dummy(void) { return __rsvg_dummy; }")'
221 ],
222 capture: true,
223 output: '_rsvg_dummy.c'
224 )
225 endif
226
227 librsvg_dep_args = []
228 librsvg_lib = librsvg_c_lib
229
230 # Wait on this dependency before trying to build using Rust
231 librsvg_rust_dep = rust_artifacts
232
233 if get_option('default_library') in ['shared', 'both']
234 librsvg_shared_lib = shared_library(
235 'rsvg-@0@'.format(librsvg_api_major),
236 rsvg_dummy,
237 link_whole: librsvg_c_lib,
238 link_args: link_args,
239 link_depends: librsvg_ver,
240 dependencies: library_dependencies,
241 include_directories: [includeinc],
242 override_options: default_overrides,
243 vs_module_defs: librsvg_def,
244 install: true,
245 version: meson.project_version() # it's not exact as m4
246 )
247 if get_option('default_library') == 'shared'
248 librsvg_lib = librsvg_shared_lib
249 endif
250 librsvg_rust_dep = librsvg_shared_lib
251 endif
252 if get_option('default_library') in ['static', 'both']
253 # Rust cannot yet use import libraries for MSVC which do not end in .lib.
254 # The static library must be manually generated so that it matches Meson's
255 # naming convention.
256 # See https://github.com/rust-lang/rust/issues/122455
257 librsvg_lib = custom_target(
258 'rsvg-2-static',
259 input: librsvg_c_lib,
260 output: '@0@rsvg-@1@.@2@'.format(lib_prefix, librsvg_api_major, 'a'),
261 command: [
262 python,
263 '-c',
264 'import os; import sys; import shutil; shutil.copy(sys.argv[1], sys.argv[2])',
265 '@INPUT0@',
266 '@OUTPUT0@'
267 ],
268 install: true,
269 install_dir: get_option('libdir'),
270 )
271 librsvg_dep_args += ['-DRSVG_STATIC']
272
273 librsvg_rust_dep = librsvg_lib
274 endif
275
276 # This is the main dependency to use for tests; it means "link to the library we just built"
277 librsvg_dep = declare_dependency(
278 sources: includes,
279 include_directories: [includeinc],
280 dependencies: library_dependencies,
281 compile_args: librsvg_dep_args,
282 link_with: librsvg_lib,
283 )
284
285 meson.override_dependency('librsvg-2.0', librsvg_dep)
286
287 pkg = import('pkgconfig')
288
289 # If any of the dependencies is e.g. wrap, ignore as we can't include
290 # them without knowing how they exposed the pkg-config module
291 # (if CMake, there's simply no way at all)
292 has_pkgconfig_dependencies = true
293
294 foreach i : library_dependencies_sole + private_dependencies
295 if i.found() and i.type_name() != 'pkgconfig'
296 warning('One or more dependencies are not provided by pkg-config, skipping generation of the pkg-config module.')
297 has_pkgconfig_dependencies = false
298 break
299 endif
300 endforeach
301
302 build_pixbuf_loader = build_pixbuf_loader.require(has_pkgconfig_dependencies,
303 error_message: 'The gdk-pixbuf loader target requires the pkg-config module'
304 )
305
306 if has_pkgconfig_dependencies
307 librsvg_c_pc = pkg.generate(
308 name : 'librsvg',
309 filebase: librsvg_pc,
310 description : 'library that renders svg files',
311 libraries : [librsvg_lib] + other_library_dependencies,
312 subdirs: librsvg_pc,
313 requires: library_dependencies_sole,
314 requires_private: private_dependencies,
315 libraries_private: private_libraries,
316 )
317 endif
318
319 if build_gir.allowed()
320 gir_args = [
321 '-DRSVG_COMPILATION'
322 ]
323
324 gir_includes = [
325 'GLib-2.0',
326 'GObject-2.0',
327 'Gio-2.0',
328 'cairo-1.0',
329 ]
330
331 vala_includes = [
332 'gio-2.0',
333 'cairo',
334 ]
335
336 if pixbuf_dep.found()
337 gir_includes += [
338 'GdkPixbuf-2.0',
339 ]
340
341 vala_includes += [
342 'gdk-pixbuf-2.0',
343 ]
344 endif
345
346 if get_option('default_library') == 'shared'
347 librsvg_gir = librsvg_lib
348 else
349 if is_msvc_style
350 librsvg_gir = librsvg_shared_lib
351 else
352 librsvg_gir = shared_library(
353 'rsvg-gir',
354 rsvg_dummy,
355 link_whole: librsvg_c_lib,
356 dependencies: library_dependencies,
357 include_directories: [includeinc],
358 )
359 endif
360 endif
361
362 rsvg_gir = gnome.generate_gir(
363 librsvg_gir,
364 namespace: 'Rsvg',
365 nsversion: '2.0',
366 symbol_prefix: [ 'rsvg', 'librsvg' ],
367 dependencies: library_dependencies,
368 includes: gir_includes,
369 env: extra_env,
370 export_packages: librsvg_pc,
371 header: ['librsvg/rsvg.h'],
372 install: true,
373 sources: includes,
374 extra_args: gir_args,
375 fatal_warnings: get_option('werror'),
376 )
377 endif
378
379 if build_tests
380 library_test_sources = files(
381 'tests/api.rs',
382 'tests/bugs.rs',
383 'tests/errors.rs',
384 'tests/filters.rs',
385 'tests/geometries.rs',
386 'tests/intrinsic_dimensions.rs',
387 'tests/loading_crash.rs',
388 'tests/loading_disallowed.rs',
389 'tests/primitive_geometries.rs',
390 'tests/primitives.rs',
391 'tests/reference.rs',
392 'tests/render_crash.rs',
393 'tests/shapes.rs',
394 'tests/text.rs',
395 'src/test_utils/compare_surfaces.rs',
396 'src/test_utils/mod.rs',
397 'src/test_utils/reference_utils.rs',
398 )
399
400 test(
401 'Rust tests (rsvg)',
402 cargo_wrapper,
403 timeout: -1, # no timeout
404 args: [
405 cargo_wrapper_args,
406 '--current-build-dir', meson.current_build_dir(),
407 '--command=test',
408 '--current-source-dir', meson.current_source_dir(),
409 '--packages', 'librsvg',
410 ] + avif_feature_args,
411 env: extra_env,
412 depends: librsvg_rust_dep
413 )
414
415 test(
416 'Rust tests (librsvg)',
417 cargo_wrapper,
418 timeout: -1, # no timeout
419 args: [
420 cargo_wrapper_args,
421 '--current-build-dir', meson.current_build_dir(),
422 '--command=test',
423 '--current-source-dir', meson.current_source_dir(),
424 '--packages', 'librsvg-c',
425 ] + avif_feature_args
426 + pixbuf_feature_args,
427 env: extra_env,
428 depends: librsvg_rust_dep
429 )
430 endif