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.63.0: 8```bash 9cargo install bindgen-cli --vers 0.63.0 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_mmio \ 43 virtio_net \ 44 virtio_ring \ 45 virtio_scsi \ 46 ; do \ 47 bindgen include/linux/$i.h -o $i.rs \ 48 --allowlist-file include/linux/$i.h \ 49 --with-derive-default \ 50 --with-derive-partialeq \ 51 -- -Iinclude 52done 53cd ~ 54 55# Step 6: Copy the generated files to the new version module. 56cp linux/v5_0_headers/*.rs vm-virtio/crates/virtio-bindings/src 57mv vm-virtio/crates/virtio-bindings/src/virtio_net.rs vm-virtio/crates/virtio-bindings/src/virtio_net/generated.rs 58``` 59