aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/.yandex_meta/__init__.py
blob: d25a5cef92ddc2843f683f7dc0652e359feebfb3 (plain) (blame)
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
import os.path as P
import shutil

from devtools.yamaker.fileutil import copy, subcopy
from devtools.yamaker.modules import GLOBAL, Linkable, Switch
from devtools.yamaker.project import NixProject


def post_build(self):
    # copying icudt.dat file from original repository
    icu_dat_path = f"{self.srcdir}/data/in/icudt75l.dat"
    rodata_path = f"{self.dstdir}/icudt75_dat.rodata"
    shutil.copy(icu_dat_path, rodata_path)


def post_install(self):
    result_target = self.yamakes["."]

    result_target.SRCS.add("icudt75_dat.rodata")

    result_target.CFLAGS = [
        "-DU_COMMON_IMPLEMENTATION",
        "-DU_I18N_IMPLEMENTATION",
        "-DU_IO_IMPLEMENTATION",
    ]

    # Requires that U_STATIC_IMPLEMENTATION be defined in user code that links against ICU's static libraries
    # See https://htmlpreview.github.io/?https://github.com/unicode-org/icu/blob/master/icu4c/readme.html#RecBuild
    windows_cflags = Linkable()
    windows_cflags.CFLAGS = [
        GLOBAL("-DU_STATIC_IMPLEMENTATION"),
    ]

    default_cflags = Linkable()
    default_cflags.CFLAGS = [
        "-DU_STATIC_IMPLEMENTATION",
    ]

    result_target.after(
        "CFLAGS",
        Switch(
            {
                "OS_WINDOWS": windows_cflags,
                "default": default_cflags,
            }
        ),
    )

    # Win
    # TODO add CYGWINMSVC ?
    # TODO add _CRT_SECURE_NO_DEPRECATE ?

    # stubdata is there because it is linked in shared library during build
    # And even though it's target is missing in Project and no ya.make references this sources, they are copied
    # In arcadia full icudata is always statically linked in
    # So we should not need it
    shutil.rmtree(P.join(self.dstdir, "stubdata"))

    # copy_top_sources does not work due to nixsrcdir
    subcopy(P.join(self.tmpdir, "icu"), self.dstdir, ["LICENSE", "*.html", "*.css"])

    # Usual icu4c includes look like this `#include "unicode/brkiter.h"`
    # And all headers is installed in ${PREFIX}/include/unicode
    # But in sources layout is different - headers for each sublibrary is separate, and inside sublib sources
    # So all headers are inside source/common/unicode, source/i18n/unicode and source/io/unicode
    # With original layout one need to use ADDINCL to contrib/libs/icu/common to be able to `#include "unicode/brkiter.h"`
    # But that will leak headers from contrib/libs/icu, i.e. contrib/libs/icu/common/util.h
    # So we move public headers to separate dirs, to avoid unnecessary headers
    for sublib in [
        "common",
        "i18n",
        "io",
    ]:
        src = P.join(self.dstdir, sublib, "unicode")
        copy(
            [src],
            P.join(self.dstdir, "include"),
        )
        shutil.rmtree(src)


icu = NixProject(
    owners=[
        "g:cpp-contrib",
    ],
    arcdir="contrib/libs/icu",
    nixattr="icu67",
    # https://github.com/NixOS/nixpkgs/blob/b2f6aa631edc025cb6748133864317983bf5c6d1/pkgs/development/libraries/icu/base.nix#L17-L20
    nixsrcdir="icu/source",
    put_with={
        "icuio": [
            "icuuc",
            "icui18n",
        ],
    },
    install_targets=[
        "icuio",
    ],
    copy_sources=[
        "common/unicode/*.h",
        "common/*.h",
        "i18n/*.h",
    ],
    disable_includes=[
        "sys/isa_defs.h",
    ],
    # We setup ADDINCL GLOBAL, so we have sinlge "usual" way to include ICU headers by default
    addincl_global={".": {"./include"}},
    ignore_commands=[
        "bash",
    ],
    post_build=post_build,
    post_install=post_install,
)