@@ -7,6 +7,7 @@ use std::{
77} ;
88
99use anyhow:: Result ;
10+ use base_db:: CrateName ;
1011use cargo_metadata:: camino:: Utf8Path ;
1112use cargo_metadata:: { BuildScript , Message } ;
1213use paths:: { AbsPath , AbsPathBuf } ;
@@ -290,7 +291,7 @@ fn inject_cargo_env(package: &cargo_metadata::Package, build_data: &mut PackageB
290291 let env = & mut build_data. envs ;
291292
292293 // FIXME: Missing variables:
293- // CARGO_PKG_HOMEPAGE, CARGO_CRATE_NAME, CARGO_BIN_NAME, CARGO_BIN_EXE_<name>
294+ // CARGO_BIN_NAME, CARGO_BIN_EXE_<name>
294295
295296 let mut manifest_dir = package. manifest_path . clone ( ) ;
296297 manifest_dir. pop ( ) ;
@@ -309,8 +310,11 @@ fn inject_cargo_env(package: &cargo_metadata::Package, build_data: &mut PackageB
309310 env. push ( ( "CARGO_PKG_AUTHORS" . into ( ) , authors) ) ;
310311
311312 env. push ( ( "CARGO_PKG_NAME" . into ( ) , package. name . clone ( ) ) ) ;
313+ // FIXME: This isn't really correct (a package can have many crates with different names), but
314+ // it's better than leaving the variable unset.
315+ env. push ( ( "CARGO_CRATE_NAME" . into ( ) , CrateName :: normalize_dashes ( & package. name ) . to_string ( ) ) ) ;
312316 env. push ( ( "CARGO_PKG_DESCRIPTION" . into ( ) , package. description . clone ( ) . unwrap_or_default ( ) ) ) ;
313- // env.push(("CARGO_PKG_HOMEPAGE".into(), package.homepage.clone().unwrap_or_default()));
317+ env. push ( ( "CARGO_PKG_HOMEPAGE" . into ( ) , package. homepage . clone ( ) . unwrap_or_default ( ) ) ) ;
314318 env. push ( ( "CARGO_PKG_REPOSITORY" . into ( ) , package. repository . clone ( ) . unwrap_or_default ( ) ) ) ;
315319 env. push ( ( "CARGO_PKG_LICENSE" . into ( ) , package. license . clone ( ) . unwrap_or_default ( ) ) ) ;
316320
0 commit comments