aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/build_shaderc.py
blob: 93b42bd70e77d760efa9d7a935ce44e254222acf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python

# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


"""
Script to build the shaderc library.
"""

import argparse
import os
import shlex
import shutil
import subprocess
import sys

def main():
  parser = argparse.ArgumentParser(description='Builds shaderc')
  parser.add_argument('-s', '--src-dir', required=True, help=
      'path to shaderc source')
  parser.add_argument('-t', '--build-type', required=True, help=
      'Either Release or Debug')
  parser.add_argument('-a', '--arch-type', required=True, help=
      'Either x86 or x86_64')
  parser.add_argument('-o', '--output-dir', required=True, help=
      'Directory for cmake build')
  parser.add_argument('-p', '--project_type', required=True, help=
      'Project type to use. Must be "ninja", "MSVS2013", or "MSVS2015"')
  args = parser.parse_args()

  args.src_dir = os.path.abspath(args.src_dir)
  args.output_dir = os.path.abspath(args.output_dir)

  if not os.path.isdir(args.src_dir):
    sys.exit(args.src_dir + ' is not a directory.')

  if 'Release' in args.build_type:
    args.build_type = "Release"
  elif 'Debug' in args.build_type:
    args.build_type = "Debug"
  else:
    args.exit('Invalid build type: ' + args.build_type);

  if args.arch_type == 'x86':
    vs_arch = ''
  elif args.arch_type == 'x86_64':
    vs_arch = ' Win64'
  else:
    sys.exit('Invalid arch type: ' + args.arch_type);

  if args.project_type == 'ninja':
    generator = 'Ninja'
  elif args.project_type == 'MSVS2013':
    generator = 'Visual Studio 12 2013' + vs_arch
  elif args.project_type == "MSVS2015":
    generator = 'Visual Studio 14 2015' + vs_arch
  else:
    sys.exit('Invalid project type: ' + args.project_type);

  if os.path.isdir(args.output_dir):
    shutil.rmtree(args.output_dir)

  try:
    os.makedirs(args.output_dir)
  except os.error:
    sys.exit('Error creating output dir ' + args.output_dir)

  try:
    build_type_arg='-DCMAKE_BUILD_TYPE=' + args.build_type
    subprocess.check_call(['cmake', '-G', generator,
        '-DSPIRV_SKIP_EXECUTABLES=ON', '-DSHADERC_ENABLE_SHARED_CRT=ON',
        args.src_dir, build_type_arg], cwd=args.output_dir)
  except subprocess.CalledProcessError as error:
    sys.exit('Error (ret code: {code}) calling "{cmd}" in {dir}'.format(
        code = error.returncode, cmd = error.cmd, dir = args.src_dir))

  try:
    subprocess.check_call(['cmake', '--build', args.output_dir, '--config',
        args.build_type], cwd=args.output_dir)
  except subprocess.CalledProcessError as error:
    sys.exit('Error (ret code: {code}) calling "{cmd}" in {dir}'.format(
        code = error.returncode, cmd = error.cmd, dir = args.src_dir))

if __name__ == '__main__':
  main()