margelo / react-native-quick-crypto

⚡️ A fast implementation of Node's `crypto` module written in C/C++ JSI
Other
699 stars 83 forks source link

iOS build fail faskpbkdf2.c openssl #361

Closed elsa17z closed 3 months ago

elsa17z commented 3 months ago

I am using Expo Development Build with EAS build

"react": "18.2.0",
"react-native": "0.73.6",
"react-native-quick-crypto": "0.7.0",
"expo": "~50.0.19",

I already tried adding specifying extraPods using expo-build-properties as suggested by https://stackoverflow.com/questions/29082174/ios-xcode-build-failing-due-to-openssl/76455587

        extraPods: [
          {
            name: "OpenSSL-Universal",
            configurations: ["Release"],
            modular_headers: true,
          },
        ],

Interestingly, even when I revert to 0.7.0-rc.5, which was previously working for me after testing, it failed

Tue, 02 Jul 2024 06:51:34 GMT › Compiling react-native-quick-crypto Pods/react-native-quick-crypto » fastpbkdf2.c

Tue, 02 Jul 2024 06:51:34 GMT ❌ (/Users/expo/Library/Developer/Xcode/DerivedData/SarmizaDev-dlxoxljtontrlmcvirjouaaufzoo/Build/Intermediates.noindex/ArchiveIntermediates/SarmizaDev/BuildProductsPath/Debug-iphoneos/XCFrameworkIntermediates/OpenSSL-Universal/OpenSSL.framework/Headers/e_os2.h:234:12)

232 | defined(osf) || defined(sgi) || defined(hpux) || \ 233 | defined(OPENSSL_SYS_VMS) || defined (OpenBSD)

234 | # include | ^ include of non-modular header inside framework module 'OpenSSL.e_os2': '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/inttypes.h' [-Werror,-Wnon-modular-include-in-framework-module] 235 | # undef OPENSSL_NO_INTTYPES_H 236 | / Because the specs say that inttypes.h includes stdint.h if present / 237 | # undef OPENSSL_NO_STDINT_H

Tue, 02 Jul 2024 06:51:34 GMT ❌ (node_modules/react-native-quick-crypto/cpp/fastpbkdf2/fastpbkdf2.c:23:10)

21 | #endif 22 |

23 | #include <openssl/sha.h> | ^ could not build module 'OpenSSL' 24 | 25 | / --- MSVC doesn't support C99 --- / 26 | #ifdef _MSC_VER

youssdevx commented 3 months ago

Same problem here, everything ok locally but when building on EAS, it fails

5o50 commented 3 months ago

Same problem here the build fails on EAS

› Compiling react-native-quick-crypto fastpbkdf2.c

❌  (/Users/expo/Library/Developer/Xcode/DerivedData/App-dpvtzyngqjkefhapdnqfaiblhvon/Build/Intermediates.noindex/ArchiveIntermediates/App/BuildProductsPath/Debug-iphoneos/XCFrameworkIntermediates/OpenSSL-Universal/OpenSSL.framework/Headers/e_os2.h:234:12)

  232 |      defined(__osf__) || defined(__sgi) || defined(__hpux) || \
  233 |      defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__)
> 234 | #  include <inttypes.h>
      |            ^ include of non-modular header inside framework module 'OpenSSL.e_os2': '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/inttypes.h' [-Werror,-Wnon-modular-include-in-framework-module]
  235 | #  undef OPENSSL_NO_INTTYPES_H
  236 | /* Because the specs say that inttypes.h includes stdint.h if present */
  237 | #  undef OPENSSL_NO_STDINT_H

❌  (../../node_modules/react-native-quick-crypto/cpp/fastpbkdf2/fastpbkdf2.c:23:10)

  21 | #endif
  22 | 
> 23 | #include <openssl/sha.h>
     |          ^ could not build module 'OpenSSL'
  24 | 
  25 | /* --- MSVC doesn't support C99 --- */
  26 | #ifdef _MSC_VER
› Compiling react-native-quick-crypto Pods/react-native-quick-crypto » MGLWebCrypto.cpp
⚠️  Script has ambiguous dependencies causing it to run on every build.
   To fix, go to: Xcode » App/App» Build Phases » 'Upload Debug Symbols to Sentry'
   Either: Uncheck "Based on dependency analysis", or select output files to trigger the script
    Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencie
