• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Contributing to virtio-bindings
2
3## Dependencies
4
5### Bindgen
6The bindings are currently generated using
7[bindgen](https://rust-lang.github.io/rust-bindgen/) version 0.70.1:
8```bash
9cargo install bindgen-cli --vers 0.70.1
10```
11
12### Linux Kernel
13Generating bindings depends on the Linux kernel, so you need to have the
14repository on your machine:
15
16```bash
17git clone https://github.com/torvalds/linux.git
18```
19
20## Example for updating to a new kernel version
21
22For this example we assume that you have both linux and virtio-bindings
23repositories in your root.
24
25```bash
26# linux is the repository that you cloned at the previous step.
27cd linux
28# Step 1: Checkout the version you want to generate the bindings for.
29git checkout v5.0
30
31# Step 2: Generate the bindings from the kernel headers. We need to generate a
32# file for each one of the virtio headers. For the moment, we are only picking
33# headers that we are interested in. Feel free to add additional header files if
34# you need them for your project.
35make headers_install INSTALL_HDR_PATH=v5_0_headers
36cd v5_0_headers
37for i in \
38        virtio_blk \
39        virtio_config \
40        virtio_gpu \
41        virtio_ids \
42        virtio_input \
43        virtio_mmio \
44        virtio_net \
45        virtio_ring \
46        virtio_scsi \
47        ; do \
48    bindgen include/linux/$i.h -o $i.rs \
49    --allowlist-file include/linux/$i.h \
50    --with-derive-default \
51    --with-derive-partialeq \
52    -- -Iinclude
53done
54cd ~
55
56# Step 6: Copy the generated files to the new version module.
57cp linux/v5_0_headers/*.rs vm-virtio/virtio-bindings/src
58mv vm-virtio/virtio-bindings/src/virtio_net.rs vm-virtio/virtio-bindings/src/virtio_net/generated.rs
59```
60