@succinctlabs/react-native-zcam1 0.4.0-alpha.4 → 0.4.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,16 +16,23 @@ execute_process(
16
16
  # paths with Windows path separators.
17
17
  get_filename_component(UNIFFI_BINDGEN_PATH "${UNIFFI_BINDGEN_PATH}" DIRECTORY)
18
18
 
19
+ option(ZCAM1_ENABLE_PROVING "Enable proving support" OFF)
20
+
19
21
  # Specifies a path to native header files.
20
22
  include_directories(
21
23
  ../cpp
22
24
  ../cpp/generated
23
- ../cpp/proving
24
- ../cpp/proving/generated
25
25
 
26
26
  ${UNIFFI_BINDGEN_PATH}/cpp/includes
27
27
  )
28
28
 
29
+ if (ZCAM1_ENABLE_PROVING)
30
+ include_directories(
31
+ ../cpp/proving
32
+ ../cpp/proving/generated
33
+ )
34
+ endif()
35
+
29
36
  add_library(zcam1-sdk SHARED
30
37
  ../cpp/zcam1-sdk.cpp
31
38
  ../cpp/generated/zcam1_c2pa_utils.cpp
@@ -35,12 +42,14 @@ add_library(zcam1-sdk SHARED
35
42
  cpp-adapter.cpp
36
43
  )
37
44
 
38
- add_library(zcam1-proving SHARED
39
- ../cpp/proving/zcam1-proving.cpp
40
- ../cpp/proving/generated/zcam1_common.cpp
41
- ../cpp/proving/generated/zcam1_proving_utils.cpp
42
- cpp-adapter-proving.cpp
43
- )
45
+ if (ZCAM1_ENABLE_PROVING)
46
+ add_library(zcam1-proving SHARED
47
+ ../cpp/proving/zcam1-proving.cpp
48
+ ../cpp/proving/generated/zcam1_common.cpp
49
+ ../cpp/proving/generated/zcam1_proving_utils.cpp
50
+ cpp-adapter-proving.cpp
51
+ )
52
+ endif()
44
53
 
45
54
  # Set C++ compiler flags
46
55
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
@@ -62,14 +71,16 @@ cmake_path(
62
71
  add_library(my_rust_lib STATIC IMPORTED)
63
72
  set_target_properties(my_rust_lib PROPERTIES IMPORTED_LOCATION ${MY_RUST_LIB})
64
73
 
65
- cmake_path(
66
- SET MY_RUST_PROVING_LIB
67
- ${CMAKE_SOURCE_DIR}/src/main/jniProvingLibs/${ANDROID_ABI}/libzcam1_proving_bindings.a
74
+ if (ZCAM1_ENABLE_PROVING)
75
+ cmake_path(
76
+ SET MY_RUST_PROVING_LIB
77
+ ${CMAKE_SOURCE_DIR}/src/main/jniProvingLibs/${ANDROID_ABI}/libzcam1_proving_bindings.a
68
78
 
69
- NORMALIZE
70
- )
71
- add_library(my_rust_proving_lib STATIC IMPORTED)
72
- set_target_properties(my_rust_proving_lib PROPERTIES IMPORTED_LOCATION ${MY_RUST_PROVING_LIB})
79
+ NORMALIZE
80
+ )
81
+ add_library(my_rust_proving_lib STATIC IMPORTED)
82
+ set_target_properties(my_rust_proving_lib PROPERTIES IMPORTED_LOCATION ${MY_RUST_PROVING_LIB})
83
+ endif()
73
84
 
74
85
  # Add ReactAndroid libraries, being careful to account for different versions.
75
86
  find_package(ReactAndroid REQUIRED CONFIG)
@@ -85,16 +96,20 @@ endif()
85
96
  # This if-then-else can be removed once this library does not support version below 0.76
86
97
  if (REACTNATIVE_MERGED_SO)
87
98
  target_link_libraries(zcam1-sdk ReactAndroid::reactnative)
88
- target_link_libraries(zcam1-proving ReactAndroid::reactnative)
99
+ if (ZCAM1_ENABLE_PROVING)
100
+ target_link_libraries(zcam1-proving ReactAndroid::reactnative)
101
+ endif()
89
102
  else()
90
103
  target_link_libraries(zcam1-sdk
91
104
  ReactAndroid::turbomodulejsijni
92
105
  ReactAndroid::react_nativemodule_core
93
106
  )
94
- target_link_libraries(zcam1-proving
95
- ReactAndroid::turbomodulejsijni
96
- ReactAndroid::react_nativemodule_core
97
- )
107
+ if (ZCAM1_ENABLE_PROVING)
108
+ target_link_libraries(zcam1-proving
109
+ ReactAndroid::turbomodulejsijni
110
+ ReactAndroid::react_nativemodule_core
111
+ )
112
+ endif()
98
113
  endif()
99
114
 
100
115
  find_package(fbjni REQUIRED CONFIG)
@@ -105,10 +120,12 @@ target_link_libraries(
105
120
  ${LOGCAT}
106
121
  my_rust_lib
107
122
  )
108
- target_link_libraries(
109
- zcam1-proving
110
- fbjni::fbjni
111
- ReactAndroid::jsi
112
- ${LOGCAT}
113
- my_rust_proving_lib
114
- )
123
+ if (ZCAM1_ENABLE_PROVING)
124
+ target_link_libraries(
125
+ zcam1-proving
126
+ fbjni::fbjni
127
+ ReactAndroid::jsi
128
+ ${LOGCAT}
129
+ my_rust_proving_lib
130
+ )
131
+ endif()
@@ -23,6 +23,26 @@ def getPackageVersion() {
23
23
  return packageJson.version
24
24
  }
25
25
 
26
+ // Proving is opt-in.
27
+ //
28
+ // Enable proving in one of these ways:
29
+ //
30
+ // 1) Environment variable (works for Expo + non-Expo):
31
+ // ZCAM1_ENABLE_PROVING=1 ./gradlew ...
32
+ //
33
+ // 2) gradle.properties (recommended for Expo plugins):
34
+ // android/gradle.properties:
35
+ // enableProving=true
36
+ //
37
+ def isProvingEnabled() {
38
+ def fromEnv = System.getenv("ZCAM1_ENABLE_PROVING")
39
+ if (fromEnv == "1" || fromEnv?.toLowerCase() == "true") return true
40
+ def fromProps = rootProject.findProperty("enableProving") ?: project.findProperty("enableProving")
41
+ return fromProps == "true" || fromProps == true
42
+ }
43
+
44
+ def enableProving = isProvingEnabled()
45
+
26
46
  task downloadJniLibs {
27
47
  def version = getPackageVersion()
28
48
  def baseUrl = "https://github.com/succinctlabs/zcam1-sdk/releases/download/react-native-zcam1-v${version}"
@@ -36,7 +56,12 @@ task downloadJniLibs {
36
56
  // - dir present, marker absent → Yalc/local dev (package includes JNI libs), skip
37
57
  // - dir present, marker present, version differs → re-download (public npm upgrade)
38
58
  // - dir present, marker present, version matches → already up to date, skip
39
- [Zcam1Jni: jniLibsDir, Zcam1ProvingJni: jniLibsProvingDir].each { name, dir ->
59
+ def libs = [Zcam1Jni: jniLibsDir]
60
+ if (enableProving) {
61
+ libs["Zcam1ProvingJni"] = jniLibsProvingDir
62
+ }
63
+
64
+ libs.each { name, dir ->
40
65
  def zipName = "${name}.zip"
41
66
  def zipUrl = "${baseUrl}/${zipName}"
42
67
 
@@ -72,6 +97,23 @@ task downloadJniLibs {
72
97
 
73
98
  afterEvaluate {
74
99
  preBuild.dependsOn downloadJniLibs
100
+ // CMake build tasks don't depend on preBuild, so explicitly wire them to
101
+ // downloadJniLibs so the .a files are present before ninja links against them.
102
+ tasks.configureEach { task ->
103
+ if (task.name.startsWith("buildCMake") || task.name.startsWith("configureCMake")) {
104
+ task.dependsOn downloadJniLibs
105
+ }
106
+ }
107
+
108
+ // The React Native gradle plugin does not wire the app's configureCMake task to depend
109
+ // on this module's generateCodegenArtifactsFromSchema, so on a fresh npm install the
110
+ // app's CMake configuration fails because the codegen JNI directory doesn't exist yet.
111
+ // Fix: make every app:configureCMake* task depend on our codegen task.
112
+ rootProject.findProject(":app")?.tasks?.configureEach { task ->
113
+ if (task.name.startsWith("configureCMake")) {
114
+ task.dependsOn tasks.named("generateCodegenArtifactsFromSchema")
115
+ }
116
+ }
75
117
  }
76
118
 
77
119
  def reactNativeArchitectures() {
@@ -132,7 +174,7 @@ android {
132
174
  }
133
175
  externalNativeBuild {
134
176
  cmake {
135
- arguments '-DANDROID_STL=c++_shared'
177
+ arguments '-DANDROID_STL=c++_shared', "-DZCAM1_ENABLE_PROVING=${enableProving ? '1' : '0'}"
136
178
  abiFilters (*reactNativeArchitectures())
137
179
  }
138
180
  }
package/app.plugin.js CHANGED
@@ -1,11 +1,29 @@
1
1
  import ConfigPlugins from "@expo/config-plugins";
2
- const { withPodfileProperties } = ConfigPlugins;
2
+ const { withPodfileProperties, withGradleProperties } = ConfigPlugins;
3
+
3
4
  function withZcam1Sdk(config, props) {
4
5
  const enableProving = !!(props && props.enableProving);
5
- return withPodfileProperties(config, (config) => {
6
+
7
+ // iOS: write to Podfile.properties.json (read by Zcam1Sdk.podspec)
8
+ config = withPodfileProperties(config, (config) => {
6
9
  config.modResults.enableProving = enableProving ? "true" : "false";
7
10
  return config;
8
11
  });
12
+
13
+ // Android: write to gradle.properties (read by build.gradle)
14
+ config = withGradleProperties(config, (config) => {
15
+ config.modResults = config.modResults.filter(
16
+ (item) => !(item.type === "property" && item.key === "enableProving")
17
+ );
18
+ config.modResults.push({
19
+ type: "property",
20
+ key: "enableProving",
21
+ value: enableProving ? "true" : "false",
22
+ });
23
+ return config;
24
+ });
25
+
26
+ return config;
9
27
  }
10
28
 
11
29
  export { withZcam1Sdk as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@succinctlabs/react-native-zcam1",
3
- "version": "0.4.0-alpha.4",
3
+ "version": "0.4.0-alpha.5",
4
4
  "description": "ZCAM1 SDK",
5
5
  "main": "./lib/module/index.js",
6
6
  "codegenConfig": {