Last active
February 6, 2023 04:34
-
-
Save PretorianCC/34d668f7137afe9b6ed30d1a5a5619ab to your computer and use it in GitHub Desktop.
(Ржавый код) Инструменты
This file contains hidden or 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
// src/main.rs (Точка входа приложения по умолчанию) | |
fn main() { | |
println!("Ржавый код!"); | |
} |
This file contains hidden or 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
// src/lib.rs (Точка входа в библиотеку по умолчанию) | |
pub fn f() {} // Является общедоступным элементом в корне, поэтому он доступен извне. | |
mod m { | |
pub fn g() {} // Нет общедоступного пути ('m' не общедоступен) от root, поэтому 'g'. | |
} |
This file contains hidden or 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
// src/my_module.rs (любой файл вашего проекта) | |
fn f() -> u32 { 0 } | |
#[cfg(test)] | |
mod test { | |
use super::f; // Необходимо импортировать элементы из родительского модуля. | |
// Имеет доступ к непубличным членам. | |
#[test] | |
fn ff() { | |
assert_eq!(f(), 0); | |
} | |
} |
This file contains hidden or 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
// tests/sample.rs (пример интеграционного теста) | |
#[test] | |
fn my_sample() { | |
assert_eq!(my_crate::f(), 123); // Интеграционные тесты (и бенчмарки) «зависят» от crate, как 3-я сторона. | |
} |
This file contains hidden or 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
// benches/sample.rs (пример теста производительности) | |
#![feature(test)] | |
extern crate test; // Обычно это не нужно в новых версиях rust | |
use test::{black_box, Bencher}; | |
#[bench] | |
fn my_algo(b: &mut Bencher) { | |
b.iter(|| black_box(my_crate::f())); // 'black_box' предотвращает оптимизацию 'f'. | |
} |
This file contains hidden or 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
// build.rs (Пример сценария предварительной сборки) | |
fn main() { | |
// Вам нужно полагаться на env.vars, '#[cfg(...)] ' предназначен для хоста. | |
let target_os = env::var("CARGO_CFG_TARGET_OS"); | |
} |
This file contains hidden or 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
// src/lib.rs (Точка входа по умолчанию для макросов) | |
extern crate proc_macro; // Видимо нужно импортировать именно так. | |
use proc_macro::TokenStream; | |
#[proc_macro_attribute] // Крейты теперь могут использовать '#[my_attribute]' | |
pub fn my_attribute(_attr: TokenStream, item: TokenStream) -> TokenStream { | |
item | |
} |
This file contains hidden or 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
// Cargo.toml | |
[package] | |
name = "my_crate" | |
version = "0.1.0" | |
[lib] | |
proc-macro = true |
This file contains hidden or 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
[target.aarch64-linux-android] | |
linker = "[PATH_TO_TOOLCHAIN]/aarch64-linux-android/bin/aarch64-linux-android-clang" |
This file contains hidden or 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
[target.aarch64-linux-android] | |
linker = "C:/[PATH_TO_TOOLCHAIN]/prebuilt/windows-x86_64/bin/aarch64-linux-android21-clang.cmd" |
This file contains hidden or 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
set CC=C:\[PATH_TO_TOOLCHAIN]\prebuilt\windows-x86_64\bin\aarch64-linux-android21-clang.cmd | |
set CXX=C:\[PATH_TO_TOOLCHAIN]\prebuilt\windows-x86_64\bin\aarch64-linux-android21-clang.cmd | |
set AR=C:\[PATH_TO_TOOLCHAIN]\prebuilt\windows-x86_64\bin\aarch64-linux-android-ar.exe | |
… |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment