denoland / rusty_v8

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

Can't build by `cargo build` #1634

Open felixf4xu opened 1 month ago

felixf4xu commented 1 month ago

Hi,

I cloned this repo and its submodules, then in the root folder of the repo, I run cargo build

warning: /home/ccccc/github/rusty_v8/Cargo.toml: file `/home/ccccc/github/rusty_v8/build.rs` found to be present in multiple build targets:
  * `integration-test` target `build`
  * `build-script` target `build-script-build`
   Compiling v8 v129.0.0 (/home/ccccc/github/rusty_v8)
error: couldn't read /home/ccccc/github/rusty_v8/gen/src_binding_release_x86_64-unknown-linux-gnu.rs: No such file or directory (os error 2)
 --> src/binding.rs:5:1
  |
5 | include!(env!("RUSTY_V8_SRC_BINDING_PATH"));
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `v8` (lib) due to 1 previous error

I'm not sure if this is the right first step to build.

I did not set any env variable.

bartlomieju commented 1 month ago

You will need to specify V8_FROM_SOURCE=1 env var as per https://github.com/denoland/rusty_v8?tab=readme-ov-file#build-v8-from-source

felixf4xu commented 1 month ago

thanks, but what I want is to build with the .a (v8 library).

By what setting will this repo built with the binary form of v8 library? From what I read from the readme, it should be default.

Anything that I missed?

bartlomieju commented 1 month ago

@devsnek can you take a look?

devsnek commented 1 month ago

@felixf4xu if you're building with a pre-existing .a file you will also need a src_binding.rs file. building with V8_FROM_SOURCE=1 will create this file, which is the intended way to build from the repo.

felixf4xu commented 1 month ago

Thanks, I guess I was confused by the readme:

Binaries builds are turned on by default: cargo build will initiate a download from github to get the static lib. To disable this build using the V8_FROM_SOURCE environmental variable.

Anyway, I would like to share my steps to build this repo.

  1. build with V8_FROM_SOURCE=1 at least once
    V8_FROM_SOURCE=1 cargo build

    This will fail after a lot of c++ errors which is not a surprise, but it will create the target/debug/gn_out/src_binding.rs file and print out this line

    [v8 129.0.0] cargo:rustc-env=RUSTY_V8_SRC_BINDING_PATH=/home/ccc/github/rusty_v8/target/debug/gn_out/src_binding.rs
  2. then build with V8_FROM_SOURCE=0 again with src_binding.rs
    V8_FROM_SOURCE=0 RUSTY_V8_SRC_BINDING_PATH=/home/ccc/github/rusty_v8/target/debug/gn_out/src_binding.rs cargo build

    it will build successfully very fast, because target/debug/gn_out/obj/librusty_v8.a is downloaded not compiled.

Then I can go on to try the examples by cargo build --example hello_world and cargo run --example hello_world , it's nice to see the output of 3 + 4 = 7!

But this building process makes me wonder, if only src_binding.rs is needed, is there any easier step to create it instead of forcing to build from source once? it says

/* automatically generated by rust-bindgen 0.69.4 */

Option 1: can we just generate src_binding.rs instead of try to build all v8 from source?

Option 2: can we check in the src_binding.rs file into git? I see it's generated by src/binding.hpp and v8/include, and both of those 2 dependencies are checked in, so it might be possible to also check in src_binding.rs together in one commit to avoid version mismatch.