error: failed to run custom build command for `tun-tap v0.1.4`

128 views Asked by At

I want to make a TCP server in rust but I get the error: 'error: failed to run custom build command for tun-tap v0.1.4'. I saw some other posts that had a similar issue, but there solution did not work for me.

What do I have: OS: Windows CMake installed (Version: 3.27.4) Rust (rustc 1.75.0-nightly) Cargo (cargo 1.75.0-nightly)

Crate: tun-tap v0.1.4 (installed)

I have tried updating rust, CMake and Cargo. Also clean building the project after the updates. This was what I found online for similar issue's. I still have the same problem.

This is the verbose build log from the project:
       Fresh autocfg v1.1.0
       Fresh cfg-if v0.1.10
       Fresh lazy_static v1.4.0
       Fresh winapi-build v0.1.1
       Fresh semver-parser v0.7.0
       Fresh futures v0.1.31
       Fresh scopeguard v1.2.0
       Fresh iovec v0.1.4
       Fresh log v0.4.20
       Fresh winapi v0.2.8
       Fresh byteorder v1.5.0
       Fresh semver v0.9.0
       Fresh bytes v0.4.12
       Fresh num_cpus v1.16.0
       Fresh lock_api v0.3.4
       Fresh fnv v1.0.7
       Fresh cc v1.0.83
       Fresh scoped-tls v0.1.2
       Fresh maybe-uninit v2.0.0
       Fresh crossbeam-utils v0.7.2
       Fresh rustc_version v0.2.3
       Fresh winapi v0.3.9
       Fresh slab v0.4.9
       Fresh tokio-io v0.1.13
       Fresh memoffset v0.5.6
       Fresh tokio-sync v0.1.8
       Fresh tokio-executor v0.1.10
       Fresh smallvec v0.6.14
       Fresh kernel32-sys v0.2.2
       Fresh net2 v0.2.39
       Fresh ws2_32-sys v0.2.1
       Fresh crossbeam-epoch v0.8.2
       Fresh crossbeam-queue v0.2.3
       Fresh tokio-codec v0.1.2
   Compiling tun-tap v0.1.4
       Fresh libc v0.2.149
       Fresh miow v0.2.2
       Fresh crossbeam-deque v0.7.4
       Fresh tokio-timer v0.2.13
       Fresh tokio-current-thread v0.1.7
     Running `C:\Users\name\RustroverProjects\serverTCP\target\debug\build\tun-tap-ca08b732199efdac\build-script-build`
       Fresh parking_lot_core v0.6.3
       Fresh mio v0.6.23
       Fresh tokio-threadpool v0.1.18
       Fresh parking_lot v0.9.0
       Fresh tokio-fs v0.1.7
       Fresh tokio-reactor v0.1.12
       Fresh tokio-udp v0.1.6
       Fresh tokio-tcp v0.1.4
       Fresh tokio v0.1.22
       Fresh tokio-core v0.1.18
error: failed to run custom build command for `tun-tap v0.1.4`                                                                                                                                                                     

Caused by:
  process didn't exit successfully: `C:\Users\name\RustroverProjects\serverTCP\target\debug\build\tun-tap-ca08b732199efdac\build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("x86_64-pc-windows-msvc")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-pc-windows-msvc")
  cargo:rerun-if-env-changed=CC_x86_64-pc-windows-msvc
  CC_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CC_x86_64_pc_windows_msvc
  CC_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  DEBUG = Some("true")
  cargo:rerun-if-env-changed=CFLAGS_x86_64-pc-windows-msvc
  CFLAGS_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_pc_windows_msvc
  CFLAGS_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.37.32822\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-W4" "-FoC:\\Users\\name\\RustroverProjects\\serverTCP\\target\\debug\\build\\tun-tap-e9c5c2c2bb1e0d64\\out\\src/tuntap.o" "-c" "src/tuntap.c"
  tuntap.c
  src/tuntap.c(10): fatal error C1083: Cannot open include file: 'sys/socket.h': No such file or directory
  exit code: 2

  --- stderr


  error occurred: Command "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.37.32822\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-W4" "-FoC:\\Users\\name\\RustroverProjects\\serverTCP\\target\\debug\\build\\tun-tap-e9c5c2c2bb1e0d64\\out\\src/tuntap.o" "-c" "src/tuntap.c" with args "cl.exe" did not execute successfully (status code exit code: 2).

I can see that the "sys/socket.h" is not there because windows is thrash. How can this be fixed?

1

There are 1 answers

1
bk2204 On BEST ANSWER

The tun-tap crate is designed for Unix and uses a C file that depends on sys/socket.h, which is a normal location for socket definitions on Unix, but doesn't exist on Windows. The crate README documents that it's tested only on Linux and may not work elsewhere.

As it stands, this crate cannot functionally compile on Windows without code changes. You may wish to try under the Windows Subsystem for Linux, although whether that will be useful for you depends on what you want to do.

Alternatively, you may be able to implement your code without the need for the tun-tap crate. It is absolutely possible to implement a TCP server in Rust using the standard library or using Tokio (if you prefer an async approach) and the tun-tap crate isn't necessary to do that.