@@ -57,9 +57,9 @@ The ``meson.build`` definition in your project root should look like:
5757 default_options: ['cpp_std=c++17', 'b_ndebug=if-release'],
5858 )
5959
60- py = import('python').find_installation()
60+ python = import('python').find_installation()
6161 nanobind_dep = dependency('nanobind')
62- py .extension_module(
62+ mod = python .extension_module(
6363 'my_module_name',
6464 sources: ['path_to_module.cpp'],
6565 dependencies: [nanobind_dep],
@@ -103,9 +103,9 @@ to build extensions against the CPython 3.12 stable ABI, use:
103103 default_options: ['cpp_std=c++17', 'b_ndebug=if-release'],
104104 )
105105
106- py = import('python').find_installation()
106+ python = import('python').find_installation()
107107 nanobind_dep = dependency('nanobind')
108- py .extension_module(
108+ mod = python .extension_module(
109109 'my_module_name',
110110 sources: ['path_to_module.cpp'],
111111 dependencies: [nanobind_dep],
@@ -114,3 +114,22 @@ to build extensions against the CPython 3.12 stable ABI, use:
114114 )
115115
116116 as your ``meson.build `` file.
117+
118+ Stub generation
119+ ---------------
120+
121+ You can configure the build to write a stub file for your extension module
122+ by adding the following to ``meson.build ``:
123+
124+ .. code-block :: meson
125+
126+ stubgen = nanobind_dep.get_variable('stubgen')
127+ custom_target(
128+ output: 'my_module_name.pyi',
129+ depends: mod,
130+ command: [python, stubgen, '-m', 'my_module_name', '-M', 'py.typed'],
131+ build_by_default: true
132+ )
133+
134+ Then, after building your module, the build system will use nanobind's command
135+ line interface for :ref: `stub generation <stubs >`.
0 commit comments