-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from felddy/improvement/rust-binary
Replace test binary with a Rust implementation
- Loading branch information
Showing
8 changed files
with
115 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
authors = ["Mark Feldhousen <markf@geekpad.com>"] | ||
categories = ["command-line-utilities"] | ||
description = "A tool to determine the architecture of a system." | ||
documentation = "https://github.com/felddy/reusable-workflows/blob/develop/README.md" | ||
edition = "2021" | ||
homepage = "https://github.com/felddy/reusable-workflows" | ||
keywords = ["architecture", "system", "cross-platform"] | ||
license = "CC0-1.0" | ||
name = "arch-info" | ||
repository = "https://github.com/felddy/reusable-workflows" | ||
version = "0.0.1" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[dev-dependencies] | ||
|
||
[profile.release] | ||
codegen-units = 1 | ||
lto = true | ||
opt-level = 'z' # Optimize for size. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/// Prints the architecture string based on the current compilation target. | ||
/// - If the architecture is known, prints the architecture string and exits with code 0 (success). | ||
/// - If the architecture is unknown, prints a message and exits with code 1 (error). | ||
use std::process; | ||
|
||
/// Entry point of the application. | ||
fn main() { | ||
match get_architecture() { | ||
// If an architecture is identified, print it and exit with code 0 (success). | ||
Some(arch) => { | ||
println!("{}", arch); | ||
process::exit(0); | ||
} | ||
// If the architecture is unknown, print a message and exit with code 1 (error). | ||
None => { | ||
println!("Architecture: Unknown"); | ||
process::exit(1); | ||
} | ||
} | ||
} | ||
|
||
/// Returns the architecture string based on the current compilation target. | ||
/// | ||
/// Uses Rust's conditional compilation features to determine the architecture. | ||
/// Returns `Some(arch_string)` if known, or `None` if the architecture is unknown. | ||
fn get_architecture() -> Option<&'static str> { | ||
match std::env::consts::ARCH { | ||
// ARM 64-bit architecture | ||
"aarch64" => Some("linux/arm64"), | ||
// ARM architecture with further checks for specific versions | ||
"arm" => Some(if cfg!(target_feature = "v7") { | ||
"linux/arm/v7" | ||
} else if cfg!(target_feature = "v6") { | ||
"linux/arm/v6" | ||
} else { | ||
"linux/arm" | ||
}), | ||
// MIPS architecture with endian check | ||
"mips64" => Some(if cfg!(target_endian = "little") { | ||
"linux/mips64le" | ||
} else { | ||
"linux/mips64" | ||
}), | ||
// Other architectures without specific version checks | ||
"powerpc64" => Some("linux/ppc64le"), | ||
"riscv64" => Some("linux/riscv64"), | ||
"s390x" => Some("linux/s390x"), | ||
"x86_64" => Some("linux/amd64"), | ||
"x86" => Some("linux/386"), | ||
// Fallback case for unknown architectures | ||
_ => None, | ||
} | ||
} |