Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import java.nio.file.Paths
 
buildscript {
  repositories {
    google()
    mavenCentral()
  }
 
  dependencies {
    classpath 'com.android.tools.build:gradle:7.4.2'
    // noinspection DifferentKotlinGradleVersion
  }
}
 
apply plugin: 'com.android.library'
 
def getExtOrDefault(name) {
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['OnnxruntimeModule_' + name]
}
 
def getExtOrIntegerDefault(name) {
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['OnnxruntimeModule_' + name]).toInteger()
}
 
def reactNativeArchitectures() {
  def value = project.getProperties().get("reactNativeArchitectures")
  return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}
 
def resolveBuildType() {
  Gradle gradle = getGradle()
  String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
  return tskReqStr.contains('Release') ? 'release' : 'debug'
}
 
static def findNodeModules(baseDir) {
  def basePath = baseDir.toPath().normalize()
  while (basePath) {
    def nodeModulesPath = Paths.get(basePath.toString(), "node_modules")
    def reactNativePath = Paths.get(nodeModulesPath.toString(), "react-native")
    if (nodeModulesPath.toFile().exists() && reactNativePath.toFile().exists()) {
      return nodeModulesPath.toString()
    }
    basePath = basePath.getParent()
  }
  throw new GradleException("onnxruntime-react-native: Failed to find node_modules/ path!")
}
 
def nodeModules = findNodeModules(projectDir);
 
def readPackageJsonField(field) {
  // locate user's project dir
  def reactnativeRootDir = project.rootDir.parentFile
  // get package.json file in root directory
  def packageJsonFile = new File(reactnativeRootDir, 'package.json')
  if (packageJsonFile.exists()) {
    def packageJsonContents = packageJsonFile.getText()
    def packageJson = new groovy.json.JsonSlurper().parseText(packageJsonContents)
    return packageJson.get(field)
  } else {
    logger.warn("Could not find package.json file in the expected directory: ${reactnativeRootDir}. ${field} will not be enabled.")
  }
}
 
boolean ortExtensionsEnabled = readPackageJsonField('onnxruntimeExtensionsEnabled') == "true"
boolean useQnn = readPackageJsonField('onnxruntimeUseQnn') == "true"
 
