-
Notifications
You must be signed in to change notification settings - Fork 85
/
build.rs
65 lines (53 loc) · 1.94 KB
/
build.rs
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
extern crate itertools;
extern crate semver;
extern crate serde;
extern crate serde_json;
#[cfg(windows)]
extern crate winres;
#[path = "src/jsonstructs_versionsdb.rs"]
mod jsonstructs_versionsdb;
use anyhow::Result;
use serde_json::Value;
use std::env;
use std::fs::File;
use std::path::Path;
use std::path::PathBuf;
fn main() -> Result<()> {
let target_platform = std::env::var("TARGET").unwrap();
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let db_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap())
.join("versiondb")
.join(format!("versiondb-{}.json", target_platform));
let version_db_path = out_path.join("versionsdb.json");
std::fs::copy(&db_path, &version_db_path).unwrap();
let file = File::open(&db_path)?;
let data: Value = serde_json::from_reader(file)?;
let bundled_version_as_string: String =
data["AvailableChannels"]["release"]["Version"].to_string();
let bundled_dbversion_as_string: String = data["Version"].to_string();
let bundled_version_path = Path::new(&out_path).join("bundled_version.rs");
std::fs::write(
&bundled_version_path,
format!(
"pub const BUNDLED_JULIA_VERSION: &str = {}; pub const BUNDLED_DB_VERSION: &str = {};",
bundled_version_as_string, bundled_dbversion_as_string
),
)
.unwrap();
#[cfg(windows)]
{
let mut res = winres::WindowsResource::new();
res.set_icon("src/julia.ico");
#[cfg(feature = "winpkgidentityext")]
res.set_manifest_file("deploy/winpkgidentityext/app.manifest");
res.compile().unwrap();
}
let various_constants_path = Path::new(&out_path).join("various_constants.rs");
std::fs::write(
&various_constants_path,
format!("pub const JULIAUP_TARGET: &str = \"{}\";", &target_platform),
)
.unwrap();
built::write_built_file().expect("Failed to acquire build-time information");
Ok(())
}