alexcrichton / curl-rust

Rust bindings to libcurl
MIT License
1k stars 234 forks source link

Fix build error with clang #472

Closed ehuss closed 1 year ago

ehuss commented 1 year ago

Due to some include files being rearranged in more recent versions of curl, the sys/time.h header was no longer being included for timeval.c, which was causing the error:

  cargo:warning=curl/lib/timeval.c:106:11: error: call to undeclared function 'gettimeofday'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  cargo:warning=    (void)gettimeofday(&now, NULL);
  cargo:warning=          ^
  cargo:warning=1 error generated.

This fixes it by setting HAVE_SYS_TIME_H which would normally be set by the configure script.

I don't actually know why gcc treats this as a warning, and clang treats it as an error.

Details: curl_setup.h used to include curl.h which always imports sys/time.h. However, https://github.com/curl/curl/commit/e5839f4ee706054d3a9bb7430e0eac061d78e35a removed the curl.h import. The only way sys/time.h gets imported otherwise is in curl_setup_once.h, but that is conditional on HAVE_SYS_TIME_H.