o
    Wod>!                     @  s  d dl mZ d dlZd dlZd dlZd dlZddlm	Z	m
Z
 ddlmZmZmZmZmZ ddlmZmZmZ ejreddl	mZmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" g g ddgddgddgddgddgdZ#G dd deZ$G dd de$Z%dS )    )annotationsN   )coredatamlog)EnvironmentExceptionMesonException
Popen_safe	OptionKey	join_args   )Compilerrust_buildtype_argsclike_debug_args)MutableKeyedOptionDictTypeKeyedOptionDictType)MachineInfo)Environment)DynamicLinker)MachineChoice)ExternalProgram)
Dependency-Czopt-level=0zopt-level=1zopt-level=2zopt-level=3zopt-level=s)plain0g123sc                      s(  e Zd ZU dZdZddgg g ddgdZded< 						d[d\ fddZd]ddZd^d#d$Z	d_d'd(Z
d`d*d+Zdad,d-Zdbd/d0Zdcd2d3Zddd6d7Zded9d:Zedfd;d<Zdgd>d?ZdhdBdCZdidFdGZdjdIdJZdkdLdMZdl fdNdOZdldPdQZdmdSdTZdldUdVZdldWdXZdldYdZZ  ZS )nRustCompilerZrustZrustcz-Awarningsz-W)r   r   r   r   zT.Dict[str, T.List[str]]_WARNING_LEVELSNexelistT.List[str]versionstrfor_machiner   is_crossboolinfo'MachineInfo'exe_wrapperT.Optional['ExternalProgram']full_versionT.Optional[str]linkerT.Optional['DynamicLinker']c	           	   
     sV   t  jg |||||||d || _| jtd d| jjv r)| jtd d S d S )N)r'   r-   r/   Z
b_coloroutlinkZb_vscrt)super__init__r+   Zbase_optionsaddr	   r/   id)	selfr"   r$   r&   r'   r)   r+   r-   r/   	__class__ xhome/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/compilers/rust.pyr3   9   s   zRustCompiler.__init__returnc                 C  s   dS )NFr9   r6   r9   r9   r:   needs_static_linkerF   s   z RustCompiler.needs_static_linkerwork_direnvironment'Environment'Nonec                 C  s  t j|d}t j|d}t|ddd}|td W d    n1 s(w   Y  | jd||g }tj	|tj
tj
|d}| \}}	t|tsMJ t|	tsTJ |jdd	d
}
|	jdd	d
}tdt| td t|
 td t| td |jdkrtd|   d| jr| jd u rd S | j |g }n|g}tj	|tjtjd}|  |jdkrtd|   d S )Nz	sanity.rsZrusttestwzutf-8)encodingz.fn main() {
                }
                -o)stdoutstderrcwdreplace)errorsz#Sanity check compiler command line:zSanity check compile stdout:z"-----
Sanity check compile stderr:z-----r   zRust compiler z cannot compile programs.)rE   rF   z9Executables created by Rust compiler %s are not runnable.)ospathjoinopenwritetextwrapdedentr"   
subprocessPopenPIPEcommunicate
isinstancebytesdecoder   debugr
   
returncoder   Zname_stringr'   r+   Zget_commandDEVNULLwait)r6   r>   r?   Zsource_nameZoutput_nameZofileZcmdlistZpcZ_stdoZ_stdestdostdeper9   r9   r:   sanity_checkI   sH   







zRustCompiler.sanity_check	outtargetoutfilec                 C  s   d|gS )Nz
--dep-infor9   )r6   r`   ra   r9   r9   r:   get_dependency_gen_argsq      z$RustCompiler.get_dependency_gen_args	buildtypec                 C     t | S N)r   )r6   rd   r9   r9   r:   get_buildtype_argst   rc   zRustCompiler.get_buildtype_argsc                 C  s4   | j ddddg }t|\}}}|jdddd S )	NF)Zccachez--printZsysroot
r   )maxsplitr   )Zget_exelistr   split)r6   cmdpr\   r]   r9   r9   r:   get_sysrootw   s   zRustCompiler.get_sysrootis_debugc                 C  re   rf   )r   )r6   rn   r9   r9   r:   get_debug_args|   rc   zRustCompiler.get_debug_argsoptimization_levelc                 C  re   rf   )rust_optimization_args)r6   rp   r9   r9   r:   get_optimization_args   rc   z"RustCompiler.get_optimization_argsparameter_list	build_dirc                 C  s   t |D ]<\}}|d d dkr@dD ]-}t|d }|d | d| dkr?|d | tjtj|||d   ||<  nqq|S )Nr   z-L)Z
dependencyZcrateZnativeZ	frameworkall   =)	enumeratelenrJ   rK   normpathrL   )r6   rs   rt   idxijZcombined_lenr9   r9   r:   &compute_parameters_with_absolute_paths   s   .z3RustCompiler.compute_parameters_with_absolute_paths
outputnamec                 C  s   d|gS )NrD   r9   )r6   r   r9   r9   r:   get_output_args   rc   zRustCompiler.get_output_argsc                 C  s   dd| gS )Nr   zlinker=r9   )clsr/   r$   r9   r9   r:   use_linker_args   s   zRustCompiler.use_linker_args'MutableKeyedOptionDictType'c                 C  s(   t d| j| jd}|tdg ddiS )NstdmachinelangzRust edition to use)noneZ2015Z2018Z2021r   )r	   r&   languager   ZUserComboOption)r6   keyr9   r9   r:   get_options   s   zRustCompiler.get_optionsdep'Dependency'c                 C     g S rf   r9   )r6   r   r9   r9   r:   get_dependency_compile_args   s   z(RustCompiler.get_dependency_compile_argsoptions'KeyedOptionDictType'c                 C  s<   g }t d| j| jd}|| }|jdkr|d|j  |S )Nr   r   r   z
--edition=)r	   r&   r   valueappend)r6   r   argsr   r   r9   r9   r:   get_option_compile_args   s   
z$RustCompiler.get_option_compile_argscrt_valc                 C  r   rf   r9   )r6   r   rd   r9   r9   r:   get_crt_compile_args   s   z!RustCompiler.get_crt_compile_args	colortypec                 C  s"   |dv r
d| gS t d| )N>   autoalwaysneverz--color=zInvalid color type for rust )r   )r6   r   r9   r9   r:   get_colorout_args   s   zRustCompiler.get_colorout_argsc                   s,   g }t   D ]}|dd| g q|S )Nr   z	link-arg=)r2   get_linker_always_argsextend)r6   r   ar7   r9   r:   r      s   z#RustCompiler.get_linker_always_argsc                 C     ddgS )Nz-Dr    r9   r<   r9   r9   r:   get_werror_args   s   zRustCompiler.get_werror_argslevelc                 C  s
   | j | S rf   r!   )r6   r   r9   r9   r:   get_warn_args   s   
