aboutsummaryrefslogtreecommitdiff
path: root/icing/portable/platform.h
blob: 4c115e1da26e1affc6ea07234ab29ce093a59942 (plain)
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
// Copyright (C) 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef ICING_PORTABLE_PLATFORM_H_
#define ICING_PORTABLE_PLATFORM_H_

#include "unicode/uversion.h"

namespace icing {
namespace lib {

// Returns true if the test was built with the CFStringTokenizer as the
// implementation of LanguageSegmenter.
inline bool IsCfStringTokenization() {
#if defined(__APPLE__) && !defined(ICING_IOS_ICU4C_SEGMENTATION)
  return true;
#endif  // defined(__APPLE__) && !defined(ICING_IOS_ICU4C_SEGMENTATION)
  return false;
}

inline bool IsReverseJniTokenization() {
#ifdef ICING_REVERSE_JNI_SEGMENTATION
  return true;
#endif  // ICING_REVERSE_JNI_SEGMENTATION
  return false;
}

inline bool IsIcuTokenization() {
  return !IsReverseJniTokenization() && !IsCfStringTokenization();
}

inline bool IsIcu72PlusTokenization() {
  if (!IsIcuTokenization()) {
    return false;
  }
  UVersionInfo version_array;
  u_getVersion(version_array);
  return version_array[0] >= 72;
}

// Whether we're running on android_x86
inline bool IsAndroidX86() {
#if defined(__ANDROID__) && defined(__i386__)
  return true;
#endif  // defined(__ANDROID__) && defined(__i386__)
  return false;
}

// Whether we're running on android_armeabi-v7a
inline bool IsAndroidArm() {
#if defined(__ANDROID__) && defined(__arm__)
  return true;
#endif  // defined(__ANDROID__) && defined(__arm__)
  return false;
}

// Whether the running test is an iOS test.
inline bool IsIosPlatform() {
#if defined(__APPLE__)
  return true;
#endif  // defined(__APPLE__)
  return false;
}

// TODO(b/259129263): verify the flag works for different platforms.
#if defined(__arm__) || defined(__i386__)
#define ICING_ARCH_BIT_32
#elif defined(__aarch64__) || defined(__x86_64__)
#define ICING_ARCH_BIT_64
#else
#define ICING_ARCH_BIT_UNKNOWN
#endif

enum Architecture {
  UNKNOWN,
  BIT_32,
  BIT_64,
};

// Returns which architecture we're running on.
//
// Architecture macros pulled from
// https://developer.android.com/ndk/guides/cpu-features
inline Architecture GetArchitecture() {
#if defined(ICING_ARCH_BIT_32)
  return BIT_32;
#elif defined(ICING_ARCH_BIT_64)
  return BIT_64;
#else
  return UNKNOWN;
#endif
}

}  // namespace lib
}  // namespace icing

#endif  // ICING_PORTABLE_PLATFORM_H_