o
    uJAfH  ã                   @  sd  U d dl mZ 	 d dlZd dlZd dlZddlmZ ddlmZ ddlm	Z	 d dl
mZ ejrBddlmZ dd	lmZ d
dlmZ neZdgdgdgdgdgdgdgdgddœ	Zded< dgdgdgdgdgdgdgdgdgddœ
Zded< g dgg dgdgddgddgdœZded< g dgdœZded< G d d!„ d!eejd"ZG d#d$„ d$eƒZG d%d&„ d&eƒZdS )'é    )ÚannotationsNé   )Úarglist)Úmesonlib)Úmlog)ÚCompileCheckMode)ÚEnvironment)Ú
Dependencyé   )ÚCLikeCompilerz	/arch:SSEz
/arch:SSE2z	/arch:AVXz
/arch:AVX2)	ÚmmxÚsseÚsse2Ússe3Ússe41Ússe42ÚavxÚavx2Úneonz$T.Dict[str, T.Optional[T.List[str]]]Úvs32_instruction_set_args)
r   r   r   r   Zssse3r   r   r   r   r   Úvs64_instruction_set_argsú/Odz/O1ú/O2ú/Gw)ÚplainÚ0ÚgÚ1Ú2Ú3ÚsúT.Dict[str, T.List[str]]Úmsvc_optimization_argsz/Zi)FTzT.Dict[bool, T.List[str]]Úmsvc_debug_argsc                   @  sþ  e Zd ZU dZdgZdgZejdg Zg Z	de
d< g dgdgd	gd
gdœZde
d< g d¢Zg dgdgdgdgdœZde
d< dZdƒdd„Zd„dd„Zd…dd„Zd†dd „Zd‡d"d#„Zdˆd%d&„Zd„d'd(„Zd„d)d*„Zd„d+d,„Zd„d-d.„Zd‰d0d1„ZdŠd3d4„Zd‹d6d7„ZdŒd:d;„Zdd=d>„ZdŽd@dA„Zd„dBdC„ZddEdF„Z ddJdK„Z!d„dLdM„Z"d„dNdO„Z#d‘dRdS„Z$e%dŽdTdU„ƒZ&e%dŽdVdW„ƒZ'd„dXdY„Z(d’d\d]„Z)d“d`da„Z*d”dfdg„Z+d•d–djdk„Z,d—dndo„Z-d˜dsdt„Z.d™dudv„Z/d„dwdx„Z0dšdzd{„Z1d›d|d}„Z2d…d~d„Z3dœd€d„Z4d‚S )ÚVisualStudioLikeCompilera&  A common interface for all compilers implementing an MSVC-style
    interface.

    A number of compilers attempt to mimic MSVC, with varying levels of
    success, such as Clang-CL and ICL (the Intel C/C++ Compiler for Windows).
    This class implements as much common logic as possible.
    z/W3r   ÚexecinfoúT.List[str]Úinternal_libsz/MDz/MDdz/MTz/MTd)ÚnoneÚmdÚmddÚmtÚmtdr!   Úcrt_args)z/nologoz/showIncludesú/utf-8z/W2z/W4z/Wall)r   r   r   r   Ú
everythingÚ	warn_argsFÚtargetÚstrc                 C  sª   dd„ dD ƒ| _ || _d|v pd|v | _d|v rd| _nd|v r$d| _nd|v r,d	| _nd
|v r4d
| _n|| _t | jd¡rG| j  t d¡¡ | j	d usNJ ‚| j| j	_d S )Nc                 S  s   h | ]}t  |¡’qS © )r   Ú	OptionKey)Ú.0Úor3   r3   úM/usr/lib/python3.10/site-packages/mesonbuild/compilers/mixins/visualstudio.pyÚ	<setcomp>{   s    z4VisualStudioLikeCompiler.__init__.<locals>.<setcomp>)Úb_pchÚb_ndebugÚb_vscrtÚx64Úx86_64Ú86Úx86Úaarch64Úarm64Úarmz>=19.28.29910Ú
b_sanitize)
Úbase_optionsr1   Úis_64Úmachiner   Úversion_compareÚversionÚaddr4   Úlinker©Úselfr1   r3   r3   r7   Ú__init__z   s    z!VisualStudioLikeCompiler.__init__Úreturnc                 C  s
   | j  ¡ S ©N)Úalways_argsÚcopy©rL   r3   r3   r7   Úget_always_args   s   
