Skip to content

Commit 9ded473

Browse files
authored
Merge pull request #39 from du33169/win-wheel
Building wheels for Windows (close #26)
2 parents 6661a90 + 5c86169 commit 9ded473

16 files changed

+436
-336
lines changed

.github/workflows/win_wheels.yml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Win-Wheels
2+
3+
on:
4+
push:
5+
# branches: [ devel ]
6+
tags: [ '*' ]
7+
workflow_dispatch:
8+
9+
jobs:
10+
build_win_wheels:
11+
name: Build ${{ matrix.cibw-only }} wheel
12+
13+
strategy:
14+
matrix:
15+
include:
16+
#windows wheels
17+
- cibw-only: cp38-win_amd64
18+
os: windows-latest
19+
- cibw-only: cp39-win_amd64
20+
os: windows-latest
21+
- cibw-only: cp310-win_amd64
22+
os: windows-latest
23+
- cibw-only: cp311-win_amd64
24+
os: windows-latest
25+
#linux wheels
26+
# - cibw-only: cp38-manylinux_x86_64
27+
# os: ubuntu-latest
28+
# - cibw-only: cp39-manylinux_x86_64
29+
# os: ubuntu-latest
30+
# - cibw-only: cp310-manylinux_x86_64
31+
# os: ubuntu-latest
32+
# - cibw-only: cp311-manylinux_x86_64
33+
# os: ubuntu-latest
34+
defaults:
35+
run: #
36+
shell: ${{ matrix.os == 'windows-latest' && 'msys2 {0}' || 'bash' }}
37+
38+
runs-on: ${{ matrix.os }}
39+
40+
steps:
41+
- name: Checkout source
42+
uses: actions/checkout@v4
43+
44+
- name: Set up MSYS2
45+
if: ${{ runner.os == 'Windows' }}
46+
uses: msys2/setup-msys2@v2
47+
with:
48+
release: false
49+
msystem: ucrt64
50+
install: make mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-gcc-fortran mingw-w64-ucrt-x86_64-gcc-libgfortran mingw-w64-ucrt-x86_64-gsl mingw-w64-ucrt-x86_64-zlib
51+
52+
- name: Set up Python
53+
id: setup-python
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: '3.11'
57+
update-environment: false
58+
59+
- name: replace '\' to '/' in python path, only effective on windows
60+
id: replace-path
61+
run: echo "py_path=$(echo "${{ steps.setup-python.outputs.python-path }}" | sed 's/\\/\//g')" >> $GITHUB_OUTPUT
62+
63+
- name: install cibuildwheel
64+
run: |
65+
${{ steps.replace-path.outputs.py_path }} -m pip install cibuildwheel
66+
67+
- name: Build binary wheels
68+
run: |
69+
echo "using python at: ${{ steps.replace-path.outputs.py_path }}"
70+
${{ steps.replace-path.outputs.py_path }} -m cibuildwheel --only ${{ matrix.cibw-only }}
71+
env:
72+
CIBW_TEST_SKIP: "*"
73+
74+
- name: Show built files
75+
run: ls -la wheelhouse
76+
77+
- uses: actions/upload-artifact@v4
78+
with:
79+
name: dist-wheels-${{ matrix.cibw-only }}
80+
path: ./wheelhouse/*.whl
81+

requirements/runtime.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
numpy>=1.23.2 ; python_version < '4.0' and python_version >= '3.11' # Python 3.11
2-
numpy>=1.21.6 ; python_version < '3.11' and python_version >= '3.10' # Python 3.10
3-
numpy>=1.21.6 ; python_version < '3.10' and python_version >= '3.9' # Python 3.9
4-
numpy>=1.21.6 ; python_version < '3.9' and python_version >= '3.8' # Python 3.8
1+
numpy>=1.23.2,<2 ; python_version < '4.0' and python_version >= '3.11' # Python 3.11
2+
numpy>=1.21.6,<2 ; python_version < '3.11' and python_version >= '3.10' # Python 3.10
3+
numpy>=1.21.6,<2 ; python_version < '3.10' and python_version >= '3.9' # Python 3.9
4+
numpy>=1.21.6,<2 ; python_version < '3.9' and python_version >= '3.8' # Python 3.8
55

66
joblib>=1.1.0
77
pyyaml>=5.4.1
88

99
fiona>=1.8.22 ; python_version < '4.0' and python_version >= '3.11' # Python 3.11+
1010
fiona>=1.8.21 ; python_version < '3.11'
1111

12-
scikit_learn>=1.1.3 ; python_version < '4.0' and python_version >= '3.11' # Python 3.11+
13-
scikit_learn>=1.1.1 ; python_version < '3.11' and python_version >= '3.10' # Python 3.10
12+
scikit_learn==1.1.3 ; python_version < '4.0' and python_version >= '3.11' # Python 3.11+
13+
scikit_learn==1.1.1 ; python_version < '3.11' and python_version >= '3.10' # Python 3.10
1414
scikit-learn>=0.24.2 ; python_version < '3.10' and python_version >= '3.9' # Python 3.9
1515
scikit-learn>=0.24.2 ; python_version < '3.9' and python_version >= '3.8' # Python 3.8
1616

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def parse_description():
8383
readme_fpath = join(dirname(__file__), "README.rst")
8484
# This breaks on pip install, so check that it exists.
8585
if exists(readme_fpath):
86-
with open(readme_fpath, "r") as f:
86+
with open(readme_fpath, "r",encoding='utf-8') as f:
8787
text = f.read()
8888
return text
8989
return ""
@@ -281,7 +281,7 @@ def gen_packages_items():
281281
setupkw["package_dir"] = {
282282
"": "src/python",
283283
}
284-
284+
setupkw["cmake_args"] = []+ (['-GMSYS Makefiles' ] if os.name == 'nt' else [])
285285
### <special non-xcookie generated code>
286286
setupkw['include_package_data'] = True
287287
setupkw['package_data'] = {

src/cxx/CMakeLists.txt

+39-74
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
option(BUILD_SCCD "Enable sccd c library" TRUE)
2-
if (BUILD_SCCD)
2+
set(THREADS_PREFER_PTHREAD_FLAG ON)
3+
4+
# Find required external libraries
5+
find_package(Threads REQUIRED)
6+
find_package(ZLIB REQUIRED)
7+
if(WIN32)
8+
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
9+
endif()
10+
find_package(GSL REQUIRED)
311

4-
set(THREADS_PREFER_PTHREAD_FLAG ON)
12+
enable_language(Fortran)
13+
# Corresponds to FFLAGS
14+
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g -fPIC")
515

6-
# Find required external libraries
7-
find_package(Threads REQUIRED)
8-
find_package(ZLIB REQUIRED)
9-
find_package(GSL REQUIRED)
16+
# Hacks:
17+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
1018

11-
# enable_language(Fortran)
12-
# Corresponds to FFLAGS
13-
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g -fPIC")
19+
add_library(GLMnet STATIC "GLMnet.f")
20+
21+
set(SCCD_MODULE_NAME "sccd")
22+
if (BUILD_SCCD)
1423

15-
# Hacks:
16-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
17-
18-
add_library(GLMnet STATIC "GLMnet.f")
1924
# set_target_properties(GLMnet PROPERTIES LINKER_LANGUAGE Fortran)
2025

21-
set(SCCD_MODULE_NAME "sccd")
2226
# Add other C sources
2327
list(APPEND sccd_sources "cold.c" "input.c" "2d_array.c" "utilities.c" "misc.c" "multirobust.c" "output.c" "s_ccd.c" "KFAS.c" "lbfgs.c" "distribution_math.c")
2428
## Create C++ library. Specify include dirs and link libs as normal
@@ -28,28 +32,6 @@ if (BUILD_SCCD)
2832
# I'm having trouble making the shared library work.
2933
add_library(${SCCD_MODULE_NAME} STATIC ${sccd_sources})
3034

31-
#target_include_directories(
32-
# ${SCCD_MODULE_NAME}
33-
# PUBLIC
34-
# ${NumPy_INCLUDE_DIRS}
35-
# ${PYTHON_INCLUDE_DIRS}
36-
# ${CMAKE_CURRENT_SOURCE_DIR}
37-
#)
38-
39-
#message(STATUS "ZLIB::ZLIB = ${ZLIB::ZLIB}")
40-
#message(STATUS "Threads::Threads = ${Threads::Threads}")
41-
message(STATUS "Threads = ${Threads}")
42-
43-
# LIB = -L$(GSL_SCI_LIB) -lz -lpthread -lgsl -lgslcblas -lgfortran -lm
44-
target_link_libraries(
45-
${SCCD_MODULE_NAME} PUBLIC
46-
ZLIB::ZLIB
47-
Threads::Threads
48-
GSL::gsl
49-
GSL::gslcblas
50-
GLMnet
51-
)
52-
5335
#target_compile_definitions(${SCCD_MODULE_NAME} PUBLIC
5436
# "NPY_NO_DEPRECATED_API"
5537
# #"NPY_1_7_API_VERSION=0x00000007"
@@ -65,54 +47,37 @@ if (BUILD_SCCD)
6547
#install(TARGETS ${SCCD_MODULE_NAME} LIBRARY DESTINATION "${_install_dest}../tool/python/pycold")
6648

6749
else() # build standalone program that accepts csv as input, mainly for testing purpose
68-
set(THREADS_PREFER_PTHREAD_FLAG ON)
69-
70-
# Find required external libraries
71-
find_package(Threads REQUIRED)
72-
find_package(ZLIB REQUIRED)
73-
find_package(GSL REQUIRED)
74-
75-
enable_language(Fortran)
7650

7751
set(CMAKE_BUILD_TYPE Debug)
7852

79-
# Corresponds to FFLAGS
80-
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g -fPIC")
81-
82-
# Hacks:
83-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
84-
85-
add_library(GLMnet STATIC "GLMnet.f")
8653
set_target_properties(GLMnet PROPERTIES LINKER_LANGUAGE Fortran)
8754

88-
89-
set(SCCD_MODULE_NAME "cold")
9055
# Add other C sources
9156
list(APPEND sccd_sources "cold.c" "input.c" "2d_array.c" "utilities.c" "misc.c" "multirobust.c" "output.c" "s_ccd.c" "KFAS.c" "lbfgs.c" "distribution_math.c" "sccd-desktop.c")
9257
## Create C++ library. Specify include dirs and link libs as normal
9358

9459
add_executable(${SCCD_MODULE_NAME} ${sccd_sources})
9560

96-
#target_include_directories(
97-
# ${SCCD_MODULE_NAME}
98-
# PUBLIC
99-
# ${NumPy_INCLUDE_DIRS}
100-
# ${PYTHON_INCLUDE_DIRS}
101-
# ${CMAKE_CURRENT_SOURCE_DIR}
102-
#)
103-
104-
#message(STATUS "ZLIB::ZLIB = ${ZLIB::ZLIB}")
105-
#message(STATUS "Threads::Threads = ${Threads::Threads}")
106-
message(STATUS "Threads = ${Threads}")
107-
108-
# LIB = -L$(GSL_SCI_LIB) -lz -lpthread -lgsl -lgslcblas -lgfortran -lm
109-
target_link_libraries(
110-
${SCCD_MODULE_NAME} PUBLIC
111-
ZLIB::ZLIB
112-
Threads::Threads
113-
GSL::gsl
114-
GSL::gslcblas
115-
GLMnet
116-
)
11761
endif()
11862

63+
#target_include_directories(
64+
# ${SCCD_MODULE_NAME}
65+
# PUBLIC
66+
# ${NumPy_INCLUDE_DIRS}
67+
# ${PYTHON_INCLUDE_DIRS}
68+
# ${CMAKE_CURRENT_SOURCE_DIR}
69+
#)
70+
71+
#message(STATUS "ZLIB::ZLIB = ${ZLIB::ZLIB}")
72+
#message(STATUS "Threads::Threads = ${Threads::Threads}")
73+
message(STATUS "Threads = ${Threads}")
74+
75+
# LIB = -L$(GSL_SCI_LIB) -lz -lpthread -lgsl -lgslcblas -lgfortran -lm
76+
target_link_libraries(
77+
${SCCD_MODULE_NAME} PUBLIC
78+
ZLIB::ZLIB
79+
Threads::Threads
80+
GSL::gsl
81+
GSL::gslcblas
82+
GLMnet
83+
)

0 commit comments

Comments
 (0)