-
Notifications
You must be signed in to change notification settings - Fork 27
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
Custom command wrapping lipo to generate universal binaries in macOS #116
base: main
Are you sure you want to change the base?
Conversation
Hi @czoido ! As you may have read here or in the conan slack channel, I'm interested on creating my Macos application universal binary. From what I understand I must currently build 2 application bundles and then run lipo to create the final univeral bundle. Would you document here how I could benefit from your work ? |
Hi @MartinDelille! What this command does is to generate universal binaries for already existing binaries for multiple architectures by running
And then, if you want to get universal binaries to link with them in your application you can do something like:
What will give you all the dependencies in a full_deploy folder in separated folders by architecture. Then running:
Will iterate through all the files structure, looking for mach-o files and running This is really just a convenience wrapper, we don't have a model in Conan currently to manage binaries with multiple architecture while we are starting to investigate it. |
Thanks @czoido ! I managed to create the universal folder by fixing two typo 👍
I'm now wondering how I can use this folder for my application ? The |
Looks good to me. Although I'd love to see this available in Conan itself for other extensions: tools.apple.lipo? @MartinDelille unfortunately that's still an open research topic. One thing that got lost in these PRs was an example Xcode project. See here for older code with an example containing an Xcode project: The conan extension approach only goes as far as using conan to build universal libraries of your projects dependencies. If you're building macOS or iOS only app, this might be sufficient. I don't this solves the universal binary issue for many people, but it's an important first step and having this lipo code somewhere official is good too. See the longer discussion here to appreciate the difficulties: I intend to look into this further but haven't had a chance. I have a 1.0 wrapper with a cmake toolchain working (albeit quite ugly) and intend to figure out how to port it. Hopefully show that it's possible to do this with single architecture packages. |
@MartinDelille, as @gmeeker said, after generating the universal binaries, you have to manually add them to the solution you want to build as Conan does not have built-in support for universal binaries (we are currently investigating how to support them). One possible workaround is to modify the last generated config file, renaming the file and pointing the folders that point to the last deployed binaries to the folder where you created the universal binaries. You can find an example for the workaround in this repo. For a simple project that uses fmt:
CMakeLists.txt: cmake_minimum_required(VERSION 3.15)
project(example LANGUAGES CXX)
find_package(fmt REQUIRED CONFIG)
add_executable(example example.cpp)
target_compile_features(example PRIVATE cxx_std_14)
target_link_libraries(example PRIVATE fmt::fmt) conanfile.txt: [requires]
fmt/10.2.1
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout It could look similar to this
This is just a fast workaround to test, we will be doing some research to do this in Conan natively very soon. Hope this helps! |
Hi @czoido ! Sorry for not answering after your detailed explaination! This is unfortunately too complicated to integrate If I really need to support universal build, I'll build two application bundle and run lipo on it afterward outside of conan. |
Motivated by #52
Partially based on: #53 and #58
cc/ @gmeeker