Git Product home page Git Product logo

Comments (7)

AbrilRBS avatar AbrilRBS commented on July 18, 2024 1

Hi @ViliusSutkus89 thanks a lot for taking the time to report the issue, we appreciate it.

We'll take a look into this as soon as we can, you might be onto something :)

from conan.

ViliusSutkus89 avatar ViliusSutkus89 commented on July 18, 2024

I have a workaround in def generate(self): which sets the correct ENV vars for the toolchain, but it's not really fun applying that workaround to each affected package.

    def generate(self):
        tc = AutotoolsToolchain(self)
        # ...
        env = tc.environment()
        if cross_building(self) and self.settings.os == "Android":
            # NDK binary paths need to be supplied as posixpath, not os path, even on windows
            # This means no backslashes, because scripts in NDK don't like backslashes
            android_ndk_home = self.conf.get("tools.android:ndk_path").replace("\\", "/")

            target_host_triple = {
                "armv7": "armv7a-linux-androideabi",
                "armv8": "aarch64-linux-android",
                "x86": "i686-linux-android",
                "x86_64": "x86_64-linux-android",
            }[self.settings.get_safe("arch")]
            api_level = self.settings.os.get_safe("api_level")

            build_machine = "{}-x86_64".format({"Linux": "linux", "Macos": "darwin","Windows": "windows"}[str(self.settings_build.os)])

            toolchain = posixpath.join(android_ndk_home, "toolchains", "llvm", "prebuilt", build_machine, "bin")

            if self.settings_build.os == "Windows":
                executable_suffix = ".exe"
            else:
                executable_suffix = ""

            env.define("AR", posixpath.join(toolchain, "llvm-ar" + executable_suffix))
            env.define("AS", posixpath.join(toolchain, "llvm-as" + executable_suffix))
            env.define("RANLIB", posixpath.join(toolchain, "llvm-ranlib" + executable_suffix))
            env.define("CC", posixpath.join(toolchain, "{}{}-clang".format(target_host_triple, api_level)))
            env.define("CXX", posixpath.join(toolchain, "{}{}-clang++".format(target_host_triple, api_level)))
            env.define("LD", posixpath.join(toolchain, "ld" + executable_suffix))
            env.define("STRIP", posixpath.join(toolchain, "llvm-strip" + executable_suffix))

        tc.generate(env)

from conan.

ViliusSutkus89 avatar ViliusSutkus89 commented on July 18, 2024

I've ran into more autotools packages that I want to use, so instead of patching every single one of them, I've added the toolchain to my host profile:

{% set android_home = os.getenv("ANDROID_HOME") %}
{% set ndk_version = "26.3.11579264" %}
{% set api_level = "21" %}

[settings]
os=Android
os.api_level={{api_level}}
arch=armv8
build_type=RelWithDebInfo
compiler=clang
compiler.version=17
compiler.cppstd=20
compiler.libcxx=c++_static

[conf]
tools.android:ndk_path={{android_home}}/ndk/{{ndk_version}}

[buildenv]
AR={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
AS={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-as
RANLIB={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib
CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android{{api_level}}-clang
CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android{{api_level}}-clang++
LD={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/ld
STRIP={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip

CC and CXX are different for each abi:

CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi{{api_level}}-clang
CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi{{api_level}}-clang++
CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android{{api_level}}-clang
CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android{{api_level}}-clang++
CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android{{api_level}}-clang
CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android{{api_level}}-clang++

I still count this as a workaround, not a proper solution, because I would have to add it to host profiles of every downstream user of my Android libraries.

from conan.

ViliusSutkus89 avatar ViliusSutkus89 commented on July 18, 2024

(Corrected armv7 CC and CXX values in the previous comment)

from conan.

SpaceIm avatar SpaceIm commented on July 18, 2024

tools.android:ndk_path is not a silver bullet.

There is indeed some magic in CMakeToolchain & MesonToolchain when tools.android:ndk_path is set:

  • For CMakeToolchain, the path of CMake toolchain of Android NDK is deduced and injected
  • For MesonToolchain, paths to binaries are deduced in order to fill CC, CXX & AR

Except of that there is no magic, so your profile must provide these information. It's not really an issue for conancenter, but for conan client.
The confusion comes from the fact that this micro-management of Android NDK details has been implemented in some conan helpers and not in others, so there is now an expectation from users that it should work out of the box irrespective of underlying build system.

from conan.

ViliusSutkus89 avatar ViliusSutkus89 commented on July 18, 2024

Fully agree with the part that this is a conan client, not a conan center issue. Sorry about misfiling. Haven't looked much into conan client code yet, but I assume that it would be the correct place for a proper solution, not these profile workarounds.

from conan.

jcar87 avatar jcar87 commented on July 18, 2024

moving this to conan client -!

from conan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.