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

How would you cross compile x86/arm on x86_64 on all platforms? #118

Open
bwrsandman opened this issue Jul 13, 2023 · 4 comments
Open

How would you cross compile x86/arm on x86_64 on all platforms? #118

bwrsandman opened this issue Jul 13, 2023 · 4 comments

Comments

@bwrsandman
Copy link

Is there a straightforward way to use this action to cross compile using vcpkg triplets and not with chainload toolchains.

For the record, using android toolchains work pretty well.

I am using the Ninja Multi-Config generator

On windows

With -m32 and with -DCMAKE_SYSTEM_PROCESSOR=x86, it builds the dependencies alright but still tries to build in x64.

-- Running vcpkg install - done
-- The C compiler identification is MSVC 19.36.32535.0
-- The CXX compiler identification is MSVC 19.36.32535.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SDL2: optimized;D:/a/openblack/openblack/cmake-build-presets/ninja-multi-vcpkg/vcpkg_installed/x86-windows/lib/SDL2.lib;debug;D:/a/openblack/openblack/cmake-build-presets/ninja-multi-vcpkg/vcpkg_installed/x86-windows/debug/lib/SDL2d.lib  
-- Found PkgConfig: C:/Strawberry/perl/bin/pkg-config.bat (found version "0.26") 
-- Checking for module 'minizip'
--   Found minizip, version 1.2.13
CMake Error at vcpkg/scripts/buildsystems/vcpkg.cmake:855 (_find_package):
Error:   Could not find a configuration file for package "bgfx" that is compatible
  with requested version "".

  The following configuration files were considered but not accepted:

    D:/a/openblack/openblack/cmake-build-presets/ninja-multi-vcpkg/vcpkg_installed/x86-windows/share/bgfx/bgfxConfig.cmake, version: 1.118. (32bit)

Call Stack (most recent call first):
  CMakeLists.txt:101 (find_package)

On Linux

Seems like cmake is unable to find a good compiler after setting -m32

