react-native-lingua 0.1.2 → 0.2.1

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.
package/Lingua.podspec CHANGED
@@ -15,50 +15,19 @@ Pod::Spec.new do |s|
15
15
 
16
16
  s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}"
17
17
  s.private_header_files = "ios/**/*.h"
18
- s.vendored_frameworks = "ios/*.xcframework"
19
18
 
20
- # Build Rust library from source during pod install
21
- s.prepare_command = <<-CMD
22
- set -e
23
-
24
- # Check if Rust is installed
25
- if ! command -v cargo &> /dev/null; then
26
- echo "❌ Error: Rust is not installed."
27
- echo "Please install Rust: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
28
- exit 1
29
- fi
30
-
31
- # Check if iOS targets are installed
32
- if ! rustup target list --installed | grep -q "aarch64-apple-ios"; then
33
- echo "❌ Error: iOS Rust targets not installed."
34
- echo "Please run: rustup target add aarch64-apple-ios aarch64-apple-ios-sim"
35
- exit 1
36
- fi
37
-
38
- # Build the xcframework
39
- cd rust
40
- make header
41
-
42
- # Build for iOS targets
43
- echo "Building Rust library for iOS..."
44
- cargo build --release --target aarch64-apple-ios
45
- cargo build --release --target aarch64-apple-ios-sim
46
-
47
- # Create xcframework
48
- mkdir -p generated/include
49
- xcodebuild -create-xcframework \
50
- -library target/aarch64-apple-ios/release/liblingua_native.a \
51
- -headers generated/include \
52
- -library target/aarch64-apple-ios-sim/release/liblingua_native.a \
53
- -headers generated/include \
54
- -output generated/liblingua_native.xcframework
55
-
56
- # Copy to ios directory
57
- cp -rf generated/*.xcframework ../ios/
58
- cp -f generated/include/liblingua.h ../cpp/
59
-
60
- echo "✅ Rust library built successfully"
61
- CMD
19
+ s.pod_target_xcconfig = {
20
+ 'LIBRARY_SEARCH_PATHS' => '"$(PODS_TARGET_SRCROOT)/ios/build"',
21
+ 'OTHER_LDFLAGS' => '-llingua_native'
22
+ }
23
+
24
+ s.script_phase = {
25
+ :name => 'Build Rust Library',
26
+ :script => 'bash "${PODS_TARGET_SRCROOT}/ios/build.sh"',
27
+ :execution_position => :before_compile,
28
+ :input_files => ['${PODS_TARGET_SRCROOT}/rust/src/**/*.rs', '${PODS_TARGET_SRCROOT}/rust/Cargo.toml'],
29
+ :output_files => ['${PODS_TARGET_SRCROOT}/ios/build/liblingua_native.a', '${PODS_TARGET_SRCROOT}/cpp/liblingua.h']
30
+ }
62
31
 
63
32
  install_modules_dependencies(s)
64
33
  end
package/README.md CHANGED
@@ -48,7 +48,7 @@ npm install react-native-lingua
48
48
  yarn add react-native-lingua
