Skip to content

Commit

Permalink
Run Hermes CMake from cargo
Browse files Browse the repository at this point in the history
Summary:
Use the `cmake` crate instead of relying on an existing build of Hermes.
The crate puts the libraries in a given destination path, whence they
can be linked by `build.rs` directives.

It also handles the use of `--release` and sets the optimization and
debug flags automatically.

We have to `rerun-if-changed` in the relevant directories,
but we can't include the entire `hermes` directory because that would
capture all the other `juno` crates as well.

Reviewed By: tmikov

Differential Revision: D33714180

fbshipit-source-id: c68deea1fa652d46abda14185240e0db6b186127
  • Loading branch information
avp authored and facebook-github-bot committed Jan 26, 2022
1 parent 67fe974 commit 6c53047
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 42 deletions.
19 changes: 17 additions & 2 deletions unsupported/juno/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion unsupported/juno/crates/hermes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ libc = "0.2"
thiserror = "1.0"

[build-dependencies]
toml = "=0.5.7"
cmake = "0.1"
49 changes: 28 additions & 21 deletions unsupported/juno/crates/hermes/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,39 @@
* LICENSE file in the root directory of this source tree.
*/

use std::{env, fs};
use toml::Value;

fn main() {
let hermes_build = match env::var("HERMES_BUILD") {
Ok(dir) => dir,
Err(_) => {
let file =
fs::read_to_string(format!("{}/../../.hermes.toml", env!("CARGO_MANIFEST_DIR")))
.expect("Must provide either HERMES_BUILD env variable or .hermes.toml file");
let value = file.parse::<Value>().unwrap();
value["hermes_build"].as_str().unwrap().to_owned()
}
};
println!("cargo:rerun-if-changed=../../../../include");
println!("cargo:rerun-if-changed=../../../../lib");
println!("cargo:rerun-if-changed=../../../../external");
println!("cargo:rerun-if-changed=../../../../cmake");
println!("cargo:rerun-if-changed=../../../../CMakeLists.txt");

// Build sourceMap library because it depends on everything we depend on here
// via the hermesParser library.
let dst = cmake::Config::new("../../../../")
.build_target("hermesSourceMap")
.build();

println!("cargo:rustc-link-search={}/lib/Parser", hermes_build);
println!("cargo:rustc-link-search={}/build/lib/Parser", dst.display());
println!(
"cargo:rustc-link-search={}/build/lib/Platform/Unicode",
dst.display()
);
println!(
"cargo:rustc-link-search={}/build/lib/SourceMap",
dst.display()
);
println!(
"cargo:rustc-link-search={}/build/lib/Support",
dst.display()
);
println!(
"cargo:rustc-link-search={}/lib/Platform/Unicode",
hermes_build
"cargo:rustc-link-search={}/build/external/dtoa",
dst.display()
);
println!("cargo:rustc-link-search={}/lib/SourceMap", hermes_build);
println!("cargo:rustc-link-search={}/lib/Support", hermes_build);
println!("cargo:rustc-link-search={}/external/dtoa", hermes_build);
println!(
"cargo:rustc-link-search={}/external/llvh/lib/Support",
hermes_build
"cargo:rustc-link-search={}/build/external/llvh/lib/Support",
dst.display()
);

println!("cargo:rustc-link-lib=hermesSourceMap");
Expand Down
2 changes: 1 addition & 1 deletion unsupported/juno/crates/juno_support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ thiserror = "1.0"
url = "2.2.2"

[build-dependencies]
toml = "=0.5.7"
cmake = "0.1"
33 changes: 16 additions & 17 deletions unsupported/juno/crates/juno_support/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
* LICENSE file in the root directory of this source tree.
*/

use std::{env, fs};
use toml::Value;

fn main() {
let hermes_build = match env::var("HERMES_BUILD") {
Ok(dir) => dir,
Err(_) => {
let file =
fs::read_to_string(format!("{}/../../.hermes.toml", env!("CARGO_MANIFEST_DIR")))
.expect("Must provide either HERMES_BUILD env variable or .hermes.toml file");
let value = file.parse::<Value>().unwrap();
value["hermes_build"].as_str().unwrap().to_owned()
}
};

println!("cargo:rustc-link-search={}/lib/Support", hermes_build);
println!("cargo:rustc-link-search={}/external/dtoa", hermes_build);

println!("cargo:rerun-if-changed=../../../../include");
println!("cargo:rerun-if-changed=../../../../lib");
println!("cargo:rerun-if-changed=../../../../external");
println!("cargo:rerun-if-changed=../../../../cmake");
println!("cargo:rerun-if-changed=../../../../CMakeLists.txt");
let dst = cmake::Config::new("../../../../")
.build_target("hermesSupport")
.build();
println!(
"cargo:rustc-link-search={}/build/lib/Support",
dst.display()
);
println!("cargo:rustc-link-lib=hermesSupport");
println!(
"cargo:rustc-link-search={}/build/external/dtoa",
dst.display()
);
println!("cargo:rustc-link-lib=dtoa");
}

0 comments on commit 6c53047

Please sign in to comment.