theodelrieu / conan-darwin-toolchain

Conan build require to cross build to any darwin platform
MIT License
31 stars 21 forks source link

Handle universal/fat binaries #2

Open MathPlayer opened 6 years ago

MathPlayer commented 6 years ago

In Apple world it's quite common to have a binary with multiple architectures merged together. There is a conan issue discussing about a generic implementation. Since it's quite hard to find such an implementation, I was thinking that a particular, Apple specific one can be added as part of this package. If you agree, I can start working on something, using the examples from the mentioned issue.

ghost commented 6 years ago

Do you have an example that is working? I cannot find it anywhere.

theodelrieu commented 5 years ago

Sorry for the delay, I had notifications turned off on my own repo...

I'd like to see what you can come up with :), I resigned myself to using separate archs + a custom script invoking lipo, but we can still experiment.

paulocoutinhox commented 5 years ago

Any news about how to create it?

Whats the current solution? Create one profile for each arch and after join with lipo externally?

Thanks.

theodelrieu commented 5 years ago

Whats the current solution? Create one profile for each arch and after join with lipo externally?

This is currently what I'm doing. Although you can use a single profile and change the arch setting each time:

conan create . user/channel --profile ios -s arch=armv8

MathPlayer commented 5 years ago

The only thing I've found is that all archs for the same platform can be included in the same profile, maybe something like the following will work (example only for iOS):

diff --git a/conanfile.py b/conanfile.py
index dcfe743..3334407 100644
--- a/conanfile.py
+++ b/conanfile.py
@@ -48,6 +48,9 @@ class DarwinToolchainConan(ConanFile):
         if self.settings.os == "watchOS" and self.settings.arch == "armv8":
             darwin_arch = "arm64_32"

+        if self.settings.os == "iOS":
+            darwin_arch = ["arm64", "armv7"]
+
         xcrun = tools.XCRun(self.settings)
         sysroot = xcrun.sdk_path

@@ -67,10 +70,19 @@ class DarwinToolchainConan(ConanFile):

         # CMake issue, for details look https://github.com/conan-io/conan/issues/2378
         cflags = copy.copy(common_flags)
-        cflags.extend(["-arch", darwin_arch])
+        if self.settings.os != "iOS":
+            cflags.extend(["-arch", darwin_arch])
+        else:
+            for arch in darwin_arch:
+                cflags.extend(["-arch", arch])
+
         self.cpp_info.cflags = cflags
         link_flags = copy.copy(common_flags)
-        link_flags.append("-arch %s" % darwin_arch)
+        if self.settings.os != "iOS":
+            link_flags.append("-arch %s" % darwin_arch)
+        else:
+            for arch in darwin_arch:
+                link_flags.append("-arch %s" % arch)

         self.cpp_info.sharedlinkflags.extend(link_flags)
         self.cpp_info.exelinkflags.extend(link_flags)
paulocoutinhox commented 5 years ago

Will be nice implement array of arch, i agree.

In my tool i have created all steps to generate universal framework in our business: https://github.com/ezored/target-ios/blob/master/build/ezored_target.py#L191

Thanks anyway.

theodelrieu commented 5 years ago

Unfortunately, there is no way for a consumer to provide multiple archs to the recipe, this is a Conan limitation.

The toolchain could force all architectures as you mention, but there is no way to select only a few architectures (e.g. there are currently 5 architectures for iOS IIRC).

Furthermore, you'd have to find a way to set the package ID accordingly depending on the archs you used (to avoid colliding two packages built with armv8/armv7 and armv8/armv7s).

I think this issue should be reconsidered if Conan introduces support for multiple values' settings/options.

I would advise you to open an issue about this topic (or find an already opened one), there might be other use-cases for multiple values' settings than the one we're discussing here.

a4z commented 4 years ago

Will be nice implement array of arch, i agree.

In my tool i have created all steps to generate universal framework in our business: https://github.com/ezored/target-ios/blob/master/build/ezored_target.py#L191

Thanks anyway.

the link does not work anymore, but I found your repo @prsolucoes , ezored , looks interesting and could be exactly what I need to kick start me with conan (to which I am pretty new) for what I need, what is djiini + some things for android ios , so exactly what you prepared will test this now