-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.rs
57 lines (42 loc) · 1.73 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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.
use std::path::PathBuf;
use std::{env, fs};
fn main() {
if env::var("GITHUB_ACTIONS").is_ok() {
// CI doesn't build with schemafy deterministically
return;
}
println!("cargo:rerun-if-changed=assets/schema.json");
let schema = PathBuf::from("assets/schema.json").canonicalize().unwrap();
let types = PathBuf::from("src/types.rs");
schemafy_lib::Generator::builder()
.with_input_file(&schema)
.build()
.generate_to_file(&types)
.unwrap();
let types = types.canonicalize().unwrap();
let contents = fs::read_to_string(&types).unwrap();
// some limitations of schemafy will not allow it to parse the correct
// integer type as they incorrectly fallback any integer to `i64`
let contents = contents.replace("Vec<i64>", "Vec<u8>");
let contents = contents.replace("i64", "u64");
let contents = contents.replace("Vec<u64>", "Vec<u8>");
let header = r#"// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.
//! Arguments and responses to the module requests
// THIS FILE IS AUTO GENERATED!!
#![allow(missing_docs)]
use alloc::string::String;
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
"#;
let contents = header.to_owned() + &contents;
fs::write(&types, contents).unwrap();
}