__init__.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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="icu67",
  72. # https://github.com/NixOS/nixpkgs/blob/b2f6aa631edc025cb6748133864317983bf5c6d1/pkgs/development/libraries/icu/base.nix#L17-L20
  73. nixsrcdir="icu/source",
  74. put_with={
  75. "icuio": [
  76. "icuuc",
  77. "icui18n",
  78. ],
  79. },
  80. install_targets=[
  81. "icuio",
  82. ],
  83. copy_sources=[
  84. "common/unicode/*.h",
  85. "common/*.h",
  86. "i18n/*.h",
  87. ],
  88. disable_includes=[
  89. "sys/isa_defs.h",
  90. ],
  91. # We setup ADDINCL GLOBAL, so we have sinlge "usual" way to include ICU headers by default
  92. addincl_global={".": {"./include"}},
  93. ignore_commands=[
  94. "bash",
  95. ],
  96. post_build=post_build,
  97. post_install=post_install,
  98. )