66import subprocess
77import sys
88
9+
10+ TARGET_OS_CANONICAL = {
11+ "linux" : "linux" ,
12+ "mac" : "macos" ,
13+ "macos" : "macos" ,
14+ "darwin" : "macos" ,
15+ "win" : "windows" ,
16+ "windows" : "windows" ,
17+ }
18+
919def has_env_flag (name ):
1020 return os .environ .get (name , "0" ) == "1"
1121
@@ -75,8 +85,19 @@ def copy_headers():
7585 artifacts_dir = os .path .join (".." , "artifacts" , "headers" )
7686 for skiaDir in ["include" , "modules" , "src" ]:
7787 copy_includes (skiaDir , os .path .join (artifacts_dir , skiaDir ))
78-
79-
88+
89+
90+ def _ensure_arch_supported (target_os , arch ):
91+ supported = {
92+ "linux" : {"x64" , "arm64" , "arm" },
93+ "macos" : {"x64" , "arm64" },
94+ "windows" : {"x64" , "arm64" },
95+ }
96+
97+ if arch not in supported .get (target_os , set ()):
98+ raise ValueError (f"Unsupported architecture { arch } for { target_os } " )
99+
100+
80101def collect_defines (path ):
81102 lines = read_all_lines (path )
82103 defines = []
@@ -123,16 +144,6 @@ def gen_linux(arch, self_contained, args):
123144 llvm_target = llvm_arch + "-linux-gnu"
124145
125146 args .update ({
126- "skia_use_harfbuzz" : False ,
127- "skia_use_icu" : False ,
128- "skia_use_piex" : True ,
129- # "skia_use_sfntly": False, Not supported anymore
130- "skia_use_system_expat" : False ,
131- "skia_use_system_freetype2" : False ,
132- "skia_use_system_libjpeg_turbo" : False ,
133- "skia_use_system_libpng" : False ,
134- "skia_use_system_libwebp" : False ,
135- "skia_use_system_zlib" : False ,
136147 "skia_use_vulkan" : True ,
137148 "skia_use_x11" : False
138149 })
@@ -162,14 +173,42 @@ def gen_linux(arch, self_contained, args):
162173 "-lc"
163174 ])
164175
165-
176+
177+ def gen_macos (arch , self_contained , args ):
178+ _ensure_arch_supported ("macos" , arch )
179+
180+ args .update ({
181+ "skia_use_vulkan" : False ,
182+ "skia_use_metal" : True ,
183+ "target_os" : "mac" ,
184+ "target_cpu" : arch ,
185+ })
186+
187+
188+ def gen_windows (arch , self_contained , args ):
189+ _ensure_arch_supported ("windows" , arch )
190+
191+ args .update ({
192+ "skia_use_vulkan" : True ,
193+ "target_os" : "win" ,
194+ "target_cpu" : arch ,
195+ "clang_win" : "C:/Program Files/LLVM"
196+ })
197+
166198def build_target (target_os , arch , self_contained , debug ):
167199 output_name = f"{ target_os } _{ arch } "
168200 if debug :
169201 output_name += "_debug"
170202 gn_dir = os .path .join ("out" , output_name )
171203 artifacts_dir = os .path .join (".." , "artifacts" , output_name )
172204
205+ canonical_os = TARGET_OS_CANONICAL .get (target_os )
206+ if canonical_os is None :
207+ print (f"Unsupported target OS: { target_os } " , file = sys .stderr )
208+ sys .exit (1 )
209+
210+ _ensure_arch_supported (canonical_os , arch )
211+
173212 args = {
174213 "is_debug" : debug ,
175214 "is_official_build" : not debug ,
@@ -180,11 +219,26 @@ def build_target(target_os, arch, self_contained, debug):
180219 "extra_cflags_cc" : [],
181220 "extra_ldflags" : [],
182221 "skia_enable_skottie" : True ,
222+ "skia_use_harfbuzz" : False ,
223+ "skia_use_icu" : False ,
224+ "skia_use_piex" : True ,
225+ "skia_use_system_expat" : False ,
226+ "skia_use_system_freetype2" : False ,
227+ "skia_use_system_libjpeg_turbo" : False ,
228+ "skia_use_system_libpng" : False ,
229+ "skia_use_system_libwebp" : False ,
230+ "skia_use_system_zlib" : False ,
231+
183232 }
184- if target_os == "linux" :
233+
234+ if canonical_os == "linux" :
185235 gen_linux (arch , self_contained , args )
236+ elif canonical_os == "macos" :
237+ gen_macos (arch , self_contained , args )
238+ elif canonical_os == "windows" :
239+ gen_windows (arch , self_contained , args )
186240 else :
187- print (f"Unsupported target OS: { target_os } " , file = sys .stderr )
241+ print (f"Unsupported target OS: { canonical_os } " , file = sys .stderr )
188242 sys .exit (1 )
189243
190244 os .makedirs (gn_dir , exist_ok = True )
@@ -246,4 +300,4 @@ def main():
246300 build_target (target_os , arch , self_contained , debug )
247301
248302if __name__ == "__main__" :
249- main ()
303+ main ()
0 commit comments