Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
build_metal_library.py
Go to the documentation of this file.
1# Copyright 2013 The Flutter Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import sys
6
7import argparse
8import errno
9import os
10import subprocess
11
12
14 try:
15 os.makedirs(path)
16 except OSError as exc:
17 if exc.errno == errno.EEXIST and os.path.isdir(path):
18 pass
19 else:
20 raise
21
22
23def main():
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
48 make_directories(os.path.dirname(args.depfile))
49
50 command = [
51 'xcrun',
52 ]
53
54 # Select the SDK.
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 # These warnings are from generated code and would make no sense to the
74 # GLSL author.
75 '-Wno-unused-variable',
76 # Both user and system header will be tracked.
77 '-MMD',
78 # Like -Os (and thus -O2), but reduces code size further.
79 '-Oz',
80 # Allow aggressive, lossy floating-point optimizations.
81 '-ffast-math',
82 # Record symbols in a separate *.metallibsym file.
83 '-frecord-sources=flat',
84 '-MF',
85 args.depfile,
86 '-o',
87 args.output,
88 ]
89
90 # Select the Metal standard and the minimum supported OS versions.
91 # The Metal standard must match the specification in impellerc.
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:
115 print(cpe.output)
116 return cpe.returncode
117
118 return 0
119
120
121if __name__ == '__main__':
122 if sys.platform != 'darwin':
123 raise Exception('This script only runs on Mac')
124 sys.exit(main())
void print(void *str)
Definition bridge.cpp:126
Definition main.py:1