@@ -129,24 +129,40 @@ is_proc_macro_dep_enabled = rule(
129129    build_setting  =  config .bool (flag  =  True ),
130130)
131131
132- def  _get_rustc_env ( attr ,  toolchain ,  crate_name ):
133-     """Gathers rustc environment variables 
132+ def  env_vars_from_version ( version ):
133+     """Gathers rustc environment variables corresponding to the version  
134134
135135    Args: 
136-         attr (struct): The current target's attributes 
137-         toolchain (rust_toolchain): The current target's rust toolchain context 
138-         crate_name (str): The name of the crate to be compiled 
136+         version (str): The version of the crate to be compiled 
139137
140138    Returns: 
141139        dict: Rustc environment variables 
142140    """ 
143-     version  =  attr .version  if  hasattr (attr , "version" ) else  "0.0.0" 
144141    major , minor , patch  =  version .split ("." , 2 )
145142    if  "-"  in  patch :
146143        patch , pre  =  patch .split ("-" , 1 )
147144    else :
148145        pre  =  "" 
149146
147+     return  {
148+         "CARGO_PKG_VERSION" : version ,
149+         "CARGO_PKG_VERSION_MAJOR" : major ,
150+         "CARGO_PKG_VERSION_MINOR" : minor ,
151+         "CARGO_PKG_VERSION_PATCH" : patch ,
152+         "CARGO_PKG_VERSION_PRE" : pre ,
153+     }
154+ 
155+ def  _get_rustc_env (attr , toolchain , crate_name ):
156+     """Gathers rustc environment variables 
157+ 
158+     Args: 
159+         attr (struct): The current target's attributes 
160+         toolchain (rust_toolchain): The current target's rust toolchain context 
161+         crate_name (str): The name of the crate to be compiled 
162+ 
163+     Returns: 
164+         dict: Rustc environment variables 
165+     """ 
150166    result  =  {
151167        "CARGO_CFG_TARGET_ARCH" : ""  if  toolchain .target_arch  ==  None  else  toolchain .target_arch ,
152168        "CARGO_CFG_TARGET_OS" : ""  if  toolchain .target_os  ==  None  else  toolchain .target_os ,
@@ -155,12 +171,13 @@ def _get_rustc_env(attr, toolchain, crate_name):
155171        "CARGO_PKG_DESCRIPTION" : "" ,
156172        "CARGO_PKG_HOMEPAGE" : "" ,
157173        "CARGO_PKG_NAME" : attr .name ,
158-         "CARGO_PKG_VERSION" : version ,
159-         "CARGO_PKG_VERSION_MAJOR" : major ,
160-         "CARGO_PKG_VERSION_MINOR" : minor ,
161-         "CARGO_PKG_VERSION_PATCH" : patch ,
162-         "CARGO_PKG_VERSION_PRE" : pre ,
163174    }
175+ 
176+     version_default  =  None  if  toolchain ._incompatible_do_not_inject_degenerate_version_to_rustc_env  else  "0.0.0" 
177+     version  =  getattr (attr , "version" , version_default )
178+     if  version :
179+         result .update (env_vars_from_version (version ))
180+ 
164181    if  hasattr (attr , "_is_proc_macro_dep_enabled" ) and  attr ._is_proc_macro_dep_enabled [IsProcMacroDepEnabledInfo ].enabled :
165182        is_proc_macro_dep  =  "0" 
166183        if  hasattr (attr , "_is_proc_macro_dep" ) and  attr ._is_proc_macro_dep [IsProcMacroDepInfo ].is_proc_macro_dep :
0 commit comments