Skip to content

Commit

Permalink
feature: add msys2 support for C-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Jan 6, 2024
1 parent 4e53f15 commit 70be6a3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/msys2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: MSYS2 Tests

on:
push:
branches-ignore:
- "dependabot/**"
pull_request:

jobs:
test:
name: Test with MSYS2 ${{ matrix.sys }}
runs-on: windows-2022
strategy:
matrix:
include:
- { sys: msys, toolchain: "gcc" }
- { sys: mingw64, env: mingw-w64-x86_64- }
- { sys: ucrt64, env: mingw-w64-ucrt-x86_64- }
- { sys: clang64, env: mingw-w64-clang-x86_64- }
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: 'Setup MSYS2'
uses: msys2/setup-msys2@v2
with:
msystem: ${{matrix.sys}}
update: true
install: >-
make
${{matrix.env}}cmake
${{matrix.env}}ninja
${{matrix.env}}${{matrix.toolchain || 'toolchain' }}
${{matrix.env}}python
${{matrix.env}}python-pip
${{matrix.env}}python-pytest
${{matrix.env}}python-setuptools
${{matrix.env}}python-typing_extensions
${{matrix.env}}python-wheel
- name: "Run tests"
shell: msys2 {0}
env:
CIBUILDWHEEL: 1
run: |
python -m pip install -v --no-build-isolation .
python -m pytest
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ Changelog
=========
Future
------
- Add MSYS2 support for C-extension
- Better logging on base64 build failure when C-extension build is optional
- Drop python 3.6 support

1.3.2
Expand Down
18 changes: 10 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
)


def get_cmake_extra_config(plat_name: str | None, build_type: str) -> list[str]:
def get_cmake_extra_config(plat_name: str | None, build_type: str) -> tuple[bool, list[str]]:
log.info("getting cmake extra config")
extra_config = []
machine = platform_module.machine().lower()
Expand All @@ -80,13 +80,14 @@ def get_cmake_extra_config(plat_name: str | None, build_type: str) -> list[str]:
log.info(" sysconfig LDFLAGS: %s", sysconfig.get_config_var("LDFLAGS"))

platform = plat_name or platform
is_msvc = platform.startswith("win")

if not IS_WINDOWS:
if not is_msvc:
extra_config.append(f"-DCMAKE_BUILD_TYPE={build_type}")

if IS_WINDOWS:
if not platform.startswith("win"):
msg = f"Building {platform} is not supported on Windows"
if is_msvc:
if not IS_WINDOWS:
msg = f"Building {platform} is only supported on Windows"
raise ValueError(msg)
# setup cross-compile
# assumes VS2019 or VS2022 will be used as the default generator
Expand Down Expand Up @@ -129,7 +130,7 @@ def get_cmake_extra_config(plat_name: str | None, build_type: str) -> list[str]:
else:
log.warning("`%s` is not a known value for CMAKE_OSX_ARCHITECTURES", arch)

return extra_config
return is_msvc, extra_config


def cmake(*args: str) -> None:
Expand Down Expand Up @@ -158,10 +159,11 @@ def base64_build(plat_name: str | None) -> Generator[bool, None, None]:
try:
try:
cmake("--version")
config_options.extend(get_cmake_extra_config(plat_name, build_type))
is_msvc, extra_config = get_cmake_extra_config(plat_name, build_type)
config_options.extend(extra_config)
cmake(*config_options)
cmake("--build", str(build_dir), "--config", build_type, "--verbose")
if IS_WINDOWS:
if is_msvc:
shutil.copyfile(build_dir / build_type / "base64.lib", build_dir / "base64.lib")
base64_built = True
except Exception as e:
Expand Down

0 comments on commit 70be6a3

Please sign in to comment.