24 parser = argparse.ArgumentParser()
25 parser.add_argument(
26 '--output', type=str, required=True, help='The location to generate the Metal library to.'
27 )
28 parser.add_argument('--depfile', type=str, required=True, help='The location of the depfile.')
29 parser.add_argument(
30 '--source',
31 type=str,
32 action='append',
33 required=True,
34 help='The source file to compile. Can be specified multiple times.'
35 )
36 parser.add_argument(
37 '--platform',
38 required=True,
39 choices=['mac', 'ios', 'ios-simulator'],
40 help='Select the platform.'
41 )
42 parser.add_argument(
43 '--metal-version', required=True, help='The language standard version to compile for.'
44 )
45
46 args = parser.parse_args()
47
49
50 command = [
51 'xcrun',
52 ]
53
54
55 command += ['-sdk']
56 if args.platform == 'mac':
57 command += [
58 'macosx',
59 ]
60 elif args.platform == 'ios':
61 command += [
62 'iphoneos',
63 ]
64 elif args.platform == 'ios-simulator':
65 command += [
66 'iphonesimulator',
67 ]
68 else:
69 raise 'Unknown target platform'
70
71 command += [
72 'metal',
73
74
75 '-Wno-unused-variable',
76
77 '-MMD',
78
79 '-Oz',
80
81 '-ffast-math',
82
83 '-frecord-sources=flat',
84 '-MF',
85 args.depfile,
86 '-o',
87 args.output,
88 ]
89
90
91
92 if args.platform == 'mac':
93 command += [
94 '--std=macos-metal%s' % args.metal_version,
95 '-mmacos-version-min=10.14',
96 ]
97 elif args.platform == 'ios':
98 command += [
99 '--std=ios-metal%s' % args.metal_version,
100 '-mios-version-min=11.0',
101 ]
102 elif args.platform == 'ios-simulator':
103 command += [
104 '--std=ios-metal%s' % args.metal_version,
105 '-miphonesimulator-version-min=11.0',
106 ]
107 else:
108 raise 'Unknown target platform'
109
110 command += args.source
111
112 try:
113 subprocess.check_output(command, stderr=subprocess.STDOUT, text=True)
114 except subprocess.CalledProcessError as cpe:
116 return cpe.returncode
117
118 return 0
119
120
def print(*args, **kwargs)