Skip to content

Commit 09abd3a

Browse files
committed
fix: refine codes
1 parent 5035192 commit 09abd3a

File tree

9 files changed

+1
-326
lines changed

9 files changed

+1
-326
lines changed

core/src/ten_rust/src/build.rs

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -129,85 +129,6 @@ fn auto_gen_schema_bindings_from_c() {
129129
}
130130
}
131131

132-
fn auto_gen_value_bindings_from_c() {
133-
let mut base_dir = env::current_dir()
134-
.unwrap_or("Failed to get path of //ten_rust/src".into());
135-
base_dir.pop();
136-
base_dir.pop();
137-
138-
let mut value_header = base_dir.clone();
139-
value_header
140-
.push("include_internal/ten_utils/value/bindings/rust/value_proxy.h");
141-
if !value_header.exists() {
142-
println!("Path of value_proxy.h: {}", value_header.to_str().unwrap());
143-
panic!("The //include_internal/ten_utils/value/bindings/rust/value_proxy.h does not exist.");
144-
}
145-
146-
println!("cargo:rerun-if-changed={}", value_header.to_str().unwrap());
147-
148-
base_dir.push("include");
149-
150-
let binding_gen = bindgen::Builder::default()
151-
.clang_arg(format!("-I{}", base_dir.to_str().unwrap()))
152-
.no_copy("ten_value_t")
153-
.header(value_header.to_str().unwrap())
154-
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
155-
.generate()
156-
.expect("Unable to generate bindings");
157-
158-
let value_dir = Path::new("src/value/");
159-
let generated_bindings = value_dir.join("bindings.rs");
160-
let temp_bindings = value_dir.join(format!("bindings_{}.rs.tmp", id()));
161-
162-
binding_gen
163-
.write_to_file(&temp_bindings)
164-
.expect("Unable to write bindings into file.");
165-
166-
// Add some rules to the bindings file to disable clippy lints.
167-
let bindings_content = fs::read_to_string(&temp_bindings)
168-
.expect("Unable to read generated bindings");
169-
let disabled_clippy_lints = [
170-
"#![allow(non_upper_case_globals)]",
171-
"#![allow(non_camel_case_types)]",
172-
"#![allow(non_snake_case)]",
173-
"#![allow(dead_code)]",
174-
"#![allow(improper_ctypes)]",
175-
"#![allow(improper_ctypes_definitions)]",
176-
"#![allow(clippy::upper_case_acronyms)]",
177-
];
178-
let new_bindings_content =
179-
disabled_clippy_lints.join("\n") + "\n\n" + &bindings_content;
180-
fs::write(&temp_bindings, new_bindings_content)
181-
.expect("Unable to add clippy lint rules to the generated bindings.");
182-
183-
let max_retries = 5;
184-
// 500 milliseconds delay between retries.
185-
let retry_delay = Duration::from_millis(500);
186-
187-
for attempt in 1..=max_retries {
188-
// Atomically move the temporary file to the target file.
189-
match fs::rename(&temp_bindings, &generated_bindings) {
190-
Ok(_) => {
191-
println!("File renamed successfully.");
192-
break;
193-
}
194-
Err(e) if attempt < max_retries => {
195-
println!(
196-
"Attempt {}/{} failed: {}. Retrying...",
197-
attempt, max_retries, e
198-
);
199-
thread::sleep(retry_delay);
200-
}
201-
Err(e) => {
202-
panic!(
203-
"Unable to move temporary bindings to final destination after {} attempts: {}",
204-
max_retries, e
205-
);
206-
}
207-
}
208-
}
209-
}
210-
211132
// The current auto-detection only supports limited environment combinations;
212133
// for example, cross-compilation is not supported.
213134
fn auto_detect_utils_library_path() -> PathBuf {
@@ -257,7 +178,6 @@ fn auto_detect_utils_library_path() -> PathBuf {
257178

258179
fn main() {
259180
auto_gen_schema_bindings_from_c();
260-
auto_gen_value_bindings_from_c();
261181

262182
// If the auto-detected utils library path is incorrect, we can specify it
263183
// using the environment variable.

core/src/ten_rust/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,3 @@ pub mod telemetry;
2424
// declarations.
2525
/// cbindgen:ignore
2626
pub mod schema;
27-
28-
/// cbindgen:ignore
29-
pub mod value;

core/src/ten_rust/src/value/mod.rs

Lines changed: 0 additions & 131 deletions
This file was deleted.

core/src/ten_rust/tests/test_case/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ mod interface;
1111
mod json_schema;
1212
mod pkg_info;
1313
mod schema;
14-
mod value;

core/src/ten_rust/tests/test_case/value.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.

core/src/ten_utils/value/BUILD.gn

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@
77
import("//build/ten_utils/utils.gni")
88

99
ten_utils_glob("value") {
10-
deps = [
11-
"bindings:value_bindings",
12-
"//third_party/yyjson",
13-
]
10+
deps = [ "//third_party/yyjson" ]
1411
}

core/src/ten_utils/value/bindings/BUILD.gn

Lines changed: 0 additions & 11 deletions
This file was deleted.

core/src/ten_utils/value/bindings/rust/BUILD.gn

Lines changed: 0 additions & 10 deletions
This file was deleted.

core/src/ten_utils/value/bindings/rust/value_proxy.c

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)