▸ ** ARCHIVE FAILED **
▸ The following build commands failed:
▸   CompileC /Users/expo/Library/Developer/Xcode/DerivedData/App-dpvtzyngqjkefhapdnqfaiblhvon/Build/Intermediates.noindex/ArchiveIntermediates/App/IntermediateBuildFilesPath/Pods.build/Debug-iphoneos/react-native-quick-crypto.build/Objects-normal/arm64/fastpbkdf2.o /Users/expo/workingdir/build/node_modules/react-native-quick-crypto/cpp/fastpbkdf2/fastpbkdf2.c normal arm64 c com.apple.compilers.llvm.clang.1_0.compiler (in target 'react-native-quick-crypto' from project 'Pods')
▸ (1 failure)

package.json

 "react": "18.3.1",
 "react-native": "0.74.2",
 "react-native-quick-crypto": "^0.7.0",
 "expo": "^51.0.17",

also tried this in app.config.js without success

    [
      'expo-build-properties',
      {
        android: {
          packagingOptions: {
            pickFirst: [
              'lib/x86/libcrypto.so',
              'lib/x86_64/libcrypto.so',
              'lib/armeabi-v7a/libcrypto.so',
              'lib/arm64-v8a/libcrypto.so',
            ],
          },
        },
        ios: {
          useFrameworks: 'static',
          extraPods: [
            {
              name: 'OpenSSL-Universal',
              modular_headers: true,
              configurations: ['Debug', 'Release'],
            },
          ],
        },
      },
    ],

tried reverting to 0.7.0-rc.4 which was working before but it is not anymore

HellAsus commented 3 months ago

I have the same problem. EAS build failed. expo: 50.0.19 react-native-quick-crypto: 0.7.0-rc.9 and 0.7.0

hanwong commented 3 months ago

I just installed and built it and get the same error

"dependencies": {
    "react": "18.2.0",
    "react-native": "0.74.3",
    "react-native-quick-crypto": "^0.7.0"
  },
ishkash69 commented 3 months ago

any update on this???

elsa17z commented 3 months ago

Update: Implemented the solution suggested by https://github.com/krzyzanowskim/OpenSSL/issues/217 (script below, using @expo/config-plugins) however encountering another error, trying to fix now

Wed, 03 Jul 2024 10:14:40 GMT

⚠️ ld: Could not find or use auto-linked framework 'CoreAudioTypes': framework 'CoreAudioTypes' not found Wed, 03 Jul 2024 10:14:40 GMT

⚠️ ld: Could not find or use auto-linked framework 'OpenSSL': framework 'OpenSSL' not found Wed, 03 Jul 2024 10:14:40 GMT

❌ Undefined symbols for architecture arm64 ┌─ Symbol: _ASN1_INTEGER_get_int64 └─ Referenced from: margelo::GetRsaKeyDetail(facebook::jsi::Runtime&, std::__1::shared_ptr) in libreact-native-quick-crypto.a18 1630Wed, 03 Jul 2024 10:14:42 GMT ❌ ld: symbol(s) not found for architecture arm64

1631Wed, 03 Jul 2024 10:14:42 GMT ❌ clang: error: linker command failed with exit code 1 (use -v to see invocation)

const { withDangerousMod, withPlugins } = require("@expo/config-plugins");
const fs = require("fs");
const path = require("path");

const withNonModularIncludesFix = (config) => {
  return withDangerousMod(config, [
    "ios",
    (config) => {
      const podfilePath = path.join(
        config.modRequest.platformProjectRoot,
        "Podfile"
      );

      if (fs.existsSync(podfilePath)) {
        let podfileContents = fs.readFileSync(podfilePath, "utf-8");
        console.log("podfileContents", podfileContents);
        const postInstallRegex = /post_install do \|installer\|([\s\S]*?)end/;
        const clangSetting = `
  installer.pods_project.build_configuration_list.build_configurations.each do |configuration|
    configuration.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
  end`;

        if (postInstallRegex.test(podfileContents)) {
          // Append to existing post_install block
          podfileContents = podfileContents.replace(
            postInstallRegex,
            (match, group) =>
              `post_install do |installer|${group}${clangSetting}\nend`
          );
        } else {
          // Add a new post_install block
          const postInstallScript = `
post_install do |installer|${clangSetting}
end
`;
          podfileContents += postInstallScript;
        }

        fs.writeFileSync(podfilePath, podfileContents, "utf-8");
      } else {
        console.warn(`Podfile not found at ${podfilePath}`);
      }

      return config;
    },
  ]);
};

