Open3

rustいれてみよ

Ryosuke HosoiRyosuke Hosoi
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

ふむ

ryo@rtiny:~$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
warning: it looks like you have an existing installation of Rust at:
warning: /usr/bin
warning: rustup should not be installed alongside Rust. Please uninstall your existing Rust first.
warning: Otherwise you may have confusion unless you are careful with your PATH
warning: If you are sure that you want both rustup and your already installed Rust
warning: then please reply `y' or `yes' or set RUSTUP_INIT_SKIP_PATH_CHECK to yes
warning: or pass `-y' to ignore all ignorable checks.
error: cannot install while Rust is installed

Continue? (y/N) N

error: cannot install while Rust is installed

もう入ってるんかいw

ryo@rtiny:~$ rustc
Usage: rustc [OPTIONS] INPUT

Options:
    -h, --help          Display this message
        --cfg SPEC      Configure the compilation environment
    -L [KIND=]PATH      Add a directory to the library search path. The
                        optional KIND can be one of dependency, crate, native,
                        framework, or all (the default).
    -l [KIND=]NAME      Link the generated crate(s) to the specified native
                        library NAME. The optional KIND can be one of
                        static, framework, or dylib (the default).
        --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]
                        Comma separated list of types of crates
                        for the compiler to emit
        --crate-name NAME
                        Specify the name of the crate being built
        --edition 2015|2018|2021
                        Specify which edition of the compiler to use when
                        compiling code.
        --emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
                        Comma separated list of types of output for the
                        compiler to emit
        --print [crate-name|file-names|sysroot|target-libdir|cfg|target-list|target-cpus|target-features|relocation-mode
ls|code-models|tls-models|target-spec-json|native-static-libs]
                        Compiler information to print on stdout
    -g                  Equivalent to -C debuginfo=2
    -O                  Equivalent to -C opt-level=2
    -o FILENAME         Write output to <filename>
        --out-dir DIR   Write output to compiler-chosen filename in <dir>
        --explain OPT   Provide a detailed explanation of an error message
        --test          Build a test harness
        --target TARGET Target triple for which the code is compiled
    -W, --warn OPT      Set lint warnings
    -A, --allow OPT     Set lint allowed
    -D, --deny OPT      Set lint denied
    -F, --forbid OPT    Set lint forbidden
        --cap-lints LEVEL
                        Set the most restrictive lint level. More restrictive
                        lints are capped at this level
    -C, --codegen OPT[=VALUE]
                        Set a codegen option
    -V, --version       Print version info and exit
    -v, --verbose       Use verbose output

Additional help:
    -C help             Print codegen options
    -W help             Print 'lint' options and default settings
    --help -v           Print the full set of options rustc accepts

ryo@rtiny:~$ dpkg -l | grep rust
ii  libstd-rust-1.53:amd64                     1.53.0+dfsg1+llvm-4ubuntu1~20.04.1              amd64        Rust standard libraries
ii  libstd-rust-dev:amd64                      1.53.0+dfsg1+llvm-4ubuntu1~20.04.1              amd64        Rust standard libraries - development files
ii  p11-kit-modules:amd64                      0.23.20-1ubuntu0.1                              amd64        p11-glue proxy and trust modules
ii  rustc                                      1.53.0+dfsg1+llvm-4ubuntu1~20.04.1              amd64        Rust systems programming language

rustupはないけどrustcは入ってるのか〜

違いがわからん

Ryosuke HosoiRyosuke Hosoi

ちゃんとドキュメントを読めってことで、

https://www.rust-lang.org/tools/install

を見る・・・

rustは6週間と慌ただしい目のリリースサイクルで、rustupってのはrust一式のインストールと管理をしてくれるツールなのね
で、cargoがrustのパッケージマネージャーで、rustcがrustコンパイラ、なるほど、把握

Ryosuke HosoiRyosuke Hosoi

hello worldしてみよう

ryo@rtiny:~/work/rust$ vi hello.rs
ryo@rtiny:~/work/rust$ cat hello.rs
fn main() {
    print!("Hello World!")
}

ソース書いて

ryo@rtiny:~/work/rust$ rustc hello.rs 

コンパイルする

ryo@rtiny:~/work/rust$ ls -l
合計 9788
-rwxrwxr-x 1 ryo ryo 10015552 128 19:01 hello
-rw-rw-r-- 1 ryo ryo       41 128 19:00 hello.rs
ryo@rtiny:~/work/rust$ file *
hello:    ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=79c1faa2c47860d38c312befedd373d494393b18, for GNU/Linux 3.2.0, with debug_info, not stripped
hello.rs: C source, ASCII text

実行可能ファイルが出来てる

ryo@rtiny:~/work/rust$ ./hello 
Hello World!

動くね〜
(最後Hellow World!の後ろにプロンプトがでてきてるけど省略した)