2025-05-17 01:27:34 +02:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
2025-06-19 23:26:05 +02:00
|
|
|
use core::panic;
|
|
|
|
use std::env::VarError;
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
|
enum TargetOs {
|
|
|
|
Windows,
|
|
|
|
MacOS,
|
|
|
|
Unix,
|
|
|
|
}
|
|
|
|
|
2025-03-19 03:13:50 +01:00
|
|
|
fn main() {
|
2025-06-19 23:26:05 +02:00
|
|
|
let target_os = match env_opt("CARGO_CFG_TARGET_OS").as_str() {
|
|
|
|
"windows" => TargetOs::Windows,
|
|
|
|
"macos" | "ios" => TargetOs::MacOS,
|
|
|
|
_ => TargetOs::Unix,
|
|
|
|
};
|
|
|
|
let icuuc_soname = env_opt("EDIT_CFG_ICUUC_SONAME");
|
|
|
|
let icui18n_soname = env_opt("EDIT_CFG_ICUI18N_SONAME");
|
|
|
|
let cpp_exports = env_opt("EDIT_CFG_ICU_CPP_EXPORTS");
|
|
|
|
let renaming_version = env_opt("EDIT_CFG_ICU_RENAMING_VERSION");
|
|
|
|
let renaming_auto_detect = env_opt("EDIT_CFG_ICU_RENAMING_AUTO_DETECT");
|
|
|
|
|
|
|
|
// If none of the `EDIT_CFG_ICU*` environment variables are set,
|
|
|
|
// we default to enabling `EDIT_CFG_ICU_RENAMING_AUTO_DETECT` on UNIX.
|
|
|
|
// This slightly improves portability at least in the cases where the SONAMEs match our defaults.
|
|
|
|
let renaming_auto_detect = if !renaming_auto_detect.is_empty() {
|
|
|
|
renaming_auto_detect.parse::<bool>().unwrap()
|
|
|
|
} else {
|
|
|
|
target_os == TargetOs::Unix
|
|
|
|
&& icuuc_soname.is_empty()
|
|
|
|
&& icui18n_soname.is_empty()
|
|
|
|
&& cpp_exports.is_empty()
|
|
|
|
&& renaming_version.is_empty()
|
|
|
|
};
|
|
|
|
if renaming_auto_detect && !renaming_version.is_empty() {
|
|
|
|
// It makes no sense to specify an explicit version and also ask for auto-detection.
|
|
|
|
panic!(
|
|
|
|
"Either `EDIT_CFG_ICU_RENAMING_AUTO_DETECT` or `EDIT_CFG_ICU_RENAMING_VERSION` must be set, but not both"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let icuuc_soname = if !icuuc_soname.is_empty() {
|
|
|
|
&icuuc_soname
|
|
|
|
} else {
|
|
|
|
match target_os {
|
|
|
|
TargetOs::Windows => "icuuc.dll",
|
|
|
|
TargetOs::MacOS => "libicucore.dylib",
|
|
|
|
TargetOs::Unix => "libicuuc.so",
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let icui18n_soname = if !icui18n_soname.is_empty() {
|
|
|
|
&icui18n_soname
|
|
|
|
} else {
|
|
|
|
match target_os {
|
|
|
|
TargetOs::Windows => "icuin.dll",
|
|
|
|
TargetOs::MacOS => "libicucore.dylib",
|
|
|
|
TargetOs::Unix => "libicui18n.so",
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let icu_export_prefix =
|
|
|
|
if !cpp_exports.is_empty() && cpp_exports.parse::<bool>().unwrap() { "_" } else { "" };
|
|
|
|
let icu_export_suffix =
|
|
|
|
if !renaming_version.is_empty() { format!("_{renaming_version}") } else { String::new() };
|
|
|
|
|
|
|
|
println!("cargo::rerun-if-env-changed=EDIT_CFG_ICUUC_SONAME");
|
|
|
|
println!("cargo::rustc-env=EDIT_CFG_ICUUC_SONAME={icuuc_soname}");
|
|
|
|
println!("cargo::rerun-if-env-changed=EDIT_CFG_ICUI18N_SONAME");
|
|
|
|
println!("cargo::rustc-env=EDIT_CFG_ICUI18N_SONAME={icui18n_soname}");
|
|
|
|
println!("cargo::rerun-if-env-changed=EDIT_CFG_ICU_EXPORT_PREFIX");
|
|
|
|
println!("cargo::rustc-env=EDIT_CFG_ICU_EXPORT_PREFIX={icu_export_prefix}");
|
|
|
|
println!("cargo::rerun-if-env-changed=EDIT_CFG_ICU_EXPORT_SUFFIX");
|
|
|
|
println!("cargo::rustc-env=EDIT_CFG_ICU_EXPORT_SUFFIX={icu_export_suffix}");
|
|
|
|
println!("cargo::rerun-if-env-changed=EDIT_CFG_ICU_RENAMING_AUTO_DETECT");
|
|
|
|
println!("cargo::rustc-check-cfg=cfg(edit_icu_renaming_auto_detect)");
|
|
|
|
if renaming_auto_detect {
|
|
|
|
println!("cargo::rustc-cfg=edit_icu_renaming_auto_detect");
|
|
|
|
}
|
|
|
|
|
2025-04-13 01:28:11 +02:00
|
|
|
#[cfg(windows)]
|
2025-06-19 23:26:05 +02:00
|
|
|
if target_os == TargetOs::Windows {
|
2025-06-03 17:47:26 +02:00
|
|
|
winresource::WindowsResource::new()
|
2025-04-30 12:40:28 +02:00
|
|
|
.set_manifest_file("src/bin/edit/edit.exe.manifest")
|
2025-04-08 23:29:44 +02:00
|
|
|
.set("FileDescription", "Microsoft Edit")
|
2025-05-01 14:39:44 +02:00
|
|
|
.set("LegalCopyright", "© Microsoft Corporation. All rights reserved.")
|
2025-06-12 18:25:03 -05:00
|
|
|
.set_icon("assets/edit.ico")
|
2025-04-08 23:29:44 +02:00
|
|
|
.compile()
|
|
|
|
.unwrap();
|
2025-03-19 03:13:50 +01:00
|
|
|
}
|
|
|
|
}
|
2025-06-19 23:26:05 +02:00
|
|
|
|
|
|
|
fn env_opt(name: &str) -> String {
|
|
|
|
match std::env::var(name) {
|
|
|
|
Ok(value) => value,
|
|
|
|
Err(VarError::NotPresent) => String::new(),
|
|
|
|
Err(VarError::NotUnicode(_)) => {
|
|
|
|
panic!("Environment variable `{name}` is not valid Unicode")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|