toolchain("msvc") {
  lib_switch = ""
  lib_dir_switch = "/LIBPATH:"

  tool("asm") {
    command = "ml.exe {{asmflags}} /nologo /c /Fo {{output}} {{source}}"
    outputs =
        [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj" ]
    description = "assemble {{source}}"
  }

  tool("cc") {
    pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
    command = "cl.exe /nologo /showIncludes /FC {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
    depsformat = "msvc"
    outputs =
        [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj" ]
    description = "compile {{source}}"
  }

  tool("cxx") {
    pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
    command = "cl.exe /nologo /showIncludes /FC {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
    depsformat = "msvc"
    outputs =
        [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj" ]
    description = "compile {{source}}"
  }

  tool("alink") {
    rspfile = "{{output}}.rsp"
    command = "lib.exe /nologo {{arflags}} /OUT:{{output}} @$rspfile"
    outputs = [ "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" ]
    default_output_extension = ".lib"
    default_output_dir = "{{target_out_dir}}"
    rspfile_content = "{{inputs_newline}}"
    description = "link {{output}}"
  }

  tool("solink") {
    dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
    libname = "${dllname}.lib"
    pdbname = "${dllname}.pdb"
    rspfile = "${dllname}.rsp"
    command = "link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
    outputs = [
      dllname,
      libname,
      pdbname,
    ]
    default_output_extension = ".dll"
    default_output_dir = "{{root_out_dir}}"
    link_output = libname
    depend_output = libname
    runtime_outputs = [
      dllname,
      pdbname,
    ]
    rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
    description = "link {{output}}"
  }

  tool("link") {
    exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
    pdbname = "$exename.pdb"
    rspfile = "$exename.rsp"
    command = "link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
    default_output_extension = ".exe"
    default_output_dir = "{{root_out_dir}}"
    outputs = [ exename ]
    rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
    description = "link {{output}}"
  }

  tool("stamp") {
    command = "cmd.exe /c echo > {{output}}"
    description = "stamp {{output}}"
  }

  tool("copy") {
    # Note: The build in copy command can't handle forward slashes as path separators.
    # Use a python script as a work around.
    # command = "cmd.exe /c copy /Y {{source}} {{output}}"

    copy_cmd = rebase_path("copy.py")
    command = "python \"$copy_cmd\" {{source}} {{output}}"

    description = "copy {{source}} {{output}}"
  }
}
