@@ -19,32 +19,43 @@ Pod::Spec.new do |s|
1919
2020 s . source = { :git => "https://github.com/margelo/react-native-quick-crypto.git" , :tag => "#{ s . version } " }
2121
22- # cocoapod for Sodium has not been updated for a while, so we need to build it ourselves
23- # https://github.com/jedisct1/swift-sodium/issues/264#issuecomment-2864963850
24- s . prepare_command = <<-CMD
25- # Create ios directory if it doesn't exist
26- mkdir -p ios
22+ sodium_enabled = ENV [ 'SODIUM_ENABLED' ] == '1'
23+ Pod ::UI . puts ( "[QuickCrypto] Has libsodium #{ sodium_enabled ? "enabled" : "disabled" } !" )
2724
28- # Download libsodium
29- curl -L -s -o ios/libsodium.tar.gz https://download.libsodium.org/libsodium/releases/libsodium-1.0.20-stable.tar.gz
25+ if sodium_enabled
26+ # cocoapod for Sodium has not been updated for a while, so we need to build it ourselves
27+ # https://github.com/jedisct1/swift-sodium/issues/264#issuecomment-2864963850
28+ s . prepare_command = <<-CMD
29+ # Create ios directory if it doesn't exist
30+ mkdir -p ios
3031
31- # Clean previous extraction
32- rm -rf ios/libsodium- stable
32+ # Download libsodium
33+ curl -L -s -o ios/libsodium.tar.gz https://download.libsodium.org/libsodium/releases/libsodium-1.0.20- stable.tar.gz
3334
34- # Extract the full tarball
35- tar -xzf ios/libsodium.tar.gz -C ios
35+ # Clean previous extraction
36+ rm -rf ios/libsodium-stable
3637
37- # Run configure and make to generate all headers including private ones
38- cd ios/libsodium-stable && \
39- ./configure --disable-shared --enable-static && \
40- make -j$(sysctl -n hw.ncpu)
38+ # Extract the full tarball
39+ tar -xzf ios/libsodium.tar.gz -C ios
4140
42- # Cleanup
43- cd ../../
44- rm -f ios/libsodium.tar.gz
45- CMD
41+ # Run configure and make to generate all headers including private ones
42+ cd ios/libsodium-stable && \
43+ ./configure --disable-shared --enable-static && \
44+ make -j$(sysctl -n hw.ncpu)
4645
47- s . source_files = [
46+ # Cleanup
47+ cd ../../
48+ rm -f ios/libsodium.tar.gz
49+ CMD
50+ else
51+ s . prepare_command = <<-CMD
52+ # Clean up libsodium files if they exist
53+ rm -rf ios/libsodium-stable
54+ rm -f ios/libsodium.tar.gz
55+ CMD
56+ end
57+
58+ base_source_files = [
4859 # implementation (Swift)
4960 "ios/**/*.{swift}" ,
5061 # ios (Objective-C++)
@@ -55,25 +66,35 @@ Pod::Spec.new do |s|
5566 "deps/**/*.{hpp,cpp}" ,
5667 # dependencies (C)
5768 "deps/**/*.{h,c}" ,
58- # libsodium sources
59- "ios/libsodium-stable/src/libsodium/**/*.{h,c}"
6069 ]
6170
62- s . pod_target_xcconfig = {
71+ if sodium_enabled
72+ base_source_files += [ "ios/libsodium-stable/src/libsodium/**/*.{h,c}" ]
73+ end
74+
75+ s . source_files = base_source_files
76+
77+ xcconfig = {
6378 # C++ compiler flags, mainly for folly.
6479 "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES" ,
6580 # Set C++ standard to C++20
6681 "CLANG_CXX_LANGUAGE_STANDARD" => "c++20" ,
67- # Header search paths for vendored libsodium
68- "HEADER_SEARCH_PATHS" => [
82+ "CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES" => "YES"
83+ }
84+
85+ if sodium_enabled
86+ sodium_headers = [
6987 "\" $(PODS_TARGET_SRCROOT)/ios/libsodium-stable/src/libsodium/include\" " ,
7088 "\" $(PODS_TARGET_SRCROOT)/ios/libsodium-stable/src/libsodium/include/sodium\" " ,
7189 "\" $(PODS_TARGET_SRCROOT)/ios/libsodium-stable\" " ,
7290 "\" $(PODS_ROOT)/../../packages/react-native-quick-crypto/ios/libsodium-stable/src/libsodium/include\" " ,
7391 "\" $(PODS_ROOT)/../../packages/react-native-quick-crypto/ios/libsodium-stable/src/libsodium/include/sodium\" "
74- ] . join ( ' ' ) ,
75- "CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES" => "YES"
76- }
92+ ]
93+ xcconfig [ "HEADER_SEARCH_PATHS" ] = sodium_headers . join ( ' ' )
94+ xcconfig [ "GCC_PREPROCESSOR_DEFINITIONS" ] = "$(inherited) BLSALLOC_SODIUM=1"
95+ end
96+
97+ s . pod_target_xcconfig = xcconfig
7798
7899 # Add all files generated by Nitrogen
79100 load "nitrogen/generated/ios/QuickCrypto+autolinking.rb"
0 commit comments