@@ -50,5 +50,67 @@ destination = "project/lib/{shared_library}"
5050Destination templates support ` {module} ` , ` {target} ` , ` {profile} ` , ` {library} ` ,
5151` {shared_library} ` , and ` {python_extension_name} ` .
5252
53+ ### Generated files and headers
54+
55+ ` command ` artifacts run an argv-list command and then validate explicit outputs.
56+ Outputs can be packaged into the wheel, installed as wheel shared data, or used
57+ only as required validation checks. ` header ` artifacts are a typed shorthand for
58+ validated header outputs and can also use ` generator = "cbindgen" ` in CLI or
59+ build-script mode.
60+
61+ ``` toml
62+ [[tool .hatch .build .hooks .hatch-rs .artifacts ]]
63+ name = " generated-package-files"
64+ kind = " command"
65+ command = [" python" , " scripts/write_generated_files.py" ]
66+ inputs = [" scripts/write_generated_files.py" ]
67+
68+ [[tool .hatch .build .hooks .hatch-rs .artifacts .outputs ]]
69+ source = " project/generated/package.txt"
70+ destination = " project/generated/package.txt"
71+ install-scheme = " package"
72+
73+ [[tool .hatch .build .hooks .hatch-rs .artifacts ]]
74+ name = " public-c-header"
75+ kind = " header"
76+ source = " project/include/project.h"
77+ destination = " include/project/project.h"
78+ install-scheme = " shared-data"
79+ ```
80+
81+ ### ABI validation and artifact metadata
82+
83+ Shared-library artifacts can validate the copied C ABI library before the wheel
84+ is finalized. The hook can check expected exported symbols, verify headers and
85+ ABI strings/macros, load the copied library with ` ctypes.CDLL ` , run project
86+ validation commands, include Windows import libraries, and emit a package-local
87+ artifact manifest.
88+
89+ ``` toml
90+ [tool .hatch .build .hooks .hatch-rs ]
91+ module = " project"
92+ target-dir = " isolated"
93+ artifact-manifest = true
94+
95+ [[tool .hatch .build .hooks .hatch-rs .artifacts ]]
96+ name = " c-abi"
97+ kind = " shared-library"
98+ manifest = " rust/Cargo.toml"
99+ library = " project_ffi"
100+ crate-type = " cdylib"
101+ destination = " project/lib/{shared_library}"
102+ expected-symbols = [" project_ffi_answer" ]
103+ expected-headers = [" project/include/project.h" ]
104+ expected-abi-strings = [" PROJECT_ABI_VERSION" ]
105+ runtime-load = true
106+ include-import-lib = true
107+
108+ [[tool .hatch .build .hooks .hatch-rs .artifacts .validation-commands ]]
109+ command = [" python" , " scripts/validate_abi.py" , " {destination}" , " {header}" ]
110+ ```
111+
112+ ` include-import-lib ` only packages an import library on Windows targets, where
113+ Cargo emits ` .dll.lib ` or ` .dll.a ` files for downstream native linkers.
114+
53115> [ !NOTE]
54116> This library was generated using [ copier] ( https://copier.readthedocs.io/en/stable/ ) from the [ Base Python Project Template repository] ( https://github.com/python-project-templates/base ) .
0 commit comments