Skip to content

Commit 6c53047

Browse files
avpfacebook-github-bot
authored andcommitted
Run Hermes CMake from cargo
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
1 parent 67fe974 commit 6c53047

File tree

5 files changed

+63
-42
lines changed

5 files changed

+63
-42
lines changed

unsupported/juno/Cargo.lock

+17-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unsupported/juno/crates/hermes/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ libc = "0.2"
1212
thiserror = "1.0"
1313

1414
[build-dependencies]
15-
toml = "=0.5.7"
15+
cmake = "0.1"

unsupported/juno/crates/hermes/build.rs

+28-21
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,39 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
use std::{env, fs};
9-
use toml::Value;
10-
118
fn main() {
12-
let hermes_build = match env::var("HERMES_BUILD") {
13-
Ok(dir) => dir,
14-
Err(_) => {
15-
let file =
16-
fs::read_to_string(format!("{}/../../.hermes.toml", env!("CARGO_MANIFEST_DIR")))
17-
.expect("Must provide either HERMES_BUILD env variable or .hermes.toml file");
18-
let value = file.parse::<Value>().unwrap();
19-
value["hermes_build"].as_str().unwrap().to_owned()
20-
}
21-
};
9+
println!("cargo:rerun-if-changed=../../../../include");
10+
println!("cargo:rerun-if-changed=../../../../lib");
11+
println!("cargo:rerun-if-changed=../../../../external");
12+
println!("cargo:rerun-if-changed=../../../../cmake");
13+
println!("cargo:rerun-if-changed=../../../../CMakeLists.txt");
14+
15+
// Build sourceMap library because it depends on everything we depend on here
16+
// via the hermesParser library.
17+
let dst = cmake::Config::new("../../../../")
18+
.build_target("hermesSourceMap")
19+
.build();
2220

23-
println!("cargo:rustc-link-search={}/lib/Parser", hermes_build);
21+
println!("cargo:rustc-link-search={}/build/lib/Parser", dst.display());
22+
println!(
23+
"cargo:rustc-link-search={}/build/lib/Platform/Unicode",
24+
dst.display()
25+
);
26+
println!(
27+
"cargo:rustc-link-search={}/build/lib/SourceMap",
28+
dst.display()
29+
);
30+
println!(
31+
"cargo:rustc-link-search={}/build/lib/Support",
32+
dst.display()
33+
);
2434
println!(
25-
"cargo:rustc-link-search={}/lib/Platform/Unicode",
26-
hermes_build
35+
"cargo:rustc-link-search={}/build/external/dtoa",
36+
dst.display()
2737
);
28-
println!("cargo:rustc-link-search={}/lib/SourceMap", hermes_build);
29-
println!("cargo:rustc-link-search={}/lib/Support", hermes_build);
30-
println!("cargo:rustc-link-search={}/external/dtoa", hermes_build);
3138
println!(
32-
"cargo:rustc-link-search={}/external/llvh/lib/Support",
33-
hermes_build
39+
"cargo:rustc-link-search={}/build/external/llvh/lib/Support",
40+
dst.display()
3441
);
3542

3643
println!("cargo:rustc-link-lib=hermesSourceMap");

unsupported/juno/crates/juno_support/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ thiserror = "1.0"
1313
url = "2.2.2"
1414

1515
[build-dependencies]
16-
toml = "=0.5.7"
16+
cmake = "0.1"

unsupported/juno/crates/juno_support/build.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
use std::{env, fs};
9-
use toml::Value;
10-
118
fn main() {
12-
let hermes_build = match env::var("HERMES_BUILD") {
13-
Ok(dir) => dir,
14-
Err(_) => {
15-
let file =
16-
fs::read_to_string(format!("{}/../../.hermes.toml", env!("CARGO_MANIFEST_DIR")))
17-
.expect("Must provide either HERMES_BUILD env variable or .hermes.toml file");
18-
let value = file.parse::<Value>().unwrap();
19-
value["hermes_build"].as_str().unwrap().to_owned()
20-
}
21-
};
22-
23-
println!("cargo:rustc-link-search={}/lib/Support", hermes_build);
24-
println!("cargo:rustc-link-search={}/external/dtoa", hermes_build);
25-
9+
println!("cargo:rerun-if-changed=../../../../include");
10+
println!("cargo:rerun-if-changed=../../../../lib");
11+
println!("cargo:rerun-if-changed=../../../../external");
12+
println!("cargo:rerun-if-changed=../../../../cmake");
13+
println!("cargo:rerun-if-changed=../../../../CMakeLists.txt");
14+
let dst = cmake::Config::new("../../../../")
15+
.build_target("hermesSupport")
16+
.build();
17+
println!(
18+
"cargo:rustc-link-search={}/build/lib/Support",
19+
dst.display()
20+
);
2621
println!("cargo:rustc-link-lib=hermesSupport");
22+
println!(
23+
"cargo:rustc-link-search={}/build/external/dtoa",
24+
dst.display()
25+
);
2726
println!("cargo:rustc-link-lib=dtoa");
2827
}

0 commit comments

Comments
 (0)