1load(
2    "//tools/build_defs/oss:rn_defs.bzl",
3    "ANDROID",
4    "APPLE",
5    "CXX",
6    "fb_xplat_cxx_test",
7    "get_apple_compiler_flags",
8    "get_apple_inspector_flags",
9    "get_preprocessor_flags_for_build_mode",
10    "react_native_target",
11    "react_native_xplat_target",
12    "rn_xplat_cxx_library",
13    "subdir_glob",
14)
15
16APPLE_COMPILER_FLAGS = get_apple_compiler_flags()
17
18rn_xplat_cxx_library(
19    name = "androidswitch",
20    srcs = glob(
21        ["androidswitch/react/renderer/components/androidswitch/*.cpp"],
22        exclude = glob(["tests/**/*.cpp"]),
23    ),
24    headers = glob(
25        ["androidswitch/react/renderer/components/androidswitch/*.h"],
26        exclude = glob(["tests/**/*.h"]),
27    ),
28    header_namespace = "",
29    exported_headers = subdir_glob(
30        [
31            ("", "*.h"),
32            ("androidswitch/react/renderer/components/androidswitch", "*.h"),
33        ],
34        prefix = "react/renderer/components/androidswitch",
35    ),
36    compiler_flags_pedantic = True,
37    cxx_tests = [":tests"],
38    fbandroid_deps = [
39        react_native_target("jni/react/jni:jni"),
40    ],
41    fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
42    fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
43    force_static = True,
44    labels = [
45        "pfh:ReactNative_CommonInfrastructurePlaceholder",
46    ],
47    platforms = (ANDROID, APPLE, CXX),
48    preprocessor_flags = [
49        "-DLOG_TAG=\"ReactNative\"",
50        "-DWITH_FBSYSTRACE=1",
51    ],
52    visibility = ["PUBLIC"],
53    deps = [
54        react_native_xplat_target("react/renderer/debug:debug"),
55        react_native_xplat_target("react/renderer/core:core"),
56        react_native_xplat_target("react/renderer/graphics:graphics"),
57        react_native_xplat_target("react/renderer/components/view:view"),
58        react_native_xplat_target("react/renderer/uimanager:uimanager"),
59        react_native_xplat_target("react/renderer/componentregistry:componentregistry"),
60        "//xplat/js/react-native-github:generated_components-rncore",
61    ],
62)
63
64fb_xplat_cxx_test(
65    name = "tests",
66    srcs = glob(["tests/**/*.cpp"]),
67    headers = glob(["tests/**/*.h"]),
68    compiler_flags = [
69        "-fexceptions",
70        "-frtti",
71        "-std=c++17",
72        "-Wall",
73    ],
74    contacts = ["[email protected]"],
75    platforms = (
76        # `Apple` and `Android` flavors are disabled because the module depends on `textlayoutmanager` which requires real an Emulator/Simulator to run.
77        #  At the same time, the code of tests does not rely on the simulator capabilities and it would be wasteful to add `fbandroid_use_instrumentation_test = True`.
78        # (Beware of this option though.)
79        # ANDROID,
80        # APPLE,
81        CXX
82    ),
83    deps = [
84        ":androidswitch",
85        "//xplat/third-party/gmock:gtest",
86    ],
87)
88