-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
145 lines (121 loc) · 5.22 KB
/
build.rs
File metadata and controls
145 lines (121 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use std::path::Path;
use std::process::{Command};
fn log(message: &str) {
println!("cargo:warning={message}");
}
fn main() {
// 1. Define paths
// TODO: add support for different project folders
let scala_project_dir = Path::new("daisy");
// 2. Tell Cargo when to re-run this script.
// Re-run if any Scala source files or the build.sbt changes.
println!("cargo:rerun-if-changed=daisy/src/");
println!("cargo:rerun-if-changed=daisy/build.sbt");
// 3. Check if sbt is installed
if Command::new("sbt").arg("--version").output().is_err() {
log("cargo:warning=sbt not found, installing sbt and dependencies...");
// Update package list
log("Running: sudo apt-get update");
Command::new("sudo")
.args(&["apt-get", "update"])
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to run apt-get update");
// Install curl if not present
log("Running: sudo apt-get install -y curl");
Command::new("sudo")
.args(&["apt-get", "install", "-y", "curl"])
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to install curl");
// Add SBT repository
log("Running: Adding SBT repository to apt sources");
Command::new("sh")
.arg("-c")
.arg("echo 'deb https://repo.scala-sbt.org/scalasbt/debian all main' | sudo tee /etc/apt/sources.list.d/sbt.list")
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to add sbt repository");
log("Running: Adding SBT old repository to apt sources");
Command::new("sh")
.arg("-c")
.arg("echo 'deb https://repo.scala-sbt.org/scalasbt/debian /' | sudo tee /etc/apt/sources.list.d/sbt_old.list")
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to add sbt old repository");
// Add SBT GPG key
log("Running: Adding SBT GPG key");
Command::new("sh")
.arg("-c")
.arg("curl -sL 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823' | sudo tee /etc/apt/trusted.gpg.d/sbt.asc")
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to add sbt GPG key");
// Update package list again
log("Running: sudo apt-get update");
Command::new("sudo")
.args(&["apt-get", "update"])
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to run apt-get update");
// Install Java 8
log("Running: sudo apt-get install -y openjdk-8-jdk");
Command::new("sudo")
.args(&["apt-get", "install", "-y", "openjdk-8-jdk"])
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to install Java 8");
// Install SBT
log("Running: sudo apt-get install -y sbt");
Command::new("sudo")
.args(&["apt-get", "install", "-y", "sbt"])
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to install sbt");
log("cargo:warning=sbt and dependencies installed successfully");
}
// 4. Build Daisy project
log("cargo:warning=Building Daisy Scala project...");
log("Running: sbt update (in daisy directory)");
let sbt_update = Command::new("sbt")
.current_dir(scala_project_dir)
.arg("update")
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to run 'sbt update' in daisy directory");
if !sbt_update.success() {
panic!("'sbt update' failed in daisy directory");
}
log("Running: sbt compile (in daisy directory)");
let sbt_compile = Command::new("sbt")
.current_dir(scala_project_dir)
.arg("compile")
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to run 'sbt compile' in daisy directory");
if !sbt_compile.success() {
panic!("'sbt compile' failed in daisy directory");
}
log("Running: sbt script (in daisy directory)");
let sbt_script = Command::new("sbt")
.current_dir(scala_project_dir)
.arg("script")
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to run 'sbt script' in daisy directory");
if !sbt_script.success() {
panic!("'sbt script' failed in daisy directory");
}
log("cargo:warning=Daisy build completed successfully");
}