文書更新:2020年11月09日(月) 午前6時43分23秒

Home > 備忘録 > 言語関連 > rust に関すること > rust のインストール( 40 )

必要なパッケージをインストールする

  1. rust をインストールする
  2. [root@server]# dnf install rust cargo

cargo について

  1. cargo コマンドの使用法
  2. [root@server]# cargo new hello --bin	// 新規プロジェクトを作成する
    
    
    [root@server]# cargo build	// コンパイルだけ行う
    
    
    [root@server]# cargo run		// コンパイルして実行する
    
    
    [root@server]# cargo build --release		// リリース用のコンパクトで高速なバイナリを作成する

Hello world

  1. ディレクトリーを移動する
  2. [root@server]# cd /xxx/yyyy
  3. 新規プロジェクトを作成する
  4. [root@/yyyy]# cargo new hello --bin
  5. source code
  6. /xxx/yyyy/src/hello.rs
    fn main() {
        println!"Hello, world!");
    }
  7. 実行する
  8. [root@/yyyy]# cargo run

cargo の help

[root@server]# cargo --help
Rust's package manager

USAGE:
    cargo [OPTIONS] [SUBCOMMAND]

OPTIONS:
    -V, --version           Print version info and exit
        --list              List installed commands
        --explain <CODE>    Run `rustc --explain CODE`
    -v, --verbose           Use verbose output (-vv very verbose/build.rs output)
    -q, --quiet             No output printed to stdout
        --color <WHEN>      Coloring: auto, always, never
        --frozen            Require Cargo.lock and cache are up to date
        --locked            Require Cargo.lock is up to date
        --offline           Run without accessing the network
    -Z <FLAG>...            Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
    -h, --help              Prints help information

Some common cargo commands are (see all commands with --list):
    build, b    Compile the current package
    check, c    Analyze the current package and report errors, but don't build object files
    clean       Remove the target directory
    doc         Build this package's and its dependencies' documentation
    new         Create a new cargo package
    init        Create a new cargo package in an existing directory
    run, r      Run a binary or example of the local package
    test, t     Run the tests
    bench       Run the benchmarks
    update      Update dependencies listed in Cargo.lock
    search      Search registry for crates
    publish     Package and upload this package to the registry
    install     Install a Rust binary. Default location is $HOME/.cargo/bin
    uninstall   Uninstall a Rust binary

See 'cargo help <command>' for more information on a specific command.