DouglasGray / xsk-rs

A Rust interface for Linux AF_XDP sockets
MIT License
68 stars 16 forks source link

Missing asm/types.h during build #32

Closed DavidAntliff closed 2 months ago

DavidAntliff commented 2 months ago

I am attempting to build 85b1f5ebf1661c680306fad4904889f25050be55 on an Ubuntu 22.04 with kernel 6.5.0-45-generic.

I figured that xdp-tutorial setup dependencies was the closest thing to the dependencies I might need for this project, so I installed everything I needed to successfully ./configure && make that project.

Then, returning to this project:

$ cargo build --tests
...
   Compiling libxdp-sys v0.2.0
   Compiling netlink-sys v0.8.6
   Compiling netlink-proto v0.11.3
   Compiling rtnetlink v0.14.1
error: failed to run custom build command for `libxdp-sys v0.2.0`

Caused by:
  process didn't exit successfully: `/..../xsk-rs.git/target/debug/build/libxdp-sys-8b968c09fd6120ef/build-script-build` (exit status: 101)
  --- stdout

  lib

    libxdp
      CLANG    xdp-dispatcher.o

  --- stderr
  In file included from xdp-dispatcher.c:3:
  In file included from ../../headers/linux/bpf.h:11:
  /usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
  #include <asm/types.h>
           ^~~~~~~~~~~~~
  1 error generated.
  make[2]: *** [Makefile:137: xdp-dispatcher.o] Error 1
  make[1]: *** [Makefile:20: libxdp] Error 2
  make: *** [Makefile:28: libxdp] Error 2
  thread 'main' panicked at /home/..../.cargo/registry/src/index.crates.io-6f17d22bba15001f/libxdp-sys-0.2.0/build.rs:20:5:
  make failed
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I see this is referring to /usr/include/linux/ rather than a path related to the current kernel, like /usr/src/linux-headers-6.5.0-45-generic/. There is no asm/types.h anywhere in this tree.

asm/types.h does occur under /usr/src/linux-headers-6.5.0-45-generic/ (owned by package linux-headers-6.5.0-45-generic) as /usr/src/linux-headers-6.5.0-45-generic/arch/x86/include/generated/uapi/asm/types.h. This matches my kernel version.

I'm at a bit of a loss as to how to satisfy this project's need for asm/types.h, as the named file simply doesn't exist in my /usr/include/linux directory (owned by package linux-libc-dev:amd64). Apparently, this directory has special significance for system libraries, and should not be used for general "compile against current kernel headers" tasks, but I don't know if this applies to this project.

What's the right way to fix this, please?

DavidAntliff commented 2 months ago

This seems to work, but I have no idea if it's a good idea or not:

$ sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm

Refer https://github.com/openwrt/openwrt/issues/12239#issuecomment-2285252245

However, I've since learned that installing gcc-multilib creates this symlink:

$ sudo apt-get install gcc-multilib
$ ls -l /usr/include/asm
lrwxrwxrwx 1 root root 20 Aug  5  2021 /usr/include/asm -> x86_64-linux-gnu/asm
DavidAntliff commented 2 months ago

This means the full set of packages I needed to install, for Ubuntu 22.04, is:

$ sudo apt-get install \
    linux-headers-$(uname -r) \
    clang \
    llvm \
    libelf-dev \
    libpcap-dev \
    build-essential \
    libc6-dev-i386 \
    gcc-multilib

Hope this helps someone down the line.

DouglasGray commented 2 months ago

sorry just saw this. closing as it appears resolved, thanks

DavidAntliff commented 2 months ago

My only suggestion would be to have this project’s getting started docs point to the xdp-tutorial’s dependency install docs, as it wasn’t clear to me initially how to build this project. Unlike most Rust projects, this one has quite a few non-cargo-managed dependencies. The symlink issue is just an Ubuntu quirk, perhaps.

DouglasGray commented 2 months ago

good idea. will do that some time this week when I fix the clippy errors. thanks for the help!