49
49
  ```
50
50
 
51
- The native libraries will be built automatically during `postinstall`.
51
+ The native libraries will be built automatically during the native build process (Xcode/Gradle).
52
52
 
53
53
  ### iOS Setup
54
54
 
@@ -98,10 +98,7 @@ task buildRust(type: Exec) {
98
98
  workingDir file("${projectDir}/../rust")
99
99
  commandLine 'make', 'android'
100
100
 
101
- // Only run if jniLibs don't exist
102
- onlyIf {
103
- !file("${projectDir}/jniLibs/arm64-v8a/liblingua_native.a").exists()
104
- }
101
+
105
102
 
106
103
  dependsOn buildRustHeader
107
104
  }
@@ -21,7 +21,7 @@ struct ConfidenceValue {
21
21
 
22
22
  extern "C" {
23
23
 
24
- void set_error(const char **err, const str *error_message);
24
+ void set_error(const char **err, const char *error_message);
25
25
 
26
26
  const char *get_error();
27
27
 
package/ios/build.sh ADDED
@@ -0,0 +1,73 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Setup path to rust/cargo
5
+ # Xcode doesn't load .zshrc/.bashrc, so we need to find cargo manually if not in PATH
6
+ export PATH="$HOME/.cargo/bin:$PATH"
7
+
8
+ if ! command -v cargo &> /dev/null; then
9
+ echo "error: Rust not found. Please install Rust: https://rustup.rs"
10
+ exit 1
11
+ fi
12
+
13
+ # Move to rust directory
14
+ TOOLS_DIR=$(cd "$(dirname "$0")/../rust" && pwd)
15
+ cd "$TOOLS_DIR"
16
+
17
+ echo "Building Rust library for ARCHS=$ARCHS PLATFORM_NAME=$PLATFORM_NAME"
18
+
19
+ LIBS=()
20
+
21
+ for ARCH in $ARCHS; do
22
+ TARGET=""
23
+ if [ "$PLATFORM_NAME" == "iphoneos" ]; then
24
+ if [ "$ARCH" == "arm64" ]; then
25
+ TARGET="aarch64-apple-ios"
26
+ fi
27
+ elif [ "$PLATFORM_NAME" == "iphonesimulator" ]; then
28
+ if [ "$ARCH" == "arm64" ]; then
29
+ TARGET="aarch64-apple-ios-sim"
30
+ elif [ "$ARCH" == "x86_64" ]; then
31
+ TARGET="x86_64-apple-ios"
32
+ fi
33
+ fi
34
+
35
+ if [ -z "$TARGET" ]; then
36
+ echo "warning: Unknown arch $ARCH for platform $PLATFORM_NAME, skipping"
37
+ continue
38
+ fi
39
+
40
+ echo "Building for $TARGET"
41
+ # Ensure target is added
42
+ rustup target add "$TARGET"
43
+
44
+ cargo build --release --target "$TARGET" --lib
45
+ LIBS+=("target/$TARGET/release/liblingua_native.a")
46
+ done
47
+
48
+ # Ensure header is generated and copied
49
+ HEADER_PATH="generated/include/liblingua.h"
50
+ # If header doesn't exist (maybe built fresh), force generation
51
+ if [ ! -f "$HEADER_PATH" ]; then
52
+ echo "Header generated/include/liblingua.h missing, forcing generation..."
53
+ mkdir -p generated/include
54
+ # Force build.rs to run by updating mtime of main source
55
+ touch src/lib.rs
56
+ cargo build --lib
57
+ fi
58
+
59
+ echo "Copying header to cpp/"
60
+ cp -f "$HEADER_PATH" "../cpp/liblingua.h"
61
+
62
+ # Link with Lipo
63
+ mkdir -p "../ios/build"
64
+ OUTPUT_LIB="../ios/build/liblingua_native.a"
65
+ rm -f "$OUTPUT_LIB"
66
+
67
+ if [ ${#LIBS[@]} -eq 0 ]; then
68
+ echo "error: No libraries built for ARCHS=$ARCHS"
69
+ exit 1
70
+ fi
71
+
72
+ echo "Creating universal library at $OUTPUT_LIB from ${LIBS[@]}"
73
+ lipo -create "${LIBS[@]}" -output "$OUTPUT_LIB"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-lingua",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "A lingua-rs wrapper for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -17,6 +17,7 @@
17
17
  "lib",
18
18
  "android",
19
19
  "ios/*.{h,mm}",
20
+ "ios/build.sh",
20
21
  "cpp",
21
22
  "rust/src",
22
23
  "rust/Cargo.toml",
@@ -31,6 +32,7 @@
31
32
  "!android/gradlew",
32
33
  "!android/gradlew.bat",
33
34
  "!android/local.properties",
35
+ "!android/jniLibs",
34
36
  "!cpp/liblingua.h",
35
37
  "!**/__tests__",
36
38
  "!**/__fixtures__",