module.exports = (config) => {
  return withPlugins(config, [[withNonModularIncludesFix]]);
};
MehmoodArib commented 3 months ago

Hi , Open podfile.lock and set pod version

ishkash69 commented 3 months ago
  • (1.1.2200) thanks bro worked for me.
elsa17z commented 3 months ago

@MehmoodArib OpenSSL-Universal is set to 1.1.2200, the first error does not appear but the second does, same error as above

MehmoodArib commented 3 months ago

@MehmoodArib OpenSSL-Universal is set to 1.1.2200, the first error does not appear but the second does, same error as above

Not sure my version of "react-native-quick-crypto": "^0.6.1". you can try with this version

elsa17z commented 3 months ago

@MehmoodArib Currently on 0.7.0 and was previously using 0.7.0-rc.5, I don't dare downgrading that much, will wait for a better solution, thanks tho

elsa17z commented 3 months ago

@MehmoodArib I tried using ^0.6.1 and 1.1.2200, and it gave me this error instead

I don't think this is an error related to a version of OpenSSL-Universal, but possibly some weird linking issue, anyone else gotten the same error?

Wed, 03 Jul 2024 17:02:11 GMT

⚠️ ld: ignoring duplicate libraries: '-lc++' Wed, 03 Jul 2024 17:02:11 GMT

⚠️ ld: Could not find or use auto-linked framework 'CoreAudioTypes': framework 'CoreAudioTypes' not found Wed, 03 Jul 2024 17:02:11 GMT

⚠️ ld: Could not find or use auto-linked framework 'OpenSSL': framework 'OpenSSL' not found Wed, 03 Jul 2024 17:02:11 GMT

❌ Undefined symbols for architecture arm64 ┌─ Symbol: _BIO_ctrl └─ Referenced from: margelo::ParsePublicKeyPEM(std::__1::unique_ptr<evp_pkey_st, margelo::FunctionDeleter<evp_pkey_st, &EVP_PKEY_free>>, char const, int) in libreact-native-quick-crypto.a13 Wed, 03 Jul 2024 17:02:12 GMT

❌ ld: symbol(s) not found for architecture arm64 Wed, 03 Jul 2024 17:02:12 GMT

❌ clang: error: linker command failed with exit code 1 (use -v to see invocation)

devYonz commented 3 months ago

Hi , Open podfile.lock and set pod version

  • OpenSSL-Universal (1.1.2200) I was having the same issue with OpenSSL-Universal (3.1.5006)

Two additions: 1) No need to go that far back : 3.1.5004 works fine 2) You need to add this to Podfile because lock file alone won't do it:

target 'APPNAME' do
  use_expo_modules!
  config = use_native_modules!

  use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
  use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS']

  # Add this line to specify the version of OpenSSL-Universal
  pod 'OpenSSL-Universal', '3.1.5004'

When EAS executes a build it uses no-frozen-lockfile:

 [INSTALL_DEPENDENCIES] Running "pnpm install --no-frozen-lockfile" in /var/folders/12/jzrnnf0s6yzdp4f7gh1by3600000gn/T/eas-build-local-nodejs/30c9d4ad-9b75-4c90-9c7e-38f693660bce/build/mobile-app directory

So the podlockfile in the temp directory is still the 3.1.5006 version.

hanwong commented 3 months ago

Hi ,

Open podfile.lock and set pod version

  • OpenSSL-Universal (1.1.2200)

    I was having the same issue with OpenSSL-Universal (3.1.5006)

Thanks it's worked for me, how about another version in 3?

elsa17z commented 3 months ago

@hanwong 3.1.5004 works for me with react-native-quick-crypto 0.7.0, if you are using expo, you need to use expo-build-properties and specify the following, I wasn't specifying the Debug configuration and that's why it was failing

            extraPods: [
              {
                name: "OpenSSL-Universal",
                configurations: ["Release", "Debug"],
                modular_headers: true,
                version: "3.1.5004",
              },
            ],