Generate project files with CMake
  Running command '/home/runner/work/_temp/1782060854/cmake-3.26.4-linux-x86_64/bin/cmake' with args '--preset,ninja-multi-vcpkg,-DOPENBLACK_WARNINGS_AS_ERRORS=ON,-DCMAKE_C_FLAGS=-m32,-DCMAKE_CXX_FLAGS=-m32,-DCMAKE_EXE_LINKER_FLAGS=-m32,-DCMAKE_SHARED_LINKER_FLAGS=-m32,-DCMAKE_SYSTEM_PROCESSOR=x86,-DVCPKG_TARGET_TRIPLET=x86-linux' in current directory '/home/runner/work/openblack/openblack'.
  Preset CMake variables:
  
    CMAKE_TOOLCHAIN_FILE:FILEPATH="/home/runner/work/openblack/openblack/vcpkg/scripts/buildsystems/vcpkg.cmake"
    OPENBLACK_USE_VCPKG:BOOL="TRUE"
  
  Preset environment variables:
  
    VCPKG_ROOT="./vcpkg"
  
  -- Running vcpkg install
  Detecting compiler hash for triplet x64-linux...
  Detecting compiler hash for triplet x86-linux...
  [LogCollection][Start]File:'/home/runner/work/openblack/openblack/vcpkg/buildtrees/detect_compiler/config-x86-linux-rel-out.log':
  -- The C compiler identification is GNU 11.3.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - failed
  -- Check for working C compiler: /usr/bin/cc
  -- Check for working C compiler: /usr/bin/cc - broken
  -- Configuring incomplete, errors occurred!
  
  [LogCollection][End]File:'/home/runner/work/openblack/openblack/vcpkg/buildtrees/detect_compiler/config-x86-linux-rel-out.log'.
  [LogCollection][Start]File:'/home/runner/work/openblack/openblack/vcpkg/buildtrees/detect_compiler/config-x86-linux-rel-err.log':
  CMake Error at /home/runner/work/_temp/1782060854/cmake-3.26.4-linux-x86_64/share/cmake-3.26/Modules/CMakeTestCCompiler.cmake:67 (message):
  Error:   The C compiler
  
      "/usr/bin/cc"
  
    is not able to compile a simple test program.
  
    It fails with the following output:
  
      Change Dir: /home/runner/work/openblack/openblack/vcpkg/buildtrees/detect_compiler/x86-linux-rel/CMakeFiles/CMakeScratch/TryCompile-y1svaO
      
      Run Build Command(s):/home/runner/work/_temp/1782060854/ninja-1.11.1.g95dee.kitware.jobserver-1_x86_64-linux-gnu/ninja -v cmTC_e1caf && [1/2] /usr/bin/cc   -fPIC  -m32 -o CMakeFiles/cmTC_e1caf.dir/testCCompiler.c.o -c /home/runner/work/openblack/openblack/vcpkg/buildtrees/detect_compiler/x86-linux-rel/CMakeFiles/CMakeScratch/TryCompile-y1svaO/testCCompiler.c
      [2/2] : && /usr/bin/cc -fPIC  -m32 -m32 CMakeFiles/cmTC_e1caf.dir/testCCompiler.c.o -o cmTC_e1caf   && :
      FAILED: cmTC_e1caf 
      : && /usr/bin/cc -fPIC  -m32 -m32 CMakeFiles/cmTC_e1caf.dir/testCCompiler.c.o -o cmTC_e1caf   && :
      /usr/bin/ld: cannot find Scrt1.o: No such file or directory
      /usr/bin/ld: cannot find crti.o: No such file or directory
      /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a when searching for -lgcc
      /usr/bin/ld: cannot find -lgcc: No such file or directory
      /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a when searching for -lgcc
      /usr/bin/ld: cannot find -lgcc: No such file or directory
      collect2: error: ld returned 1 exit status
      ninja: build stopped: subcommand failed.
      
      
  
    
  
    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:11 (enable_language)
  
@lukka
Copy link
Owner

lukka commented Jul 13, 2023

@bwrsandman by reading your log, the build on Windows and on Linux are failing in a way that is not what the action can help with, but it is up to you to setup the build correctly and to the runner's OS image to provide the proper toolsets.
If there is anything that run-vpckg can be doing, let me know, at the moment run-vcpkg does not try to be helpful to execute cross compiling. The only thing it does is to setup the environment on Windows by using the vcpkg env command that setups the environment according to the vcpkg's triplet in use.

@bwrsandman
Copy link
Author

Looks like it's the environment variable VCPKG_DEFAULT_TRIPLET that needs to be set alongside -DVCPKG_TARGET_TRIPLET.

Might I suggest that an option triplet that sets all that implicitly could make testing cross platform easier?

@lukka
Copy link
Owner

lukka commented Jul 16, 2023

@bwrsandman currently the documentation (both for run-cmake and run-vcpkg) states to set a default vcpkg triplet could be set using by adding the definition of the VCPKG_DEFAULT_TRIPLET env var, for example:
env: VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }}

Supposing we have a triplet input added for run-cmake, when it is specified by the user:

  • the VCPKG_DEFAULT_TRIPLET should be set to the same value (always overriding an existing value?).
    • Does it need to be set as "workflow-wide" environment variable, or only for the execution(s) of the cmake process?
  • the argument -DVCPKG_TARGET_TRIPLET=<triplet> must be passed to cmake. It this needed in any case?

@bwrsandman
Copy link
Author

I believe this only needs to be set when configuring and can be ignored if you're not cross compiling.
Setting the triplet is only for vcpkg libraries.
You're on your own for the main app you're building.
On linux you have to install the proper.
I find it very tricky but I got it all working https://github.com/openblack/openblack/pull/520/files

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

No branches or pull requests

2 participants