@@ -260,15 +260,6 @@ if toolchain_arg != []
260260 cargo_wrapper_args += toolchain_arg
261261endif
262262
263- includes = files (
264- ' include/accesskit.h'
265- )
266-
267- install_headers (
268- includes,
269- subdir : ' @0@' .format(accesskit_c_lib_name),
270- )
271-
272263library_sources = files (
273264 ' Cargo.lock' ,
274265 ' Cargo.toml' ,
@@ -280,6 +271,48 @@ library_sources = files(
280271 ' src/windows.rs' ,
281272)
282273
274+ # Header generation with cbindgen
275+ generated_headers_directory = meson .project_source_root() / ' include'
276+ rustup = find_program (' rustup' , required : false )
277+ cbindgen = find_program (' cbindgen' , required : false )
278+ clang_format = find_program (' clang-format' , required : false )
279+
280+ if rustup.found() and cbindgen.found() and clang_format.found()
281+ # Generate header with cbindgen, then format
282+ generated_header = custom_target (
283+ ' accesskit_unformatted.h' ,
284+ output : ' accesskit_unformatted.h' ,
285+ depend_files : [library_sources, ' .clang-format' , ' cbindgen.toml' ],
286+ command : [
287+ rustup, ' run' , ' nightly-2025-03-27' ,
288+ cbindgen, ' --crate' , ' accesskit-c' , ' --output' , ' @OUTPUT@' ,
289+ meson .project_source_root()
290+ ],
291+ build_by_default : false ,
292+ )
293+
294+ formatted_header = custom_target (
295+ ' accesskit.h' ,
296+ input : generated_header,
297+ output : ' accesskit.h' ,
298+ command : [clang_format, ' @INPUT@' ],
299+ capture : true ,
300+ build_by_default : false ,
301+ install : true ,
302+ install_dir : generated_headers_directory,
303+ install_tag : [' generated-headers' ],
304+ )
305+ endif
306+
307+ includes = files (
308+ generated_headers_directory / ' accesskit.h'
309+ )
310+
311+ install_headers (
312+ includes,
313+ subdir : ' @0@' .format(accesskit_c_lib_name),
314+ )
315+
283316rust_artifacts = custom_target (
284317 ' accesskit-c' ,
285318 build_by_default : true ,
@@ -440,6 +473,7 @@ if get_option('default_library') in ['static', 'both']
440473 ],
441474 install : true ,
442475 install_dir : get_option (' libdir' ),
476+ install_tag : [' devel' ],
443477 )
444478endif
445479
0 commit comments