SoftwareNetwork / sw

Software Manager. Build System, Build System Generator and Package Manager. C/C++ and other languages. Tools and libraries for Software Management.
https://software-network.org
Other
115 stars 23 forks source link

Error compiling for iOS arm64 from macOS arm64 #110

Closed Ottunger closed 1 year ago

Ottunger commented 1 year ago

Describe the bug Linked to https://github.com/SoftwareNetwork/sw/issues/100 : we've finalized months ago our build targetting android (on Windows, never got it to run on macOS) but I'd like to build for iOS now.

I'm therefore using the project https://github.com/leetal/ios-cmake to make an integration with XCode compiler into CMake. I've tested the build from both a bundled in CLion CMake and a complete separate CMake version. I use Ninja as XCode is not supported by sw.

The build fails as such (I see a -platform x64 in there that I don't like):

gregoire@Gregoires-MBP-2 satoris-ocr % /opt/homebrew/bin/cmake --build cmake-build-release --config Release
[1/5] sw: building dependencies
FAILED: CMakeFiles/sw_build_dependencies /Users/gregoire/dev/satoris-ocr/cmake-build-release/CMakeFiles/sw_build_dependencies 
cd /Users/gregoire/dev/satoris-ocr/cmake-build-release && /usr/local/bin/sw -static -platform x64 -compiler appleclang-14.0 -d /Users/gregoire/dev/satoris-ocr/cmake-build-release/.sw/cmake -config r build @/Users/gregoire/dev/satoris-ocr/cmake-build-release/.sw/cmake/sw.txt -ide-copy-to-dir /Users/gregoire/dev/satoris-ocr/cmake-build-release/Release -ide-fast-path /Users/gregoire/dev/satoris-ocr/cmake-build-release/.sw/cmake/deps/Release-90d1a046.deps
[1/4198] [org.sw.demo.openldap.ldap-2.6.3]/libraries/libldap/extended.c
[2/4198] [org.sw.demo.jxl-0.6.1]/lib/jxl/dec_external_image.cc
[3/4198] [org.sw.demo.badger.curl.libcurl-7.87.0]/lib/asyn-thread.c
[4/4198] [org.sw.demo.openssl.crypto-1.1.1.20]/crypto/pem/pem_x509.c
[5/4198] [org.sw.demo.oberhumer.lzo.lzo-2.10.0]/src/lzo1b_3.c
[6/4198] [org.sw.demo.jxl-0.6.1]/lib/jxl/jpeg/enc_jpeg_data_reader.cc
[7/4198] [org.sw.demo.facebook.zstd.zstd-1.5.4]/lib/compress/zstd_compress.c
[8/4198] [org.sw.demo.openssl.crypto-1.1.1.20]/crypto/aes/aes_wrap.c
[9/4198] [org.sw.demo.badger.curl.libcurl-7.87.0]/lib/pingpong.c
[11/4198] [org.sw.demo.openexr.IlmImf-2.5.8]/OpenEXR/IlmImf/ImfCompressionAttribute.cpp
[12/4198] [org.sw.demo.intel.opencv.imgproc-4.7.0]/modules/imgproc/src/resize.lasx.cpp
[13/4198] [org.sw.demo.openexr.IlmImf-2.5.8]/OpenEXR/IlmImf/ImfKeyCode.cpp
[14/4198] [org.sw.demo.openssl.crypto-1.1.1.20]/crypto/pem/pvkfmt.c
[15/4198] [org.sw.demo.openexr.ilmbase.IlmThread-2.5.8]/IlmBase/IlmThread/IlmThreadPool.cpp
[16/4198] [org.sw.demo.badger.curl.libcurl-7.87.0]/lib/vtls/hostcheck.c
[17/4198] [org.sw.demo.openssl.crypto-1.1.1.20]/crypto/ts/ts_rsp_print.c
[18/4198] [org.sw.demo.openssl.crypto-1.1.1.20]/crypto/x509/x509_ext.c
[19/4198] [org.sw.demo.madler.zlib-1.2.13]/crc32.c
[20/4198] [org.sw.demo.openssl.crypto-1.1.1.20]/crypto/ec/ecp_smpl.c
[22/4198] [org.sw.demo.oberhumer.lzo.lzo-2.10.0]/src/lzo_init.c
[23/4198] [org.sw.demo.openssl.crypto-1.1.1.20]/crypto/o_time.c
[25/4198] [org.sw.demo.openexr.IlmImf-2.5.8]/OpenEXR/IlmImf/ImfHeader.cpp
[26/4198] [org.sw.demo.intel.opencv.core-4.7.0]/modules/core/src/count_non_zero.dispatch.cpp
[27/4198] [org.sw.demo.openssl.crypto-1.1.1.20]/crypto/bn/bn_recp.c
[28/4198] [org.sw.demo.openssl.crypto-1.1.1.20]/crypto/asn1/a_object.c
[29/4198] [org.sw.demo.gnu.iconv.libcharset-1.16.0]/libcharset/lib/localcharset.c
[30/4198] [org.sw.demo.openssl.crypto-1.1.1.20]/crypto/asn1/a_utctm.c
[31/4198] [org.sw.demo.oberhumer.lzo.lzo-2.10.0]/src/lzo1x_1k.c
[34/4198] [org.sw.demo.webmproject.webp-1.2.4]/src/dsp/upsampling.c
[36/4198] [org.sw.demo.expat-2.5.0]/lib/xmlrole.c
[37/4198] [org.sw.demo.openexr.IlmImf-2.5.8]/OpenEXR/IlmImf/ImfStdIO.cpp
[38/4198] [org.sw.demo.xz_utils.lzma-5.4.0]/src/common/tuklib_physmem.c
Exception in file /Users/egor/dev/sw/src/sw/builder/command.cpp:840, function execute1: When executing: [org.sw.demo.intel.opencv.imgproc-4.7.0]/modules/imgproc/src/resize.lasx.cpp
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:88:27: error: unknown type name '__m256i'
                    const __m256i CV_DECL_ALIGNED(64) *addr = (__m256i*)(x_ofs + x);
                          ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:88:64: error: use of undeclared identifier '__m256i'
                    const __m256i CV_DECL_ALIGNED(64) *addr = (__m256i*)(x_ofs + x);
                                                               ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:88:72: error: expected expression
                    const __m256i CV_DECL_ALIGNED(64) *addr = (__m256i*)(x_ofs + x);
                                                                       ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:89:21: error: unknown type name '__m256i'
                    __m256i CV_DECL_ALIGNED(64) pixels = v256_lut_quads((schar *)S, (int *)addr).val;
                    ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:112:27: error: unknown type name '__m256i'
                    const __m256i CV_DECL_ALIGNED(64) *addr = (__m256i*)(x_ofs + x);
                          ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:112:64: error: use of undeclared identifier '__m256i'
                    const __m256i CV_DECL_ALIGNED(64) *addr = (__m256i*)(x_ofs + x);
                                                               ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:112:72: error: expected expression
                    const __m256i CV_DECL_ALIGNED(64) *addr = (__m256i*)(x_ofs + x);
                                                                       ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:113:21: error: unknown type name '__m256i'
                    __m256i CV_DECL_ALIGNED(64) pixels = v256_lut_quads((schar *)S, (int *)addr).val;
                    ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:151:15: error: unknown type name '__m256i'
        const __m256i CV_DECL_ALIGNED(64) shuffle_mask = _v256_set_b(15,14,11,10,13,12,9,8,7,6,3,2,5,4,1,0,
              ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:151:58: error: use of undeclared identifier '_v256_set_b'
        const __m256i CV_DECL_ALIGNED(64) shuffle_mask = _v256_set_b(15,14,11,10,13,12,9,8,7,6,3,2,5,4,1,0,
                                                         ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:153:15: error: unknown type name '__m256i'
        const __m256i CV_DECL_ALIGNED(64) permute_mask = _v256_set_w(7, 5, 3, 1, 6, 4, 2, 0);
              ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:153:58: error: use of undeclared identifier '_v256_set_w'
        const __m256i CV_DECL_ALIGNED(64) permute_mask = _v256_set_w(7, 5, 3, 1, 6, 4, 2, 0);
                                                         ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:168:27: error: unknown type name '__m256i'
                    const __m256i CV_DECL_ALIGNED(64) *addr = (__m256i*)(x_ofs + x);
                          ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:168:64: error: use of undeclared identifier '__m256i'
                    const __m256i CV_DECL_ALIGNED(64) *addr = (__m256i*)(x_ofs + x);
                                                               ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:168:72: error: expected expression
                    const __m256i CV_DECL_ALIGNED(64) *addr = (__m256i*)(x_ofs + x);
                                                                       ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:169:21: error: unknown type name '__m256i'
                    __m256i CV_DECL_ALIGNED(64) pixels1 = v256_lut_quads((schar *)S, (int *)addr).val;
                    ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:171:27: error: unknown type name '__m256i'
                    const __m256i CV_DECL_ALIGNED(64) *addr2 = (__m256i*)(x_ofs + x + 8);
                          ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:171:65: error: use of undeclared identifier '__m256i'
                    const __m256i CV_DECL_ALIGNED(64) *addr2 = (__m256i*)(x_ofs + x + 8);
                                                                ^
/Users/gregoire/.sw/storage/pkg/86/f0/9c6e/src/sdir/modules/imgproc/src/resize.lasx.cpp:171:73: error: expected expression
                    const __m256i CV_DECL_ALIGNED(64) *addr2 = (__m256i*)(x_ofs + x + 8);
                                                                        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
command failed: exit code = 1
Total errors: 1
ninja: build stopped: subcommand failed.

It has been configuerd without errors with

/opt/homebrew/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/Applications/CLion.app/Contents/bin/ninja/mac/ninja -G Ninja -DCMAKE_TOOLCHAIN_FILE=ios.toolchain.cmake -DPLATFORM=OS64 -S . -B cmake-build-release -DENABLE_BITCODE=FALSE

Expected behavior Build could create static libraries for import into an iOS project later.

To Reproduce Steps to reproduce the behavior:

  1. Use as CMakeLists.txt (my bet is that a single empty cpp file with a main will make the same error as the error is in building the libs)
    
    cmake_minimum_required(VERSION 3.22)
    project(satoris_ocr)

set(CMAKE_CXX_STANDARD 23) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif()

set(CMAKE_CXX_FLAGS "-Wall -Wextra")

set(CMAKE_CXX_FLAGS_DEBUG "-g")

set(CMAKE_CXX_FLAGS_RELEASE "-O2")

set(SW_DIR C:\Users\Ottunger\.sw\storage\etc\sw\static)

set(SW_BUILD_SHARED_LIBS 0) set(DEPENDENCIES org.sw.demo.google.tesseract.libtesseract-5.2.0 org.sw.demo.intel.opencv.videoio org.sw.demo.intel.opencv.imgcodecs org.sw.demo.intel.opencv.imgproc org.sw.demo.sqlite3 )

find_package(SW REQUIRED) sw_add_package(${DEPENDENCIES}) sw_execute()

file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

add_library(satoris_ocr STATIC process.cpp MRZBuilder.cpp ocr.cpp) target_link_libraries(satoris_ocr ${DEPENDENCIES} iphlpapi.lib)

add_library(satoris_ocr_shared SHARED process.cpp MRZBuilder.cpp ocr.cpp)

set_target_properties(satoris_ocr_shared PROPERTIES PUBLIC_HEADER "ocr.h;ocr_type.h")

target_link_libraries(satoris_ocr_shared ${DEPENDENCIES} iphlpapi.lib)

add_executable(satoris_ocr_exe main.cpp)

target_link_libraries(satoris_ocr_exe org.sw.demo.intel.opencv.imgcodecs iphlpapi.lib)

2. Configure and build using CMake as above 

**Information:**
 - Paste `sw --version` output.
```sh
gregoire@Gregoires-MBP-2 satoris-ocr % sw --version
sw.client.sw version 1.0.0
git revision 04536355191c090cecdaf978fd06fc2d09f26cf1
assembled on
14.12.2022 22:46:07 UTC
14.12.2022 23:46:07 CET
egorpugin commented 1 year ago

Do you have crash call stacks? Why do you think issue with sw checks rather than with some code?

Ottunger commented 1 year ago

I mean, I get "regular" buffer overflows. Which make methink not sufficiently large buffers are allocated, because we never actually ran checks on the device but copied the one from another target (a macOs laptop). Wouldn't that make sense?

egorpugin commented 1 year ago

What are "regular" overflows? Do you have stack traces? Is your host arm64 or x64?

Ottunger commented 1 year ago

OK, I think I found the problem with memory, I think it is indeed not related to sw build here!

Ottunger commented 1 year ago

I'm closing this as I can confirm my build is OK. Hope no one will need a more straightforward way than copying macOS checks.