@@ -342,6 +342,22 @@ def merge_kw_args(self, state: ModuleState, kwargs: T.Union[RustPackageExecutabl
342342
343343 kwargs ['override_options' ].setdefault ('rust_std' , self .package .manifest .package .edition )
344344
345+ def _apply_rustc_env (self , state : ModuleState ,
346+ native : MachineChoice ,
347+ result : T .Union [BothLibraries , BuildTarget ]) -> None :
348+ env = self .package .get_rustc_env (state .environment , state .subdir , native )
349+ if not env :
350+ return
351+ # On Windows we need a tiny native wrapper to set the env before
352+ # running rustc
353+ from .. import cargo as _cargo
354+ _cargo .interpreter .ensure_meson_env_exe (state .environment )
355+ if isinstance (result , BothLibraries ):
356+ result .shared .rust_compile_env = dict (env )
357+ result .static .rust_compile_env = dict (env )
358+ else :
359+ result .rust_compile_env = dict (env )
360+
345361 def _library_method (self , state : ModuleState , args : T .Tuple [
346362 T .Optional [T .Union [str , StructuredSources ]],
347363 T .Optional [StructuredSources ]], kwargs : RustPackageLibrary ,
@@ -366,22 +382,25 @@ def _library_method(self, state: ModuleState, args: T.Tuple[
366382
367383 lib_args : T .Tuple [str , SourcesVarargsType ] = (tgt_name , [sources ])
368384 self .merge_kw_args (state , kwargs )
385+ native = kwargs ['native' ]
369386
387+ result : T .Union [BothLibraries , SharedLibrary , StaticLibrary , SharedModule ]
370388 if shared_mod :
371- return state ._interpreter .build_target (state .current_node , lib_args ,
372- T .cast ('_kwargs.SharedModule' , kwargs ),
373- SharedModule )
374-
375- if static and shared :
376- return state ._interpreter .build_both_libraries (state .current_node , lib_args , kwargs )
389+ result = state ._interpreter .build_target (state .current_node , lib_args ,
390+ T .cast ('_kwargs.SharedModule' , kwargs ),
391+ SharedModule )
392+ elif static and shared :
393+ result = state ._interpreter .build_both_libraries (state .current_node , lib_args , kwargs )
377394 elif shared :
378- return state ._interpreter .build_target (state .current_node , lib_args ,
379- T .cast ('_kwargs.SharedLibrary' , kwargs ),
380- SharedLibrary )
395+ result = state ._interpreter .build_target (state .current_node , lib_args ,
396+ T .cast ('_kwargs.SharedLibrary' , kwargs ),
397+ SharedLibrary )
381398 else :
382- return state ._interpreter .build_target (state .current_node , lib_args ,
383- T .cast ('_kwargs.StaticLibrary' , kwargs ),
384- StaticLibrary )
399+ result = state ._interpreter .build_target (state .current_node , lib_args ,
400+ T .cast ('_kwargs.StaticLibrary' , kwargs ),
401+ StaticLibrary )
402+ self ._apply_rustc_env (state , native , result )
403+ return result
385404
386405 def _proc_macro_method (self , state : 'ModuleState' , args : T .Tuple [
387406 T .Optional [T .Union [str , StructuredSources ]],
@@ -519,7 +538,10 @@ def executable_method(self, state: 'ModuleState', args: T.Tuple[
519538
520539 exe_args : T .Tuple [str , SourcesVarargsType ] = (tgt_name , [sources ])
521540 self .merge_kw_args (state , kwargs )
522- return state ._interpreter .build_target (state .current_node , exe_args , kwargs , Executable )
541+ native = kwargs ['native' ]
542+ result = state ._interpreter .build_target (state .current_node , exe_args , kwargs , Executable )
543+ self ._apply_rustc_env (state , native , result )
544+ return result
523545
524546
525547class RustSubproject (RustCrate ):
0 commit comments