theodelrieu / conan-android-ndk

Conan build requirement to cross build to Android with the Android NDK
MIT License
11 stars 7 forks source link

[OpenSSL] "Unsupported options: no-canonical-prefixes" #7

Open Linux13524 opened 5 years ago

Linux13524 commented 5 years ago

Description of Problem, Request, or Question

I am trying to build OpenSSL with this profile:

[settings]
os=Android
arch=armv7
os.api_level=21
compiler=clang
compiler.libcxx=libc++
compiler.version=7.0
build_type=Release
os_build=Linux
arch_build=x86_64

[build_requires]
android-ndk/r18@theodelrieu/testing

The command ./Configure android-armeabi -isystem/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sources/cxx-stl/llvm-libc++abi/include -isystem/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sources/cxx-stl/llvm-libc++/include -isystem/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sysroot/usr/include/arm-linux-androideabi --target=arm-none-linux-androideabi21 --sysroot=/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sysroot -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes --gcc-toolchain=/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -mfpu=neon -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -DNDEBUG -Oz -Wformat -Werror=format-security -Werror=implicit-function-declaration -O3 -fPIC --with-zlib-include="/home/lk/.conan/data/zlib/1.2.11/conan/stable/package/3fb95ed85ddddc32c8a68fbda3fc929cdd5c192b/include" --with-zlib-lib="/home/lk/.conan/data/zlib/1.2.11/conan/stable/package/3fb95ed85ddddc32c8a68fbda3fc929cdd5c192b/lib" results in the following error:

Failure!  build file wasn't produced.
Please read INSTALL and associated NOTES files.  You may also have to look over
your available compiler tool chain or change your configuration.

***** Unsupported options: no-canonical-prefixes

Related issue: openssl/openssl#3493

Package Details (Include if Applicable)

Steps to reproduce (Include if Applicable)

  1. Clone recipe:
    git clone https://github.com/conan-community/conan-openssl.git
    cd conan-openssl
  2. Create package:
    conan create . linux13524/testing -pr android_21_armeabi-v7a_clang -b missing

    To see the actual error message, I had to run the ./Configure command manually...

theodelrieu commented 5 years ago

Hello, I remember facing this issue. I will be able to work on it Monday though.

Thanks for the report.

Linux13524 commented 5 years ago

Do you know, why is the error not written to console by conan? I just get:

[...]
OpenSSL/1.1.1a@linux13524/testing: Calling build()
OpenSSL/1.1.1a@linux13524/testing: =====> Options:  --with-zlib-include="/home/lk/.conan/data/zlib/1.2.11/conan/stable/package/3fb95ed85ddddc32c8a68fbda3fc929cdd5c192b/include" --with-zlib-lib="/home/lk/.conan/data/zlib/1.2.11/conan/stable/package/3fb95ed85ddddc32c8a68fbda3fc929cdd5c192b/lib"
OpenSSL/1.1.1a@linux13524/testing: ------RUNNING-------
bash -l -c -o pipefail "./Configure android-arm -isystem/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sources/cxx-stl/llvm-libc++abi/include -isystem/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sources/cxx-stl/llvm-libc++/include -isystem/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sysroot/usr/include/arm-linux-androideabi --target=arm-none-linux-androideabi21 --sysroot=/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sysroot -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes --gcc-toolchain=/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -mfpu=neon -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -DNDEBUG -Oz -Wformat -Werror=format-security -Werror=implicit-function-declaration -O3 -fPIC --with-zlib-include=\"/home/lk/.conan/data/zlib/1.2.11/conan/stable/package/3fb95ed85ddddc32c8a68fbda3fc929cdd5c192b/include\" --with-zlib-lib=\"/home/lk/.conan/data/zlib/1.2.11/conan/stable/package/3fb95ed85ddddc32c8a68fbda3fc929cdd5c192b/lib\" | while read line; do printf \"%c\" .; done"OpenSSL/1.1.1a@linux13524/testing: 
OpenSSL/1.1.1a@linux13524/testing: ERROR: Package '534df50dac7c680f5f1cff0af81b32be7b5b5a24' build failed
OpenSSL/1.1.1a@linux13524/testing: WARN: Build folder /home/lk/.conan/data/OpenSSL/1.1.1a/linux13524/testing/build/534df50dac7c680f5f1cff0af81b32be7b5b5a24
ERROR: OpenSSL/1.1.1a@linux13524/testing: Error in build() method, line 83
    self.unix_build()
while calling 'unix_build', line 216
    self.run_in_src("./Configure %s %s" % (target, self._get_flags()), win_bash=win_bash)
while calling 'run_in_src', line 103
    self.run(command, win_bash=win_bash, output=buf)
    ConanException: Error 255 while executing bash -l -c -o pipefail "./Configure android-arm -isystem/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sources/cxx-stl/llvm-libc++abi/include -isystem/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sources/cxx-stl/llvm-libc++/include -isystem/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sysroot/usr/include/arm-linux-androideabi --target=arm-none-linux-androideabi21 --sysroot=/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sysroot -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes --gcc-toolchain=/home/lk/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -mfpu=neon -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -DNDEBUG -Oz -Wformat -Werror=format-security -Werror=implicit-function-declaration -O3 -fPIC --with-zlib-include=\"/home/lk/.conan/data/zlib/1.2.11/conan/stable/package/3fb95ed85ddddc32c8a68fbda3fc929cdd5c192b/include\" --with-zlib-lib=\"/home/lk/.conan/data/zlib/1.2.11/conan/stable/package/3fb95ed85ddddc32c8a68fbda3fc929cdd5c192b/lib\" | while read line; do printf \"%c\" .; done"

