Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Improve CMakeToolchain support for xcode flags #9448

Closed
danimtb opened this issue Aug 19, 2021 · 37 comments · Fixed by #10985
Closed

[feature] Improve CMakeToolchain support for xcode flags #9448

danimtb opened this issue Aug 19, 2021 · 37 comments · Fixed by #10985

Comments

@danimtb
Copy link
Member

danimtb commented Aug 19, 2021

Coming from conan-io/conan-center-index#5545

The darwing-toolchain generator recipe used to provide some useful configurable apple flags: https://github.com/ezored/conan-darwin-toolchain/blob/stable/1.3.0/conanfile.py#L87-L127

We should take a look at the cmake flags used there and see if we can improve the integration for cmake apple-clang projects

cc/ @theodelrieu @paulo-coutinho

@lasote
Copy link
Contributor

lasote commented Sep 1, 2021

To discuss:

  • About the bitcode: We could add a [conf] entry and improve the CMakeToolchain to set the corresponding variable. I suggest "tools.darwin:bitcode_generation_mode": "Activate the bitcode generation in OSX platfom: 'marker', 'bitcode'". I wouldn't couple it to CMake because it is a clang option on Darwin that could be used by other generators. Actually the CMAKE_XCODE_ATTRIBUTE_XXX are only applied when the generator is xcode, otherwise the bare cflags -fembed-bitcode-marker and -fembed-bitcode should be adjusted to the compiler flags somehow.

  • About the CLANG_ENABLE_OBJC_ARC, it only applies to objective C. Looks like something very specific, right? I would say then, why don't create [conf] entries for other cflags like sanitizers and so on? Not sure about the limit.

  • About the GCC_SYMBOLS_PRIVATE_EXTERN. Same comment, that eventually adjust the -fvisibility=hidden so, why supporting that flag and not others? Just because xcode allows it?

@memsharded

@memsharded
Copy link
Member

About the bitcode:

Yes, probably "tools.darwin:bitcode_generation_mode" => tools.apple:... to be more aligned with our namespaces.

About the CLANG_ENABLE_OBJC_ARC,

I have been trying to push the idea of generic CFLAGS, CXXFLAGS injection via [conf] for all integrations that will listen to them. Maybe it would be better to solve the generic flags problem?

@lasote
Copy link
Contributor

lasote commented Sep 2, 2021

I think yes, we should at least start by supporting something generic like cflags and see later if we create specific [conf] entries for higher-level stuff.

@lasote
Copy link
Contributor

lasote commented Sep 2, 2021

I'm moving this to Done as the look into of 1.40 and assigning to 1.41.

@a4z
Copy link
Contributor

a4z commented Sep 13, 2021

all apple cmake flags, like bitcode is very well handled by that: https://conan.io/center/ios-cmake
bitcode makes only sense for iOS, tvOS, watchOS, and there only for the target, not simulator

@theodelrieu
Copy link
Contributor

@a4z

and there only for the target, not simulator

Are you sure about that? I've used those flags for simulators as well.

@a4z
Copy link
Contributor

a4z commented Sep 13, 2021

I have written a linter for conan packages that checks the generated binaries if they contain bitcode, since I wanted to get that error after package creation, not on consumtion
Through that I detected that. Then I started to think about it and realized that it makes sense.
(I might add a blog entry on how to do that when I find the time)

The actually problem we have with the iOS/tvOS/watchOS build is that the conan docs are not mentioning the ios-cmake toolchain, and that recipes with custom/other builds need to handle that internal , openssl and libcurl for example. In doubt , they always should generate bitcode, because soon that will be required for devices anyway, and other builds do not care.
That said, I did not have time to look into the bitcode -> M1 relation, maybe apple sees the M1 as mobile device and it adds bitcode to the binary even if the target is BigSur

@a4z
Copy link
Contributor

a4z commented Sep 13, 2021

Addressed on problem and added some docs for the iOS toolchain,
conan-io/docs#2223

This should (hopefully) show and explain a bit more details

@paulocoutinhox
Copy link
Contributor

paulocoutinhox commented Sep 13, 2021

Hi,

Bitcode is only for apple recompile your application and delivery smaller size app (store or adhoc):
https://developer.apple.com/documentation/xcode/doing-basic-optimization-to-reduce-your-app-s-size

So, i've disabled it for simulators too:
https://github.com/ezored/ezored/blob/version-3/files/config/target_ios.py#L37

@a4z Your solution is good, be all flags need affect dependencies too. All options/flags from ios-cmake need be passed to all dependencies, like here:
https://github.com/ezored/ezored/blob/version-3/files/targets/ios/conan/profile/ezored_ios_profile#L8-L9

@a4z
Copy link
Contributor

a4z commented Sep 13, 2021

Yes, of course, you are supposed to rebuild all the conan packages you use with the same profiles, so all dependencies are compatible, but this is how you do it (hopefully) anyway with conan.

bitcode is required for watch and tvos, I think, for iOS it is optional (for now)

I think you do not need to omit the bitcode flag for the x86_64 simulator, it will just have no effect.
Not sure how the compilation on M1 behaves, would need have to check, but I would not be surprised if there would be bitcode in the simulator binaries, so omitting it there could make sense, or not, I do not think you gain a lot not using it

@lasote lasote self-assigned this Sep 14, 2021
@lasote
Copy link
Contributor

lasote commented Sep 14, 2021

