-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more information about the target
- Loading branch information
1 parent
b7d6aa7
commit aee0d6f
Showing
14 changed files
with
281 additions
and
16 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
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,29 @@ | ||
use build_info_common::{CpuInfo, Endianness, TargetInfo}; | ||
|
||
pub(crate) fn get_info() -> TargetInfo { | ||
TargetInfo { | ||
triple: std::env::var("TARGET").unwrap_or_else(|_| "UNKNOWN".to_string()), | ||
family: std::env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_else(|_| "UNKNOWN".to_string()), | ||
os: std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| "UNKNOWN".to_string()), | ||
cpu: CpuInfo { | ||
arch: std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_else(|_| "UNKNOWN".to_string()), | ||
pointer_width: std::env::var("CARGO_CFG_TARGET_POINTER_WIDTH") | ||
.expect("Could not read `CARGO_CFG_TARGET_POINTER_WIDTH`") | ||
.parse() | ||
.expect("Could not parse the target pointer width from `CARGO_CFG_TARGET_POINTER_WIDTH`"), | ||
endianness: match std::env::var("CARGO_CFG_TARGET_ENDIAN") { | ||
Ok(val) => match val.as_str() { | ||
"little" => Endianness::Little, | ||
"big" => Endianness::Big, | ||
_ => panic!("Unknown endianness: {val:?}"), | ||
}, | ||
Err(err) => panic!("Could not read `CARGO_CFG_TARGET_ENDIAN`: {err}"), | ||
}, | ||
features: std::env::var("CARGO_CFG_TARGET_FEATURE") | ||
.unwrap_or_default() | ||
.split(',') | ||
.map(|s| s.to_owned()) | ||
.collect(), | ||
}, | ||
} | ||
} |
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
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,43 @@ | ||
use std::any::Any; | ||
|
||
use build_info_common::CpuInfo; | ||
use num_bigint::BigInt; | ||
|
||
use super::{as_arguments_0, as_field_name, FormatSpecifier, Type, Value, OP_FIELD_ACCESS}; | ||
|
||
impl Value for CpuInfo { | ||
fn call(&self, func: &str, args: &[Box<dyn Value>]) -> anyhow::Result<Box<dyn Value>> { | ||
match func { | ||
OP_FIELD_ACCESS => match as_field_name(args) { | ||
"arch" => Ok(Box::new(self.arch.clone())), | ||
"pointer_width" => Ok(Box::new(BigInt::from(self.pointer_width))), | ||
"endianness" => Ok(Box::new(self.endianness)), | ||
"features" => Ok(Box::new(self.features.clone())), | ||
_ => self.call_base(func, args), | ||
}, | ||
"to_string" => { | ||
as_arguments_0(args)?; | ||
Ok(Box::new(self.to_string())) | ||
} | ||
_ => self.call_base(func, args), | ||
} | ||
} | ||
|
||
fn get_type(&self) -> Type { | ||
Type::CompilerInfo | ||
} | ||
|
||
fn as_any(&self) -> &dyn Any { | ||
self | ||
} | ||
|
||
fn format(&self, buffer: &mut String, spec: FormatSpecifier) { | ||
use std::fmt::Write; | ||
|
||
match spec { | ||
FormatSpecifier::Default => write!(buffer, "{self}").unwrap(), | ||
FormatSpecifier::Debug => write!(buffer, "{self:?}").unwrap(), | ||
FormatSpecifier::DebugAlt => write!(buffer, "{self:#?}").unwrap(), | ||
} | ||
} | ||
} |
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,35 @@ | ||
use std::any::Any; | ||
|
||
use build_info_common::Endianness; | ||
|
||
use super::{as_arguments_0, FormatSpecifier, Type, Value}; | ||
|
||
impl Value for Endianness { | ||
fn call(&self, func: &str, args: &[Box<dyn Value>]) -> anyhow::Result<Box<dyn Value>> { | ||
match func { | ||
"to_string" => { | ||
as_arguments_0(args)?; | ||
Ok(Box::new(self.to_string())) | ||
} | ||
_ => self.call_base(func, args), | ||
} | ||
} | ||
|
||
fn get_type(&self) -> Type { | ||
Type::CompilerChannel | ||
} | ||
|
||
fn as_any(&self) -> &dyn Any { | ||
self | ||
} | ||
|
||
fn format(&self, buffer: &mut String, spec: FormatSpecifier) { | ||
use std::fmt::Write; | ||
|
||
match spec { | ||
FormatSpecifier::Default => write!(buffer, "{self}").unwrap(), | ||
FormatSpecifier::Debug => write!(buffer, "{self:?}").unwrap(), | ||
FormatSpecifier::DebugAlt => write!(buffer, "{self:#?}").unwrap(), | ||
} | ||
} | ||
} |
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,42 @@ | ||
use std::any::Any; | ||
|
||
use build_info_common::TargetInfo; | ||
|
||
use super::{as_arguments_0, as_field_name, FormatSpecifier, Type, Value, OP_FIELD_ACCESS}; | ||
|
||
impl Value for TargetInfo { | ||
fn call(&self, func: &str, args: &[Box<dyn Value>]) -> anyhow::Result<Box<dyn Value>> { | ||
match func { | ||
OP_FIELD_ACCESS => match as_field_name(args) { | ||
"triple" => Ok(Box::new(self.triple.clone())), | ||
"family" => Ok(Box::new(self.family.clone())), | ||
"os" => Ok(Box::new(self.os.clone())), | ||
"cpu" => Ok(Box::new(self.cpu.clone())), | ||
_ => self.call_base(func, args), | ||
}, | ||
"to_string" => { | ||
as_arguments_0(args)?; | ||
Ok(Box::new(self.to_string())) | ||
} | ||
_ => self.call_base(func, args), | ||
} | ||
} | ||
|
||
fn get_type(&self) -> Type { | ||
Type::CompilerInfo | ||
} | ||
|
||
fn as_any(&self) -> &dyn Any { | ||
self | ||
} | ||
|
||
fn format(&self, buffer: &mut String, spec: FormatSpecifier) { | ||
use std::fmt::Write; | ||
|
||
match spec { | ||
FormatSpecifier::Default => write!(buffer, "{self}").unwrap(), | ||
FormatSpecifier::Debug => write!(buffer, "{self:?}").unwrap(), | ||
FormatSpecifier::DebugAlt => write!(buffer, "{self:#?}").unwrap(), | ||
} | ||
} | ||
} |
Oops, something went wrong.