@@ -156,7 +156,36 @@ impl fmt::Display for Error {
156
156
Error :: Command {
157
157
ref command,
158
158
ref cause,
159
- } => write ! ( f, "Failed to run `{}`: {}" , command, cause) ,
159
+ } => {
160
+ match cause. kind ( ) {
161
+ io:: ErrorKind :: NotFound => {
162
+ let crate_name = std:: env:: var ( "CARGO_PKG_NAME" ) ;
163
+ let crate_name = crate_name. as_deref ( ) . unwrap_or ( "sys" ) ;
164
+ let instructions = if cfg ! ( target_os = "macos" ) || cfg ! ( target_os = "ios" ) {
165
+ "Try `brew install pkg-config` if you have Homebrew.\n "
166
+ } else if cfg ! ( unix) {
167
+ "Try `apt install pkg-config`, or `yum install pkg-config`,\n \
168
+ or `pkg install pkg-config` depending on your distribution.\n "
169
+ } else {
170
+ "" // There's no easy fix for Windows users
171
+ } ;
172
+ write ! ( f, "Could not run `{command}`\n \
173
+ The pkg-config command could not be found.\n \
174
+ \n \
175
+ Most likely, you need to install a pkg-config package for your OS.\n \
176
+ {instructions}\
177
+ \n \
178
+ If you've already installed it, ensure the pkg-config command is one of the\n \
179
+ directories in the PATH environment variable.\n \
180
+ \n \
181
+ If you did not expect this build to link to a pre-installed system library,\n \
182
+ then check documentation of the {crate_name} crate for an option to\n \
183
+ build the library from source, or disable features or dependencies\n \
184
+ that require pkg-config.", command = command, instructions = instructions, crate_name = crate_name)
185
+ }
186
+ _ => write ! ( f, "Failed to run command `{}`, because: {}" , command, cause) ,
187
+ }
188
+ }
160
189
Error :: Failure {
161
190
ref command,
162
191
ref output,
0 commit comments