setup-cpp icon indicating copy to clipboard operation
setup-cpp copied to clipboard

add mingw cross-compiler

Open abeimler opened this issue 3 years ago • 10 comments

Hi, I was experimenting with gcc-mingw for ubuntu and cross-compiling. So I added gcc-mingw-w64 into setup-cpp.

It seems to work in a docker container and builds. pnpm build && docker build -f ./dev/docker/ubuntu_node.mingw.dockerfile -t setup_cpp:ubuntu-mingw .

TODOs:

  • [x] ~~add powershell into setup-cpp - ./setup_cpp.js --powershell true (this is a task on it's own) [help wanted]~~ #105
    • need powershell for vcpkg (Could not find Z_VCPKG_BUILTIN_POWERSHELL_PATH using the following names powershell)
  • [x] add more platforms
    • [x] Arch Linux: install mingw-w64 via AUR (We need something like setupAURPack)
    • [x] Fedora: install mingw64-gcc
    • [x] Windows: uses the already existing installation
  • [ ] update alternatives and CC/CXX env. in Ubuntu ??? @aminya
    • Not sure about this one ... Do I really want to switch the compiler in on my HOST System ? (still good for docker and CI?)
  • [x] ~~setup toolchain for cmake~~ - https://github.com/aminya/project_options/issues/140
    • need to setup triplets -DVCPKG_TARGET_TRIPLET="x64-mingw-dynamic" for vcpkg and cmake toolchain -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="/home/cmake/x86_64-w64-mingw32-toolchain.cmake"
  • [ ] default version for Ubuntu etc. ??? - getVersion, DefaultUbuntuVersion, etc. @aminya
  • [x] spellchecker and formatting

image

Notes:

  • add new task in dev/cpp_vcpkg_project for testing
  mingw_build:
    - task: build_template
      vars:
        FEATURE_TESTS: OFF
        CMAKE_BUILD_TYPE: Release
        CONFIGURE_FLAGS: -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="/home/cmake/x86_64-w64-mingw32-toolchain.cmake" -DVCPKG_TARGET_TRIPLET="x64-mingw-dynamic"

abeimler avatar Jul 19 '22 23:07 abeimler

LLVM installations fail on Ubuntu 22. The reason is that the default versions for LLVM don't include Ubuntu 22

https://github.com/aminya/setup-cpp/blob/ff922a9c5eb9b5ab01c4fa359b4edbddd46fd92c/src/default_versions.ts#L26-L42

aminya avatar Jul 21 '22 18:07 aminya

Powershell support is added. Do you want to update this PR?

aminya avatar Aug 08 '22 18:08 aminya

Powershell support is added. Do you want to update this PR?

Yes ... Sry, I will update it later.

abeimler avatar Aug 18 '22 21:08 abeimler

Note Docker (ubuntu-20.04, ubuntu_node.mingw.dockerfile, 14, 6, 0) fails, cuz dev/cpp_vcpkg_project didn't have this task:

  mingw_build:
    - task: build_template
      vars:
        FEATURE_TESTS: OFF
        CMAKE_BUILD_TYPE: Release
        CONFIGURE_FLAGS: -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="/home/cmake/x86_64-w64-mingw32.toolchain.cmake" -DVCPKG_TARGET_TRIPLET="x64-mingw-dynamic"

I added it for Testing in my local repo

abeimler avatar Aug 18 '22 22:08 abeimler

I have some problems running yay (in the docker container)
ERROR: Running makepkg as root is not allowed as it can cause permanent, catastrophic damage to your system.

  // yay can't run as root, so skip update
  if (!didUpdate && aur != 'yay') {
    execRootSync(pacman, ["-Sy", "--noconfirm"])
    didUpdate = true
  }

  if (!didInit && aur != 'yay') {
    // install base-devel
    execRootSync(pacman, ["-Sy", "--noconfirm", "base-devel"])
    didInit = true
  }

I skip the update part, idk if this is OK. @aminya

I also did a big mistake in "update", change it to pacman -Sy .. x.x I'm sry

abeimler avatar Aug 18 '22 23:08 abeimler

Not an fedora user, just installed mingw with setupDnfPack("mingw64-gcc", version).

Have some problem building the example:

task: [build_template] cmake ./ -B ./build -G 'Ninja Multi-Config' -DCMAKE_BUILD_TYPE:STRING=Release -DFEATURE_TESTS:BOOL=OFF -DFEATURE_DOCS:BOOL='OFF' -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="/home/cmake/x86_64-w64-mingw32.toolchain.cmake" -DVCPKG_TARGET_TRIPLET="x64-mingw-dynamic"
-- vcpkg is already installed at /root/vcpkg.
-- Running vcpkg install
A suitable version of cmake was not found (required v3.24.0). Downloading portable cmake v3.24.0...
Downloading cmake...
  https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0-linux-x86_64.tar.gz -> /root/vcpkg/downloads/cmake-3.24.0-linux-x86_64.tar.gz
Extracting cmake...
Detecting compiler hash for triplet x64-linux...
error: while detecting compiler information:
The log file content at "/root/vcpkg/buildtrees/detect_compiler/stdout-x64-linux.log" is:
-- Found external ninja('1.11.0').
-- Configuring x64-linux-rel
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:96 (message):
    Command failed: /root/vcpkg/downloads/tools/cmake-3.24.0-linux/cmake-3.24.0-linux-x86_64/bin/cmake /root/vcpkg/scripts/detect_compiler -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/root/vcpkg/packages/detect_compiler_x64-linux -DCMAKE_MAKE_PROGRAM=/root/ninja/ninja -DCMAKE_SYSTEM_NAME=Linux -DBUILD_SHARED_LIBS=OFF -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/root/vcpkg/scripts/toolchains/linux.cmake -DVCPKG_TARGET_TRIPLET=x64-linux -DVCPKG_SET_CHARSET_FLAG=ON -DVCPKG_PLATFORM_TOOLSET=external -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE -DCMAKE_VERBOSE_MAKEFILE=ON -DVCPKG_APPLOCAL_DEPS=OFF -DCMAKE_TOOLCHAIN_FILE=/root/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON -DVCPKG_CXX_FLAGS= -DVCPKG_CXX_FLAGS_RELEASE= -DVCPKG_CXX_FLAGS_DEBUG= -DVCPKG_C_FLAGS= -DVCPKG_C_FLAGS_RELEASE= -DVCPKG_C_FLAGS_DEBUG= -DVCPKG_CRT_LINKAGE=dynamic -DVCPKG_LINKER_FLAGS= -DVCPKG_LINKER_FLAGS_RELEASE= -DVCPKG_LINKER_FLAGS_DEBUG= -DVCPKG_TARGET_ARCHITECTURE=x64 -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_BINDIR:STRING=bin -D_VCPKG_ROOT_DIR=/root/vcpkg -DZ_VCPKG_ROOT_DIR=/root/vcpkg -D_VCPKG_INSTALLED_DIR=/home/app/build/vcpkg_installed -DVCPKG_MANIFEST_INSTALL=OFF
    Working Directory: /root/vcpkg/buildtrees/detect_compiler/x64-linux-rel
    Error code: 1
    See logs for more information:
      /root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-CMakeCache.txt.log
      /root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-out.log
      /root/vcpkg/buildtrees/detect_compiler/config-x64-linux-rel-err.log

Call Stack (most recent call first):
  scripts/cmake/vcpkg_configure_cmake.cmake:328 (vcpkg_execute_required_process)
  scripts/detect_compiler/portfile.cmake:18 (vcpkg_configure_cmake)
  scripts/ports.cmake:147 (include)



error: vcpkg was unable to detect the active compiler's information. See above for the CMake failure output.
-- Running vcpkg install - failed
CMake Error at /root/vcpkg/scripts/buildsystems/vcpkg.cmake:860 (message):
  vcpkg install failed.  See logs for more information:
  /home/app/build/vcpkg-manifest-install.log
Call Stack (most recent call first):
  /root/cmake/cmake-3.23.2-linux-x86_64/share/cmake-3.23/Modules/CMakeDetermineSystem.cmake:124 (include)
  CMakeLists.txt:22 (project)

abeimler avatar Aug 18 '22 23:08 abeimler

Could you make a PR to add the MinGW toolchain in project_options?

aminya avatar Aug 20 '22 02:08 aminya

I fixed the docker builds and add fedora- and arch-linux-support. Seems to work when I test it with pnpm run test.docker.ubuntu.mingw, pnpm run test.docker.fedora.mingw and pnpm run test.docker.arch.mingw

abeimler avatar Oct 14 '22 11:10 abeimler

Could you make a PR to add the MinGW toolchain in project_options?

tbh I don't really know how, I can add a cmake/toolchains-folder, but then what. This needs to be done in https://github.com/aminya/project_options/issues/140

When using vcpkg, for a successful build I need to add some flags: -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="/home/cmake/toolchains/x86_64-w64-mingw32.toolchain.cmake" -DVCPKG_TARGET_TRIPLET="x64-mingw-dynamic" (idk about conan...)

abeimler avatar Oct 14 '22 11:10 abeimler

See my comment at https://github.com/aminya/project_options/issues/140#issuecomment-1283494365

aminya avatar Oct 19 '22 06:10 aminya

abeimler avatar Dec 29 '22 23:12 abeimler

Installing mingw (in linux) itself seems to work ... but installing powershell in arch or building the cpp example in fedora didn't work.

  1. Ubuntu-Mingw Build (+ powershell): image

  2. Arch-Mingw Build (without powershell): image

2.1. Arch-Mingw (+ powershell): image

  1. Fedora-Mingw (+ powershell): image image

abeimler avatar Jul 20 '23 11:07 abeimler

@aminya For the "arch linux + yay"-Problem, I would suggest to auto-detect some popular AUR-Helper/pacman wrapper.

A CLI option for arch-linux-user would be also nice:

--pacman-wrapper yay

abeimler avatar Jul 20 '23 11:07 abeimler

We can comment out the Fedora Mingw and Arch Mingw inside CI for now if the errors are not fixable.

aminya avatar Jul 21 '23 07:07 aminya

We can comment out the Fedora Mingw and Arch Mingw inside CI for now if the errors are not fixable.

agree, the powershell problem is a bug of its own and for the fedora error, I need to do more testing with project_options (MinGW installation works though)

abeimler avatar Jul 22 '23 08:07 abeimler