Skip to content

Commit fdbfb61

Browse files
authored
remove CARGO_WORKSPACE_DIR from .env (trustwallet#4429)
* remove CARGO_WORKSPACE_DIR from .env * rustfmt tw_ffi.rs
1 parent 385185d commit fdbfb61

File tree

2 files changed

+49
-55
lines changed

2 files changed

+49
-55
lines changed

rust/.cargo/config.toml

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

rust/tw_macros/src/tw_ffi.rs

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -160,66 +160,62 @@ pub fn tw_ffi(attr: TokenStream2, item: TokenStream2) -> Result<TokenStream2> {
160160
docs,
161161
};
162162

163-
if let Ok(out_dir) = env::var("CARGO_WORKSPACE_DIR") {
164-
let bindings_dir = Path::new(&out_dir).join("bindings");
165-
fs::create_dir_all(&bindings_dir).expect("Failed to create bindings directory");
166-
let yaml_file_path = bindings_dir.join(format!("{}.yaml", class));
167-
168-
let mut config = if yaml_file_path.exists() {
169-
match fs::read_to_string(&yaml_file_path) {
170-
Ok(contents) => match serde_yaml::from_str(&contents) {
171-
Ok(config) => config,
172-
Err(_) => {
173-
let _ = fs::remove_file(&yaml_file_path);
174-
TWConfig {
175-
class,
176-
..Default::default()
177-
}
178-
},
179-
},
180-
Err(_) => TWConfig {
181-
class,
182-
..Default::default()
163+
let out_dir = env::var("CARGO_WORKSPACE_DIR").unwrap_or_default();
164+
let bindings_dir = Path::new(&out_dir).join("bindings");
165+
fs::create_dir_all(&bindings_dir).expect("Failed to create bindings directory");
166+
let yaml_file_path = bindings_dir.join(format!("{}.yaml", class));
167+
168+
let mut config = if yaml_file_path.exists() {
169+
match fs::read_to_string(&yaml_file_path) {
170+
Ok(contents) => match serde_yaml::from_str(&contents) {
171+
Ok(config) => config,
172+
Err(_) => {
173+
let _ = fs::remove_file(&yaml_file_path);
174+
TWConfig {
175+
class,
176+
..Default::default()
177+
}
183178
},
184-
}
185-
} else {
186-
TWConfig {
179+
},
180+
Err(_) => TWConfig {
187181
class,
188182
..Default::default()
189-
}
190-
};
191-
match args.ty {
192-
Some(TWFFIType::StaticFunction) => {
193-
if let Some(idx) = config
194-
.static_functions
195-
.iter()
196-
.position(|f| f.name == function.name)
197-
{
198-
config.static_functions[idx] = function;
199-
} else {
200-
config.static_functions.push(function);
201-
}
202183
},
203-
Some(TWFFIType::Constructor) => {
204-
update_or_append_function(&mut config.constructors, function);
205-
},
206-
Some(TWFFIType::Destructor) => {
207-
config.destructor = Some(function);
208-
},
209-
Some(TWFFIType::Method) => {
210-
update_or_append_function(&mut config.methods, function);
211-
},
212-
Some(TWFFIType::Property) => {
213-
update_or_append_function(&mut config.properties, function);
214-
},
215-
_ => panic!("Invalid FFI type"),
216184
}
217-
let yaml_output: String =
218-
serde_yaml::to_string(&config).expect("Failed to serialize to YAML");
219-
fs::write(&yaml_file_path, yaml_output).expect("Failed to write YAML file");
220185
} else {
221-
panic!("CARGO_WORKSPACE_DIR is not set");
186+
TWConfig {
187+
class,
188+
..Default::default()
189+
}
190+
};
191+
match args.ty {
192+
Some(TWFFIType::StaticFunction) => {
193+
if let Some(idx) = config
194+
.static_functions
195+
.iter()
196+
.position(|f| f.name == function.name)
197+
{
198+
config.static_functions[idx] = function;
199+
} else {
200+
config.static_functions.push(function);
201+
}
202+
},
203+
Some(TWFFIType::Constructor) => {
204+
update_or_append_function(&mut config.constructors, function);
205+
},
206+
Some(TWFFIType::Destructor) => {
207+
config.destructor = Some(function);
208+
},
209+
Some(TWFFIType::Method) => {
210+
update_or_append_function(&mut config.methods, function);
211+
},
212+
Some(TWFFIType::Property) => {
213+
update_or_append_function(&mut config.properties, function);
214+
},
215+
_ => panic!("Invalid FFI type"),
222216
}
217+
let yaml_output: String = serde_yaml::to_string(&config).expect("Failed to serialize to YAML");
218+
fs::write(&yaml_file_path, yaml_output).expect("Failed to write YAML file");
223219

224220
Ok(item)
225221
}

0 commit comments

Comments
 (0)