rusty_v8 icon indicating copy to clipboard operation
rusty_v8 copied to clipboard

Can't build by `cargo build`

Open felixf4xu opened this issue 1 year ago • 5 comments

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.

felixf4xu avatar Oct 01 '24 15:10 felixf4xu

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

bartlomieju avatar Oct 01 '24 16:10 bartlomieju

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?

felixf4xu avatar Oct 02 '24 02:10 felixf4xu

@devsnek can you take a look?

bartlomieju avatar Oct 02 '24 12:10 bartlomieju

@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.

devsnek avatar Oct 02 '24 16:10 devsnek

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
  1. 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.

felixf4xu avatar Oct 03 '24 05:10 felixf4xu

I also hit this issue - the onboarding is really confusing - should the build.rs do some extra checks and print a useful message instead? Or have some defaults that "just work" on the first cargo build ?

nyurik avatar Jan 31 '25 22:01 nyurik

src_binding.rs is target and build configuration specific, so it can´t be easily checked in. If you're building from the git repo the only officially supported way is with V8_FROM_SOURCE=1. If you don´t want to build from source, just use the crate.

devsnek avatar Jan 31 '25 22:01 devsnek

@devsnek could you adjust the README? This section is really confusing, as it implies that git clone with submodules + cargo build should work from the start.

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.

nyurik avatar Jan 31 '25 22:01 nyurik