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

Building on Windows #4

Open
randomdude opened this issue Apr 3, 2024 · 0 comments
Open

Building on Windows #4

randomdude opened this issue Apr 3, 2024 · 0 comments

Comments

@randomdude
Copy link

Hi all! I recently had call to build Packaide under Windows, and had some difficulty (partly because I was using non-system python, and so had to rebuild python-boost - for the curious, I wanted to build against FreeCAD's Python). I ran in to a couple of roadblocks and unfortunately I'm not skilled enough in CMake to remedy them properly and submit a pull request. Best I can do is summarise what I did for any other Windows users that are having trouble.

I wrote a script to automate this, but it's written for (cygwin's) bash, so it is unlikely to be useful for most users. Nevertheless, I'll include excerpts to illustrate my points. as I go along.

BTW, for those whose threat model allows it, I've made my compiled binaries available - https://github.com/randomdude/Packaide/releases/tag/1.0 . I'm also terrible at Python packaging so YMMV - they might not work, but I'll do my best to fix them if so.

These steps worked for me using Boost 1.84.0 and Visual Studio 2017.

  • If you're using non-system Python (ie, you want to rebuild Boost_python), then edit the project-config.jam file after invoking bootstrap.bat. Specify paths to your Python there, eg:
using python  : 3.8 : "C:\\Program Files\\FreeCAD 0.19\\bin"
     : "C:\\Program Files\\FreeCAD 0.19\\bin\\include"
     : "C:\\Program Files\\FreeCAD 0.19\\bin\\libs"
     ;
  • Build Boost with just Python and System options, and be sure to specify shared linking
cmd /c call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat" \& b2 toolset=msvc-141 link=shared --with-python --with-system address-model=64
  • After building boost, copy stage/lib/boost_python[pythonver]-*.lib to remove the version number.
for x in `ls stage/lib/boost_python$pythonver-*.lib`; do
	newname=`echo $x | sed -e "s/boost_python$pythonver-/boost_python-/g"`
	cp $x $newname
done
  • I found I had to patch Boost - something goes wrong with compiler detection and I'm in no way knowlegable enough to fix it. Simple enough, change std::snprintf to snprintf in the boost/assert/source_location.hpp file. I found I had to do this in both vcpkg boost and the one I'd build, strangely.
sed -i.bak installed/x64-windows/include/boost/assert/source_location.hpp -e 's/std::snprintf/snprintf/g'
sed -i.bak ../boost_1_84_0/boost/assert/source_location.hpp -e 's/std::snprintf/snprintf/g'
  • Before you invoke CMake, edit src/CMakeLists.txt and remove the following line:
target_compile_options(PackaideBindings PRIVATE -Wfatal-errors)

Otherwise, VS will refuse to build (as it doesn't understand -Wfatal-errors. I considered submitting a fix for this, but don't feel comfortable just removing -Wfatal-errors for all platforms - I'll leave it to someone who knows how to CMake to do it properly.

  • When invoking CMake, we can't specify the usual target for Boost, since that would include vcpkg's version and not the one we've just built. Specify it manually, and also specify other build deps.
"/cygdrive/c/Program Files/CMake/bin/cmake.exe"								\
	-G "Visual Studio 15 2017 Win64"											\
	-DPython3_EXECUTABLE="C:\\Program Files\\FreeCAD 0.19\\bin\\python.exe"		\
	-DPYTHON_LIBRARY="C:\\Program Files\\FreeCAD 0.19\\bin\\libs\\python38.lib"	\
	-DBOOST_ROOT:PATHNAME="C: ... /boost_1_84_0"					\
	-DBoost_LIBRARY_DIRS:FILEPATH="C:... /boost_1_84_0/stage/lib\"		\
	-DCGAL_DIR="C:.../vcpkg/installed/x64-windows/share/cgal"			\
	-DGMP_LIBRARIES="C:.../vcpkg/installed/x64-windows/lib/gmp.lib"		\
	-DGMP_INCLUDE_DIR="C:.../vcpkg/installed/x64-windows/include"		\
	-DMPFR_LIBRARIES="C:.../vcpkg/installed/x64-windows/lib/mpfr.lib"		\
	-DMPFR_INCLUDE_DIR="C:.../vcpkg/installed/x64-windows/include"		\
	-DBoost_COMPILER=-vc141 ..

I had to tweak the generated project, too - we need to put the python version number back into the libraries-to-link list. If I was smart, I'd know how to fix this in CMake, but unfortunately, I am not :) Use something like '38' for pythonver.

sed -i.bak -e "s/boost_python-\(.*\)-1_84.lib/boost_python${pythonver}-\1-1_84.lib/g" src/PackaideBindings.vcxproj

Finally, when installing, you'll need to change the installed PackadeBindings.dll to PackadeBindings.pyd, since Windows Python requires this extension. You'll need the appropriate runtimes in your PATH - initially I was lazy and just copied mpfr.dll, gmp.dll, and stage/lib/boost_python${pythonver}-vc141-mt-x64-1_84.dll into the Python libs directory, and that worked. I actually have a wheel package set up for Packaide now - see above - but I'm pretty new to Python packaging and so it may well be suboptimal and/or broken.

Apologies for the somewhat rambly nature of this not-really-a-bug! I spent about a week getting Packaide playing nicely with FreeCAD on Windows, and all packaged up via Jenkins. Having sunk that time into it, I'm keen to document the process by sharing my experiences and try to save someone else the hassle.

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

No branches or pull requests

1 participant