z(VisualStudioLikeCompiler.get_always_argsc                 C  ó   dS )NÚpchr3   rR   r3   r3   r7   Úget_pch_suffix“   ó   z'VisualStudioLikeCompiler.get_pch_suffixÚnamec                 C  s6   t j |¡ d¡d d… }| |  ¡ ¡ d |¡}|S )NÚ.éÿÿÿÿ)ÚosÚpathÚbasenameÚsplitÚappendrV   Újoin)rL   rX   ZchoppedÚpchnamer3   r3   r7   Úget_pch_name–   s   
z%VisualStudioLikeCompiler.get_pch_nameÚheaderc                 C  s   t ‚rO   )ÚNotImplementedError©rL   rc   r3   r3   r7   Úget_pch_base_nameœ   ó   z*VisualStudioLikeCompiler.get_pch_base_nameÚpch_dirc                 C  s4   |   |¡}|  |¡}d| d| dtj ||¡ gS )Nz/FIz/Yuú/Fp)rf   rb   r[   r\   r`   )rL   rh   rc   Úbasera   r3   r3   r7   Úget_pch_use_args    s   

 z)VisualStudioLikeCompiler.get_pch_use_argsc                 C  ó   dgS )Nú/EPr3   rR   r3   r3   r7   Úget_preprocess_only_args¥   ó   z1VisualStudioLikeCompiler.get_preprocess_only_argsc                 C  ó   ddgS )Nrm   z/Pr3   rR   r3   r3   r7   Úget_preprocess_to_file_args¨   ó   z4VisualStudioLikeCompiler.get_preprocess_to_file_argsc                 C  rl   )Nz/cr3   rR   r3   r3   r7   Úget_compile_only_args«   ro   z.VisualStudioLikeCompiler.get_compile_only_argsc                 C  rp   )Nr   z/Oi-r3   rR   r3   r3   r7   Úget_no_optimization_args®   rr   z1VisualStudioLikeCompiler.get_no_optimization_argsÚvaluec                 C  s$   |dkrg S |dkrt  d¡‚dgS )Nr(   Úaddressz1VS only supports address sanitizer at the moment.z/fsanitize=address)r   ÚMesonException)rL   ru   r3   r3   r7   Úsanitizer_compile_args±   s
   
z/VisualStudioLikeCompiler.sanitizer_compile_argsÚ
outputnamec                 C  s2   | j dkr
d| gS | d¡rd| gS d| gS )NÚPREPROCESSORz/Fiz.exez/Feú/Fo)ÚmodeÚendswith)rL   ry   r3   r3   r7   Úget_output_args¸   s
   




z(VisualStudioLikeCompiler.get_output_argsÚ	buildtypec                 C  ó   g S rO   r3   )rL   r   r3   r3   r7   Úget_buildtype_args¿   rW   z+VisualStudioLikeCompiler.get_buildtype_argsÚis_debugÚboolc                 C  s   t | S rO   )r#   )rL   r‚   r3   r3   r7   Úget_debug_argsÂ   rr   z'VisualStudioLikeCompiler.get_debug_argsÚoptimization_levelc                 C  s(   t | }t | jd¡rdd„ |D ƒ}|S )Nz<18.0c                 S  ó   g | ]}|d kr|‘qS )r   r3   )r5   Úargr3   r3   r7   Ú
<listcomp>È   ó    zBVisualStudioLikeCompiler.get_optimization_args.<locals>.<listcomp>)r"   r   rG   rH   )rL   r…   Úargsr3   r3   r7   Úget_optimization_argsÅ   s   z.VisualStudioLikeCompiler.get_optimization_argsrŠ   c                 C  s
   dg| S )Nz/linkr3   )rL   rŠ   r3   r3   r7   Úlinker_to_compiler_argsË   s   
z0VisualStudioLikeCompiler.linker_to_compiler_argsc                 C  r€   rO   r3   rR   r3   r3   r7   Úget_pic_argsÎ   rW   z%VisualStudioLikeCompiler.get_pic_argsÚdefsfilec                 C  s   t |tƒs	tdƒ‚d| gS )Nz%Module definitions file should be strz/DEF:)Ú
isinstancer2   ÚRuntimeError)rL   rŽ   r3   r3   r7   Úgen_vs_module_defs_argsÑ   s   

z0VisualStudioLikeCompiler.gen_vs_module_defs_argsÚsourcera   úT.Tuple[str, T.List[str]]c                 C  s.   t j |¡d d }|d| d| d| gfS )Nr   z.objz/Ycri   r{   )r[   r\   Úsplitext)rL   rc   r’   ra   Úobjnamer3   r3   r7   Úgen_pch_argsØ   s   z%VisualStudioLikeCompiler.gen_pch_argsc                 C  rl   )Nz/openmpr3   rR   r3   r3   r7   Úopenmp_flagsÜ   ro   z%VisualStudioLikeCompiler.openmp_flagsc                 C  r€   rO   r3   rR   r3   r3   r7   Úopenmp_link_flagsß   rW   z*VisualStudioLikeCompiler.openmp_link_flagsÚenvú'Environment'c                 C  r€   rO   r3   )rL   r™   r3   r3   r7   Úthread_flagsã   rW   z%VisualStudioLikeCompiler.thread_flagsc              	   C  sB  g }|D ]š}|dv rq|  d¡rd|dd …  }n€|  d¡r'd|dd …  }nr|  d¡r=|dd … }|| jv r8q|d }n\|  d	¡rY|  d
¡rPd|dd …  }nId|dd …  }n@|  d¡ru|  d¡rld|dd …  }n-d|dd …  }n$|dkrzq|  d¡sˆ|  d¡sˆ|dkr™z| d¡ W n	 ty˜   Y nw | |¡ q|S )N>   ú-pthreadz-mms-bitfieldsú	-LIBPATH:ú	/LIBPATH:é	   ú-Lé   ú-lú.libú-isystemz	-isystem=ú/Ié   z
-idirafterz-idirafter=é   é
   rœ   z/source-charset:z/execution-charset:z/validate-charset-r.   )Ú
startswithÚignore_libsÚremoveÚ
ValueErrorr_   )ÚclsrŠ   ÚresultÚirX   r3   r3   r7   Úunix_args_to_nativeæ   sD   









ÿÿz,VisualStudioLikeCompiler.unix_args_to_nativec                 C  sd   g }|D ]+}|  d¡r| d|dd …  ¡ q| d¡r*tj |¡s*| d| ¡ q| |¡ q|S )N)rž   r   r    rŸ   )z.ar£   r¢   )r©   r_   r}   r[   r\   Úisabs)r­   rŠ   r®   r‡   r3   r3   r7   Únative_args_to_unix  s   
z,VisualStudioLikeCompiler.native_args_to_unixc                 C  rl   )Nz/WXr3   rR   r3   r3   r7   Úget_werror_args"  ro   z(VisualStudioLikeCompiler.get_werror_argsr\   Ú	is_systemc                 C  s   |dkrd}d| gS )NÚ rY   ú-Ir3   ©rL   r\   r´   r3   r3   r7   Úget_include_args%  s   
z)VisualStudioLikeCompiler.get_include_argsÚparameter_listÚ	build_dirc              
   C  s¤   t |ƒD ]K\}}|d d… dks|d d… dkr0|d d… tj tj ||dd … ¡¡ ||< q|d d… dkrO|d d… tj tj ||dd … ¡¡ ||< q|S )Nr¡   r¶   r¥   rŸ   rž   )Ú	enumerater[   r\   Únormpathr`   )rL   r¹   rº   Úidxr¯   r3   r3   r7   Ú&compute_parameters_with_absolute_paths+  s    0.€z?VisualStudioLikeCompiler.compute_parameters_with_absolute_pathsÚcoder|   r   úT.Tuple[bool, bool]c                 C  s†   |t jkrdnd}| j||||d'}|jdkr$d|jfW  d   ƒ S ||jv p-||jv  |jfW  d   ƒ S 1 s<w   Y  d S )NZ4044Z9002)Ú
