Страница 3 из 4
Re: Rust
Добавлено: 13 май 2022, 17:06
Olej
Olej писал(а): ↑13 май 2022, 15:02
1. многоплатформенность: как Rust установить на процессоры ARM, на малые архитектуры типа Raspberry Pi, Orange Pi ?
Такая вот совсем игрушечная машина:
Код: Выделить всё
olej@orangepione:~$ inxi -MCxxxf
Machine: Type: ARM Device System: Xunlong Orange Pi One details: Allwinner sun8i Family rev: N/A serial: 02c000815fd5e717
CPU: Info: Quad Core model: ARMv7 v7l variant: cortex-a7 bits: 32 type: MCP arch: v7l rev: 5 bogomips: 0
Speed: 1008 MHz min/max: 480/1008 MHz Core speeds (MHz): 1: 1008 2: 1008 3: 1008 4: 1008
Features: edsp evtstrm fastmult half idiva idivt lpae neon thumb tls vfp vfpd32 vfpv3 vfpv4
C 4Gb SD картой в качестве носителя:
Код: Выделить всё
olej@orangepione:~$ df
Файловая система 1K-блоков Использовано Доступно Использовано% Cмонтировано в
udev 193268 0 193268 0% /dev
tmpfs 50356 3876 46480 8% /run
/dev/mmcblk0p1 3562820 2062752 1433268 60% /
tmpfs 251764 0 251764 0% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 251764 0 251764 0% /tmp
/dev/zram1 49560 7072 38904 16% /var/log
tmpfs 50352 0 50352 0% /run/user/1000
И операционная система (сборка
Armbian):
Код: Выделить всё
olej@R420:~$ ssh olej@192.168.1.104
olej@192.168.1.104's password:
___ ____ _ ___
/ _ \| _ \(_) / _ \ _ __ ___
| | | | |_) | | | | | | '_ \ / _ \
| |_| | __/| | | |_| | | | | __/
\___/|_| |_| \___/|_| |_|\___|
Welcome to Armbian 22.02.1 with Linux 5.15.25-sunxi
System load: 2% Up time: 45 min Local users: 3
Memory usage: 18% of 491M IP: 192.168.1.104
CPU temp: 58°C Usage of /: 60% of 3.4G
Last login: Fri May 13 16:48:42 2022 from 192.168.1.14
Код: Выделить всё
olej@orangepione:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Re: Rust
Добавлено: 13 май 2022, 17:08
Olej
Olej писал(а): ↑13 май 2022, 17:06
Такая вот совсем игрушечная машина:
Код: Выделить всё
olej@orangepione:~$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
Welcome to Rust!
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
/home/olej/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory located at:
/home/olej/.cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/home/olej/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/home/olej/.profile
/home/olej/.bashrc
/home/olej/.zshenv
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: armv7-unknown-linux-gnueabihf
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1
info: profile set to 'default'
info: default host triple is armv7-unknown-linux-gnueabihf
info: syncing channel updates for 'stable-armv7-unknown-linux-gnueabihf'
info: latest update on 2022-04-07, rust version 1.60.0 (7737e0b5c 2022-04-04)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
19.5 MiB / 19.5 MiB (100 %) 5.9 MiB/s in 7s ETA: 0s
info: downloading component 'rust-std'
23.8 MiB / 23.8 MiB (100 %) 5.4 MiB/s in 14s ETA: 0s
info: downloading component 'rustc'
79.3 MiB / 79.3 MiB (100 %) 5.5 MiB/s in 19s ETA: 0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
5.7 MiB / 5.7 MiB (100 %) 2.5 MiB/s in 2s ETA: 0s
info: installing component 'clippy'
2.4 MiB / 2.4 MiB (100 %) 2.2 MiB/s in 1s ETA: 0s
info: installing component 'rust-docs'
19.5 MiB / 19.5 MiB (100 %) 318.4 KiB/s in 5m 37s ETA: 0s
info: installing component 'rust-std'
23.8 MiB / 23.8 MiB (100 %) 1.7 MiB/s in 44s ETA: 0s
5 IO-ops / 5 IO-ops (100 %) 0 IOPS in 12s ETA: Unknown
info: installing component 'rustc'
79.3 MiB / 79.3 MiB (100 %) 1.5 MiB/s in 1m 14s ETA: 0s
5 IO-ops / 5 IO-ops (100 %) 0 IOPS in 6s ETA: Unknown
info: installing component 'rustfmt'
3.4 MiB / 3.4 MiB (100 %) 2.3 MiB/s in 2s ETA: 0s
info: default toolchain set to 'stable-armv7-unknown-linux-gnueabihf'
stable-armv7-unknown-linux-gnueabihf installed - rustc 1.60.0 (7737e0b5c 2022-04-04)
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).
To configure your current shell, run:
source $HOME/.cargo/env
Код: Выделить всё
olej@orangepione:~$ rustc --version
rustc 1.60.0 (7737e0b5c 2022-04-04)
Код: Выделить всё
olej@orangepione:~$ du -hs .cargo
13M .cargo
Вот сколько это добро занимает на "диске" (SD-карте).
P.S. Но как показывает опыт неудачной, пока, установки на Raspberry Pi, для
установки (разархивирования и т.п.) нужно больше ... ну, порядка до 1Gb
Re: Rust
Добавлено: 13 май 2022, 18:04
Olej
Olej писал(а): ↑13 май 2022, 17:08
Вот сколько это добро занимает на "диске" (SD-карте).
Тестовый проект:
Код: Выделить всё
olej@orangepione:~/Rust$ pwd
/home/olej/Rust
olej@orangepione:~/Rust$ time cargo new fibo --bin
Created binary (application) `fibo` package
real 0m4,256s
user 0m3,126s
sys 0m0,289s
Добавляю туда файл исходного кода:
Код: Выделить всё
olej@orangepione:~/Rust$ cat /home/olej/Rust/fibo/src/main.rs
use std::env;
fn fibo(x: u64) -> u64 {
if x < 2 { 1 }
else { fibo(x - 1) + fibo(x - 2) }
}
fn main() {
let args: Vec<String> = env::args().collect();
let num: u64 = args[ 1 ].trim().parse().unwrap();
println!("{}", fibo(num));
}
Обязательно!:
Код: Выделить всё
olej@orangepione:~/Rust/fibo$ pwd
/home/olej/Rust/fibo
Код: Выделить всё
olej@orangepione:~/Rust/fibo$ cargo build --release
Compiling fibo v0.1.0 (/home/olej/Rust/fibo)
Finished release [optimized] target(s) in 16.15s
И проверю время сборки:
Код: Выделить всё
olej@orangepione:~/Rust/fibo$ cargo clean
olej@orangepione:~/Rust/fibo$ time cargo build --release
Compiling fibo v0.1.0 (/home/olej/Rust/fibo)
Finished release [optimized] target(s) in 10.15s
real 0m11,109s
user 0m13,007s
sys 0m1,095s
Для такого "малыша" - совершенно приемлемо ... небольшой тест как-то собрать.
Re: Rust
Добавлено: 13 май 2022, 18:30
Olej
Olej писал(а): ↑13 май 2022, 18:04
Для такого "малыша" - совершенно приемлемо ... небольшой тест как-то собрать.
Код: Выделить всё
olej@orangepione:~/Rust/fibo$ time target/release/fibo 40
165580141
real 0m3,164s
user 0m3,153s
sys 0m0,006s
Код: Выделить всё
olej@orangepione:~/Rust/fibo$ time target/release/fibo 45
1836311903
real 0m34,001s
user 0m33,991s
sys 0m0,006s
Тот же код на X86_64 сервере 40-процессорном (
код на Rust):
Код: Выделить всё
olej@R420:~/2022/Rust/fibo/target/release$ time ./fibo 45
1836311903
real 0m4,949s
user 0m4,941s
sys 0m0,001s
Re: Rust
Добавлено: 13 май 2022, 19:18
Olej
Olej писал(а): ↑13 май 2022, 17:06
Такая вот совсем игрушечная машина:
И ещё один экземпляр - Raspberry Pi :
Код: Выделить всё
olej@raspberrypi:~ $ inxi -MCxxxf
Machine: Type: ARM Device System: Raspberry Pi 2 Model B Rev 1.1 details: BCM2835 rev: a21041 serial: 00000000f57e2ca8
CPU: Info: Quad Core model: ARMv7 v7l variant: cortex-a7 bits: 32 type: MCP arch: v7l rev: 5 bogomips: 0
Speed: 600 MHz min/max: 600/1000 MHz Core speeds (MHz): 1: 600 2: 600 3: 600 4: 600
Features: edsp evtstrm fastmult half idiva idivt lpae neon thumb tls vfp vfpd32 vfpv3 vfpv4
Код: Выделить всё
olej@raspberrypi:/home $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
Welcome to Rust!
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
/home/olej/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory located at:
/home/olej/.cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/home/olej/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/home/olej/.profile
/home/olej/.bashrc
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: armv7-unknown-linux-gnueabihf
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1
info: profile set to 'default'
info: default host triple is armv7-unknown-linux-gnueabihf
info: syncing channel updates for 'stable-armv7-unknown-linux-gnueabihf'
info: latest update on 2022-04-07, rust version 1.60.0 (7737e0b5c 2022-04-04)
info: downloading component 'cargo'
5.7 MiB / 5.7 MiB (100 %) 5.4 MiB/s in 8s ETA: 0s
info: downloading component 'clippy'
info: downloading component 'rust-docs'
19.5 MiB / 19.5 MiB (100 %) 5.5 MiB/s in 6s ETA: 0s
info: downloading component 'rust-std'
23.8 MiB / 23.8 MiB (100 %) 5.6 MiB/s in 5s ETA: 0s
info: downloading component 'rustc'
79.3 MiB / 79.3 MiB (100 %) 5.5 MiB/s in 26s ETA: 0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
5.7 MiB / 5.7 MiB (100 %) 1.3 MiB/s in 4s ETA: 0s
info: installing component 'clippy'
2.4 MiB / 2.4 MiB (100 %) 1.2 MiB/s in 2s ETA: 0s
info: installing component 'rust-docs'
19.5 MiB / 19.5 MiB (100 %) 397.9 KiB/s in 8m 38s ETA: 0s
9 IO-ops / 9 IO-ops (100 %) 4 IOPS in 2s ETA: 0s
info: installing component 'rust-std'
23.8 MiB / 23.8 MiB (100 %) 1.3 MiB/s in 1m 26s ETA: 0s
info: installing component 'rustc'
79.3 MiB / 79.3 MiB (100 %) 1.3 MiB/s in 1m 49s ETA: 0s
9 IO-ops / 9 IO-ops (100 %) 3 IOPS in 3s ETA: 0s
info: installing component 'rustfmt'
3.4 MiB / 3.4 MiB (100 %) 1.2 MiB/s in 7s ETA: 0s
info: default toolchain set to 'stable-armv7-unknown-linux-gnueabihf'
stable-armv7-unknown-linux-gnueabihf installed - rustc 1.60.0 (7737e0b5c 2022-04-04)
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).
To configure your current shell, run:
source $HOME/.cargo/env
Код: Выделить всё
olej@raspberrypi:~ $ rustc --version
rustc 1.60.0 (7737e0b5c 2022-04-04)
Re: Rust
Добавлено: 13 май 2022, 19:27
Olej
Тест:
Код: Выделить всё
olej@raspberrypi:~/Rust $ pwd
/home/olej/Rust
olej@raspberrypi:~/Rust $ time cargo new fibo --bin
Created binary (application) `fibo` package
real 0m10,558s
user 0m5,480s
sys 0m0,720s
Код: Выделить всё
olej@raspberrypi:~/Rust $ cd fibo
olej@raspberrypi:~/Rust/fibo $ time cargo build --release
Compiling fibo v0.1.0 (/home/olej/Rust/fibo)
Finished release [optimized] target(s) in 23.42s
real 0m25,141s
user 0m21,957s
sys 0m2,401s
Выполнение:
Код: Выделить всё
olej@raspberrypi:~/Rust/fibo $ time target/release/fibo 40
165580141
real 0m5,490s
user 0m5,461s
sys 0m0,020s
Код: Выделить всё
olej@raspberrypi:~/Rust/fibo $ time target/release/fibo 45
1836311903
real 1m0,549s
user 0m59,855s
sys 0m0,570s
P.S. Удивляет, в который раз, что массово разрекламированный английский Raspberry Pi стоимостью $35 по самым разным показателям,
чуть ли не в 2 раза уступает китайцу Orange Pi One (минимальный вариант семейства), гораздо миниатюрнее и менее укомплектованному, стоимостью в $9!
Re: Rust
Добавлено: 14 май 2022, 00:13
Olej
Olej писал(а): ↑13 май 2022, 15:06
Кстати ... в отношении размеров инсталляции Rust на X86_64 :
Olej писал(а): ↑13 май 2022, 15:06
Код: Выделить всё
olej@R420:~$ du -hs ~/.cargo
15M /home/olej/.cargo
Тут я определённо ошибся - то что инсталлируется, это:
Код: Выделить всё
olej@R420:~$ rustup toolchain list
stable-x86_64-unknown-linux-gnu (default)
Код: Выделить всё
olej@R420:~$ ls -l ~/.rustup/toolchains
итого 4
drwxrwxr-x 7 olej olej 4096 мая 12 21:19 stable-x86_64-unknown-linux-gnu
olej@R420:~$ du -hs ~/.rustup/toolchains
1,1G /home/olej/.rustup/toolchains
Код: Выделить всё
olej@R420:~$ du -hs ~/.cargo
15M /home/olej/.cargo
Это X86_64.
Re: Rust
Добавлено: 14 май 2022, 00:17
Olej
Olej писал(а): ↑14 май 2022, 00:13
Это X86_64.
А это соответственно, ARM Raspberry Pi :
Код: Выделить всё
olej@raspberrypi:~ $ du -hs .rustup
1,2G .rustup
olej@raspberrypi:~ $ du -hs .cargo
13M .cargo
olej@raspberrypi:~ $ uname -a
Linux raspberrypi 5.15.32-v7+ #1538 SMP Thu Mar 31 19:38:48 BST 2022 armv7l GNU/Linux
Итого ... порядка 1.4Gb нужно иметь свободного места.
Re: Rust
Добавлено: 15 май 2022, 11:31
Olej
Olej писал(а): ↑13 май 2022, 15:02
2. как обеспечивается кросс-разработка в Rust?
В этот вопрос много ясности вносит
Rust (Русский).
Хотя это:
Состояние перевода: На этой странице представлен перевод статьи Rust. Дата последней синхронизации: 20 января 2022.
И вот в тему:
Использование
Вам может потребоваться вручную установить инструментарий, например stable, beta, nightly или 1.58.0. Это также необходимо сделать, если вы хотите использовать/тестировать другой инструментарий.
Код: Выделить всё
$ rustup toolchain install [i]toolchain[/i]
Теперь вы можете запускать команды Rust, выполняя rustup run toolchain command. Однако, чтобы использовать эти команды напрямую, необходимо активировать инструментарий:
Кросс-компиляция
С помощью rustup
Использовать кросс-компиляцию с rustup очень легко. Он поддерживает очень много целевых платформ. Полный их список можно увидеть с помощью команды rustup target list.
Например, если вы хотите использовать stable Rust для Windows с компилятором GNU, сделайте следующее:
Код: Выделить всё
$ rustup toolchain install stable-x86_64-pc-windows-gnu
Эта команда установит только rust и инструменты для вашей целевой платформы, и для кросс-компиляции нужно сделать ещё несколько вещей.
Основная логика понятна - для каждой архитектуры устанавливаем свой toolchain
Сам список всех доступных toolchain имеем на странице относительно инсталляций Rust и уже приводился на предыдущей странице темы:
Rust
Re: Rust
Добавлено: 15 май 2022, 11:37
Olej
Olej писал(а): ↑15 май 2022, 11:31
Основная логика понятна - для каждой архитектуры устанавливаем свой toolchain
Сам список всех доступных toolchain имеем на странице относительно инсталляций Rust и уже приводился на предыдущей странице темы: Rust
Вот как это выглядит на X86_64:
Код: Выделить всё
olej@R420:~/2022/Rust/f2$ rustup toolchain list
stable-x86_64-unknown-linux-gnu (default)
Код: Выделить всё
olej@R420:~/.rustup/toolchains$
olej@R420:~$ tree .rustup -L 3
.rustup
├── downloads
├── settings.toml
├── tmp
├── toolchains
│ └── stable-x86_64-unknown-linux-gnu
│ ├── bin
│ ├── etc
│ ├── lib
│ ├── libexec
│ └── share
└── update-hashes
└── stable-x86_64-unknown-linux-gnu
10 directories, 2 files
olej@R420:~$ du -hs .rustup
1,1G .rustup
А вот как то же выглядит на ARM
Код: Выделить всё
olej@raspberrypi:~ $ rustup toolchain list
stable-armv7-unknown-linux-gnueabihf (default)
Код: Выделить всё
olej@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye