はるさめ氏の日常

主に弱電とマイコンを扱っています。たまにネットワークも

cargo-generate のインストールで躓いたのでメモ

普通であれば,コマンド一発で入るはずの cargo-generate ,なぜか素直にインストールできなかったので備忘録がてら

環境

使用 PC:Intel N100 搭載ノート PC
ホスト名:N100
ユーザ名:user
OS:Ubuntu Desktop 22.04.4 LTS Minimum Install

過去に行ったインストール手順はこちらの Issue 通りです

github.com

なにはともあれインストールしてみる

以下,実行コマンドと出力

user@N100:~$ cargo install cargo-generate
    Updating crates.io index
  Installing cargo-generate v0.19.0
    Updating crates.io index
   Compiling libc v0.2.153
   Compiling proc-macro2 v1.0.79
   Compiling unicode-ident v1.0.12
   Compiling thiserror v1.0.58
   Compiling autocfg v1.1.0
   Compiling serde v1.0.197
   Compiling memchr v2.7.1
   Compiling quote v1.0.35
   Compiling syn v2.0.53
   Compiling regex-syntax v0.8.2
   Compiling aho-corasick v1.1.2
   Compiling cfg-if v1.0.0
   Compiling jobserver v0.1.28
   Compiling cc v1.0.90
   Compiling pkg-config v0.3.30
   Compiling regex-automata v0.4.6
   Compiling bitflags v2.4.2
   Compiling once_cell v1.19.0
   Compiling vcpkg v0.2.15
   Compiling num-traits v0.2.18
   Compiling thiserror-impl v1.0.58
   Compiling serde_derive v1.0.197
   Compiling num-conv v0.1.0
   Compiling powerfmt v0.2.0
   Compiling time-core v0.1.2
   Compiling tinyvec_macros v0.1.1
   Compiling same-file v1.0.6
   Compiling bstr v1.9.1
   Compiling gix-trace v0.1.8
   Compiling walkdir v2.4.0
   Compiling tinyvec v1.6.0
   Compiling time-macros v0.2.17
   Compiling deranged v0.3.11
   Compiling num_threads v0.1.7
   Compiling itoa v1.0.10
   Compiling unicode-normalization v0.1.23
   Compiling time v0.3.34
   Compiling openssl-sys v0.9.101
   Compiling libz-sys v1.1.15
   Compiling prodash v26.2.2
   Compiling faster-hex v0.9.0
   Compiling gix-hash v0.13.3
   Compiling rustix v0.38.31
   Compiling sha1_smol v1.0.0
   Compiling smallvec v1.13.1
   Compiling gix-features v0.36.1
error: failed to run custom build command for `openssl-sys v0.9.101`

Caused by:
  process didn't exit successfully: `/tmp/cargo-installD247LF/release/build/openssl-sys-4ee3b2acf08778eb/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR
  X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR
  X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR
  X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=OPENSSL_STATIC
  cargo:rerun-if-env-changed=OPENSSL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: 
  pkg-config exited with status code 1
  > PKG_CONFIG_PATH=/usr/lib/pkgconfig PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags openssl

  The system library `openssl` required by crate `openssl-sys` was not found.
  The file `openssl.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
  PKG_CONFIG_PATH contains the following:
      - /usr/lib/pkgconfig

  HINT: you may need to install a package such as openssl, openssl-dev or openssl-devel.


  --- stderr
  thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-sys-0.9.101/build/find_normal.rs:190:5:


  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = x86_64-unknown-linux-gnu
  $TARGET = x86_64-unknown-linux-gnu
  openssl-sys = 0.9.101


  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to compile `cargo-generate v0.19.0`, intermediate artifacts can be found at `/tmp/cargo-installD247LF`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

failed to run custom build command for openssl-sys v0.9.101

HINT: you may need to install a package such as openssl, openssl-dev or openssl-devel.

とのことなので,以下のコマンドを実行

user@N100:~$ sudo apt-get install libssl-dev

そして,cargo-generate をインストール

user@N100:~$ cargo install cargo-generate
    Updating crates.io index
  Installing cargo-generate v0.19.0
    Updating crates.io index
   Compiling libc v0.2.153
   Compiling proc-macro2 v1.0.79
〜〜中略〜〜
   Compiling sanitize-filename v0.5.0
   Compiling git2 v0.18.2
   Compiling auth-git2 v0.5.4
   Compiling cargo-generate v0.19.0
    Finished release [optimized] target(s) in 4m 10s
  Installing /home/user/.cargo/bin/cargo-generate
   Installed package `cargo-generate v0.19.0` (executable `cargo-generate`)

無事通った

参考

https://github.com/sfackler/rust-openssl#manual-configuration

以上のページを参考にした