extra_argsr|   r   F)r   ÚLINKÚ_build_wrapperÚ
returncodeÚcachedÚstderrÚstdout)rL   rŠ   r™   r¿   r|   Zwarning_textÚpr3   r3   r7   Úhas_arguments7  s   
þ$ýz&VisualStudioLikeCompiler.has_argumentsÚrel_objrU   c                 C  s0   |  d¡d d… }|dg7 }dd |¡ g}|S )NrY   rZ   Zpdbz/Fd)r^   r`   )rL   rÊ   rU   ZpdbarrrŠ   r3   r3   r7   Úget_compile_debugfile_args>  s   
z3VisualStudioLikeCompiler.get_compile_debugfile_argsÚinstruction_setúT.Optional[T.List[str]]c                 C  s   | j r	t |d ¡S t |d ¡S rO   )rE   r   Úgetr   ©rL   rÌ   r3   r3   r7   Úget_instruction_set_argsD  s   z1VisualStudioLikeCompiler.get_instruction_set_argsrH   ÚintúT.Optional[str]c                 C  sš   |dk rdS |dk rdS |dk rdS |dk rdS |d	k rd
S |dk r$dS |dk r*dS |dk r0dS |dk r6dS |dk r<dS |dk rBdS t  d| j›¡ d S )Ni  z7.0ix  z7.1iÜ  z8.0i@  z9.0i¤  z10.0i  z11.0il  z12.0iv  z14.0i€  ú14.1iŠ  z14.2i”  z14.3z#Could not find toolset for version )r   ÚwarningrH   ©rL   rH   r3   r3   r7   Ú_calculate_toolset_versionI  s0   z3VisualStudioLikeCompiler._calculate_toolset_versionc                 C  sB   zt d | j d¡dd… ¡ƒ}W n
 ty   Y d S w |  |¡S )Nrµ   rY   r   r¡   )rÑ   r`   rH   r^   r¬   rÖ   rÕ   r3   r3   r7   Úget_toolset_versionc  s   "ÿ
