__init__.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import shutil
  2. from devtools.yamaker.arcpath import ArcPath
  3. from devtools.yamaker import fileutil
  4. from devtools.yamaker import pathutil
  5. from devtools.yamaker.modules import Program, Linkable, Recursable, Switch
  6. from devtools.yamaker.project import CMakeNinjaNixProject
  7. def post_build(self):
  8. # neon-compat.h is replaced during CMake build upon native / cross-compilation under arm.
  9. # As we do not run such compilation, we have to generate corresponding source manually.
  10. shutil.copy(
  11. f"{self.srcdir}/simd/arm/neon-compat.h.in",
  12. f"{self.dstdir}/simd/arm/neon-compat.h",
  13. )
  14. fileutil.re_sub_file(f"{self.dstdir}/simd/arm/neon-compat.h", r"\#cmakedefine", "// #cmakedefine")
  15. def post_install(self):
  16. for prj, m in self.yamakes.items():
  17. if isinstance(m, Program):
  18. m.PEERDIR.add(self.arcdir)
  19. with self.yamakes["."] as m:
  20. # These flags break build of libjpeg-turbo with local xcode toolchain.
  21. # (`ya make --maps-mobile --target-platform=local-iossim-arm64' at the time)
  22. m.CFLAGS.remove("-DELF")
  23. m.CFLAGS.remove("-D__x86_64__")
  24. m.ADDINCL.remove(self.arcdir + "/simd/x86_64")
  25. m.ADDINCL.remove(self.arcdir + "/simd/nasm")
  26. m.ADDINCL.add(ArcPath(f"{self.arcdir}/simd/nasm", FOR="asm"))
  27. m.after("CFLAGS", Switch({"SANITIZER_TYPE": Linkable(CFLAGS=["-DWITH_SANITIZER"])}))
  28. m.after("ADDINCL", Switch({"OS_DARWIN OR OS_IOS": "SET(ASM_PREFIX '_')"}))
  29. # Sources from simd/arm/aarch64/*-neon.c are included into other sources.
  30. # This heuristics is used to detect whether the source should be compiled directly.
  31. def is_direct_source(src):
  32. return pathutil.is_source(src) and "ext" not in src
  33. amd64 = {s for s in m.SRCS if s.startswith("simd/")}
  34. i386 = fileutil.files(self.dstdir + "/simd/i386", rel=self.dstdir, test=is_direct_source)
  35. arm = fileutil.files(self.dstdir + "/simd/arm/aarch32", rel=self.dstdir, test=is_direct_source)
  36. arm64 = [
  37. src for src in fileutil.listdir(f"{self.dstdir}/simd/arm", rel=self.dstdir) if is_direct_source(src)
  38. ] + [
  39. src for src in fileutil.listdir(f"{self.dstdir}/simd/arm/aarch64", rel=self.dstdir) if is_direct_source(src)
  40. ]
  41. simd_none = ["jsimd_none.c"]
  42. # This file contains the older GNU Assembler implementation of the Neon SIMD
  43. # extensions for certain algorithms.
  44. # We are using clang 12+ which has a full set of Neon intrinsics
  45. arm64.remove("simd/arm/aarch64/jsimd_neon.S")
  46. m.SRCS -= amd64
  47. m.before(
  48. "SRCS",
  49. Switch(
  50. [
  51. ("OS_ANDROID", Linkable(SRCS=simd_none)),
  52. ("ARCH_I386", Linkable(SRCS=i386)),
  53. ("ARCH_X86_64", Linkable(SRCS=amd64)),
  54. ("ARCH_ARM7 AND NOT MSVC", Linkable(SRCS=arm)),
  55. (
  56. "ARCH_ARM64 AND NOT MSVC",
  57. Linkable(SRCS=arm64, ADDINCL=[f"{self.arcdir}/simd/arm"]),
  58. ),
  59. ("default", Linkable(SRCS=simd_none)),
  60. ]
  61. ),
  62. )
  63. m.after(
  64. "RECURSE",
  65. Switch(
  66. [
  67. (
  68. "NOT OS_ANDROID AND NOT OS_IOS",
  69. Recursable(RECURSE_FOR_TESTS=["ut"]),
  70. ),
  71. ]
  72. ),
  73. )
  74. libjpeg_turbo = CMakeNinjaNixProject(
  75. arcdir="contrib/libs/libjpeg-turbo",
  76. nixattr="libjpeg",
  77. owners=["g:cpp-contrib", "g:avatars"],
  78. ignore_commands={"bash", "sed"},
  79. install_targets={"turbojpeg", "cjpeg", "djpeg", "tjunittest", "jpegtran"},
  80. put={
  81. "turbojpeg": ".",
  82. "cjpeg": "cjpeg",
  83. "djpeg": "djpeg",
  84. "jpegtran": "jpegtran",
  85. "tjunittest": "tjunittest",
  86. },
  87. platform_dispatchers=["jconfigint.h"],
  88. copy_sources=[
  89. "simd/arm/",
  90. "simd/i386/",
  91. "simd/nasm/",
  92. "simd/x86_64/",
  93. "jsimd_none.c",
  94. ],
  95. keep_paths={
  96. "ut/*.py",
  97. "ut/canondata/",
  98. "ut/ya.make",
  99. "testimages/",
  100. },
  101. post_build=post_build,
  102. post_install=post_install,
  103. )