Skip to content

Commit c441ef4

Browse files
authored
chore: Use Meson to generate the header file (#55)
1 parent f45c4a4 commit c441ef4

File tree

3 files changed

+60
-13
lines changed

3 files changed

+60
-13
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,19 @@ jobs:
110110
steps:
111111
- uses: actions/checkout@v5
112112

113-
- name: install nightly toolchain
113+
- uses: actions/setup-python@v6
114+
- run: pip install meson ninja
115+
116+
- name: install nightly Rust toolchain
114117
uses: dtolnay/rust-toolchain@master
115118
with:
116119
toolchain: nightly-2025-03-27
117120

118-
- uses: dtolnay/install@master
121+
- name: install cbindgen
122+
uses: dtolnay/install@master
119123
with:
120124
crate: cbindgen
121-
- run: cmake -S . -B build -DACCESSKIT_BUILD_HEADERS=ON -DACCESSKIT_BUILD_LIBRARIES=OFF
122-
- run: cmake --build build
125+
126+
- run: meson setup build
127+
- run: meson compile -C build accesskit.h
123128
- run: cmp build/accesskit.h include/accesskit.h

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ cmake --build build
6969
cmake --install build
7070
```
7171

72+
Alternatively, you can use Meson like so:
73+
74+
```console
75+
meson setup build
76+
meson compile -C build accesskit.h
77+
meson install -C build --tags generated-headers --no-rebuild
78+
```
79+
7280
## License
7381

7482
AccessKit is licensed under the [Apache License, Version 2.0](LICENSE-APACHE) or the [MIT license](LICENSE-MIT), at your option.

meson.build

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,6 @@ if toolchain_arg != []
260260
cargo_wrapper_args += toolchain_arg
261261
endif
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-
272263
library_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+
283316
rust_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
)
444478
endif
445479

0 commit comments

Comments
 (0)