zRustCompiler.get_warn_argsc                 C  s
   | j d S )Nr   r   r<   r9   r9   r:   get_no_warn_args   s   
zRustCompiler.get_no_warn_argsc                 C  r   )Nr   zrelocation-model=picr9   r<   r9   r9   r:   get_pic_args   s   zRustCompiler.get_pic_argsc                 C  r   rf   r9   r<   r9   r9   r:   get_pie_args   s   zRustCompiler.get_pie_args)NNN)r"   r#   r$   r%   r&   r   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   )r;   r(   )r>   r%   r?   r@   r;   rA   )r`   r%   ra   r%   r;   r#   )rd   r%   r;   r#   )r;   r%   )rn   r(   r;   r#   )rp   r%   r;   r#   )rs   r#   rt   r%   r;   r#   )r   r%   r;   r#   )r/   r%   r$   r%   r;   r#   )r;   r   )r   r   r;   r#   )r   r   r;   r#   )r   r%   rd   r%   r;   r#   )r   r%   r;   r#   )r;   r#   )r   r%   r;   r#   )__name__
__module____qualname__r   r5   r!   __annotations__r3   r=   r_   rb   rg   rm   ro   rr   r~   r   classmethodr   r   r   r   r   r   r   r   r   r   r   r   __classcell__r9   r9   r7   r:   r   ,   sD   
 	


(















r   c                   @  s   e Zd ZdZdZdS )ClippyRustCompilerzSClippy is a linter that wraps Rustc.

    This just provides us a different id
    zclippy-driver rustcN)r   r   r   __doc__r5   r9   r9   r9   r:   r      s    r   )&
__future__r   rQ   os.pathrJ   rO   typingT r   r   Zmesonlibr   r   r   r	   r
   	compilersr   r   r   TYPE_CHECKINGr   r   Z	envconfigr   r?   r   Zlinkersr   r   Zprogramsr   dependenciesr   rq   r   r   r9   r9   r9   r:   <module>   s4   
 +