2.9. プロジェクト依存関係のベンダー

プロジェクト依存関係のベンダーとは、オフライン再分配および再分散のための依存関係のローカルコピーを作成することを意味します。ベンダーの依存関係は、インターネットに接続せずに cargo ビルドツールで使用することができます。

依存関係をベンダーする cargo vendor コマンドは、cargo プラグイン cargo-vendor により提供されます。

cargo-vendor 0.1.23 をインストールするには、次のコマンドを実行します。

  • Red Hat Enterprise Linux 7 の場合:

    # yum install rust-toolset-1.35-cargo-vendor
  • Red Hat Enterprise Linux 8 の場合:

    # dnf install cargo-vendor

cargo プロジェクトのベンダーの依存関係には、プロジェクトディレクトリーに移動し、以下のように cargo ツールを実行します。

  • Red Hat Enterprise Linux 7 の場合:

    $ scl enable rust-toolset-1.35 'cargo vendor'
  • Red Hat Enterprise Linux 8 の場合:

    $ cargo vendor

これによりディレクトリー vendor が作成され、このディレクトリーへのすべての依存関係のソースがダウンロードされます。追加の設定手順はコマンドラインに表示されます。

cargo vendor コマンドは、プラットフォームに依存しない結果の依存関係を収集します。潜在的なすべてのターゲットプラットフォームの依存関係クレートがダウンロードされます。

重要

この cargo vendor コマンドは、cargo ツールの実験的かつ非実験的なプラグインです。

例2.8 プロジェクト依存関係のベンダー

この例では、例2.6「プロジェクトへの依存関係の追加および cargo で構築」 に従って依存関係で Rust プロジェクト helloworld を正常にビルドしていることを前提としています。

ディレクトリー helloworld に移動し、cargo vendor コマンドを実行して依存関係のあるプロジェクトをベンダーします。

  • Red Hat Enterprise Linux 7 の場合:

    $ scl enable rust-toolset-1.35 'cargo vendor'
     Downloading kernel32-sys v0.2.2
     Downloading redox_syscall v0.1.31
     Downloading winapi-build v0.1.1
     Downloading winapi v0.2.8
       Vendoring kernel32-sys v0.2.2 (/home/vslavik/.cargo/registry/src/github.com-1ecc6299db9ec823/kernel32-sys-0.2.2) to vendor/kernel32-sys
       Vendoring libc v0.2.32 (/home/vslavik/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.32) to vendor/libc
       Vendoring redox_syscall v0.1.31 (/home/vslavik/.cargo/registry/src/github.com-1ecc6299db9ec823/redox_syscall-0.1.31) to vendor/redox_syscall
       Vendoring time v0.1.38 (/home/vslavik/.cargo/registry/src/github.com-1ecc6299db9ec823/time-0.1.38) to vendor/time
       Vendoring winapi v0.2.8 (/home/vslavik/.cargo/registry/src/github.com-1ecc6299db9ec823/winapi-0.2.8) to vendor/winapi
       Vendoring winapi-build v0.1.1 (/home/vslavik/.cargo/registry/src/github.com-1ecc6299db9ec823/winapi-build-0.1.1) to vendor/winapi-build
    To use vendored sources, add this to your .cargo/config for this project:
    
        [source.crates-io]
        replace-with = "vendored-sources"
    
        [source.vendored-sources]
        directory = "/home/vslavik/helloworld/vendor"
  • Red Hat Enterprise Linux 8 の場合:

    $ cargo vendor

結果を確認します。

$ ls
Cargo.lock  Cargo.toml  src  target  vendor
$ tree vendor
vendor
├── kernel32-sys
│   ├── build.rs
│   ├── Cargo.toml
│   ├── README.md
│   └── src
│       └── lib.rs
├── libc
│   ├── appveyor.yml
│   ├── Cargo.toml
...
75 directories, 319 files

vendor ディレクトリーには、helloworld プログラムを構築するために必要なすべての依存関係 crates のコピーが含まれます。Windows オペレーティングシステムでプロジェクトをビルドするための Crates は、Red Hat Enterprise Linux でこのコマンドを実行してもベンダーが提供されています。

注記

tree ツールは、デフォルトの Red Hat Enterprise Linux リポジトリーから利用できます。インストールするには、以下を行います。

# yum install tree