-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
143 lines (121 loc) · 5.69 KB
/
build.rs
File metadata and controls
143 lines (121 loc) · 5.69 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
fn main() {
// ========================================
// ЧАСТЬ 1: Сборка Go библиотеки для подписи Flashbots
// ========================================
build_go_flashbots_signer();
// ========================================
// ЧАСТЬ 2: Сборка Protobuf файлов
// ========================================
// Если в проекте присутствуют src/vendor/bitquery_protos/*.proto — сгенерируем prost-типы
let vendor_root = std::path::Path::new("src/vendor/bitquery_protos");
if !vendor_root.exists() {
// Ничего не компилируем — заглушка
println!("cargo:warning=Proto files not found at src/vendor/bitquery_protos");
return;
}
let mut protos: Vec<std::path::PathBuf> = Vec::new();
let mut includes: Vec<std::path::PathBuf> = Vec::new();
includes.push(vendor_root.to_path_buf());
for entry in walkdir::WalkDir::new(vendor_root)
.into_iter()
.filter_map(Result::ok)
{
if entry.file_type().is_file() {
let path = entry.path();
if let Some(ext) = path.extension() {
if ext == "proto" {
protos.push(path.to_path_buf());
}
}
}
}
if protos.is_empty() {
return;
}
println!("cargo:rerun-if-changed=src/vendor/bitquery_protos");
let mut config = prost_build::Config::new();
// Пишем сгенерированный код в src/pending_websocket/generated, чтобы избежать include!(OUT_DIR) проблем
let gen_dir = std::path::Path::new("src/pending_websocket/generated");
std::fs::create_dir_all(&gen_dir).ok();
config.out_dir(gen_dir);
config.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]");
config
.compile_protos(&protos, &includes)
.expect("failed to compile Bitquery protos");
}
/// Сборка Go библиотеки для подписи Flashbots
fn build_go_flashbots_signer() {
let go_signer_dir = std::path::Path::new("src/flashbots/flashbots_go_signer");
// Проверяем существование Go проекта
if !go_signer_dir.exists() {
println!(
"cargo:warning=Go signer directory not found at {:?}",
go_signer_dir
);
return;
}
let go_mod_path = go_signer_dir.join("go.mod");
if !go_mod_path.exists() {
println!("cargo:warning=go.mod not found in Go signer directory");
return;
}
// Проверяем наличие Go компилятора
let go_check = std::process::Command::new("go").arg("version").output();
if go_check.is_err() {
println!("cargo:warning=Go compiler not found. Skipping Go signer build.");
println!("cargo:warning=Install Go 1.21+ to enable fast Flashbots signing.");
return;
}
println!("cargo:rerun-if-changed=src/flashbots/flashbots_go_signer/signer.go");
println!("cargo:rerun-if-changed=src/flashbots/flashbots_go_signer/go.mod");
// Собираем Go библиотеку
println!("cargo:warning=Building Go flashbots signer...");
let build_result = std::process::Command::new("sh")
.arg("-c")
.arg("cd src/flashbots/flashbots_go_signer && go build -buildmode=c-shared -o libflashbots_signer.so signer.go")
.status();
match build_result {
Ok(status) if status.success() => {
println!("cargo:warning=✅ Successfully built Go flashbots signer");
let go_signer_dir = std::path::Path::new("src/flashbots/flashbots_go_signer");
let target_dir = std::path::Path::new("target");
// Копируем .so в target/debug и target/release для удобства запуска
let lib_name = "libflashbots_signer.so";
let source = go_signer_dir.join(lib_name);
if source.exists() {
// Создаем target директории если их нет
std::fs::create_dir_all("target/debug").ok();
std::fs::create_dir_all("target/release").ok();
// Копируем в обе директории
let debug_dest = target_dir.join("debug").join(lib_name);
let release_dest = target_dir.join("release").join(lib_name);
std::fs::copy(&source, &debug_dest).ok();
std::fs::copy(&source, &release_dest).ok();
println!(
"cargo:warning=📋 Copied {} to target/debug/ and target/release/",
lib_name
);
}
// Указываем Cargo где искать библиотеку
println!("cargo:rustc-link-search=native=src/flashbots/flashbots_go_signer");
println!("cargo:rustc-link-search=native=target/debug");
println!("cargo:rustc-link-search=native=target/release");
println!("cargo:rustc-link-lib=dylib=flashbots_signer");
// Также устанавливаем rpath для автоматического поиска
println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN");
println!(
"cargo:rustc-link-arg=-Wl,-rpath,{}",
std::env::current_dir()
.unwrap()
.join("src/flashbots/flashbots_go_signer")
.display()
);
}
Ok(status) => {
println!("cargo:warning=❌ Go build failed with status: {}", status);
}
Err(e) => {
println!("cargo:warning=❌ Failed to execute Go build: {}", e);
}
}
}