|
1 | 1 | # Contributing to virtio-bindings
|
2 | 2 |
|
3 |
| -## Overview |
| 3 | +## Dependencies |
4 | 4 |
|
5 |
| -virtio-bindings is periodically updated with imported virtio headers from the |
6 |
| -Linux kernel. The Linux header files have kernel header dependencies that are |
7 |
| -removed during import so that bindgen can process them in isolation without a |
8 |
| -full set of kernel headers. This is also necessary because the licenses of |
9 |
| -individual kernel header files varies and we only want to distribute |
10 |
| -BSD-licensed virtio headers. |
| 5 | +### Bindgen |
| 6 | +The bindings are currently generated using |
| 7 | +[bindgen](https://rust-lang.github.io/rust-bindgen/) version 0.71.1: |
| 8 | +```bash |
| 9 | +cargo install bindgen-cli --vers 0.71.1 |
| 10 | +``` |
11 | 11 |
|
12 |
| -## Importing kernel headers |
| 12 | +### Linux Kernel |
13 | 13 | Generating bindings depends on the Linux kernel, so you need to have the
|
14 | 14 | repository on your machine:
|
15 | 15 |
|
16 | 16 | ```bash
|
17 | 17 | git clone https://github.com/torvalds/linux.git
|
18 | 18 | ```
|
19 | 19 |
|
20 |
| -Install the headers so they can be used for import: |
21 |
| -```bash |
22 |
| -cd linux |
23 |
| -git checkout <linux-version> |
24 |
| -make headers_install INSTALL_HDR_PATH=headers-<linux-version> |
25 |
| -``` |
| 20 | +## Example for updating to a new kernel version |
26 | 21 |
|
27 |
| -Import kernel headers into `include/`: |
28 |
| -```bash |
29 |
| -cd ~/vm-virtio/virtio-bindings |
30 |
| -./import-linux-headers.sh path/to/headers-<linux-version> |
31 |
| -``` |
| 22 | +For this example we assume that you have both linux and virtio-bindings |
| 23 | +repositories in your home directory. |
32 | 24 |
|
33 |
| -Test that the build still works: |
34 | 25 | ```bash
|
35 |
| -cargo build |
| 26 | +cd ~/vm-virtio/virtio-bindings |
| 27 | +scripts/generate-bindings.sh ~/linux |
36 | 28 | ```
|
37 |
| - |
38 |
| -## Adding bindings for new header files |
39 |
| -New kernel headers can be added as follows: |
40 |
| -1. Add the new file to import-linux-headers.sh so it is imported from the Linux |
41 |
| - kernel header directory into include/. |
42 |
| -2. Add the new file to build.rs so bindgen generates bindings. |
43 |
| -3. Add the new module to src/lib.rs so the generated bindings are exposed in |
44 |
| - the crate. |
45 |
| -4. Check if `cargo build` still succeeds. If the header has new kernel header |
46 |
| - dependencies then you need to add them (if they are BSD licensed) or stub |
47 |
| - them out (if they are not BSD licensed). |
0 commit comments