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

add mingw cross-compiler #103

Merged
merged 15 commits into from Jul 24, 2023
Merged

add mingw cross-compiler #103

merged 15 commits into from Jul 24, 2023

Conversation

abeimler
Copy link
Contributor

@abeimler abeimler commented Jul 19, 2022

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:

  • add powershell into setup-cpp - ./setup_cpp.js --powershell true (this is a task on it's own) [help wanted] Add powershell tool #105
    • need powershell for vcpkg (Could not find Z_VCPKG_BUILTIN_POWERSHELL_PATH using the following names powershell)
  • add more platforms
    • Arch Linux: install mingw-w64 via AUR (We need something like setupAURPack)
    • Fedora: install mingw64-gcc
    • 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?)
  • setup toolchain for cmake - Add toolchain support project_options#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
  • 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"

@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.16)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather this be part of project_options

dev/docker/ubuntu_node.mingw.dockerfile Outdated Show resolved Hide resolved
@abeimler abeimler mentioned this pull request Jul 21, 2022
8 tasks
src/main.ts Outdated Show resolved Hide resolved
@aminya

This comment was marked as resolved.

@aminya
Copy link
Owner

aminya commented Aug 8, 2022

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

@abeimler
Copy link
Contributor Author

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

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

@abeimler
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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)

@aminya
Copy link
Owner

aminya commented Aug 20, 2022

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

@abeimler
Copy link
Contributor Author

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 abeimler marked this pull request as ready for review October 14, 2022 11:33
@abeimler abeimler changed the title WIP: add mingw cross-compiler add mingw cross-compiler Oct 14, 2022
@abeimler
Copy link
Contributor Author

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 aminya/project_options#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...)

@aminya
Copy link
Owner

aminya commented Oct 19, 2022

See my comment at aminya/project_options#140 (comment)

@abeimler abeimler changed the title add mingw cross-compiler WIP: add mingw cross-compiler Dec 28, 2022
@abeimler abeimler marked this pull request as draft December 28, 2022 11:48
* add docker mingw tests
* add node16 test
@abeimler
Copy link
Contributor Author

abeimler commented Dec 29, 2022

@abeimler abeimler marked this pull request as ready for review April 2, 2023 00:11
@abeimler abeimler changed the title WIP: add mingw cross-compiler add mingw cross-compiler Apr 2, 2023
@abeimler
Copy link
Contributor Author

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
Copy link
Contributor Author

@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

@aminya
Copy link
Owner

aminya commented Jul 21, 2023

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

@abeimler
Copy link
Contributor Author

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)

Copy link
Owner

@aminya aminya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@aminya aminya merged commit 14b5580 into aminya:master Jul 24, 2023
9 of 11 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants