-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconfigure.py
executable file
·1513 lines (1278 loc) · 47.3 KB
/
configure.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
#
# Copyright 2023 Nope Forge
# Copyright 2021-2022 GoPro Inc.
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import argparse
import functools
import hashlib
import logging
import os
import os.path as op
import pathlib
import platform
import shlex
import shutil
import stat
import subprocess
import sysconfig
import tarfile
import textwrap
import urllib.request
import venv
import zipfile
from multiprocessing import Pool
from subprocess import run
_CPU_FAMILIES = [
"arm",
"aarch64",
"x86_64",
]
_ANDROID_VERSION = 28
_ANDROID_COMPILER_MAP = dict(
arm=f"armv7a-linux-androideabi{_ANDROID_VERSION}",
aarch64=f"aarch64-linux-android{_ANDROID_VERSION}",
x86_64=f"x86_64-linux-android{_ANDROID_VERSION}",
)
_ANDROID_ABI_MAP = dict(
arm="armeabi-v7a",
aarch64="arm64-v8a",
x86_64="x86_64",
)
_ANDROID_BUILD_MAP = dict(
Linux="linux-x86_64",
Darwin="darwin-x86_64",
Windows="windows-x86_64",
)
_ANDROID_CROSS_FILE_TPL = textwrap.dedent(
"""\
[constants]
ndk_home = '{ndk_home}'
toolchain = ndk_home / 'toolchains/llvm/prebuilt/{ndk_build}/bin'
[binaries]
c = toolchain / '{compiler}-clang'
cpp = toolchain / '{compiler}-clang++'
strip = toolchain / 'llvm-strip'
ar = toolchain / 'llvm-ar'
pkg-config = 'pkg-config'
[host_machine]
system = 'android'
cpu_family = '{cpu_family}'
cpu = '{cpu}'
endian = 'little'
"""
)
def _get_android_cross_file_path(cfg):
return op.join(cfg.prefix, f"meson-android-{cfg.args.host_arch}.ini")
def _gen_android_cross_file(cfg):
cross_file = _ANDROID_CROSS_FILE_TPL.format(
ndk_home=cfg.android_ndk_home,
ndk_build=cfg.android_ndk_build,
compiler=cfg.android_compiler,
cpu_family=cfg.cpu_family,
cpu=cfg.cpu,
)
cross_file_path = _get_android_cross_file_path(cfg)
os.makedirs(op.dirname(cross_file_path), exist_ok=True)
with open(cross_file_path, "w") as fp:
fp.write(cross_file)
_IOS_ABI_MAP = dict(
aarch64="arm64",
x86_64="x86_64",
)
_IOS_CROSS_FILE_TPL = textwrap.dedent(
"""\
[constants]
root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer'
sysroot = root / 'SDKs/iPhoneOS.sdk'
[built-in options]
c_args = ['-arch', '{abi}', '-isysroot', sysroot]
c_link_args = ['-arch', '{abi}', '-isysroot', sysroot]
objc_args = ['-arch', '{abi}', '-isysroot', sysroot]
objc_link_args = ['-arch', '{abi}', '-isysroot', sysroot]
cpp_args = ['-arch', '{abi}', '-isysroot', sysroot]
cpp_link_args = ['-arch', '{abi}', '-isysroot', sysroot]
objcpp_args = ['-arch', '{abi}', '-isysroot', sysroot]
objcpp_link_args = ['-arch', '{abi}', '-isysroot', sysroot]
[properties]
root = root
[binaries]
c = 'clang'
cpp = 'clang++'
objc = 'clang'
strip = 'strip'
pkg-config = 'pkg-config'
[host_machine]
system = 'darwin'
subsystem = 'ios'
cpu_family = '{cpu_family}'
cpu = '{cpu}'
endian = 'little'
"""
)
def _get_ios_cross_file_path(cfg):
return op.join(cfg.prefix, f"meson-ios-{cfg.args.host_arch}.ini")
def _gen_ios_cross_file(cfg):
cross_file = _IOS_CROSS_FILE_TPL.format(
abi=cfg.ios_abi,
cpu_family=cfg.cpu_family,
cpu=cfg.cpu,
)
cross_file_path = _get_ios_cross_file_path(cfg)
os.makedirs(op.dirname(cross_file_path), exist_ok=True)
with open(cross_file_path, "w") as fp:
fp.write(cross_file)
_ROOTDIR = op.abspath(op.dirname(__file__))
_SYSTEM = "MinGW" if sysconfig.get_platform().startswith("mingw") else platform.system()
_RENDERDOC_ID = f"renderdoc_{_SYSTEM}"
_EXTERNAL_DEPS = dict(
boringssl=dict(
version="ec6cb3e",
url="https://codeload.github.com/google/boringssl/zip/@VERSION@",
dst_file="boringssl-@[email protected]",
sha256="02ccd210fb184a312ce1d86c946aecc570640968f8745d1ee0805d8b48c10b06",
),
ffmpeg=dict(
version="7.0",
url="https://ffmpeg.org/releases/ffmpeg-@[email protected]",
dst_file="ffmpeg-@[email protected]",
sha256="4426a94dd2c814945456600c8adfc402bee65ec14a70e8c531ec9a2cd651da7b",
),
ffmpeg_Windows=dict(
version="7.0",
url="https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2024-04-30-12-51/ffmpeg-n@[email protected]",
dst_file="ffmpeg-@[email protected]",
sha256="16a6b831ac85225e8fe43e6114489514f94cefb95bbb896586e19aec183c6f85",
),
nopemd=dict(
version="12.0.1",
url="https://github.com/NopeForge/nope.media/archive/v@[email protected]",
dst_file="nope.media-@[email protected]",
sha256="e83d5b144c00820482c262cf134fff73b53112135faff119b25cc7e64978aa8a",
),
egl_registry=dict(
version="9ab6036",
url="https://github.com/KhronosGroup/EGL-Registry/archive/@[email protected]",
dst_file="egl-registry-@[email protected]",
sha256="b981b5a250d4f10284c670ae89f4a43c9eac42adca65306e5d56b921f609c46b",
),
opengl_registry=dict(
version="d0342a4",
url="https://github.com/KhronosGroup/OpenGL-Registry/archive/@[email protected]",
dst_file="opengl-registry-@[email protected]",
sha256="8e6efa8d9ec5ef1b2c735b2fc2afdfed210a3a5aa01c48e572326914e27bb221",
),
sdl2_Windows=dict(
version="2.30.2",
url="https://github.com/libsdl-org/SDL/releases/download/release-@VERSION@/SDL2-devel-@[email protected]",
dst_file="SDL2-@[email protected]",
sha256="fc5d6c096a6b82f86613060dfef553a09b9e08afcb401fefac4b9ca221265cda",
),
glslang=dict(
version="14.2.0",
dst_file="glslang-@[email protected]",
url="https://github.com/KhronosGroup/glslang/archive/refs/tags/@[email protected]",
sha256="14a2edbb509cb3e51a9a53e3f5e435dbf5971604b4b833e63e6076e8c0a997b5",
),
glslang_Windows=dict(
# Use the legacy master-tot Windows build until the main-tot one is
# fixed, or until the glslang project provides Windows builds for their
# stable releases
# See: https://github.com/KhronosGroup/glslang/issues/3186
version="master",
dst_file="glslang-@[email protected]",
dst_dir="glslang-@VERSION@",
url="https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip",
sha256="skip",
),
pkgconf=dict(
version="1.9.5",
url="https://github.com/pkgconf/pkgconf/archive/refs/tags/pkgconf-@[email protected]",
sha256="3fd0ace7d4398d75f0c566759f9beb4f8b3984fee7ed9804d41c52b193d9745a",
),
renderdoc_Windows=dict(
version="1.29",
url="https://renderdoc.org/stable/@VERSION@/RenderDoc_@VERSION@_64.zip",
sha256="6307cb8e342237f4c1814a9203428606db5b33722cb7ec0d17c3b930c2ee4584",
),
renderdoc_Linux=dict(
version="1.29",
url="https://renderdoc.org/stable/@VERSION@/renderdoc_@[email protected]",
sha256="ae61cd6cfd82930c5928aed8a6d2c7f4a6b13df54033975425386a19efdbf0e7",
),
freetype=dict(
version="2-13-2",
url="https://github.com/freetype/freetype/archive/refs/tags/VER-@[email protected]",
sha256="427201f5d5151670d05c1f5b45bef5dda1f2e7dd971ef54f0feaaa7ffd2ab90c",
),
harfbuzz=dict(
version="8.4.0",
url="https://github.com/harfbuzz/harfbuzz/archive/refs/tags/@[email protected]",
sha256="9f1ca089813b05944ad1ce8c7e018213026d35dc9bab480a21eb876838396556",
),
fribidi=dict(
version="1.0.13",
url="https://github.com/fribidi/fribidi/archive/refs/tags/v@[email protected]",
sha256="f24e8e381bcf76533ae56bd776196f3a0369ec28e9c0fdb6edd163277e008314",
),
moltenvk_iOS=dict(
version="1.2.8",
url="https://github.com/KhronosGroup/MoltenVK/releases/download/v1.2.8/MoltenVK-ios.tar",
sha256="778980f84f1afe7f5058df469fe9715d767a9891afb5497dd90ff29a7fa384a1",
),
)
def _is_local(system):
return system in {"Linux", "MinGW", "Darwin", "Windows"}
def _get_external_deps(args):
deps = ["nopemd"]
host, _ = _get_host(args)
if host == "Android":
deps.append("boringssl")
deps.append("ffmpeg")
deps.append("glslang")
deps.append("freetype")
deps.append("harfbuzz")
deps.append("fribidi")
elif host == "iOS":
deps.append("boringssl")
deps.append("ffmpeg")
deps.append("moltenvk_iOS")
deps.append("glslang")
deps.append("freetype")
deps.append("harfbuzz")
deps.append("fribidi")
elif host == "Windows":
deps.append("pkgconf")
deps.append("egl_registry")
deps.append("opengl_registry")
deps.append("ffmpeg_Windows")
deps.append("sdl2_Windows")
deps.append("glslang_Windows")
deps.append("freetype")
deps.append("harfbuzz")
deps.append("fribidi")
if "gpu_capture" in args.debug_opts:
if host not in {"Windows", "Linux"}:
raise Exception(f"Renderdoc is not supported on {host}")
deps.append(_RENDERDOC_ID)
return {dep: _EXTERNAL_DEPS[dep] for dep in deps}
def _guess_base_dir(dirs):
smallest_dir = sorted(dirs, key=lambda x: len(x))[0]
return pathlib.Path(smallest_dir).parts[0]
def _get_brew_prefix():
prefix = None
try:
proc = run(["brew", "--prefix"], capture_output=True, text=True, check=True)
prefix = proc.stdout.strip()
except FileNotFoundError:
# Silently pass if brew is not installed
pass
return prefix
def _file_chk(path, chksum_hexdigest):
if chksum_hexdigest == "skip":
return True
chksum = hashlib.sha256()
with open(path, "rb") as f:
while True:
buf = f.read(8196)
if not buf:
break
chksum.update(buf)
match_ = chksum.hexdigest() == chksum_hexdigest
if not match_:
logging.warning("%s: mismatching check sum", path)
return match_
def _fix_permissions(path):
for root, dirs, files in os.walk(path, topdown=True):
for file in files:
os.chmod(op.join(root, file), stat.S_IRUSR | stat.S_IWUSR)
for directory in dirs:
os.chmod(op.join(root, directory), stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
def _rmtree(path, ignore_errors=False, onerror=None):
"""
shutil.rmtree wrapper that is resilient to permission issues when
encountering read-only files or directories lacking the executable
permission.
"""
try:
shutil.rmtree(path, ignore_errors, onerror=onerror)
except Exception:
_fix_permissions(path)
shutil.rmtree(path, ignore_errors, onerror=onerror)
def _get_external_dir(args):
host, host_arch = _get_host(args)
if _is_local(host):
return op.join(_ROOTDIR, "external")
else:
return op.join(_ROOTDIR, "external", host, host_arch)
def _download_extract(args, dep_item):
logging.basicConfig(level="INFO") # Needed for every process on Windows
name, dep = dep_item
version = dep["version"]
url = dep["url"].replace("@VERSION@", version)
chksum = dep["sha256"]
dst_file = dep.get("dst_file", op.basename(url)).replace("@VERSION@", version)
dst_dir = dep.get("dst_dir", "").replace("@VERSION@", version)
dst_base = _get_external_dir(args)
dst_path = op.join(dst_base, dst_file)
os.makedirs(dst_base, exist_ok=True)
# Download
if not op.exists(dst_path) or not _file_chk(dst_path, chksum):
logging.info("downloading %s to %s", url, dst_file)
urllib.request.urlretrieve(url, dst_path)
assert _file_chk(dst_path, chksum)
# Extract
extracted = False
if tarfile.is_tarfile(dst_path):
with tarfile.open(dst_path) as tar:
dirs = {f.name for f in tar.getmembers() if f.isdir()}
extract_dir = op.join(dst_base, dst_dir or _guess_base_dir(dirs))
if not op.exists(extract_dir):
logging.info("extracting %s", dst_file)
tar.extractall(op.join(dst_base, dst_dir))
extracted = True
elif zipfile.is_zipfile(dst_path):
with zipfile.ZipFile(dst_path) as zip_:
dirs = {op.dirname(f) for f in zip_.namelist()}
extract_dir = op.join(dst_base, dst_dir or _guess_base_dir(dirs))
if not op.exists(extract_dir):
logging.info("extracting %s", dst_file)
zip_.extractall(op.join(dst_base, dst_dir))
extracted = True
else:
assert False
# Patch
if extracted:
patch_basedir = op.join(_ROOTDIR, "patches", name)
for patch in dep.get("patches", []):
patch_path = op.join(patch_basedir, patch)
run(["patch", "-p1", "-i", patch_path], cwd=extract_dir)
# Remove previous link if needed
target = op.join(dst_base, name)
rel_extract_dir = op.basename(extract_dir)
if op.islink(target) and os.readlink(target) != rel_extract_dir:
logging.info("unlink %s target", target)
os.unlink(target)
elif op.exists(target) and not op.islink(target):
logging.info("remove previous %s copy", target)
_rmtree(target)
# Link (or copy)
if not op.exists(target):
logging.info("symlink %s -> %s", target, rel_extract_dir)
try:
os.symlink(rel_extract_dir, target)
except OSError:
# This typically happens on Windows when Developer Mode is not
# available/enabled
logging.info("unable to symlink, fallback on copy (%s -> %s)", extract_dir, target)
shutil.copytree(extract_dir, target)
return name, target
def _get_host(args):
if args.host:
return (args.host, args.host_arch)
else:
return (_SYSTEM, platform.machine())
def _fetch_externals(args):
dependencies = _get_external_deps(args)
with Pool() as p:
return dict(p.map(functools.partial(_download_extract, args), dependencies.items()))
def _block(name, prerequisites=None):
def real_decorator(block_func):
block_func.name = name
block_func.prerequisites = prerequisites if prerequisites else []
return block_func
return real_decorator
def _get_builddir(cfg, component):
if component in cfg.externals:
return op.join(cfg.externals[component], "builddir")
if _is_local(cfg.host):
return op.join("builddir", component)
else:
return op.join("builddir", cfg.host, cfg.host_arch, component)
def _meson_compile_install_cmd(cfg, component):
builddir = _get_builddir(cfg, component)
return ["$(MESON) " + _cmd_join(action, "-C", builddir) for action in ("compile", "install")]
@_block("pkgconf-setup")
def _pkgconf_setup(cfg):
builddir = _get_builddir(cfg, "pkgconf")
return ["$(MESON_SETUP) " + _cmd_join("-Dtests=disabled", cfg.externals["pkgconf"], builddir)]
@_block("pkgconf-install", [_pkgconf_setup])
def _pkgconf_install(cfg):
ret = _meson_compile_install_cmd(cfg, "pkgconf")
pkgconf_exe = op.join(cfg.bin_path, "pkgconf.exe")
pkgconfig_exe = op.join(cfg.bin_path, "pkg-config.exe")
return ret + [f"copy {pkgconf_exe} {pkgconfig_exe}"]
@_block("egl-registry-install", [])
def _egl_registry_install(cfg):
dirs = (
"EGL",
"KHR",
)
cmds = []
for d in dirs:
src = op.join(cfg.externals["egl_registry"], "api", d)
dst = op.join(cfg.prefix, "Include", d)
cmds.append(_cmd_join("xcopy", src, dst, "/s", "/y", "/i"))
return cmds
@_block("opengl-registry-install", [])
def _opengl_registry_install(cfg):
dirs = (
"GL",
"GLES",
"GLES2",
"GLES3",
"GLSC",
"GLSC2",
)
cmds = []
for d in dirs:
src = op.join(cfg.externals["opengl_registry"], "api", d)
dst = op.join(cfg.prefix, "Include", d)
cmds.append(_cmd_join("xcopy", src, dst, "/s", "/y", "/i"))
return cmds
@_block("boringssl-setup", [])
def _boringssl_setup(cfg):
build_type = "Debug" if cfg.args.buildtype == "debug" else "Release"
cmake_args = [
"cmake",
"-GNinja",
f"-DCMAKE_BUILD_TYPE={build_type}",
f"-DCMAKE_INSTALL_PREFIX={cfg.prefix}",
"-DBUILD_SHARED_LIBS=OFF",
"-S",
cfg.externals["boringssl"],
"-B",
_get_builddir(cfg, "boringssl"),
]
if cfg.host == "Android":
cmake_args += [
f"-DCMAKE_TOOLCHAIN_FILE={cfg.android_cmake_toolchain}",
"-DANDROID_STL=c++_shared",
"-DANDROID_TOOLCHAIN=clang",
f"-DANDROID_PLATFORM=android-{_ANDROID_VERSION}",
f"-DANDROID_ABI={cfg.android_abi}",
]
elif cfg.host == "iOS":
cmake_args += [
f"-DCMAKE_OSX_SYSROOT=iphoneos",
f"-DCMAKE_OSX_ARCHITECTURES={cfg.ios_abi}",
]
return [
_cmd_join(*cmake_args),
]
@_block("boringssl-install", [_boringssl_setup])
def _boringssl_install(cfg):
builddir = _get_builddir(cfg, "boringssl")
cmds = [
_cmd_join("cmake", "--build", builddir, "--target", "crypto", "--target", "ssl", "--target", "bssl"),
_cmd_join("cmake", "--install", builddir),
]
return cmds
@_block("ffmpeg-setup", {"Android": [_boringssl_install], "iOS": [_boringssl_install]})
def _ffmpeg_setup(cfg):
muxers = [
"gif",
"image2",
"ipod",
"mov",
"mp4",
]
parsers = [
"aac",
"av1",
"flac",
"h264",
"hevc",
"mjpeg",
"png",
"vp8",
"vp9",
]
bsfs = [
"aac_adtstoasc",
"extract_extradata",
"h264_mp4toannexb",
"hevc_mp4toannexb",
"vp9_superframe",
]
protocols = [
"fd",
"file",
"http",
"https",
"pipe",
]
filters = [
"aformat",
"aresample",
"asetnsamples",
"asettb",
"copy",
"format",
"fps",
"hflip",
"palettegen",
"paletteuse",
"scale",
"settb",
"transpose",
"vflip",
]
demuxers = [
"aac",
"aiff",
"avi",
"flac",
"gif",
"image2",
"image_jpeg_pipe",
"image_pgm_pipe",
"image_png_pipe",
"image_webp_pipe",
"matroska",
"mov",
"mp3",
"mp4",
"mpegts",
"ogg",
"rawvideo",
"wav",
]
decoders = [
"aac",
"alac",
"amrnb",
"flac",
"gif",
"mjpeg",
"mp3",
"opus",
"pcm_s16be",
"pcm_s16le",
"pcm_s24be",
"pcm_s24le",
"png",
"rawvideo",
"vorbis",
"vp8",
"webp",
]
encoders = ["mjpeg", "png", "aac"]
builddir = _get_builddir(cfg, "ffmpeg")
os.makedirs(builddir, exist_ok=True)
extra_include_dir = op.join(cfg.prefix, "include")
extra_library_dir = op.join(cfg.prefix, "lib")
extra_cflags = ""
extra_ldflags = ""
extra_libs = "-lstdc++" # Required by BoringSSL
extra_args = []
if cfg.host == "Android":
decoders += [
"av1_mediacodec",
"h264_mediacodec",
"hevc_mediacodec",
"vp8_mediacodec",
"vp9_mediacodec",
]
protocols += ["android_content"]
extra_args += [
"--enable-jni",
"--enable-mediacodec",
"--target-os=android",
f"--cross-prefix={cfg.android_ndk_bin}{op.sep}llvm-",
f"--cc={cfg.android_ndk_bin}{os.sep}{cfg.android_compiler}-clang",
]
elif cfg.host == "iOS":
extra_cflags += f"-arch {cfg.ios_abi} -mios-version-min={cfg.ios_version}"
extra_ldflags += f"-arch {cfg.ios_abi} -mios-version-min={cfg.ios_version}"
extra_args += [
"--enable-videotoolbox",
"--target-os=darwin",
f"--sysroot={cfg.ios_sdk}",
]
return [
f"cd {builddir} && "
+ _cmd_join(
op.join(cfg.externals["ffmpeg"], "configure"),
"--disable-everything",
"--disable-doc",
"--disable-static",
"--disable-autodetect",
"--disable-programs",
"--enable-shared",
"--enable-cross-compile",
"--enable-hwaccels",
"--enable-avdevice",
"--enable-swresample",
"--enable-zlib",
"--enable-openssl",
"--enable-filter=%s" % ",".join(filters),
"--enable-bsf=%s" % ",".join(bsfs),
"--enable-encoder=%s" % ",".join(encoders),
"--enable-demuxer=%s" % ",".join(demuxers),
"--enable-decoder=%s" % ",".join(decoders),
"--enable-parser=%s" % ",".join(parsers),
"--enable-muxer=%s" % ",".join(muxers),
"--enable-protocol=%s" % ",".join(protocols),
f"--arch={cfg.host_arch}",
f"--extra-cflags=-I{extra_include_dir} {extra_cflags}",
f"--extra-ldflags=-L{extra_library_dir} {extra_ldflags}",
f"--extra-libs={extra_libs}",
f"--prefix={cfg.prefix}",
*extra_args,
),
]
@_block("ffmpeg-install", {"Android": [_ffmpeg_setup], "iOS": [_ffmpeg_setup]})
def _ffmpeg_install(cfg):
if cfg.host == "Windows":
dirs = (
("bin", "Scripts"),
("lib", "Lib"),
("include", "Include"),
)
cmds = []
for src, dst in dirs:
src = op.join(cfg.externals["ffmpeg_Windows"], src, "*")
dst = op.join(cfg.prefix, dst)
cmds.append(_cmd_join("xcopy", src, dst, "/s", "/y"))
return cmds
elif cfg.host in ["Android", "iOS"]:
builddir = _get_builddir(cfg, "ffmpeg")
cmds = [
f"cd {builddir} && " + _cmd_join("make", f"-j{os.cpu_count()}"),
f"cd {builddir} && " + _cmd_join("make", "install"),
]
return cmds
@_block("sdl2-install", [])
def _sdl2_install(cfg):
dirs = (
"lib",
"include",
"cmake",
)
cmds = []
for d in dirs:
src = op.join(cfg.externals["sdl2_Windows"], d, "*")
dst = op.join(cfg.prefix, d)
os.makedirs(dst, exist_ok=True)
cmds.append(_cmd_join("xcopy", src, dst, "/s", "/y"))
src = op.join(cfg.externals["sdl2_Windows"], "lib", "x64", "SDL2.dll")
dst = op.join(cfg.prefix, "Scripts")
cmds.append(_cmd_join("xcopy", src, dst, "/y"))
return cmds
@_block("moltenvk-install", [])
def _moltenvk_install(cfg):
resources = (
(op.join("static", "MoltenVK.xcframework", "ios-arm64", "libMoltenVK.a"), "lib"),
(op.join("include", "."), "include"),
)
cmds = []
for src_path, dst_path in resources:
src = op.join(cfg.externals["moltenvk_iOS"], "MoltenVK", src_path)
dst = op.join(cfg.prefix, dst_path)
os.makedirs(dst, exist_ok=True)
cmds.append(_cmd_join("cp", "-R", src, dst))
return cmds
@_block("glslang-setup", [])
def _glslang_setup(cfg):
build_type = "Debug" if cfg.args.buildtype == "debug" else "Release"
cmake_args = [
"cmake",
"-GNinja",
f"-DCMAKE_BUILD_TYPE={build_type}",
f"-DCMAKE_INSTALL_PREFIX={cfg.prefix}",
"-DBUILD_SHARED_LIBS=OFF",
"-DBUILD_EXTERNAL=OFF",
"-DENABLE_OPT=OFF",
"-S",
cfg.externals["glslang"],
"-B",
_get_builddir(cfg, "glslang"),
]
if cfg.host == "Android":
cmake_args += [
f"-DCMAKE_TOOLCHAIN_FILE={cfg.android_cmake_toolchain}",
"-DANDROID_STL=c++_shared",
"-DANDROID_TOOLCHAIN=clang",
f"-DANDROID_PLATFORM=android-{_ANDROID_VERSION}",
f"-DANDROID_ABI={cfg.android_abi}",
]
elif cfg.host == "iOS":
cmake_args += [
f"-DCMAKE_OSX_SYSROOT=iphoneos",
f"-DCMAKE_OSX_ARCHITECTURES={cfg.ios_abi}",
]
return [
_cmd_join(*cmake_args),
]
@_block("glslang-install", {"Android": [_glslang_setup], "iOS": [_glslang_setup]})
def _glslang_install(cfg):
if cfg.host in ["Android", "iOS"]:
builddir = _get_builddir(cfg, "glslang")
cmds = [
_cmd_join("cmake", "--build", builddir),
_cmd_join("cmake", "--install", builddir),
]
return cmds
elif cfg.host == "Windows":
dirs = (
("lib", "Lib"),
("include", "Include"),
("bin", "Scripts"),
)
cmds = []
for src, dst in dirs:
src = op.join(cfg.externals["glslang_Windows"], src, "*")
dst = op.join(cfg.prefix, dst)
cmds.append(_cmd_join("xcopy", src, dst, "/s", "/y"))
return cmds
@_block(
"nopemd-setup",
{
"Android": [_ffmpeg_install],
"iOS": [_ffmpeg_install],
"Windows": [_pkgconf_install, _ffmpeg_install, _sdl2_install],
},
)
def _nopemd_setup(cfg):
builddir = _get_builddir(cfg, "nopemd")
return ["$(MESON_SETUP) -Drpath=true " + _cmd_join(cfg.externals["nopemd"], builddir)]
@_block("nopemd-install", [_nopemd_setup])
def _nopemd_install(cfg):
return _meson_compile_install_cmd(cfg, "nopemd")
@_block("renderdoc-install")
def _renderdoc_install(cfg):
renderdoc_dll = op.join(cfg.externals[_RENDERDOC_ID], "renderdoc.dll")
return [f"copy {renderdoc_dll} {cfg.bin_path}"]
@_block("freetype-setup", {"Windows": [_pkgconf_install]})
def _freetype_setup(cfg):
builddir = _get_builddir(cfg, "freetype")
return ["$(MESON_SETUP) " + _cmd_join(cfg.externals["freetype"], builddir)]
@_block("freetype-install", [_freetype_setup])
def _freetype_install(cfg):
return _meson_compile_install_cmd(cfg, "freetype")
@_block("harfbuzz-setup", [_freetype_install])
def _harfbuzz_setup(cfg):
builddir = _get_builddir(cfg, "harfbuzz")
return ["$(MESON_SETUP) -Dtests=disabled " + _cmd_join(cfg.externals["harfbuzz"], builddir)]
@_block("harfbuzz-install", [_harfbuzz_setup])
def _harfbuzz_install(cfg):
return _meson_compile_install_cmd(cfg, "harfbuzz")
@_block("fribidi-setup", {"Windows": [_pkgconf_install]})
def _fribidi_setup(cfg):
builddir = _get_builddir(cfg, "fribidi")
return ["$(MESON_SETUP) " + _cmd_join("-Ddocs=false", cfg.externals["fribidi"], builddir)]
@_block("fribidi-install", [_fribidi_setup])
def _fribidi_install(cfg):
return _meson_compile_install_cmd(cfg, "fribidi")
@_block(
"nopegl-setup",
{
"Android": [
_nopemd_install,
_glslang_install,
_freetype_install,
_harfbuzz_install,
_fribidi_install,
],
"iOS": [
_nopemd_install,
_moltenvk_install,
_glslang_install,
_freetype_install,
_harfbuzz_install,
_fribidi_install,
],
"Local": [_nopemd_install],
"Windows": [
_nopemd_install,
_sdl2_install,
_egl_registry_install,
_opengl_registry_install,
_glslang_install,
_freetype_install,
_harfbuzz_install,
_fribidi_install,
],
},
)
def _nopegl_setup(cfg):
nopegl_opts = []
if cfg.args.debug_opts:
debug_opts = ",".join(cfg.args.debug_opts)
nopegl_opts += [f"-Ddebug_opts={debug_opts}"]
if cfg.args.sanitize:
nopegl_opts += [f"-Db_sanitize={cfg.args.sanitize}"]
if "gpu_capture" in cfg.args.debug_opts:
renderdoc_dir = cfg.externals[_RENDERDOC_ID]
nopegl_opts += [f"-Drenderdoc_dir={renderdoc_dir}"]
extra_library_dirs = []
extra_include_dirs = []
if cfg.host == "Android":
extra_library_dirs += [op.join(cfg.prefix, "lib")]
extra_include_dirs += [op.join(cfg.prefix, "include")]
elif cfg.host == "iOS":
extra_library_dirs += [op.join(cfg.prefix, "lib")]
extra_include_dirs += [op.join(cfg.prefix, "include")]
elif cfg.host == "Windows":
extra_library_dirs += [op.join(cfg.prefix, "Lib")]
extra_include_dirs += [op.join(cfg.prefix, "Include")]
elif cfg.host == "Darwin":
prefix = _get_brew_prefix()
if prefix:
extra_library_dirs += [op.join(prefix, "lib")]
extra_include_dirs += [op.join(prefix, "include")]
if extra_library_dirs:
opts = ",".join(extra_library_dirs)
nopegl_opts += [f"-Dextra_library_dirs={opts}"]
if extra_include_dirs:
opts = ",".join(extra_include_dirs)
nopegl_opts += [f"-Dextra_include_dirs={opts}"]
return ["$(MESON_SETUP) -Drpath=true " + _cmd_join(*nopegl_opts, "libnopegl", _get_builddir(cfg, "libnopegl"))]
@_block("nopegl-install", [_nopegl_setup])
def _nopegl_install(cfg):
return _meson_compile_install_cmd(cfg, "libnopegl")
@_block("nopegl-install-nosetup")
def _nopegl_install_nosetup(cfg):
return _meson_compile_install_cmd(cfg, "libnopegl")
@_block("pynopegl-deps-install", [_nopegl_install])
def _pynopegl_deps_install(cfg):
return ["$(PIP) " + _cmd_join("install", "-r", op.join(".", "pynopegl", "requirements.txt"))]
@_block("pynopegl-install", [_pynopegl_deps_install])
def _pynopegl_install(cfg):
ret = ["$(PIP) " + _cmd_join("-v", "install", "-e", op.join(".", "pynopegl"))]
if cfg.host != "Windows":
rpath = op.join(cfg.prefix, "lib")
ldflags = f"-Wl,-rpath,{rpath}"
ret[0] = f"LDFLAGS={ldflags} {ret[0]}"
return ret
@_block("pynopegl-utils-deps-install", [_pynopegl_install])
def _pynopegl_utils_deps_install(cfg):
#
# Requirements not installed on MinGW because:
# - PySide6 can't be pulled (required to be installed by the user outside the
# Python virtual env)
# - Pillow fails to find zlib (required to be installed by the user outside the