0

I want to use cpt to cross build several iOS packages with the arch "armv7", "armv8", "x86_64" and the build_type "Debug", "Release". But when the first package was testing, it broke my building with that "/bin/sh: bin/test_package: Bad CPU type in executable". I know I cannot run armv7 on my x86_64 host arch, but I do not want my building plan failed. How can I continue my building without testing the package or successfully testing my package.

I have checked my CMakeLists.txt and conanfile.py in my dir test_package, but I did not know how to fix that problem.

Here is part of the conanfile.py in test_package

def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def test(self):
        with tools.environment_append(RunEnvironment(self).vars):
            bin_path = os.path.join("bin", "test_package")
            self.run(bin_path, run_environment=True)

Here is my CMakeLists.txt in test_package

project(test_package)
cmake_minimum_required(VERSION 2.8.11)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})

Here is part of my build.py

builder = ConanMultiPackager()

    #  add builder settings with the arch and type of build
    def add_builder_settings(arch, build_type):
        requires = {"*": ["darwin-toolchain/1.0.4@theodelrieu/testing"]}
        options = {"darwin-toolchain:bitcode": False}
        builder.add(settings={"os": "iOS", "arch": arch, "build_type": build_type, "os.version": "10.0", "compiler": "apple-clang"},
                    build_requires=requires, options=options)

    # add build settings for iOS
    add_builder_settings("armv7", "Debug")
    add_builder_settings("armv7", "Release")
    add_builder_settings("armv8", "Debug")
    add_builder_settings("armv8", "Release")
    add_builder_settings("x86_64", "Debug")
    add_builder_settings("x86_64", "Release")

Here is my error report

libx264/20171211@username/stable (test package): Running test()
/bin/sh: bin/test_package: Bad CPU type in executable

I want to build 6 types of packages with one build.py. But it failed with building only one package.

1 Answers1

2

To avoid test_package execution when cross-building, I strongly recommend the Bincrafters idea:

from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "cmake"

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def test(self):
        if not tools.cross_building(self.settings):
            bin_path = os.path.join("bin", "test_package")
            self.run(bin_path, run_environment=True)

The idea here is skipping the execution and Conan detects that arch != build_arch.

You can take a look the in original code here:

https://github.com/bincrafters/templates/blob/master/default/test_package/conanfile.py#L15

uilianries
  • 3,363
  • 15
  • 28
  • Really appreciate that. I’m not very familiar with Conan now so I do not know that method. It was helpful and I solved that problem successfully. Thank you. – wangyushan Aug 17 '19 at 19:06