EDIT: Found it: The OpenSSL recipe disables it for clang compiler in this line.

theodelrieu commented 5 years ago

Hello,

I remember why this happens, according to the OpenSSL wiki single hyphen flags (e.g. -no-canonical-prefixes) gets the hyphen removed and added to CFLAGS.

One workaround would be to hack the recipe and add a + before the hyphen. It should only discard the + and pass -no-canonical-prefixes to the compiler.

I'd like to have a more elegant/effective way of solving the issue though, I'd suggest opening an issue on the OpenSSL recipe repo referencing this one, to get their opinion on the way to go.

maikelvdh commented 5 years ago

Alternative route is to supply to configure CPPFLAGS, CFLAGS and LDFLAGS in case of OpenSSL then you won't get bothered by the fact that the hyphens will be dropped. This does mean you would need to adapt the OpenSSL Conan recipe to deal with this specifically.

That is what I did in our company to prevent running into multiple issues with supporting OpenSSL in combination with the android toolchain.

Linux13524 commented 5 years ago

I opened the issue.. So when removing -no-canonical-prefixes or adding a + to it I get an other error unrelated to this option:

$ANDROID_NDK is not defined at (eval 9) line 26

This env variable should be added to the android-ndk recipe, right?

theodelrieu commented 5 years ago

You can go hack your local recipe in ~/.conan/data/android-ndk/r18/theodelrieu/testing/export/conanfile.py without recreating the package everytime.

I have vague memories of this error, and setting ANDROID_NDK to the ndk root path uncovered a new error IIRC.

I hope @maikelvdh has the right patch for it 😅

Linux13524 commented 5 years ago

You can go hack your local recipe in ~/.conan/data/android-ndk/r18/theodelrieu/testing/export/conanfile.py without recreating the package everytime.

Good to know. Thanks!

I hope @maikelvdh has the right patch for it 😅

I hope so too.. The hack with the + does not work for me: +-no-canonical-prefixes is passed to clang resulting in an error: no such file or directory. Seems like the + is not removed while configuring..

theodelrieu commented 5 years ago

Hmm, I guess you have to try that then:

Alternative route is to supply to configure CPPFLAGS, CFLAGS and LDFLAGS in case of OpenSSL then you won't get bothered by the fact that the hyphens will be dropped.

cajus commented 5 years ago

Hi! Just found this issue while trying to get the build for OpenSSL on Android running. @maikelvdh would you mind sharing what you changed in the OpenSSL reciepe to get it running?

I got it compiling after some time of tweaking, but now the linker claims that it can't find -ldl and -lc. For a static build. Gnaaaa.

@theodelrieu: just started with conan - before that, I used a make_standalone_toolchain.py generated toolchain for building OpenSSL. Maybe it can simplify things a bit?

theodelrieu commented 5 years ago

Hello, this is probably due to the double sysroots in NDK r18. They were unified in r19.

We are working with @SSE4 to overhaul this project by replacing it with this one, could you try with the testing/r19b branch?

We have still some tweaks to make but it should at least fix the linker error.

cajus commented 5 years ago

Thanks @theodelrieu for the quick answer. Just tried with reverted changes to my local copy of the OpenSSL reciepe. It has similar problems as this repo.

Sadly the Configure script of OpenSSL is trying to detect everything needed to set CC, CFLAGS, etc. by itself, depending on what it finds in the PATH:

OpenSSL/1.1.1b@bje/stable: ------RUNNING-------
bash -l -c -o pipefail "./Configure android-arm -O3 --sysroot=/home/cajus/.conan/data/android_ndk_installer/r19b/bje/stable/package/84fc5086d5b84ea42507b9623275f83e74452fe1/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -D__ANDROID_API__=21 no-asm no-engine no-ssl3 no-weak-ssl-ciphers no-zlib | while read line; do printf \"%c\" .; done"
no NDK arm-linux-androideabi-gcc on $PATH at (eval 9) line 124.

Finally I managed to build OpenSSL using https://github.com/bincrafters/conan-android_ndk_installer/tree/testing/r19b with two little hacks in the OpenSSL reciepe:

@@ -219,11 +219,26 @@ class OpenSSLConan(ConanFile):
         if self.settings.os == "Android":
             makefile = os.path.join(self.subfolder, "Makefile")

+            old_str = 'CROSS_COMPILE='
+            new_str = 'DISABLED_CROSS_COMPILE='
+            tools.replace_in_file(makefile, old_str, new_str, strict=self.in_local_cache)
+
+            old_str = '-mandroid'
+            new_str = ''
+            tools.replace_in_file(makefile, old_str, new_str, strict=self.in_local_cache)
+
     def unix_build(self):
         win_bash = sys.platform == "win32"
         target = self._get_target()

+        if self.settings.os == "Android":
+            old_str = 'die "no NDK $triarch-gcc on \$PATH";'
+            new_str = '-install_name '
+            tools.replace_in_file("%s/Configurations/15-android.conf" % self.subfolder, old_str, new_str,
+                              strict=self.in_local_cache)
+
         self.run_in_src("./Configure %s %s" % (target, self._get_flags()), win_bash=win_bash)
         self.run_in_src("make depend")

         self._patch_makefile()

That's not nice, but seems to produce something that passes the tests. Thanks for your help!

theodelrieu commented 5 years ago

I think there is a way to provide CC to it, but we will have to figure that out. Glad to hear!

Linux13524 commented 5 years ago

I also tried with bincrafters android-ndk-installer (r19b), but with OpenSSL version 1.0.2r and it works fine for me.