__init__.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import os.path as P
  2. import shutil
  3. from devtools.yamaker.fileutil import copy, subcopy
  4. from devtools.yamaker.modules import GLOBAL, Linkable, Switch
  5. from devtools.yamaker.project import NixProject
  6. def post_build(self):
  7. # copying icudt.dat file from original repository
  8. icu_dat_path = f"{self.srcdir}/data/in/icudt76l.dat"
  9. rodata_path = f"{self.dstdir}/icudt76_dat.rodata"
  10. shutil.copy(icu_dat_path, rodata_path)
  11. def post_install(self):
  12. result_target = self.yamakes["."]
  13. result_target.SRCS.add("icudt76_dat.rodata")
  14. result_target.CFLAGS = [
  15. "-DU_COMMON_IMPLEMENTATION",
  16. "-DU_I18N_IMPLEMENTATION",
  17. "-DU_IO_IMPLEMENTATION",
  18. ]
  19. # Requires that U_STATIC_IMPLEMENTATION be defined in user code that links against ICU's static libraries
  20. # See https://htmlpreview.github.io/?https://github.com/unicode-org/icu/blob/master/icu4c/readme.html#RecBuild
  21. windows_cflags = Linkable()
  22. windows_cflags.CFLAGS = [
  23. GLOBAL("-DU_STATIC_IMPLEMENTATION"),
  24. ]
  25. default_cflags = Linkable()
  26. default_cflags.CFLAGS = [
  27. "-DU_STATIC_IMPLEMENTATION",
  28. ]
  29. result_target.after(
  30. "CFLAGS",
  31. Switch(
  32. {
  33. "OS_WINDOWS": windows_cflags,
  34. "default": default_cflags,
  35. }
  36. ),
  37. )
  38. # Win
  39. # TODO add CYGWINMSVC ?
  40. # TODO add _CRT_SECURE_NO_DEPRECATE ?
  41. # stubdata is there because it is linked in shared library during build
  42. # And even though it's target is missing in Project and no ya.make references this sources, they are copied
  43. # In arcadia full icudata is always statically linked in
  44. # So we should not need it
  45. shutil.rmtree(P.join(self.dstdir, "stubdata"))
  46. # copy_top_sources does not work due to nixsrcdir
  47. subcopy(P.join(self.tmpdir, "icu"), self.dstdir, ["LICENSE", "*.html", "*.css"])
  48. # Usual icu4c includes look like this `#include "unicode/brkiter.h"`
  49. # And all headers is installed in ${PREFIX}/include/unicode
  50. # But in sources layout is different - headers for each sublibrary is separate, and inside sublib sources
  51. # So all headers are inside source/common/unicode, source/i18n/unicode and source/io/unicode
  52. # With original layout one need to use ADDINCL to contrib/libs/icu/common to be able to `#include "unicode/brkiter.h"`
  53. # But that will leak headers from contrib/libs/icu, i.e. contrib/libs/icu/common/util.h
  54. # So we move public headers to separate dirs, to avoid unnecessary headers
  55. for sublib in [
  56. "common",
  57. "i18n",
  58. "io",
  59. ]:
  60. src = P.join(self.dstdir, sublib, "unicode")
  61. copy(
  62. [src],
  63. P.join(self.dstdir, "include"),
  64. )
  65. shutil.rmtree(src)
  66. icu = NixProject(
  67. owners=[
  68. "g:cpp-contrib",
  69. ],
  70. arcdir="contrib/libs/icu",
  71. nixattr="icu74",
  72. put_with={
  73. "icuio": [
  74. "icuuc",
  75. "icui18n",
  76. ],
  77. },
  78. install_targets=[
  79. "icuio",
  80. ],
  81. copy_sources=[
  82. "common/unicode/*.h",
  83. "common/*.h",
  84. "i18n/*.h",
  85. ],
  86. disable_includes=[
  87. "sys/isa_defs.h",
  88. "sys/neutrino.h",
  89. "ascii_a.h",
  90. "cics.h",
  91. "mih/testptr.h",
  92. "qliept.h",
  93. "qusec.h",
  94. "qusrjobi.h",
  95. "ucln_local_hook.c",
  96. "uconfig_local.h",
  97. "udbgutil.h",
  98. "unistrm.h",
  99. ],
  100. # We setup ADDINCL GLOBAL, so we have sinlge "usual" way to include ICU headers by default
  101. addincl_global={".": {"./include"}},
  102. ignore_commands=[
  103. "bash",
  104. ],
  105. post_build=post_build,
  106. post_install=post_install,
  107. )