denoland / rusty_v8

Rust bindings for the V8 JavaScript engine
https://crates.io/crates/v8
MIT License
3.13k stars 302 forks source link

Failed to build rusty_v8 since v0.95.0 #1595

Open AuTsing opened 2 weeks ago

AuTsing commented 2 weeks ago

Since v0.95.0, a new feature #1507 has been merged. I got some errors when compiling v8.

Error message:

  ...
  ninja: Entering directory `/home/autsing/Gits/rusty_v8/target/debug/gn_out'
  ninja: no work to do.
  cargo:rustc-link-search=native=/home/autsing/Gits/rusty_v8/target/debug/gn_out/obj/
  cargo:rerun-if-env-changed=TARGET
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
  cargo:rerun-if-changed=src/binding.hpp

  --- stderr
  thread 'main' panicked at /home/autsing/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bindgen-0.69.4/lib.rs:622:31:
  Unable to find libclang: "couldn't find any valid shared libraries matching: ['libclang.so', 'libclang-*.so', 'libclang.so.*', 'libclang-*.so.*'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This error occurs in v8 build.rs running build_binding. I guess this is because bindgen denps on clang, but I haven't configured it.

My build host is WSL Ubuntu 22.04. My build steps are as follows:

  1. Install python, curl, libglib2.0-dev.
  2. Clone rusty_v8 repo.
  3. Run command V8_FROM_SOURCE=1 cargo build -vv.

This set of steps works before v0.94.0.

Acctually, I was able to build successfully in github action. So I think this may be caused by my environment not being configured. At first I wanted to build for Android, I encountered a problem that the header file could not be found. Then I tired build for x86_64-unknown-linux-gnu, I encountered the similar problem.

According to README:

The build depends on several binary tools: gn, ninja and clang. The tools will automatically be downloaded, if they are not detected in the environment.

Clang can be automatically downloaded and configured. Maybe the new version need to configure clang?

caineblood commented 2 weeks ago

The above comment asking you to download a file is malware to steal your account; do not under any circumstances download or run it. The post needs to be removed. If you have attempted to run it please have your system cleaned and your account secured immediately.

devsnek commented 2 weeks ago

I wonder if we need to set up bindgen to look in the right place for clang. Could you try temporarily setting CLANG_PATH to the downloaded clang location? (iirc it is in target/xyz/clang)

AuTsing commented 1 week ago

@devsnek Thanks for your answer. I have tried setting env CLANG_PATH, but it didn't work with the same error message.

After I looked through the doc of bindgen. I found that bindgen uses the clang installed locally(https://rust-lang.github.io/rust-bindgen/requirements.html#requirements). I didn't install them at first, so the error message show Unable to find libclang.

And I installed clang with apt install llvm-dev libclang-dev clang. I build x86_64-unknown-linux-gnu successfully.

Although it has been successfully compiled, I‘m confused about some issues. The rusty_v8 will automatically download and use clang, but bindgen will not use it, bindgen will use the locally clang. So maybe we should point out that install these requirements before we build? Or maybe we should configure bindgen to use the clang download automatically(Actually I didn't know how to configure it, I tried different ways but it didn't work)?

devsnek commented 1 week ago

I looked into this some more and it turns out that the clang we download from chromium does not include libclang shared libraries. I'm discussing with them whether these can be included, in which case it should be fairly trivial to set up build.rs to automatically use them instead of the system clang.