Skip to content

Commit e7acb45

Browse files
committed
Build to wheel on Windows
1 parent ea4b1c0 commit e7acb45

File tree

2 files changed

+104
-5
lines changed

2 files changed

+104
-5
lines changed

buildfiles/pypi/build_wheels.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Building das2py PYPI wheels
2+
3+
Here's a command line summary of what needs to be done by operating system. Includes
4+
das2C steps, since they are important.
5+
6+
## Windows
7+
8+
First get a compiler, see das2C project file
9+
[install_visual_studio](https://github.com/das-developers/das2C/blob/master/notes/install_visual_studio.txt) for help on this error prone task.
10+
11+
```batch
12+
rem clone repos
13+
14+
git clone [email protected]:microsoft/vcpkg.git
15+
git clone [email protected]:das-developers/das2C.git
16+
git clone [email protected]:das-developers/das2py.git
17+
18+
rem Initialize visual studio tools
19+
vcvarsall.bat x64
20+
21+
rem build vcpkg
22+
cd vcpkg
23+
.\boostrap-vcpkg.bat -disableMetrics
24+
.\vcpk install openssl fftw3 expat pthreads --trilet x64-windows-static
25+
cd ..\
26+
27+
rem build das2C
28+
cd das2C
29+
git checkout tags/v2.3.0
30+
set VCPKG_ROOT=C:\Users\you\git\vcpkg # Adjust as needed
31+
set LIBRARY_INC=%VCPKG_ROOT%\installed\x64-windows-static\include
32+
set LIBRARY_LIB=%VCPKG_ROOT%\installed\x64-windows-static\lib
33+
34+
nmake.exe /nologo /f buildfiles\Windows.mak build
35+
nmake.exe /nologo /f buildfiles\Windows.mak run_test
36+
cd ..\
37+
38+
rem build das2py (reuses VCPKG_ROOT setting from above)
39+
cd das2py
40+
git checkout tags/v2.3.0 # Or stay on main if testing
41+
python -m pip install numpy
42+
python -m pip install wheel
43+
python -m pip install --upgrade build
44+
python -m pip install --upgrade twain
45+
set DAS2C_LIBDIR=..\das2C\build.windows
46+
set DAS2C_INCDIR=..\das2C
47+
python -m build -w -n
48+
cd ..\
49+
50+
rem test das2py
51+
python -m pip install matplotlib
52+
python -m pip install .\das2py\dist\das2py-2.3.0-cp310-cp310-win_amd64.whl
53+
54+
python das2py\examples\ex09_cassini_fce_ephem_ticks.py 2017-09-14
55+
rem OTHER TESTS HERE
56+
57+
rem upload to pypi
58+
cd das2py
59+
python -m twine upload dist/*
60+
61+
```

setup.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from setuptools import Extension, setup
22
import os
3+
from os.path import dirname as dname
4+
from os.path import join as pjoin
35
# import numpy # <-- apparently a big no-no now.
46
import sys
57

@@ -37,19 +39,55 @@
3739
lSrc = ["src/_das2.c"]
3840

3941
if sys.platform == 'win32':
42+
43+
if bLinkStatic: # currently a synonym for not-conda
44+
# A windows hack, since we're not allowed to import numpy
45+
# inside setup.py. Any help on gitting rid of this hack
46+
# would be highly appreciated
47+
sPyDir = dname(sys.executable)
48+
lInc.append(
49+
pjoin(sPyDir, "lib", "site-packages", "numpy", "core", "include")
50+
)
51+
52+
sVcRoot = os.getenv("VCPKG_ROOT")
53+
if sVcRoot:
54+
sVcLibDir = pjoin(sVcRoot, "installed","x64-windows-static","lib")
55+
sVcIncDir = pjoin(sVcRoot, "installed","x64-windows-static","include")
56+
else:
57+
# With no other input, assume it's next door
58+
sVcLibDir = "..\\vcpkg\\installed\\x64-windows-static\\lib"
59+
sVcIncDir = "..\\vcpkg\\installed\\x64-windows-static\\include"
60+
61+
print('(setup.py) VCPKG_LIBDIR = %s'%sVcLibDir)
62+
63+
lLibDirs.append( sVcLibDir )
64+
lInc.append( sVcIncDir )
65+
lExObjs = ['%s/libdas2.3.lib'%sCLibDir]
66+
lLibs = [
67+
"fftw3", "libexpatMD", "libssl", "libcrypto", "Advapi32",
68+
"User32", "Crypt32", "zlib", "pthreadVC3", "ws2_32"
69+
]
70+
else:
71+
# Anaconda will setup the lib directories for us, but still
72+
# link das2C statically. Also anaconda and vcpkg use different
73+
# names for expaxt library
74+
lExObjs = ['%s/libdas2.3.lib'%sCLibDir]
75+
lLibs = [
76+
"fftw3", "expat", "libssl", "libcrypto",
77+
"zlib", "pthreadVC3", "ws2_32"
78+
]
79+
4080
print("setup.py: Using Headers from %s"%lInc)
4181
print("setup.py: Using Libs from %s"%lLibDirs)
82+
4283
ext = Extension(
4384
"_das2"
4485
,sources=lSrc
4586
,include_dirs=lInc
4687
,define_macros=lDefs
4788
,library_dirs=lLibDirs
48-
,libraries=[
49-
"libdas2.3", "fftw3", "expat", "libssl", "libcrypto",
50-
"zlib", "pthreadVC3", "ws2_32"
51-
]
52-
,extra_objects=['%s/libdas2.3.a'%sCLibDir]
89+
,libraries=lLibs
90+
,extra_objects=lExObjs
5391
)
5492
elif sys.platform == 'darwin':
5593

0 commit comments

Comments
 (0)