Skip to content

Commit 5e5ef3e

Browse files
committed
refactor(tauri): use env::var_os if possible
1 parent 57b9a12 commit 5e5ef3e

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

crates/tauri/build.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fn has_feature(list: &mut Vec<String>, feature: &str) -> bool {
232232

233233
// when a feature is enabled, Cargo sets the `CARGO_FEATURE_<name>` env var to 1
234234
// <https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts>
235-
std::env::var(format!("CARGO_FEATURE_{}", AsShoutySnakeCase(feature)))
235+
std::env::var_os(format!("CARGO_FEATURE_{}", AsShoutySnakeCase(feature)))
236236
.map(|x| x == "1")
237237
.unwrap_or(false)
238238
}
@@ -260,17 +260,17 @@ fn main() {
260260
alias("desktop", !mobile);
261261
alias("mobile", mobile);
262262

263-
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
263+
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
264264

265265
let checked_features_out_path = out_dir.join("checked_features");
266266
std::fs::write(checked_features_out_path, checked_features.join(","))
267267
.expect("failed to write checked_features file");
268268

269269
// workaround needed to prevent `STATUS_ENTRYPOINT_NOT_FOUND` error in tests
270270
// see https://github.com/tauri-apps/tauri/pull/4383#issuecomment-1212221864
271-
let target_env = std::env::var("CARGO_CFG_TARGET_ENV");
272-
let is_tauri_workspace = std::env::var("__TAURI_WORKSPACE__").is_ok_and(|v| v == "true");
273-
if is_tauri_workspace && target_os == "windows" && Ok("msvc") == target_env.as_deref() {
271+
let target_env = std::env::var_os("CARGO_CFG_TARGET_ENV");
272+
let is_tauri_workspace = std::env::var_os("__TAURI_WORKSPACE__").is_some_and(|v| v == "true");
273+
if is_tauri_workspace && target_os == "windows" && target_env.is_some_and(|trgt| trgt == "msvc") {
274274
embed_manifest_for_tests();
275275
}
276276

@@ -281,14 +281,16 @@ fn main() {
281281
})
282282
}
283283

284-
if let Ok(kotlin_out_dir) = std::env::var("WRY_ANDROID_KOTLIN_FILES_OUT_DIR") {
284+
if let Some(kotlin_out_dir) = std::env::var_os("WRY_ANDROID_KOTLIN_FILES_OUT_DIR") {
285285
let package = env_var("WRY_ANDROID_PACKAGE");
286286
let library = env_var("WRY_ANDROID_LIBRARY");
287287

288288
let kotlin_out_dir = PathBuf::from(&kotlin_out_dir)
289289
.canonicalize()
290290
.unwrap_or_else(move |_| {
291-
panic!("Failed to canonicalize `WRY_ANDROID_KOTLIN_FILES_OUT_DIR` path {kotlin_out_dir}")
291+
panic!(
292+
"Failed to canonicalize `WRY_ANDROID_KOTLIN_FILES_OUT_DIR` path {kotlin_out_dir:?}"
293+
)
292294
});
293295

294296
let kotlin_files_path =

0 commit comments

Comments
 (0)