-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.rs
More file actions
78 lines (64 loc) · 3.22 KB
/
build.rs
File metadata and controls
78 lines (64 loc) · 3.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
use std::{fs, path::PathBuf, vec};
fn main() {
println!("cargo:rustc-link-lib=c++");
println!("cargo:rerun-if-changed=aidl");
println!("cargo:rerun-if-changed=src/proto");
println!("cargo:rerun-if-changed=build.rs");
let out_dir = "src/proto";
fs::create_dir_all(out_dir).unwrap();
prost_build::Config::new()
.out_dir(out_dir)
.compile_protos(&["proto/storage.proto"], &["proto/"])
.expect("Failed to compile .proto files");
let mod_file = format!("{}/mod.rs", out_dir);
let mod_content = ["storage.rs"]
.iter()
.map(|file| format!("pub mod {};", file.trim_end_matches(".rs")))
.collect::<Vec<_>>()
.join("\n");
std::fs::write(&mod_file, mod_content).unwrap();
let mut aidl = rsbinder_aidl::Builder::new()
.include_dir(PathBuf::from("aidl/android/system/keystore2"))
.include_dir(PathBuf::from("aidl/android/hardware/security/keymint"))
.output(PathBuf::from("aidl.rs"));
let dirs = vec![
"aidl/android/content/pm",
"aidl/android/system/keystore2",
"aidl/android/hardware/security/keymint",
"aidl/android/security/metrics",
"aidl/android/security/keystore",
"aidl/android/apex",
"aidl/top/qwq2333/ohmykeymint",
];
for dir in dirs {
println!("Processing AIDL files in directory: {}", dir);
let dir = fs::read_dir(dir).unwrap();
for entry in dir {
let entry = entry.unwrap();
let path = entry.path();
if path.extension().and_then(|s| s.to_str()) == Some("aidl") {
aidl = aidl.source(path);
}
}
}
aidl.source(PathBuf::from(
"aidl/android/security/authorization/ResponseCode.aidl",
))
.source(PathBuf::from(
"aidl/android/hardware/security/secureclock/ISecureClock.aidl",
))
.generate()
.unwrap();
let generated_path = PathBuf::from(format!("{}/aidl.rs", std::env::var("OUT_DIR").unwrap()));
let content = fs::read_to_string(&generated_path).unwrap();
// dirty fixes for name conflicts and incorrect types
let patched_content = content
.replace("SecurityLevel.", "super::super::super::hardware::security::keymint::SecurityLevel::SecurityLevel::")
.replace("HardwareAuthenticatorType.", "super::super::super::hardware::security::keymint::HardwareAuthenticatorType::HardwareAuthenticatorType::")
.replace("r#authenticatorType: super::Digest::Digest::NONE,", "r#authenticatorType: super::HardwareAuthenticatorType::HardwareAuthenticatorType::NONE,")
.replace("r#authenticatorType: super::KeyPermission::KeyPermission::NONE,", "r#authenticatorType: super::HardwareAuthenticatorType::HardwareAuthenticatorType::NONE,")
.replace("r#authenticatorType: super::PaddingMode::PaddingMode::NONE,", "r#authenticatorType: super::HardwareAuthenticatorType::HardwareAuthenticatorType::NONE,")
.replace("r#operation: rsbinder::Strong<dyn super::IKeyMintOperation::IKeyMintOperation>,", "r#operation: Option<rsbinder::Strong<dyn super::IKeyMintOperation::IKeyMintOperation>>,");
println!("Patched AIDL content:\n{}", generated_path.display());
fs::write(generated_path, patched_content).unwrap();
}