Skip to content

Commit

Permalink
Use conditional compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Oct 25, 2024
1 parent 77212c1 commit e6cbb64
Showing 1 changed file with 68 additions and 21 deletions.
89 changes: 68 additions & 21 deletions crates/snm_atom/src/conditional_compiler.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,76 @@
pub fn get_tarball_ext() -> String {
match std::env::consts::OS {
"windows" => "zip".to_string(),
"linux" => "tar.xz".to_string(),
"macos" => "tar.xz".to_string(),
_ => "unknown".to_string(), // 默认情况
pub const fn get_tarball_ext() -> &'static str {
#[cfg(target_os = "windows")]
{
"zip"
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
"tar.xz"
}
#[cfg(not(any(target_os = "windows", target_os = "linux", target_os = "macos")))]
{
"unknown"
}
}

pub fn get_arch() -> String {
match std::env::consts::ARCH {
"x86" => "x86".to_string(),
"x86_64" => "x64".to_string(),
"arm" => "armv7l".to_string(),
"aarch64" => "arm64".to_string(),
"powerpc64" => "ppc64".to_string(),
"powerpc64le" => "ppc64le".to_string(),
"s390x" => "s390x".to_string(),
_ => "unknown".to_string(),
pub const fn get_arch() -> &'static str {
#[cfg(target_arch = "x86")]
{
"x86"
}
#[cfg(target_arch = "x86_64")]
{
"x64"
}
#[cfg(target_arch = "arm")]
{
"armv7l"
}
#[cfg(target_arch = "aarch64")]
{
"arm64"
}
#[cfg(target_arch = "powerpc64")]
{
"ppc64"
}
#[cfg(target_arch = "powerpc64le")]
{
"ppc64le"
}
#[cfg(target_arch = "s390x")]
{
"s390x"
}
#[cfg(not(any(
target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm",
target_arch = "aarch64",
target_arch = "powerpc64",
target_arch = "powerpc64le",
target_arch = "s390x"
)))]
{
"unknown"
}
}

pub fn get_os() -> String {
match std::env::consts::OS {
"macos" => "darwin".to_string(),
"windows" => "win".to_string(),
_ => std::env::consts::OS.to_string(),
pub const fn get_os() -> &'static str {
#[cfg(target_os = "macos")]
{
"darwin"
}
#[cfg(target_os = "windows")]
{
"win"
}
#[cfg(target_os = "linux")]
{
"linux"
}
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
{
"unknown"
}
}

0 comments on commit e6cbb64

Please sign in to comment.