Compiling rusty_v8 (Deno) from source

  • Thread starter Deleted member 62382
  • Start date
D

Deleted member 62382

Guest
I'm trying to build Deno (a javascript runtime built in rust) from source on FreeBSD 12.1. They only provide binaries for windows, macOS and Linux.<br>
The compilation failed at rusty_v8, which is require to compile Deno.<br>

I then try to compile directly from the rusty_v8 repository.

I've followed the instructions from the github repository:
- installed glib-2.56.3_7,1.
- installed python2.7 and create a symlink to "python" since it's required to have python and python2.7 binary is "python2".

I then ran cargo build and everything compiles until I get this error:

Code:
 Compiling rusty_v8 v0.5.0 (/root/rusty_v8)
     Running `CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_HOMEPAGE= CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=5 CARGO_PKG_NAME=rusty_v8 CARGO_PKG_REPOSITORY='https://github.com/denoland/rusty_v8' CARGO_PKG_AUTHORS='the Deno authors' CARGO_PKG_DESCRIPTION='Rust bindings to V8' CARGO_MANIFEST_DIR=/root/rusty_v8 CARGO=/usr/local/bin/cargo LD_LIBRARY_PATH='/root/rusty_v8/target/debug/deps:/usr/local/lib' CARGO_PKG_VERSION_PRE= CARGO_PKG_VERSION=0.5.0 rustc --crate-name build_script_build --edition=2018 build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=719d54043908067c -C extra-filename=-719d54043908067c --out-dir /root/rusty_v8/target/debug/build/rusty_v8-719d54043908067c -C incremental=/root/rusty_v8/target/debug/incremental -L dependency=/root/rusty_v8/target/debug/deps --extern cargo_gn=/root/rusty_v8/target/debug/deps/libcargo_gn-b31804f02f0a6a61.rlib --extern which=/root/rusty_v8/target/debug/deps/libwhich-e5ce3a8d7f279796.rlib -L native=/root/rusty_v8/target/debug/build/backtrace-sys-2d9c9cf21034351a/out`
error[E0308]: mismatched types
   --> build.rs:117:18
    |
117 | fn platform() -> &'static str {
    |    --------      ^^^^^^^^^^^^ expected `&str`, found `()`
    |    |
    |    implicitly returns `()` as its body has no tail or `return` expression

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `rusty_v8`.

Detail of the error:
Code:
This error occurs when the compiler was unable to infer the concrete type of a
variable. It can occur for several cases, the most common of which is a
mismatch in the expected type that the compiler inferred for a variable's
initializing expression, and the actual type explicitly assigned to the
variable.

For example:
```
let x: i32 = "I am not a number!";
//     ~~~   ~~~~~~~~~~~~~~~~~~~~
//      |             |
//      |    initializing expression;
//      |    compiler infers type `&str`
//      |
//    type `i32` assigned to variable `x`


I'm fairly new in the UNIX / FreeBSD world and I have no experience with Rust. I doubt it's an issue with Rust by itself, since I tried to compile the same source code
Could someone provide me some hints about what the problem could be? Or even some ressources which would help me understand why I can't compile this code?
 
It's a temporary VM anyway so this won't be a problem since I'll probably create another VM after. But thanks for the advice!

I've dig a bit more into the problem and have few more informations to provide.

Deno depends on sys-info-rs which has been ported recently to FreeBSD. I confirm it compiles correctly on FreeBSD.

Concerning, rusty_v8, the error I mentioned above comes from this function:

Code:
fn platform() -> &'static str {
  #[cfg(target_os = "windows")]
  {
    "win"
  }
  #[cfg(target_os = "linux")]
  {
    "linux64"
  }
  #[cfg(target_os = "macos")]
  {
    "mac"
  }
}

Works need to be done to port rusty_v8 to FreeBSD. LiWenHsu seems to be working on the Deno port for FreeBSD. I'll contact him to have more informations.
 
Quite often you need to patch build scripts or other files in order to get it to build correctly on FreeBSD. That's all part of the porting process.
 
Code:
fn platform() -> &'static str {
  #[cfg(target_os = "windows")]
  {
    "win"
  }
  #[cfg(target_os = "linux")]
  {
    "linux64"
  }
  #[cfg(target_os = "macos")]
  {
    "mac"
  }
}
What is happening here is that the platform function should return a string for the target FreeBSD, but here we only have:
Windows, GNU/Linux, and MacOs
So the fix should be: (for reference on target_os : https://doc.rust-lang.org/reference/conditional-compilation.html#target_os )
Code:
fn platform() -> &'static str {
  #[cfg(target_os = "windows")]
  {
    "win"
  }
  #[cfg(target_os = "linux")]
  {
    "linux64"
  }
  #[cfg(target_os = "macos")]
  {
    "mac"
  }
 #[cfg(target_os = "freebsd")]
  {
    "freebsd"
  }
}
 
Back
Top