ada-url / rust

Rust bindings for Ada URL parser
https://crates.io/crates/ada-url
Apache License 2.0
86 stars 12 forks source link

fails to build on debian sid #59

Closed ju1ius closed 10 months ago

ju1ius commented 10 months ago

Hi,

Building ada-url on debian sid fails. Running the following commands:

git clone --depth=1 https://github.com/ada-url/rust.git ada-url
cd ada-url
cargo build
Produces the following output: ``` Compiling ada-url v2.2.1 (/ada-url) The following warnings were emitted during compilation: warning: ada-url@2.2.1: In file included from ./deps/ada.cpp:3: warning: ada-url@2.2.1: ./deps/ada.h:20:10: fatal error: 'string' file not found warning: ada-url@2.2.1: #include warning: ada-url@2.2.1: ^~~~~~~~ warning: ada-url@2.2.1: 1 error generated. error: failed to run custom build command for `ada-url v2.2.1 (/ada-url)` Caused by: process didn't exit successfully: `/ada-url/target/debug/build/ada-url-ba3156cf87bc7d44/build-script-build` (exit status: 1) --- stdout OPT_LEVEL = Some("0") TARGET = Some("x86_64-unknown-linux-gnu") HOST = Some("x86_64-unknown-linux-gnu") cargo:rerun-if-env-changed=CXX_x86_64-unknown-linux-gnu CXX_x86_64-unknown-linux-gnu = None cargo:rerun-if-env-changed=CXX_x86_64_unknown_linux_gnu CXX_x86_64_unknown_linux_gnu = None cargo:rerun-if-env-changed=HOST_CXX HOST_CXX = None cargo:rerun-if-env-changed=CXX CXX = Some("clang++") cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None DEBUG = Some("true") cargo:rerun-if-env-changed=CXXFLAGS_x86_64-unknown-linux-gnu CXXFLAGS_x86_64-unknown-linux-gnu = None cargo:rerun-if-env-changed=CXXFLAGS_x86_64_unknown_linux_gnu CXXFLAGS_x86_64_unknown_linux_gnu = None cargo:rerun-if-env-changed=HOST_CXXFLAGS HOST_CXXFLAGS = None cargo:rerun-if-env-changed=CXXFLAGS CXXFLAGS = None running: "clang++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "--target=x86_64-unknown-linux-gnu" "-std=c++17" "-I" "./deps/ada.h" "-I" "./deps/ada_c.h" "-Wall" "-Wextra" "-o" "/ada-url/target/debug/build/ada-url-b4939785ec9bcc43/out/./deps/ada.o" "-c" "./deps/ada.cpp" cargo:warning=In file included from ./deps/ada.cpp:3: cargo:warning=./deps/ada.h:20:10: fatal error: 'string' file not found cargo:warning=#include cargo:warning= ^~~~~~~~ cargo:warning=1 error generated. exit status: 1 --- stderr error occurred: Command "clang++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "--target=x86_64-unknown-linux-gnu" "-std=c++17" "-I" "./deps/ada.h" "-I" "./deps/ada_c.h" "-Wall" "-Wextra" "-o" "/ada-url/target/debug/build/ada-url-b4939785ec9bcc43/out/./deps/ada.o" "-c" "./deps/ada.cpp"with args "clang++" did not execute successfully (status code exit status: 1). ```

It seems that clang cannot find the c++ stdlib... 🤔 Moreover, the build script unconditionally sets the compiler to clang++, which makes trying another compiler (or another clang version) impossible.

If I comment out the aforementioned line and build with CXX=g++ cargo build, the library builds correctly and tests pass:

$ CXX=g++ cargo build
   Compiling ada-url v2.2.1 (/ada-url)
warning: ada-url@2.2.1: cc1plus: warning: ./deps/ada.h: not a directory
warning: ada-url@2.2.1: cc1plus: warning: ./deps/ada_c.h: not a directory
    Finished dev [unoptimized + debuginfo] target(s) in 3.57s

Also note the warnings caused by the build script's passing files to cc::Build::include() instead of directories.

IMO, the build script should let the cc crate detect the correct compiler on UNIX platforms.

anonrig commented 10 months ago

Can you install libc++ to your system, and re-test it? It seems similar to https://github.com/ada-url/rust/issues/43

anonrig commented 10 months ago

IMO, the build script should let the cc crate detect the correct compiler on UNIX platforms.

Would you like to open a PR?

ju1ius commented 10 months ago

Can you install libc++ to your system, and re-test it? It seems similar to #43

After installing the libc++-dev package:

$ clang++ -O0 -std=c++17 -o ./ada.o -c ./deps/ada.cpp
In file included from ./deps/ada.cpp:3:
./deps/ada.h:20:10: fatal error: 'string' file not found
#include <string>
         ^~~~~~~~
1 error generated.

And

$ clang++ -O0 -std=c++17 -stdlib=libc++ -o ./ada.o -c ./deps/ada.cpp

So it seems that somehow clang cannot use the gcc version of the c++ stdlib on debian... That's weird, cause I'm pretty sure it used to work. Maybe it broke in a recent update...

Anyway, since gcc can compile the library just fine, I still think the compiler shouldn't be forced on end users.

Would you like to open a PR?

OK, I'll do.