Just for reference, the mentioned package https://conan.io/center/ios-cmake is using this project that provides a cmake toolchain for (iOS (+ Catalyst), watchOS, tvOS, and macOS) https://github.com/leetal/ios-cmake Almost 1000 stars. We should definitely take a look.

@lasote lasote removed their assignment Sep 14, 2021
@a4z
Copy link
Contributor

a4z commented Sep 14, 2021

Yes, ios-cmake is the defacto default to build native things since years when it comes to cmake, that's why I added it to the cci.

@lasote
Copy link
Contributor

lasote commented Sep 14, 2021

Note: Look into combine external toolchains with the conan one.

@a4z
Copy link
Contributor

a4z commented Sep 14, 2021

I am not sure what you referring to exactly

@lasote
Copy link
Contributor

lasote commented Sep 14, 2021

Internal note

@memsharded memsharded modified the milestones: 1.42, 1.43 Oct 26, 2021
@paulocoutinhox
Copy link
Contributor

paulocoutinhox commented Nov 24, 2021

Hi,

As I use my day-to-day compilation of things for Apple (iOS, watchOS, tvOS), mainly in the Ezored project (https://github.com/ezored/ezored) and several people and companies use my project and do the same thing as me, what makes the most sense is that the flags are passed to all libs at once, as you can't have one lib compiled with bitcode and one without, as this generates a compilation error. We've been doing this for years and I don't see why I keep setting these flags by dependencies, as they need to be for everyone.

Any news about this problem?

Thanks

@memsharded memsharded modified the milestones: 1.43, 1.44 Nov 30, 2021
@lasote lasote modified the milestones: 1.44, 1.45 Dec 28, 2021
@paulocoutinhox
Copy link
Contributor

Hi.

Any news about it?

Thanks.

@gegles
Copy link

gegles commented Jan 25, 2022

Yes, any updates? We desperately need to be able to build on iOS...

@paulocoutinhox
Copy link
Contributor

Hi @gegles,

I think no one has focus on it :(

What im doing to solve this problem is using the darwin-toolchain/1.5.0@ezored/stable in the recipe. It works.

Thanks.

@memsharded
Copy link
Member

Hi @gegles

This open issue is for some extra flags, but the standard support for Xcode is already there. We have tests in our tests suite that cross-compile for iOS and M1 for example:

So it is not that it is not possible to build for XCode, for OSX, iOS, but for more complete support for some things like CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE. So far it seems @paulo-coutinho mentioned ezored toolchain package can help with this.

This has been difficult to get some time to integrate in the CMakeToolchain, but it is in the backlog, hopefully we will be able to get some time for this soon.

@a4z
Copy link
Contributor

a4z commented Jan 26, 2022

I think no one has focus on it :(

not exactly true, for me things worked quite will on Mac, with the info I shared.

It is of course unfortunate that conan team decided to ignore the info I contributed as a PR to the conan docs,
so that based on that toolchains could be build up, but that's how it is.

However, the main question might be, what is your actual problem you need to solve and the solution is missing?

@gegles
Copy link

gegles commented Jan 26, 2022

Thanks @paulo-coutinho and @memsharded!

I was actually running into bitcode issues... but:

  • darwin-toolchain/1.5.0@ezored/stable overall seems to work for me now.
  • openssl/3.0.1 would not compile for me when using [options] darwin-toolchain:enable_bitcode=True
  • So I ended up disabling bitcode in my library and it seems to build fine now (at least on iOS)

My issues are now on the Android side of things... I cannot seem to make the [tool_requires]android-ndk/r22b (described in the docs) work at all, even though I am running the latest v1.44.1 conan... The tool_requires is not even recognized (profile: ConfigParser: Unrecognized field 'tool_requires' and when using build_requires I get this: android-ndk/r22: Invalid ID: os=Android is not supported by android-ndk (no binaries are available)

@paulocoutinhox
Copy link
Contributor

Hi @gegles,

I made a project that have all of this problem solved:
https://github.com/ezored/ezored

Im using openssl openssl/1.1.1k without problems with bitcode or other thing. I don't know what error you get for openssl 3.

Android things are built without problems too. My android profile on ezored:

include(default)

[settings]
os=Android
os.api_level=21
compiler=clang
compiler.version=11
compiler.libcxx=c++_static
arch=armv7

[build_requires]
*: android-ndk/r22

Maybe it help you.

@memsharded memsharded modified the milestones: 1.45, 1.46 Jan 30, 2022
@memsharded memsharded modified the milestones: 1.46, 1.47 Mar 2, 2022
@memsharded memsharded modified the milestones: 1.47, 1.48 Mar 29, 2022
@paulocoutinhox
Copy link
Contributor

Hi,

There is something new to this problem on recent releases?

Thanks.

@franramirez688
Copy link
Contributor

Hi @paulocoutinhox

I'm working on trying to bring those Xcode flags (based on conan-darwin-toolchain recipe) to CMakeToolchain directly. Still in progress but I hope we'll have something finished for the next Conan 1.48 version.

@lasote lasote changed the title [feature] Improve CMakeToolcahin support for xcode flags [feature] Improve CMakeToolchain support for xcode flags Apr 26, 2022
@memsharded
Copy link
Member

Implemented in #10985, will be in next 1.48

@paulocoutinhox
Copy link
Contributor

paulocoutinhox commented May 4, 2022

It was solved and is used in my new project:
https://nativium.github.io/

Thanks a lot!

@memsharded
Copy link
Member

Thanks for the feedback @paulocoutinhox !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants