Skip to content

Commit 1c125de

Browse files
michalmuskalameta-codesync[bot]
authored andcommitted
use jar version for unoptimised builds
Summary: This changes local debug builds (linux only) to use a `jar` rather than building the native image for eqwalizer. This speeds up iteration significantly. We had this before, but struggled with java versions. In this iteration we just use tha java from graalvm that we would use to build the native image - that way we have a consistent java version that we fully control and don't depend on the OS. Reviewed By: TD5 Differential Revision: D85784216 fbshipit-source-id: 188dd7207865fda770bf2e154e18049030acdc29
1 parent 71e2caa commit 1c125de

File tree

2 files changed

+63
-44
lines changed

2 files changed

+63
-44
lines changed

crates/eqwalizer/build.rs

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@
1111
use std::env;
1212
use std::fs;
1313
use std::path::Path;
14+
use std::path::PathBuf;
1415
use std::process::Command;
1516

1617
fn main() {
1718
let source_directory = Path::new("../../../eqwalizer/eqwalizer");
19+
let tools_dir = source_directory.join("tools");
1820
let out_dir = env::var_os("OUT_DIR").unwrap();
1921
let eqwalizer_out_dir = Path::new("../../../../../buck-out/eqwalizer/scala-3.6.4");
2022
let dest_path = Path::new(&out_dir).join("eqwalizer");
2123
let extension;
24+
let java;
2225

2326
if let Some(path) = env::var_os("ELP_EQWALIZER_PATH") {
27+
java = "java".into();
2428
let from = Path::new(&path);
2529
extension = from
2630
.extension()
@@ -30,60 +34,75 @@ fn main() {
3034
.to_string();
3135
fs::copy(from, dest_path).expect("Copying precompiled eqwalizer failed");
3236
} else {
33-
extension = "".to_string();
34-
// Use the sbt wrapper on linux or otherwise require sbt to be installed
35-
let sbt = fs::canonicalize(source_directory.join("./meta/sbt.sh")).unwrap();
36-
let output = Command::new(sbt)
37-
.arg("assembly")
38-
.current_dir(source_directory)
39-
.env("EQWALIZER_USE_BUCK_OUT", "true")
40-
.output()
41-
.expect("failed to execute sbt assembly");
37+
let jar = build_jar(source_directory, eqwalizer_out_dir);
4238

43-
if !output.status.success() {
44-
let stdout =
45-
String::from_utf8(output.stdout).expect("valid utf8 output from sbt assembly");
46-
let stderr =
47-
String::from_utf8(output.stderr).expect("valid utf8 output from sbt assembly");
48-
panic!("sbt assembly failed with stdout:\n{stdout}\n\nstderr:\n{stderr}");
39+
if env::var("OPT_LEVEL").unwrap_or_default() == "0" {
40+
extension = "jar".to_string();
41+
java = if env::var("CARGO_CFG_TARGET_OS").unwrap() == "linux" {
42+
fs::canonicalize(tools_dir.join("graalvm/bin/java")).unwrap()
43+
} else {
44+
"java".into()
45+
};
46+
fs::copy(jar, dest_path).expect("Copying fresh eqwalizer failed");
47+
} else {
48+
extension = "".to_string();
49+
java = "java".into();
50+
let image_path = build_native_image(source_directory, eqwalizer_out_dir, jar);
51+
fs::copy(image_path, dest_path).expect("Copying fresh eqwalizer failed");
4952
}
5053

51-
let jar = fs::canonicalize(eqwalizer_out_dir.join("eqwalizer.jar")).unwrap();
52-
53-
let native_image =
54-
fs::canonicalize(source_directory.join("./meta/native-image.sh")).unwrap();
55-
let image_path = fs::canonicalize(eqwalizer_out_dir)
56-
.unwrap()
57-
.join("eqwalizer");
58-
let output = Command::new(native_image)
59-
.current_dir(source_directory)
60-
.arg("-H:IncludeResources=application.conf")
61-
.arg("--no-server")
62-
.arg("--no-fallback")
63-
.arg("-jar")
64-
.arg(jar)
65-
.arg(&image_path)
66-
.output()
67-
.expect("failed to execute native-image");
68-
69-
if !output.status.success() {
70-
let stdout =
71-
String::from_utf8(output.stdout).expect("valid utf8 output from native-image");
72-
let stderr =
73-
String::from_utf8(output.stderr).expect("valid utf8 output from native-image");
74-
panic!("native-image failed with stdout:\n{stdout}\n\nstderr:\n{stderr}");
75-
}
76-
77-
fs::copy(image_path, dest_path).expect("Copying fresh eqwalizer failed");
78-
7954
rerun_if_changed(source_directory.join("build.sbt"));
8055
rerun_if_changed(source_directory.join("src"));
8156
}
8257

8358
println!("cargo:rustc-env=ELP_EQWALIZER_EXT={extension}");
59+
println!("cargo:rustc-env=ELP_EQWALIZER_JAVA={}", java.display());
8460
println!("cargo:rerun-if-env-changed=ELP_EQWALIZER_PATH");
8561
}
8662

63+
fn build_native_image(source_directory: &Path, eqwalizer_out_dir: &Path, jar: PathBuf) -> PathBuf {
64+
let native_image = fs::canonicalize(source_directory.join("./meta/native-image.sh")).unwrap();
65+
let image_path = fs::canonicalize(eqwalizer_out_dir)
66+
.unwrap()
67+
.join("eqwalizer");
68+
let output = Command::new(native_image)
69+
.current_dir(source_directory)
70+
.arg("-H:IncludeResources=application.conf")
71+
.arg("--no-server")
72+
.arg("--no-fallback")
73+
.arg("-jar")
74+
.arg(jar)
75+
.arg(&image_path)
76+
.output()
77+
.expect("failed to execute native-image");
78+
79+
if !output.status.success() {
80+
let stdout = String::from_utf8(output.stdout).expect("valid utf8 output from native-image");
81+
let stderr = String::from_utf8(output.stderr).expect("valid utf8 output from native-image");
82+
panic!("native-image failed with stdout:\n{stdout}\n\nstderr:\n{stderr}");
83+
}
84+
image_path
85+
}
86+
87+
fn build_jar(source_directory: &Path, eqwalizer_out_dir: &Path) -> PathBuf {
88+
// Use the sbt wrapper on linux or otherwise require sbt to be installed
89+
let sbt = fs::canonicalize(source_directory.join("./meta/sbt.sh")).unwrap();
90+
let output = Command::new(sbt)
91+
.arg("assembly")
92+
.current_dir(source_directory)
93+
.env("EQWALIZER_USE_BUCK_OUT", "true")
94+
.output()
95+
.expect("failed to execute sbt assembly");
96+
97+
if !output.status.success() {
98+
let stdout = String::from_utf8(output.stdout).expect("valid utf8 output from sbt assembly");
99+
let stderr = String::from_utf8(output.stderr).expect("valid utf8 output from sbt assembly");
100+
panic!("sbt assembly failed with stdout:\n{stdout}\n\nstderr:\n{stderr}");
101+
}
102+
103+
fs::canonicalize(eqwalizer_out_dir.join("eqwalizer.jar")).unwrap()
104+
}
105+
87106
fn rerun_if_changed(path: impl AsRef<Path>) {
88107
println!("cargo:rerun-if-changed={}", path.as_ref().display());
89108
}

crates/eqwalizer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl EqwalizerExe {
220220

221221
let (cmd, args) = match ext.as_str() {
222222
"jar" => (
223-
"java".into(),
223+
env!("ELP_EQWALIZER_JAVA").into(),
224224
vec!["-Xss20M".into(), "-jar".into(), path.into()],
225225
),
226226
"" => (path, vec![]),

0 commit comments

Comments
 (0)