-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Minimal proof of concept of universal binaries support for CMakeToolchain #15775
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
Merged
memsharded
merged 19 commits into
conan-io:develop2
from
czoido:basic-universal-binaries-support
Mar 5, 2024
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
18c9e17
superbasic support for universal
czoido 4e1ff17
wip
czoido 127e091
minor changes
czoido e4b24f4
minor changes
czoido a204784
add mark
czoido 5e23e05
minor changes
czoido 476d722
improve function
czoido c3fc983
minor changes
czoido efdc76b
wip
czoido 433b618
wip
czoido 7fba92d
wip
czoido 0449bf7
minor changes
czoido 3bdc8a2
fix test
czoido 47dafe5
Merge branch 'develop2' into basic-universal-binaries-support
czoido c76c19f
put mark again
czoido d1dc7c0
Merge branch 'basic-universal-binaries-support' of github.com:czoido/…
czoido 5cdc3e4
review
czoido 2d8961c
protect for None arch
czoido 79abacf
Update conans/test/unittests/tools/apple/test_apple_tools.py
memsharded File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from conans.errors import ConanException | ||
|
||
universal_arch_separator = '|' | ||
|
||
|
||
def is_universal_arch(settings_value, valid_definitions): | ||
if settings_value is None or valid_definitions is None or universal_arch_separator not in settings_value: | ||
return False | ||
|
||
parts = settings_value.split(universal_arch_separator) | ||
|
||
if parts != sorted(parts): | ||
raise ConanException(f"Architectures must be in alphabetical order separated by " | ||
f"{universal_arch_separator}") | ||
|
||
valid_macos_values = [val for val in valid_definitions if ("arm" in val or "x86" in val)] | ||
czoido marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return all(part in valid_macos_values for part in parts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
conans/test/functional/toolchains/cmake/test_universal_binaries.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import os | ||
import platform | ||
import textwrap | ||
|
||
import pytest | ||
|
||
from conans.test.utils.tools import TestClient | ||
from conans.util.files import rmdir | ||
|
||
|
||
@pytest.mark.skipif(platform.system() != "Darwin", reason="Only OSX") | ||
@pytest.mark.tool("cmake", "3.23") | ||
def test_create_universal_binary(): | ||
client = TestClient() | ||
|
||
conanfile = textwrap.dedent(""" | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMake, cmake_layout | ||
class mylibraryRecipe(ConanFile): | ||
package_type = "library" | ||
generators = "CMakeToolchain" | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
exports_sources = "CMakeLists.txt", "src/*", "include/*" | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
self.run("lipo -info libmylibrary.a") | ||
|
||
def package(self): | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["mylibrary"] | ||
""") | ||
|
||
test_conanfile = textwrap.dedent(""" | ||
import os | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMake, cmake_layout | ||
from conan.tools.build import can_run | ||
|
||
class mylibraryTestConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "CMakeDeps", "CMakeToolchain" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def test(self): | ||
exe = os.path.join(self.cpp.build.bindir, "example") | ||
self.run(f"lipo {exe} -info", env="conanrun") | ||
""") | ||
|
||
client.run("new cmake_lib -d name=mylibrary -d version=1.0") | ||
client.save({"conanfile.py": conanfile, "test_package/conanfile.py": test_conanfile}) | ||
|
||
client.run('create . --name=mylibrary --version=1.0 ' | ||
'-s="arch=armv8|armv8.3|x86_64" --build=missing -tf=""') | ||
|
||
assert "libmylibrary.a are: x86_64 arm64 arm64e" in client.out | ||
|
||
client.run('test test_package mylibrary/1.0 -s="arch=armv8|armv8.3|x86_64"') | ||
|
||
assert "example are: x86_64 arm64 arm64e" in client.out | ||
|
||
client.run('new cmake_exe -d name=foo -d version=1.0 -d requires=mylibrary/1.0 --force') | ||
|
||
client.run('install . -s="arch=armv8|armv8.3|x86_64"') | ||
|
||
client.run_command("cmake --preset conan-release") | ||
client.run_command("cmake --build --preset conan-release") | ||
client.run_command("lipo -info ./build/Release/foo") | ||
|
||
assert "foo are: x86_64 arm64 arm64e" in client.out | ||
|
||
rmdir(os.path.join(client.current_folder, "build")) | ||
|
||
client.run('install . -s="arch=armv8|armv8.3|x86_64" ' | ||
'-c tools.cmake.cmake_layout:build_folder_vars=\'["settings.arch"]\'') | ||
|
||
client.run_command("cmake --preset \"conan-armv8|armv8.3|x86_64-release\" ") | ||
client.run_command("cmake --build --preset \"conan-armv8|armv8.3|x86_64-release\" ") | ||
client.run_command("lipo -info './build/armv8|armv8.3|x86_64/Release/foo'") | ||
|
||
assert "foo are: x86_64 arm64 arm64e" in client.out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.