z,VisualStudioLikeCompiler.get_toolset_versionc                 C  s    dt jvrg S t jd  t j¡S )NZINCLUDE)r[   Úenvironr^   ÚpathseprR   r3   r3   r7   Úget_default_include_dirsk  s   
z1VisualStudioLikeCompiler.get_default_include_dirsÚcrt_valc                 C  s   |   ||¡}| j| S rO   )Úget_crt_valr-   )rL   rÛ   r   r3   r3   r7   Úget_crt_compile_argsp  s   
z-VisualStudioLikeCompiler.get_crt_compile_argsc                 C  s   |dv dfS )N>   Ú	dllexportÚ	dllimportFr3   )rL   rX   r™   r3   r3   r7   Úhas_func_attributet  s   z+VisualStudioLikeCompiler.has_func_attributec                 C  rT   )NÚmsvcr3   rR   r3   r3   r7   Úget_argument_syntaxy  rW   z,VisualStudioLikeCompiler.get_argument_syntaxc                 C  s    |   |¡}|dur|S |  |¡S )zö
        Check if the compiler prefixes an underscore to global C symbols.

        This overrides the Clike method, as for MSVC checking the
        underscore prefix based on the compiler define never works,
        so do not even try.
        N)Ú$_symbols_have_underscore_prefix_listÚ)_symbols_have_underscore_prefix_searchbin)rL   r™   r®   r3   r3   r7   Úsymbols_have_underscore_prefix|  s   


z7VisualStudioLikeCompiler.symbols_have_underscore_prefixN©r1   r2   ©rN   r&   )rN   r2   )rX   r2   rN   r2   ©rc   r2   rN   r2   )rh   r2   rc   r2   rN   r&   )ru   r2   rN   r&   )ry   r2   rN   r&   )r   r2   rN   r&   )r‚   rƒ   rN   r&   )r…   r2   rN   r&   )rŠ   r&   rN   r&   )rŽ   r2   rN   r&   )rc   r2   r’   r2   ra   r2   rN   r“   )r™   rš   rN   r&   ©r\   r2   r´   rƒ   rN   r&   )r¹   r&   rº   r2   rN   r&   ©
rŠ   r&   r™   rš   r¿   r2   r|   r   rN   rÀ   ©F©rÊ   r2   rU   rƒ   rN   r&   ©rÌ   r2   rN   rÍ   )rH   rÑ   rN   rÒ   ©rN   rÒ   )rÛ   r2   r   r2   rN   r&   )rX   r2   r™   rš   rN   rÀ   )r™   rš   rN   rƒ   )5Ú__name__Ú
__module__Ú__qualname__Ú__doc__Zstd_warn_argsZstd_opt_argsr   ÚUNIXY_COMPILER_INTERNAL_LIBSrª   r'   Ú__annotations__r-   rP   r0   ÚINVOKES_LINKERrM   rS   rV   rb   rf   rk   rn   rq   rs   rt   rx   r~   r   r„   r‹   rŒ   r   r‘   r–   r—   r˜   r›   Úclassmethodr°   r²   r³   r¸   r¾   rÉ   rË   rÐ   rÖ   r×   rÚ   rÝ   rà   râ   rå   r3   r3   r3   r7   r$   R   sv   
 ûû





















/










r$   )Ú	metaclassc                      sX   e Zd ZdZdZd‡ fdd„Zdd‡ fdd„Zddd„Zd‡ fdd„Zddd„Z	‡  Z
S )ÚMSVCCompilerz$Specific to the Microsoft Compilers.rá   r1   r2   c                   sB   t ƒ  |¡ t | jd¡rd| jv rdd„ | jD ƒ| _d S d S d S )Nz<19.00r.   c                 S  r†   )r.   r3   )r5   Úrr3   r3   r7   rˆ   ›  r‰   z)MSVCCompiler.__init__.<locals>.<listcomp>)ÚsuperrM   r   rG   rH   rP   rK   ©Ú	__class__r3   r7   rM   ”  s   ÿzMSVCCompiler.__init__FrÊ   rU   rƒ   rN   r&   c                   s.   t ƒ  ||¡}|rt | jd¡rdg| }|S )Nz>=18.0z/FS)rú   rË   r   rG   rH   )rL   rÊ   rU   rŠ   rû   r3   r7   rË     s   
z'MSVCCompiler.get_compile_debugfile_argsc                 C  s   | j S rO   )rP   rR   r3   r3   r7   rS   «  ro   zMSVCCompiler.get_always_argsrÌ   rÍ   c                   s,   | j  d¡d dkr|dkrd S tƒ  |¡S )NrY   r   Ú16r   )rH   r^   rú   rÐ   rÏ   rû   r3   r7   rÐ   ®  s   z%MSVCCompiler.get_instruction_set_argsrc   c                 C  s   t j |¡S rO   )r[   r\   r]   re   r3   r3   r7   rf   ¶  s   zMSVCCompiler.get_pch_base_nameræ   rë   rì   rç   rí   rè   )rï   rð   rñ   rò   ÚidrM   rË   rS   rÐ   rf   Ú__classcell__r3   r3   rû   r7   rø   Ž  s    	
rø   c                      s\   e Zd ZdZdZd!‡ fdd„Zd"‡ fdd„Zd#dd„Zd$dd„Zd%dd„Z	d&dd „Z
‡  ZS )'ÚClangClCompilerzSpecific to Clang-CL.zclang-clr1   r2   c                   s(   t ƒ  |¡ | j d¡ | j d¡ d S )Nr    Úsx)rú   rM   Úcan_compile_suffixesrI   rK   rû   r3   r7   rM   À  s   zClangClCompiler.__init__rŠ   r&   r™   rš   r¿   r|   r   rN   rÀ   c                   s(   |t jkr|ddg }tƒ  ||||¡S )Nz-Werror=unknown-argumentz-Werror=unknown-warning-option)r   rÂ   rú   rÉ   )rL   rŠ   r™   r¿   r|   rû   r3   r7   rÉ   Ç  s   
zClangClCompiler.has_argumentsrÒ   c                 C  rT   )NrÓ   r3   rR   r3   r3   r7   r×   Ì  rg   z#ClangClCompiler.get_toolset_versionrc   c                 C  s   |S rO   r3   re   r3   r3   r7   rf   Ð  rW   z!ClangClCompiler.get_pch_base_namer\   r´   rƒ   c                 C  s$   |dkrd}|rd| gS d| gS )Nrµ   rY   z/clang:-isystemr¶   r3   r·   r3   r3   r7   r¸   Ó  s   z ClangClCompiler.get_include_argsÚdepú'Dependency'c                 C  sN   |  ¡ dkr#g }| ¡ D ]}| d¡r|d| g7 }q||g7 }q|S | ¡ S )NÚsystemr¤   z/clang:)Úget_include_typeÚget_compile_argsr©   )rL   r  Ú	convertedr¯   r3   r3   r7   Úget_dependency_compile_argsØ  s   
z+ClangClCompiler.get_dependency_compile_argsræ   rê   rî   rè   ré   )r  r  rN   r&   )rï   rð   rñ   rò   rþ   rM   rÉ   r×   rf   r¸   r	  rÿ   r3   r3   rû   r7   r   º  s    


r   )Ú
__future__r   Úabcr[   ÚtypingÚTrµ   r   r   r   Zmesonbuild.compilers.compilersr   ÚTYPE_CHECKINGÚenvironmentr   Údependenciesr	   Zcliker   ÚCompilerÚobjectr   rô   r   r"   r#   ÚABCMetar$   rø   r   r3   r3   r3   r7   Ú<module>   sf   ÷öùþ  >,