forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
57 lines (47 loc) · 1.69 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
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
use anyhow::Result;
use move_binary_format::CompiledModule;
use std::{
env, fs,
path::{Path, PathBuf},
};
/// Save revision info to environment variable
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let sui_framwork_path = Path::new(env!("CARGO_MANIFEST_DIR"));
let move_stdlib_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("deps/move-stdlib");
let sui_framework =
sui_framework_build::build_sui_framework_modules(sui_framwork_path).unwrap();
let move_stdlib = sui_framework_build::build_move_stdlib_modules(&move_stdlib_path).unwrap();
serialize_modules_to_file(sui_framework, &out_dir.join("sui-framework")).unwrap();
serialize_modules_to_file(move_stdlib, &out_dir.join("move-stdlib")).unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!(
"cargo:rerun-if-changed={}",
sui_framwork_path.join("Move.toml").display()
);
println!(
"cargo:rerun-if-changed={}",
sui_framwork_path.join("sources").display()
);
println!(
"cargo:rerun-if-changed={}",
move_stdlib_path.join("Move.toml").display()
);
println!(
"cargo:rerun-if-changed={}",
move_stdlib_path.join("sources").display()
);
}
fn serialize_modules_to_file(modules: Vec<CompiledModule>, file: &Path) -> Result<()> {
let mut serialized_modules = Vec::new();
for module in modules {
let mut buf = Vec::new();
module.serialize(&mut buf)?;
serialized_modules.push(buf);
}
let binary = bcs::to_bytes(&serialized_modules)?;
fs::write(file, &binary)?;
Ok(())
}