├── docs ├── api │ ├── .lock │ ├── crates.js │ ├── rust_info │ │ ├── types │ │ │ ├── sidebar-items.js │ │ │ └── index.html │ │ ├── sidebar-items.js │ │ ├── all.html │ │ ├── fn.get.html │ │ ├── fn.get_with_options.html │ │ └── index.html │ ├── src-files.js │ ├── static.files │ │ ├── favicon-32x32-00000000d9d8501d.png │ │ ├── FiraSans-Medium-0000000066e2bc86.woff2 │ │ ├── FiraSans-Regular-0000000084b1ad12.woff2 │ │ ├── SourceSerif4-It-000000007236df52.ttf.woff2 │ │ ├── NanumBarunGothic-00000000f861df9d.ttf.woff2 │ │ ├── SourceCodePro-It-00000000668aca82.ttf.woff2 │ │ ├── SourceSerif4-Bold-00000000ad926a49.ttf.woff2 │ │ ├── SourceSerif4-Regular-0000000007da4a04.ttf.woff2 │ │ ├── SourceCodePro-Regular-0000000004ddb02d.ttf.woff2 │ │ ├── SourceCodePro-Semibold-00000000f27a569e.ttf.woff2 │ │ ├── LICENSE-MIT-00000000cc9db09c.txt │ │ ├── normalize-0000000091fda82d.css │ │ ├── COPYRIGHT-000000008a1f0d17.txt │ │ ├── scrape-examples-00000000aae39024.js │ │ ├── rust-logo-00000000a653c8a4.svg │ │ ├── src-script-00000000e6115c00.js │ │ ├── favicon-00000000a292be17.svg │ │ ├── FiraSans-LICENSE-000000004f3fb3ba.txt │ │ ├── SourceCodePro-LICENSE-00000000fb612b27.txt │ │ ├── SourceSerif4-LICENSE-00000000b79e562a.md │ │ ├── NanumBarunGothic-LICENSE-000000008feec719.txt │ │ ├── storage-0000000036c0a5b4.js │ │ ├── settings-000000000a4e6193.js │ │ ├── noscript-00000000626a34ad.css │ │ └── LICENSE-APACHE-00000000be5b60d4.txt │ ├── trait.impl │ │ └── core │ │ │ ├── marker │ │ │ ├── trait.Copy.js │ │ │ ├── trait.StructuralPartialEq.js │ │ │ ├── trait.Send.js │ │ │ ├── trait.Sync.js │ │ │ ├── trait.Unpin.js │ │ │ └── trait.Freeze.js │ │ │ ├── cmp │ │ │ └── trait.PartialEq.js │ │ │ ├── default │ │ │ └── trait.Default.js │ │ │ ├── fmt │ │ │ └── trait.Debug.js │ │ │ ├── clone │ │ │ └── trait.Clone.js │ │ │ └── panic │ │ │ └── unwind_safe │ │ │ ├── trait.UnwindSafe.js │ │ │ └── trait.RefUnwindSafe.js │ ├── search.desc │ │ └── rust_info │ │ │ └── rust_info-desc-0-.js │ ├── search-index.js │ ├── settings.html │ ├── help.html │ └── src │ │ └── rust_info │ │ ├── types.rs.html │ │ ├── triple.rs.html │ │ ├── lib.rs.html │ │ └── rustinfo.rs.html └── index.html ├── .gitattributes ├── .rusty-hook.toml ├── .gitignore ├── .github ├── dependabot.yml ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── workflows │ └── ci.yml └── CONTRIBUTING.md ├── src ├── lib_test.rs ├── types_test.rs ├── rustinfo_test.rs ├── types.rs ├── triple.rs ├── rustinfo.rs ├── lib.rs └── triple_test.rs ├── .editorconfig ├── Makefile.toml ├── benches └── bench_get.rs ├── tests ├── get_test.rs └── get_option_test.rs ├── CHANGELOG.md ├── Cargo.toml ├── examples └── example.rs ├── README.md └── LICENSE /docs/api/.lock: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/api/crates.js: -------------------------------------------------------------------------------- 1 | window.ALL_CRATES = ["rust_info"]; -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | *.ico binary 3 | *.woff binary 4 | -------------------------------------------------------------------------------- /.rusty-hook.toml: -------------------------------------------------------------------------------- 1 | [hooks] 2 | pre-push = "cargo make ci-flow" 3 | -------------------------------------------------------------------------------- /docs/api/rust_info/types/sidebar-items.js: -------------------------------------------------------------------------------- 1 | window.SIDEBAR_ITEMS = {"enum":["RustChannel"],"struct":["RustInfo"]}; -------------------------------------------------------------------------------- /docs/api/rust_info/sidebar-items.js: -------------------------------------------------------------------------------- 1 | window.SIDEBAR_ITEMS = {"fn":["get","get_with_options"],"mod":["types"],"struct":["Options"]}; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .c9 3 | /target 4 | temp/ 5 | **/*.rs.bk 6 | Cargo.lock 7 | **/*.log 8 | dump.rdb 9 | /rs*.sh 10 | /docs/_site 11 | /core 12 | -------------------------------------------------------------------------------- /docs/api/src-files.js: -------------------------------------------------------------------------------- 1 | var srcIndex = new Map(JSON.parse('[\ 2 | ["rust_info",["",[],["lib.rs","rustinfo.rs","triple.rs","types.rs"]]]\ 3 | ]')); 4 | createSrcSidebar(); 5 | -------------------------------------------------------------------------------- /docs/api/static.files/favicon-32x32-00000000d9d8501d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/rust_info/master/docs/api/static.files/favicon-32x32-00000000d9d8501d.png -------------------------------------------------------------------------------- /docs/api/static.files/FiraSans-Medium-0000000066e2bc86.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/rust_info/master/docs/api/static.files/FiraSans-Medium-0000000066e2bc86.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/FiraSans-Regular-0000000084b1ad12.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/rust_info/master/docs/api/static.files/FiraSans-Regular-0000000084b1ad12.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceSerif4-It-000000007236df52.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/rust_info/master/docs/api/static.files/SourceSerif4-It-000000007236df52.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/NanumBarunGothic-00000000f861df9d.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/rust_info/master/docs/api/static.files/NanumBarunGothic-00000000f861df9d.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceCodePro-It-00000000668aca82.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/rust_info/master/docs/api/static.files/SourceCodePro-It-00000000668aca82.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceSerif4-Bold-00000000ad926a49.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/rust_info/master/docs/api/static.files/SourceSerif4-Bold-00000000ad926a49.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceSerif4-Regular-0000000007da4a04.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/rust_info/master/docs/api/static.files/SourceSerif4-Regular-0000000007da4a04.ttf.woff2 -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: cargo 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: '03:00' 8 | open-pull-requests-limit: 99 9 | -------------------------------------------------------------------------------- /docs/api/static.files/SourceCodePro-Regular-0000000004ddb02d.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/rust_info/master/docs/api/static.files/SourceCodePro-Regular-0000000004ddb02d.ttf.woff2 -------------------------------------------------------------------------------- /docs/api/static.files/SourceCodePro-Semibold-00000000f27a569e.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/rust_info/master/docs/api/static.files/SourceCodePro-Semibold-00000000f27a569e.ttf.woff2 -------------------------------------------------------------------------------- /src/lib_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use doc_comment as _; 3 | 4 | #[test] 5 | fn get_test() { 6 | let rust_info = get(); 7 | 8 | assert!(rust_info.version.is_some()); 9 | assert!(rust_info.channel.is_some()); 10 | } 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | indent_style = space 10 | indent_size = 4 11 | 12 | [*.json] 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Makefile.toml: -------------------------------------------------------------------------------- 1 | 2 | [config] 3 | additional_profiles = [ 4 | "all-default-tasks", 5 | "docs-all-modification-tasks", 6 | "ci-coverage-tasks", 7 | "ci-all-build-tasks", 8 | "ci-static-code-analysis-tasks", 9 | "publish-pre-cleanup", 10 | ] 11 | 12 | [env] 13 | CARGO_MAKE_SKIP_SLOW_SECONDARY_FLOWS = true 14 | 15 | -------------------------------------------------------------------------------- /benches/bench_get.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use rust_info; 5 | use test::Bencher; 6 | 7 | #[bench] 8 | fn get(bencher: &mut Bencher) { 9 | bencher.iter(|| { 10 | let rust_info = rust_info::get(); 11 | 12 | assert!(rust_info.version.is_some()); 13 | assert!(rust_info.channel.is_some()); 14 | }); 15 | } 16 | -------------------------------------------------------------------------------- /tests/get_test.rs: -------------------------------------------------------------------------------- 1 | #[test] 2 | fn get() { 3 | let rust_info = rust_info::get(); 4 | 5 | assert!(rust_info.version.is_some()); 6 | assert!(rust_info.channel.is_some()); 7 | assert!(rust_info.target_arch.is_some()); 8 | assert!(rust_info.target_env.is_some()); 9 | assert!(rust_info.target_os.is_some()); 10 | assert!(rust_info.target_pointer_width.is_some()); 11 | assert!(rust_info.target_triple.is_some()); 12 | } 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: sagiegurari 7 | 8 | --- 9 | 10 | ### Feature Description 11 | 12 | 13 | ### Describe The Solution You'd Like 14 | 15 | 16 | ### Code Sample 17 | 18 | ```rust 19 | /// paste code here 20 | ``` 21 | -------------------------------------------------------------------------------- /docs/api/trait.impl/core/marker/trait.Copy.js: -------------------------------------------------------------------------------- 1 | (function() {var implementors = { 2 | "rust_info":[["impl Copy for RustChannel"]] 3 | };if (window.register_implementors) {window.register_implementors(implementors);} else {window.pending_implementors = implementors;}})() -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: sagiegurari 7 | 8 | --- 9 | 10 | ### Describe The Bug 11 | 12 | 13 | ### To Reproduce 14 | 15 | 16 | ### Error Stack 17 | 18 | ```console 19 | The error stack trace 20 | ``` 21 | 22 | ### Code Sample 23 | 24 | ```rust 25 | /// paste code here 26 | ``` 27 | -------------------------------------------------------------------------------- /src/types_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | #[test] 4 | fn rust_info_new() { 5 | let rust_info = RustInfo::new(); 6 | 7 | assert!(rust_info.version.is_none()); 8 | assert!(rust_info.channel.is_none()); 9 | assert!(rust_info.target_arch.is_none()); 10 | assert!(rust_info.target_env.is_none()); 11 | assert!(rust_info.target_os.is_none()); 12 | assert!(rust_info.target_pointer_width.is_none()); 13 | assert!(rust_info.target_vendor.is_none()); 14 | assert!(rust_info.target_triple.is_none()); 15 | } 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## CHANGELOG 2 | 3 | ### v0.3.3 (2024-08-30) 4 | 5 | * Enhancement: Serde support (as optional feature) #7 (thanks @SamuelMarks) 6 | 7 | ### v0.3.2 (2021-07-30) 8 | 9 | * Enhancement: enable to fetch info from custom directory location #5 (thanks @EliseZeroTwo) 10 | 11 | ### v0.3.1 (2020-05-01) 12 | 13 | * Fix target_triple for multiple platforms #3 14 | 15 | ### v0.3.0 (2019-01-06) 16 | 17 | * Adding target_triple information. 18 | 19 | ### v0.1.1 (2017-10-10) 20 | 21 | * Update exposed types. 22 | 23 | ### v0.1.0 (2017-10-10) 24 | 25 | * Initial release 26 | -------------------------------------------------------------------------------- /tests/get_option_test.rs: -------------------------------------------------------------------------------- 1 | use std::path::Path; 2 | 3 | use rust_info::Options; 4 | 5 | #[test] 6 | fn get() { 7 | let opts = Options::new().path(Some(Path::new("./").into())); 8 | let rust_info = rust_info::get_with_options(&opts); 9 | 10 | assert!(rust_info.version.is_some()); 11 | assert!(rust_info.channel.is_some()); 12 | assert!(rust_info.target_arch.is_some()); 13 | assert!(rust_info.target_env.is_some()); 14 | assert!(rust_info.target_os.is_some()); 15 | assert!(rust_info.target_pointer_width.is_some()); 16 | assert!(rust_info.target_triple.is_some()); 17 | } 18 | -------------------------------------------------------------------------------- /src/rustinfo_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use std::io::ErrorKind; 3 | 4 | #[test] 5 | fn get_exit_code_error() { 6 | let code = get_exit_code(Err(Error::new(ErrorKind::Other, "test"))); 7 | assert_eq!(code, -1); 8 | } 9 | 10 | #[test] 11 | fn load_with_values() { 12 | let rust_info = crate::get(); 13 | 14 | assert!(rust_info.version.is_some()); 15 | assert!(rust_info.channel.is_some()); 16 | assert!(rust_info.target_arch.is_some()); 17 | assert!(rust_info.target_env.is_some()); 18 | assert!(rust_info.target_os.is_some()); 19 | assert!(rust_info.target_pointer_width.is_some()); 20 | assert!(rust_info.target_triple.is_some()); 21 | } 22 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: [push, pull_request] 3 | env: 4 | CLICOLOR_FORCE: 1 5 | jobs: 6 | ci: 7 | name: CI 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | rust: [stable, beta, nightly] 13 | os: [ubuntu-latest, windows-latest, macOS-latest] 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | - name: Install rust 18 | uses: dtolnay/rust-toolchain@master 19 | with: 20 | toolchain: ${{ matrix.rust }} 21 | - name: Install cargo-make 22 | run: cargo install --debug cargo-make 23 | - name: Run CI 24 | env: 25 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 26 | run: cargo make ci-flow 27 | -------------------------------------------------------------------------------- /docs/api/trait.impl/core/cmp/trait.PartialEq.js: -------------------------------------------------------------------------------- 1 | (function() {var implementors = { 2 | "rust_info":[["impl PartialEq for RustChannel"],["impl PartialEq for RustInfo"]] 3 | };if (window.register_implementors) {window.register_implementors(implementors);} else {window.pending_implementors = implementors;}})() -------------------------------------------------------------------------------- /docs/api/trait.impl/core/default/trait.Default.js: -------------------------------------------------------------------------------- 1 | (function() {var implementors = { 2 | "rust_info":[["impl Default for RustInfo"],["impl<'path> Default for Options<'path>"]] 3 | };if (window.register_implementors) {window.register_implementors(implementors);} else {window.pending_implementors = implementors;}})() -------------------------------------------------------------------------------- /docs/api/trait.impl/core/marker/trait.StructuralPartialEq.js: -------------------------------------------------------------------------------- 1 | (function() {var implementors = { 2 | "rust_info":[["impl StructuralPartialEq for RustChannel"],["impl StructuralPartialEq for RustInfo"]] 3 | };if (window.register_implementors) {window.register_implementors(implementors);} else {window.pending_implementors = implementors;}})() -------------------------------------------------------------------------------- /docs/api/search.desc/rust_info/rust_info-desc-0-.js: -------------------------------------------------------------------------------- 1 | searchState.loadedDescShard("rust_info", 0, "rust_info\nOptions used for querying rust info\nReturns the argument unchanged.\nLoads and returns the current rust compiler version and …\nLoads and returns the current rust compiler version and …\nCallsU::from(self).\nHelper for calling default\nSets the path option\nOptionally override working directory used for querying …\ntypes\nRust beta channel\nRust nightly channel\nRust channel type\nHolds the current rust installation and setup information\nRust stable channel\nchannel\nReturns the argument unchanged.\nReturns the argument unchanged.\nCalls U::from(self).\nCalls U::from(self).\nReturns new instance\ntarget arch cfg value\ntarget env cfg value\ntarget OS cfg value\ntarget pointer width cfg value\ntarget triple constructed from target arc, vendor, os and …\ntarget vendor cfg value\nversion")
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "rust_info"
3 | version = "0.3.3"
4 | authors = ["Sagie Gur-Ari pub fn get() -> RustInfoLoads and returns the current rust compiler version and setup.
2 | In case partial data is not available, those values will be set to Option::None.
fn main() {
5 | let rust_info = rust_info::get();
6 |
7 | println!("Version: {}", rust_info.version.unwrap());
8 | println!("Channel: {:#?}", rust_info.channel.unwrap());
9 | println!("Target Arch: {}", rust_info.target_arch.unwrap_or("unknown".to_string()));
10 | println!("Target Env: {}", rust_info.target_env.unwrap_or("unknown".to_string()));
11 | println!("Target OS: {}", rust_info.target_os.unwrap_or("unknown".to_string()));
12 | println!("Target Pointer Width: {}", rust_info.target_pointer_width.unwrap_or("unknown".to_string()));
13 | println!("Target Vendor: {}", rust_info.target_vendor.unwrap_or("unknown".to_string()));
14 | println!("Target Triple: {}", rust_info.target_triple.unwrap_or("unknown".to_string()));
15 | }pub fn get_with_options(options: &Options<'_>) -> RustInfoLoads and returns the current rust compiler version and setup for a specified path.
2 | In case partial data is not available, those values will be set to Option::None.
fn main() {
5 | let opts = rust_info::Options::new().path(Some(std::path::Path::new("./").into()));
6 | let rust_info = rust_info::get_with_options(&opts);
7 |
8 | println!("Version: {}", rust_info.version.unwrap());
9 | println!("Channel: {:#?}", rust_info.channel.unwrap());
10 | println!("Target Arch: {}", rust_info.target_arch.unwrap_or("unknown".to_string()));
11 | println!("Target Env: {}", rust_info.target_env.unwrap_or("unknown".to_string()));
12 | println!("Target OS: {}", rust_info.target_os.unwrap_or("unknown".to_string()));
13 | println!("Target Pointer Width: {}", rust_info.target_pointer_width.unwrap_or("unknown".to_string()));
14 | println!("Target Vendor: {}", rust_info.target_vendor.unwrap_or("unknown".to_string()));
15 | println!("Target Triple: {}", rust_info.target_triple.unwrap_or("unknown".to_string()));
16 | }1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 | 18 19 | 19 20 | 20 21 | 21 22 | 22 23 | 23 24 | 24 25 | 25 26 | 26 27 | 27 28 | 28 29 | 29 30 | 30 31 | 31 32 | 32 33 | 33 34 | 34 35 | 35 36 | 36 37 | 37 38 | 38 39 | 39 40 | 40 41 | 41 42 | 42 43 | 43 44 | 44 45 | 45 46 | 46 47 | 47 48 | 48 49 | 49 50 |
//! # types
51 | //!
52 | //! Defines the various types and aliases.
53 | //!
54 |
55 | #[cfg(test)]
56 | #[path = "./types_test.rs"]
57 | mod types_test;
58 |
59 | #[derive(Debug, Clone, PartialEq, Copy)]
60 | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
61 | /// Rust channel type
62 | pub enum RustChannel {
63 | /// Rust stable channel
64 | Stable,
65 | /// Rust beta channel
66 | Beta,
67 | /// Rust nightly channel
68 | Nightly,
69 | }
70 |
71 | #[derive(Debug, Clone, PartialEq, Default)]
72 | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
73 | /// Holds the current rust installation and setup information
74 | pub struct RustInfo {
75 | /// version
76 | pub version: Option<String>,
77 | /// channel
78 | pub channel: Option<RustChannel>,
79 | /// target arch cfg value
80 | pub target_arch: Option<String>,
81 | /// target env cfg value
82 | pub target_env: Option<String>,
83 | /// target OS cfg value
84 | pub target_os: Option<String>,
85 | /// target pointer width cfg value
86 | pub target_pointer_width: Option<String>,
87 | /// target vendor cfg value
88 | pub target_vendor: Option<String>,
89 | /// target triple constructed from target arc, vendor, os and env
90 | pub target_triple: Option<String>,
91 | }
92 |
93 | impl RustInfo {
94 | /// Returns new instance
95 | pub fn new() -> RustInfo {
96 | Default::default()
97 | }
98 | }
99 | Extracts and provides the current rust compiler information.
3 |This library main goal is to provide development/build tools such as 4 | cargo-makethe needed information on the current rust installation and 5 | setup.
6 |fn main() {
8 | let rust_info = rust_info::get();
9 |
10 | println!("Version: {}", rust_info.version.unwrap());
11 | println!("Channel: {:#?}", rust_info.channel.unwrap());
12 | println!("Target Arch: {}", rust_info.target_arch.unwrap_or("unknown".to_string()));
13 | println!("Target Env: {}", rust_info.target_env.unwrap_or("unknown".to_string()));
14 | println!("Target OS: {}", rust_info.target_os.unwrap_or("unknown".to_string()));
15 | println!("Target Pointer Width: {}", rust_info.target_pointer_width.unwrap_or("unknown".to_string()));
16 | println!("Target Vendor: {}", rust_info.target_vendor.unwrap_or("unknown".to_string()));
17 | println!("Target Triple: {}", rust_info.target_triple.unwrap_or("unknown".to_string()));
18 | }In order to use this library, just add it as a dependency:
21 |[dependencies]
22 | rust_info = "*"
23 | Developed by Sagie Gur-Ari and licensed under the 27 | Apache 2 open source license.
28 |1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 | 18 19 | 19 20 | 20 21 | 21 22 | 22 23 | 23 24 | 24 25 | 25 26 | 26 27 | 27 28 | 28 29 | 29 30 | 30 31 | 31 32 | 32 33 | 33 34 | 34 35 | 35 36 | 36 37 | 37 38 | 38 39 | 39 40 | 40 41 | 41 42 | 42 43 | 43 44 | 44 45 | 45 46 | 46 47 | 47 48 | 48 49 | 49 50 | 50 51 | 51 52 | 52 53 | 53 54 | 54 55 | 55 56 | 56 57 | 57 58 | 58 59 | 59 60 | 60 61 | 61 62 | 62 63 | 63 64 | 64 65 | 65 66 | 66 67 | 67 68 | 68 69 | 69 70 | 70 71 | 71 72 | 72 73 | 73 74 | 74 75 |
//! # triple
76 | //!
77 | //! Manages the rust triple values and logic.
78 | //!
79 |
80 | #[cfg(test)]
81 | #[path = "./triple_test.rs"]
82 | mod triple_test;
83 |
84 | use crate::types::RustInfo;
85 |
86 | pub(crate) fn load(rust_info: &mut RustInfo) {
87 | if let (Some(arch), Some(os)) = (&rust_info.target_arch, &rust_info.target_os) {
88 | let mut triple = String::new();
89 | let mapped_arch = map_arch(arch);
90 | triple.push_str(&mapped_arch);
91 |
92 | if let Some(vendor) = &rust_info.target_vendor {
93 | let mapped_vendor = map_vendor(vendor, os);
94 |
95 | triple.push_str("-");
96 | triple.push_str(&mapped_vendor);
97 | }
98 |
99 | let mapped_os = map_os(os, arch);
100 | triple.push_str("-");
101 | triple.push_str(&mapped_os);
102 |
103 | if let Some(env) = &rust_info.target_env {
104 | if !env.is_empty() {
105 | let mapped_env = map_env(env, arch);
106 | triple.push_str("-");
107 | triple.push_str(&mapped_env);
108 | }
109 | }
110 |
111 | rust_info.target_triple = Some(triple);
112 | }
113 | }
114 |
115 | fn map_arch(arch: &str) -> String {
116 | match arch {
117 | "x86" => "i686".to_string(),
118 | _ => arch.to_string(),
119 | }
120 | }
121 |
122 | fn map_vendor(vendor: &str, os: &str) -> String {
123 | match os {
124 | "android" => "linux".to_string(),
125 | _ => vendor.to_string(),
126 | }
127 | }
128 |
129 | fn map_os(os: &str, arch: &str) -> String {
130 | match os {
131 | "macos" => "darwin".to_string(),
132 | "android" => match arch {
133 | "arm" => "androideabi".to_string(),
134 | _ => os.to_string(),
135 | },
136 | _ => os.to_string(),
137 | }
138 | }
139 |
140 | fn map_env(env: &str, arch: &str) -> String {
141 | match env {
142 | "gnu" => match arch {
143 | "arm" => "gnueabihf".to_string(),
144 | _ => env.to_string(),
145 | },
146 | _ => env.to_string(),
147 | }
148 | }
149 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 | 18 19 | 19 20 | 20 21 | 21 22 | 22 23 | 23 24 | 24 25 | 25 26 | 26 27 | 27 28 | 28 29 | 29 30 | 30 31 | 31 32 | 32 33 | 33 34 | 34 35 | 35 36 | 36 37 | 37 38 | 38 39 | 39 40 | 40 41 | 41 42 | 42 43 | 43 44 | 44 45 | 45 46 | 46 47 | 47 48 | 48 49 | 49 50 | 50 51 | 51 52 | 52 53 | 53 54 | 54 55 | 55 56 | 56 57 | 57 58 | 58 59 | 59 60 | 60 61 | 61 62 | 62 63 | 63 64 | 64 65 | 65 66 | 66 67 | 67 68 | 68 69 | 69 70 | 70 71 | 71 72 | 72 73 | 73 74 | 74 75 | 75 76 | 76 77 | 77 78 | 78 79 | 79 80 | 80 81 | 81 82 | 82 83 | 83 84 | 84 85 | 85 86 | 86 87 | 87 88 | 88 89 | 89 90 | 90 91 | 91 92 | 92 93 | 93 94 | 94 95 | 95 96 | 96 97 | 97 98 | 98 99 | 99 100 | 100 101 | 101 102 | 102 103 | 103 104 | 104 105 | 105 106 | 106 107 | 107 108 | 108 109 | 109 110 | 110 111 | 111 112 | 112 113 | 113 114 | 114 115 | 115 116 | 116 117 | 117 118 | 118 119 | 119 120 | 120 121 | 121 122 | 122 123 | 123 124 | 124 125 | 125 126 | 126 127 | 127 128 | 128 129 | 129 130 | 130 131 | 131 132 | 132 133 | 133 134 | 134 135 | 135 136 | 136 137 | 137 138 |
#![deny(
139 | future_incompatible,
140 | keyword_idents,
141 | let_underscore,
142 | nonstandard_style,
143 | unused
144 | )]
145 | #![warn(unknown_lints)]
146 |
147 | //! # rust_info
148 | //!
149 | //! Extracts and provides the current rust compiler information.
150 | //!
151 | //! This library main goal is to provide development/build tools such as
152 | //! [cargo-make](https://sagiegurari.github.io/cargo-make/)the needed information on the current rust installation and
153 | //! setup.
154 | //!
155 | //! # Examples
156 | //!
157 | //! ```
158 | //! fn main() {
159 | //! let rust_info = rust_info::get();
160 | //!
161 | //! println!("Version: {}", rust_info.version.unwrap());
162 | //! println!("Channel: {:#?}", rust_info.channel.unwrap());
163 | //! println!("Target Arch: {}", rust_info.target_arch.unwrap_or("unknown".to_string()));
164 | //! println!("Target Env: {}", rust_info.target_env.unwrap_or("unknown".to_string()));
165 | //! println!("Target OS: {}", rust_info.target_os.unwrap_or("unknown".to_string()));
166 | //! println!("Target Pointer Width: {}", rust_info.target_pointer_width.unwrap_or("unknown".to_string()));
167 | //! println!("Target Vendor: {}", rust_info.target_vendor.unwrap_or("unknown".to_string()));
168 | //! println!("Target Triple: {}", rust_info.target_triple.unwrap_or("unknown".to_string()));
169 | //! }
170 | //! ```
171 | //!
172 | //! # Installation
173 | //! In order to use this library, just add it as a dependency:
174 | //!
175 | //! ```ini
176 | //! [dependencies]
177 | //! rust_info = "*"
178 | //! ```
179 | //!
180 | //! # Contributing
181 | //! See [contributing guide](https://github.com/sagiegurari/rust_info/blob/master/.github/CONTRIBUTING.md)
182 | //!
183 | //! # License
184 | //! Developed by Sagie Gur-Ari and licensed under the
185 | //! [Apache 2](https://github.com/sagiegurari/rust_info/blob/master/LICENSE) open source license.
186 | //!
187 |
188 | #[cfg(test)]
189 | #[path = "./lib_test.rs"]
190 | mod lib_test;
191 |
192 | #[cfg(doctest)]
193 | doc_comment::doctest!("../README.md");
194 |
195 | mod rustinfo;
196 | mod triple;
197 | pub mod types;
198 |
199 | use std::{borrow::Cow, path::Path};
200 |
201 | use crate::types::RustInfo;
202 |
203 | /// Options used for querying rust info
204 | #[derive(Debug, Clone)]
205 | pub struct Options<'path> {
206 | /// Optionally override working directory used for querying `rustc`
207 | pub path: Option<Cow<'path, Path>>,
208 | }
209 |
210 | impl<'path> Default for Options<'path> {
211 | fn default() -> Self {
212 | Self { path: None }
213 | }
214 | }
215 |
216 | impl<'path> Options<'path> {
217 | /// Helper for calling `default`
218 | pub fn new() -> Self {
219 | Self::default()
220 | }
221 |
222 | /// Sets the `path` option
223 | pub fn path(mut self, path: Option<Cow<'path, Path>>) -> Self {
224 | self.path = path;
225 | self
226 | }
227 | }
228 |
229 | /// Loads and returns the current rust compiler version and setup.<br>
230 | /// In case partial data is not available, those values will be set to Option::None.
231 | ///
232 | /// # Example
233 | ///
234 | /// ```
235 | /// fn main() {
236 | /// let rust_info = rust_info::get();
237 | ///
238 | /// println!("Version: {}", rust_info.version.unwrap());
239 | /// println!("Channel: {:#?}", rust_info.channel.unwrap());
240 | /// println!("Target Arch: {}", rust_info.target_arch.unwrap_or("unknown".to_string()));
241 | /// println!("Target Env: {}", rust_info.target_env.unwrap_or("unknown".to_string()));
242 | /// println!("Target OS: {}", rust_info.target_os.unwrap_or("unknown".to_string()));
243 | /// println!("Target Pointer Width: {}", rust_info.target_pointer_width.unwrap_or("unknown".to_string()));
244 | /// println!("Target Vendor: {}", rust_info.target_vendor.unwrap_or("unknown".to_string()));
245 | /// println!("Target Triple: {}", rust_info.target_triple.unwrap_or("unknown".to_string()));
246 | /// }
247 | /// ```
248 | pub fn get() -> RustInfo {
249 | get_with_options(&Options::default())
250 | }
251 |
252 | /// Loads and returns the current rust compiler version and setup for a specified path.<br>
253 | /// In case partial data is not available, those values will be set to Option::None.
254 | ///
255 | /// # Example
256 | ///
257 | /// ```
258 | /// fn main() {
259 | /// let opts = rust_info::Options::new().path(Some(std::path::Path::new("./").into()));
260 | /// let rust_info = rust_info::get_with_options(&opts);
261 | ///
262 | /// println!("Version: {}", rust_info.version.unwrap());
263 | /// println!("Channel: {:#?}", rust_info.channel.unwrap());
264 | /// println!("Target Arch: {}", rust_info.target_arch.unwrap_or("unknown".to_string()));
265 | /// println!("Target Env: {}", rust_info.target_env.unwrap_or("unknown".to_string()));
266 | /// println!("Target OS: {}", rust_info.target_os.unwrap_or("unknown".to_string()));
267 | /// println!("Target Pointer Width: {}", rust_info.target_pointer_width.unwrap_or("unknown".to_string()));
268 | /// println!("Target Vendor: {}", rust_info.target_vendor.unwrap_or("unknown".to_string()));
269 | /// println!("Target Triple: {}", rust_info.target_triple.unwrap_or("unknown".to_string()));
270 | /// }
271 | /// ```
272 | pub fn get_with_options(options: &Options) -> RustInfo {
273 | rustinfo::get(options)
274 | }
275 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 | 18 19 | 19 20 | 20 21 | 21 22 | 22 23 | 23 24 | 24 25 | 25 26 | 26 27 | 27 28 | 28 29 | 29 30 | 30 31 | 31 32 | 32 33 | 33 34 | 34 35 | 35 36 | 36 37 | 37 38 | 38 39 | 39 40 | 40 41 | 41 42 | 42 43 | 43 44 | 44 45 | 45 46 | 46 47 | 47 48 | 48 49 | 49 50 | 50 51 | 51 52 | 52 53 | 53 54 | 54 55 | 55 56 | 56 57 | 57 58 | 58 59 | 59 60 | 60 61 | 61 62 | 62 63 | 63 64 | 64 65 | 65 66 | 66 67 | 67 68 | 68 69 | 69 70 | 70 71 | 71 72 | 72 73 | 73 74 | 74 75 | 75 76 | 76 77 | 77 78 | 78 79 | 79 80 | 80 81 | 81 82 | 82 83 | 83 84 | 84 85 | 85 86 | 86 87 | 87 88 | 88 89 | 89 90 | 90 91 | 91 92 | 92 93 | 93 94 | 94 95 | 95 96 | 96 97 | 97 98 | 98 99 | 99 100 | 100 101 | 101 102 | 102 103 | 103 104 | 104 105 | 105 106 | 106 107 | 107 108 | 108 109 | 109 110 | 110 111 | 111 112 | 112 113 | 113 114 | 114 115 | 115 116 | 116 117 | 117 118 | 118 119 | 119 120 | 120 121 | 121 122 | 122 123 | 123 124 | 124 125 | 125 126 | 126 127 | 127 128 | 128 129 | 129 130 | 130 131 | 131 132 | 132 133 | 133 134 | 134 135 | 135 136 | 136 137 | 137 138 | 138 139 | 139 140 | 140 141 | 141 142 | 142 143 | 143 144 | 144 145 | 145 146 | 146 147 | 147 148 |
//! # rustinfo
149 | //!
150 | //! Loads rust compiler information.
151 | //!
152 |
153 | #[cfg(test)]
154 | #[path = "./rustinfo_test.rs"]
155 | mod rustinfo_test;
156 |
157 | use crate::types::{RustChannel, RustInfo};
158 | use crate::{triple, Options};
159 | use std::collections::HashMap;
160 | use std::io::Error;
161 | use std::process::{Command, ExitStatus};
162 |
163 | /// Returns the exit code (-1 if no exit code found)
164 | fn get_exit_code(exit_status: Result<ExitStatus, Error>) -> i32 {
165 | match exit_status {
166 | Ok(code) => {
167 | if !code.success() {
168 | match code.code() {
169 | Some(value) => value,
170 | None => -1,
171 | }
172 | } else {
173 | 0
174 | }
175 | }
176 | _ => -1,
177 | }
178 | }
179 |
180 | fn load_version(rust_info: &mut RustInfo, options: &Options) {
181 | let mut command = Command::new("rustc");
182 |
183 | command.arg("--version");
184 |
185 | if let Some(directory) = &options.path {
186 | command.current_dir(directory);
187 | }
188 |
189 | let result = command.output();
190 |
191 | match result {
192 | Ok(output) => {
193 | let exit_code = get_exit_code(Ok(output.status));
194 |
195 | if exit_code == 0 {
196 | let stdout = String::from_utf8_lossy(&output.stdout);
197 | let parts: Vec<&str> = stdout.split(' ').collect();
198 |
199 | if (parts.len() >= 3) && (parts[0] == "rustc") {
200 | let version_part = parts[1];
201 |
202 | let version_parts: Vec<&str> = version_part.split('-').collect();
203 |
204 | if version_parts.len() > 0 {
205 | rust_info.version = Some(version_parts[0].to_string());
206 |
207 | if version_parts.len() == 1 {
208 | rust_info.channel = Some(RustChannel::Stable);
209 | } else if version_parts[1].contains("beta") {
210 | rust_info.channel = Some(RustChannel::Beta);
211 | } else if version_parts[1].contains("nightly") {
212 | rust_info.channel = Some(RustChannel::Nightly);
213 | }
214 | }
215 | }
216 | }
217 | }
218 | _ => (),
219 | };
220 | }
221 |
222 | fn load_setup(rust_info: &mut RustInfo, options: &Options) {
223 | let mut command = Command::new("rustc");
224 |
225 | command.arg("--print").arg("cfg");
226 |
227 | if let Some(directory) = &options.path {
228 | command.current_dir(directory);
229 | }
230 |
231 | let result = command.output();
232 |
233 | match result {
234 | Ok(output) => {
235 | let exit_code = get_exit_code(Ok(output.status));
236 |
237 | if exit_code == 0 {
238 | let mut values = HashMap::<String, String>::new();
239 |
240 | let stdout = String::from_utf8_lossy(&output.stdout);
241 | let lines: Vec<&str> = stdout.split('\n').collect();
242 | for mut line in lines {
243 | line = line.trim();
244 |
245 | if line.contains("=") {
246 | let parts: Vec<&str> = line.split('=').collect();
247 | let value = str::replace(parts[1], "\"", "");
248 | values.insert(parts[0].to_string(), value.to_string());
249 | }
250 | }
251 |
252 | let mut value = values.remove("target_arch");
253 | if value.is_some() {
254 | rust_info.target_arch = Some(value.unwrap());
255 | }
256 |
257 | value = values.remove("target_env");
258 | if value.is_some() {
259 | rust_info.target_env = Some(value.unwrap());
260 | }
261 |
262 | value = values.remove("target_os");
263 | if value.is_some() {
264 | rust_info.target_os = Some(value.unwrap());
265 | }
266 |
267 | value = values.remove("target_pointer_width");
268 | if value.is_some() {
269 | rust_info.target_pointer_width = Some(value.unwrap());
270 | }
271 |
272 | value = values.remove("target_vendor");
273 | if value.is_some() {
274 | rust_info.target_vendor = Some(value.unwrap());
275 | }
276 | }
277 | }
278 | _ => (),
279 | };
280 | }
281 |
282 | /// Loads and returns the current rust compiler version and setup.<br>
283 | /// In case partial data is not available, those values will be set to Option::None.
284 | pub(crate) fn get(options: &Options) -> RustInfo {
285 | let mut rust_info = RustInfo::new();
286 |
287 | load_version(&mut rust_info, options);
288 |
289 | load_setup(&mut rust_info, options);
290 |
291 | triple::load(&mut rust_info);
292 |
293 | rust_info
294 | }
295 |