scikit-build-core icon indicating copy to clipboard operation
scikit-build-core copied to clipboard

How to use gcc compiler on Github windows runners with microsoft visual studio installed

Open jiawlu opened this issue 1 year ago • 1 comments

I'm using scikit-build-core to build my c++ program on github windows runners. I would like to use gcc instead of microsoft visual studio as the compiler. Below is how I configure compiler settings in my program, but it does not work (see the log, MSVS was used)

Github workflow file

name: build-wheels

on:
  push:
    branches: [main]
  pull_request:
    branches: [main, release]
  workflow_dispatch:

jobs:
  build_wheels:
    name: Build wheel for ${{ matrix.buildplat[1] }}
    runs-on: ${{ matrix.buildplat[0] }}
    strategy:
      fail-fast: false
      matrix:
        buildplat:
          - [windows-2022, win_amd64]
        python: ["cp38"]
    steps:
      - uses: actions/checkout@v3

      - name: Build wheels for win
        if: ${{ contains(matrix.buildplat[1], 'win') }}
        uses: pypa/[email protected]
        env:
          CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
          CIBW_ENVIRONMENT_WINDOWS: >
            CC=gcc
            CXX=g++
            SKBUILD_CMAKE_ARGS="-DCMAKE_C_COMPILER=gcc;-DCMAKE_CXX_COMPILER=g++"

      - uses: actions/upload-artifact@v3
        with:
          path: ./wheelhouse/*.whl

pyproject.toml file

[project.urls]
"Source Code" = "https://github.com/jiawlu/OSM2GMNS"
"Bug Tracker" = "https://github.com/jiawlu/OSM2GMNS/issues"

[build-system]
requires = ["scikit-build-core>=0.9.0", "ninja>=1.0"]
build-backend = "scikit_build_core.build"

[project]
name = "osm2gmns"
version = "1.0.0dev1"

requires-python = ">=3.8"
dependencies = []

classifiers = [
  "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
  "Programming Language :: Python :: 3 :: Only",
  "Programming Language :: Python :: 3.8",
  "Programming Language :: Python :: 3.9",
  "Programming Language :: Python :: 3.10",
  "Programming Language :: Python :: 3.11",
  "Programming Language :: Python :: 3.12",
]


[tool.scikit-build]
wheel.packages = ["osm2gmns"]
wheel.install-dir = "osm2gmns"
wheel.expand-macos-universal-tags = true

cmake.version = ">=3.25"
cmake.args = ["-DBUILD_OSM2GMNS_EXE=OFF","-DCMAKE_C_COMPILER=gcc","-DCMAKE_CXX_COMPILER=g++","-GNinja"]
cmake.build-type = "Release"
cmake.verbose = true

sdist.include = [
    "docs",
    "python",
    "src"
]

sdist.exclude = [
  ".github",
  ".gitattributes",
  ".gitignore",
  "build"
]

[tool.cibuildwheel]
build = "*"
skip = "cp3{6,7}-*"

jiawlu avatar Jul 23 '24 16:07 jiawlu

Hmm, I would have thought that would work. You don't need CIBW_ENVIRONMENT_WINDOWS, you can just set the env vars directly. I'm not sure how well gcc works instead of MSVC when you are targeting the normal Windows CPython, it's not been officially supported since something like Python 3.3 from what I remember.

Do you have MinGW installed, though? In our tests (which build with the mingw, etc versions of Python), we have to install it: https://github.com/scikit-build/scikit-build-core/blob/8e892cec8ca87d83f4545e10ac49ef1b53b024af/.github/workflows/ci.yml#L216-L303

henryiii avatar Jul 29 '24 15:07 henryiii