craftr.ext.compiler.msvc

craftr.ext.compiler.msvc.detect(program)[source]

Detects the version of the MSVC compiler from the specified program name and returns a dictionary with information that can be passed to the constructor of MsvcCompiler or raises ToolDetectionError.

This function also supports detecting the Clang-CL compiler.

Parameters:

program – The name of the program to execute and check.

Returns:

dict of

  • name (either 'msvc' or 'clang-cl')
  • version
  • version_str
  • target
  • thread_model
  • msvc_deps_prefix

Raises:
  • OSError – If program can not be executed (eg. if it does not exist).
  • ToolDetectionError – If program is not GCC or GCC++.
craftr.ext.compiler.msvc.get_vs_install_dir(versions=None, prefer_newest=True)[source]

Returns the path to the newest installed version of Visual Studio. This is determined by reading the environment variables VS***COMNTOOLS.

If “versions” is specified, it must be a list of three-digit version numbers like 100 for Visual Studio 2010, 110 for 2012, 120 for 2013, 140 for 2015, etc.

Parameters:
  • versions – Optionally, a list of acceptable Visual Studio version numbers that will be considered. If specified, the first detected installation will be used.
  • prefer_newest – True if the newest version should be preferred.
Returns:

str of the main installation directory.

Raises:

ToolDetectionError – If no Visual Studio insallation could be found.

Note

The option VSVERSIONS can be used to override the “versions” parameter if no explicit value is specified.

craftr.ext.compiler.msvc.get_vs_environment(install_dir, arch=None)[source]

Given an installation directory returned by get_vs_install_dir(), returns the environment that is created from running the Visual Studio vars batch file.

Parameters:
  • install_dir – The installation directory.
  • arch – The architecture name. If no value is specified, an architecture matching the current host operating system is selected.

Note

The option VSARCH can be used to specify the default value for “arch” if no explicit value is specified.

class craftr.ext.compiler.msvc.MsvcCompiler(program='cl', language='c', desc=None, **kwargs)[source]

Interface for the MSVC compiler.

Parameters:
  • program – The name of the MSVC compiler program. If not specified, cl will be tested, otherwise get_vs_install_dir() will be used.
  • language – The language name to compile for. Must be c, c++ or asm.
  • desc – The description returned by detect(). If not specified, detect() will be called by the constructor.
  • kwargs – Additional arguments that will be taken into account as a Framework to compile().
compile(sources, frameworks=(), target_name=None, meta=None, **kwargs)[source]

Supported options:

  • language
  • include (/I) [list of str]
  • defines (/D) [list of str]
  • forced_include (/FI) [list of str]
  • debug (/Od /Zi /RTC1 /FC /Fd /FS) [True, False]
  • warn (/W4, /w) ['all', 'none', None]
  • optimize (/Od, /O1, /O2, /Os) ['speed', 'size', 'debug', 'none', None]
  • exceptions (/EHsc) [True, False, None]
  • autodeps (/showIncludes)
  • description
  • msvc_runtime_library (/MT, /MTd, /MD, /MDd) ['static', 'dynamic', None]
  • msvc_disable_warnings (/wd) [list of int/str]
  • program
  • additional_flags
  • msvc_additional_flags
  • msvc_compile_additional_flags
  • msvc_remove_flags
  • msvc_compile_remove_flags
  • msvc_use_default_defines

Unsupported options supported by other compilers:

  • std
  • pedantic
  • pic
  • osx_fwpath
  • osx_frameworks

Target meta variables: none

name = 'msvc'
class craftr.ext.compiler.msvc.MsvcLinker(program='link', desc=None, **kwargs)[source]

Interface for the MSVC linker.

Supported options:

  • output_type
  • keep_suffix
  • libpath
  • libs
  • msvc_libs
  • win32_libs
  • win64_libs
  • external_libs
  • msvc_external_libs
  • debug
  • description
  • program
  • additional_flags
  • msvc_additional_flags
  • msvc_link_additional_flags
  • msvc_remove_flags
  • msvc_link_remove_flags

Target meta variables:

  • link_output – The output filename of the link operation.
  • link_target – The filename that can be specified to the linker. This is necessary because on Windows you pass in a separately created .lib file instead of the .dll output file.
name = 'msvc:link'
class craftr.ext.compiler.msvc.MsvcAr(program='lib', **kwargs)[source]

Interface for the MSVC lib tool.

name = 'msvc:lib'
staticlib(output, inputs, export=(), frameworks=(), target_name=None, meta=None, **kwargs)[source]

Supported options:

  • program
  • additional_flags
  • msvc_additional_flags
  • msvc_staticlib_additional_flags
  • description

Target meta variables:

  • staticlib_output – The output filename of the library operation.
class craftr.ext.compiler.msvc.MsvcSuite(vsversions=None, vsarch=None)[source]

Represents an MSVC installation and its meta information.