def REACT_NATIVE_VERSION = ['node', '--print', "JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim()
def versionParts = REACT_NATIVE_VERSION.split("\\.")
if (versionParts.length < 2) {
  throw new GradleException("Invalid React Native version format: ${REACT_NATIVE_VERSION}. Expected format: major.minor[.patch]")
}
def REACT_NATIVE_MAJOR_VERSION = versionParts[0].toInteger()
def REACT_NATIVE_MINOR_VERSION = versionParts[1].toInteger()
 
android {
// This is needed by the new AndroidManifestNew.xml
  namespace "ai.onnxruntime.reactnative"
  compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
  buildToolsVersion getExtOrDefault('buildToolsVersion')
  defaultConfig {
    minSdkVersion getExtOrIntegerDefault('minSdkVersion')
    targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    externalNativeBuild {
      cmake {
        cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
        if (REACT_NATIVE_MAJOR_VERSION > 0 || REACT_NATIVE_MINOR_VERSION >= 71) {
          // fabricjni required c++_shared
          arguments "-DANDROID_STL=c++_shared",
            "-DNODE_MODULES_DIR=${nodeModules}",
            "-DORT_EXTENSIONS_ENABLED=${ortExtensionsEnabled}",
            "-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}",
            "-DUSE_QNN=${useQnn}",
            "-DUSE_NNAPI=${!useQnn}"
        } else {
          arguments "-DNODE_MODULES_DIR=${nodeModules}",
            "-DORT_EXTENSIONS_ENABLED=${ortExtensionsEnabled}",
            "-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}",
            "-DUSE_QNN=${useQnn}",
            "-DUSE_NNAPI=${!useQnn}"
        }
        abiFilters (*reactNativeArchitectures())
      }
    }
  }
 
  if (rootProject.hasProperty("ndkPath")) {
    ndkPath rootProject.ext.ndkPath
  }
  if (rootProject.hasProperty("ndkVersion")) {
    ndkVersion rootProject.ext.ndkVersion
  }
 
  buildFeatures {
    prefab true
  }
 
  externalNativeBuild {
    cmake {
      path "CMakeLists.txt"
    }
  }
 
  packagingOptions {
    pickFirst '**/libc++_shared.so'
    pickFirst '**/libfbjni.so'
    doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
    excludes = [
      "META-INF",
      "META-INF/**",
      "**/libjsi.so",
      "**/libfbjni.so",
      "**/libreact_nativemodule_core.so",
      "**/libturbomodulejsijni.so"
    ]
  }
 
  buildTypes {
    release {
      minifyEnabled false
    }
  }
  lintOptions {
    disable 'GradleCompatible'
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
  }
 
  sourceSets {
    main {
      java.srcDirs = ['src/main/java/']
//       A tricky situation where iOS still uses the AndroidManifest.xml file, but the Android use AndroidManifestNew.xml
      manifest.srcFile "src/main/AndroidManifestNew.xml"
      if (ortExtensionsEnabled) {
        java.exclude '**/OnnxruntimeExtensionsDisabled.java'
      } else {
        java.exclude '**/OnnxruntimeExtensionsEnabled.java'
      }
    }
  }
 
  configurations {
    extractLibs
  }
}
 
repositories {
  mavenCentral()
  google()
 
  def found = false
  def defaultDir = null
  def androidSourcesName = 'React Native sources'
 
  if (rootProject.ext.has('reactNativeAndroidRoot')) {
    defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
  } else {
    defaultDir = new File(
            projectDir,
            '/../../../node_modules/react-native/android'
    )
  }
 
  if (defaultDir.exists()) {
    maven {
      url defaultDir.toString()
      name androidSourcesName
    }
 
    logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
    found = true
  } else {
    def parentDir = rootProject.projectDir
 
    1.upto(5, {
      if (found) return true
      parentDir = parentDir.parentFile
 
      def androidSourcesDir = new File(
              parentDir,
              'node_modules/react-native'
      )
 
      def androidPrebuiltBinaryDir = new File(
              parentDir,
              'node_modules/react-native/android'
      )
 
      if (androidPrebuiltBinaryDir.exists()) {
        maven {
          url androidPrebuiltBinaryDir.toString()
          name androidSourcesName
        }
 
        logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
        found = true
      } else if (androidSourcesDir.exists()) {
        maven {
          url androidSourcesDir.toString()
          name androidSourcesName
        }
 
        logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
        found = true
      }
    })
  }
 
  if (!found) {
    throw new GradleException(
            "${project.name}: unable to locate React Native android sources. " +
                    "Ensure you have you installed React Native as a dependency in your project and try again."
    )
  }
}
 
dependencies {
  //noinspection GradleDynamicVersion
  implementation "com.facebook.react:react-android:"+ REACT_NATIVE_VERSION
  api "org.mockito:mockito-core:2.28.2"
 
  implementation "junit:junit:4.12"
 
  if (useQnn) {
    extractLibs "com.microsoft.onnxruntime:onnxruntime-android-qnn:latest.integration@aar"
  } else {
    extractLibs "com.microsoft.onnxruntime:onnxruntime-android:latest.integration@aar"
  }
 
  if (REACT_NATIVE_MAJOR_VERSION == 0 && REACT_NATIVE_MINOR_VERSION < 71) {
    extractLibs "com.facebook.fbjni:fbjni:+:headers"
    extractLibs "com.facebook.fbjni:fbjni:+"
  }
 
  // By default it will just include onnxruntime full aar package
  if (ortExtensionsEnabled) {
    implementation "com.microsoft.onnxruntime:onnxruntime-extensions-android:latest.integration@aar"
  }
}
 
task extractLibs {
  doLast {
    configurations.extractLibs.files.each {
      def file = it.absoluteFile
      copy {
        from zipTree(file)
        into "$buildDir/$file.name"
        include "**/*.h", "**/*.so"
      }
    }
  }
}
 
def nativeBuildDependsOn(dependsOnTask, variant) {
  def buildTasks = tasks.findAll({ task ->
      !task.name.contains("Clean") && (task.name.contains("externalNative") || task.name.contains("CMake")) })
  if (variant != null) {
    buildTasks = buildTasks.findAll({ task -> task.name.contains(variant) })
  }
  buildTasks.forEach { task -> task.dependsOn(dependsOnTask) }
}
 
afterEvaluate {
  nativeBuildDependsOn(extractLibs, null)
}