1 // Copyright (C) 2019 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ICING_PORTABLE_PLATFORM_H_ 16 #define ICING_PORTABLE_PLATFORM_H_ 17 18 namespace icing { 19 namespace lib { 20 21 // Returns true if the test was built with the CFStringTokenizer as the 22 // implementation of LanguageSegmenter. IsCfStringTokenization()23inline bool IsCfStringTokenization() { 24 #if defined(__APPLE__) && !defined(ICING_IOS_ICU4C_SEGMENTATION) 25 return true; 26 #endif // defined(__APPLE__) && !defined(ICING_IOS_ICU4C_SEGMENTATION) 27 return false; 28 } 29 IsReverseJniTokenization()30inline bool IsReverseJniTokenization() { 31 #ifdef ICING_REVERSE_JNI_SEGMENTATION 32 return true; 33 #endif // ICING_REVERSE_JNI_SEGMENTATION 34 return false; 35 } 36 37 // Whether we're running on android_x86 IsAndroidX86()38inline bool IsAndroidX86() { 39 #if defined(__ANDROID__) && defined(__i386__) 40 return true; 41 #endif // defined(__ANDROID__) && defined(__i386__) 42 return false; 43 } 44 45 // Whether we're running on android_armeabi-v7a IsAndroidArm()46inline bool IsAndroidArm() { 47 #if defined(__ANDROID__) && defined(__arm__) 48 return true; 49 #endif // defined(__ANDROID__) && defined(__arm__) 50 return false; 51 } 52 53 // Whether the running test is an iOS test. IsIosPlatform()54inline bool IsIosPlatform() { 55 #if defined(__APPLE__) 56 return true; 57 #endif // defined(__APPLE__) 58 return false; 59 } 60 61 enum Architecture { 62 UNKNOWN, 63 BIT_32, 64 BIT_64, 65 }; 66 67 // Returns which architecture we're running on. 68 // 69 // Architecture macros pulled from 70 // https://developer.android.com/ndk/guides/cpu-features GetArchitecture()71inline Architecture GetArchitecture() { 72 #if defined(__arm__) || defined(__i386__) 73 return BIT_32; 74 #elif defined(__aarch64__) || defined(__x86_64__) 75 return BIT_64; 76 #else 77 return UNKNOWN; 78 #endif 79 } 80 81 } // namespace lib 82 } // namespace icing 83 84 #endif // ICING_PORTABLE_PLATFORM_H_ 85