-
Notifications
You must be signed in to change notification settings - Fork 6
Add support for Windows (MSVC) #4
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,6 @@ | |
| #include "bitmasks.h" | ||
| #include "parsers.h" | ||
| #include "headers.h" | ||
| #include <fcntl.h> | ||
| #include <unistd.h> | ||
| #include <cassert> | ||
| #include <vector> | ||
| #include "dltreader.h" | ||
|
|
@@ -80,15 +78,15 @@ DltReader::DltReader(bool expectStorage) | |
|
|
||
| std::string DltReader::str(){ | ||
| return fmt::format("DltReader(buf={:p}, msg={:p}, data end={:p})", | ||
| iBuffer.begin(), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh man, indeed, the iterators are not guaranteed to be pointers. I wonder if some linter could've found this (it's not even a warning on linux&osx). |
||
| iBuffer.data(), | ||
| iMessageBegin, | ||
| iDataEnd | ||
| ); | ||
| } | ||
|
|
||
| void DltReader::selfcheck(){ | ||
| assert(iMessageBegin >= iBuffer.begin() && iMessageBegin <= iDataEnd); | ||
| assert(iDataEnd >= iBuffer.begin() && iDataEnd <= iBuffer.end()); | ||
| assert(iMessageBegin >= iBuffer.data() && iMessageBegin <= iDataEnd); | ||
| assert(iDataEnd >= iBuffer.data() && iDataEnd <= &(*iBuffer.end())); | ||
| } | ||
|
|
||
| off_t DltReader::dataLeft(){ | ||
|
|
@@ -107,8 +105,8 @@ void DltReader::consumeMessage(){ | |
|
|
||
| void DltReader::flush(){ | ||
| selfcheck(); | ||
| auto shift = iMessageBegin - iBuffer.begin(); | ||
| iDataEnd = std::copy(iMessageBegin, iDataEnd, iBuffer.begin()); | ||
| auto shift = iMessageBegin - iBuffer.data(); | ||
| iDataEnd = std::copy(iMessageBegin, iDataEnd, iBuffer.data()); | ||
| iCursor -= shift; | ||
| iMessageBegin -= shift; | ||
| selfcheck(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| #! /usr/bin/env python3 | ||
| from setuptools import setup, find_packages, Extension | ||
| from setuptools.command.build_ext import build_ext | ||
| from pathlib import Path | ||
| import os | ||
| import sys | ||
| import pathlib | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
| import shutil | ||
|
|
||
| class CMakeExtension(Extension): | ||
|
|
||
|
|
@@ -17,49 +17,60 @@ class build_ext_cmake(build_ext): | |
| def run(self): | ||
| for ext in self.extensions: | ||
| self.build_cmake(ext) | ||
| super().run() | ||
|
|
||
| def build_cmake(self, ext): | ||
| cwd = Path().absolute() | ||
| def build_cmake(self, extension): | ||
|
|
||
| # these dirs will be created in build_py, so if you don't have | ||
| # any python sources to bundle, the dirs will be missing | ||
| build_temp = Path(self.build_temp) | ||
| build_temp.mkdir(parents=True, exist_ok=True) | ||
| extdir = Path(self.get_ext_fullpath(ext.name)) | ||
| extdir.mkdir(parents=True, exist_ok=True) | ||
| build_dir = pathlib.Path(self.build_temp) | ||
|
|
||
| extension_path = pathlib.Path(self.get_ext_fullpath(extension.name)) | ||
|
|
||
| os.makedirs(build_dir, exist_ok=True) | ||
| os.makedirs(extension_path.parent.absolute(), exist_ok=True) | ||
|
|
||
| # Now that the necessary directories are created, build | ||
|
|
||
| self.announce("Configuring cmake project", level=3) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice logs =) |
||
|
|
||
| # Change your cmake arguments below as necessary | ||
| # Below is just an example set of arguments for building Blender as a Python module | ||
|
|
||
| # example of cmake args | ||
| config = 'Debug' if self.debug else 'Release' | ||
| cmake_args = [ | ||
| '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.parent.absolute()), | ||
| '-DCMAKE_BUILD_TYPE=' + config, | ||
| '-DPYBIND11_PYTHON_VERSION=%s.%s' % (sys.version_info.major, sys.version_info.minor), | ||
| ] | ||
|
|
||
| # example of build args | ||
| build_args = [ | ||
| '--config', config, | ||
| '--', '-j4' | ||
| ] | ||
|
|
||
| os.chdir(str(build_temp)) | ||
| self.spawn(['cmake', str(cwd)] + cmake_args) | ||
| if not self.dry_run: | ||
| self.spawn(['cmake', '--build', '.'] + build_args) | ||
| os.chdir(str(cwd)) | ||
| self.spawn(['cmake', '-H'+str(pathlib.Path().absolute()), '-B'+self.build_temp, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
| '-DCMAKE_BUILD_TYPE=' + config, | ||
| '-DPYBIND11_PYTHON_VERSION=%s.%s' % (sys.version_info.major, sys.version_info.minor)]) | ||
|
|
||
| self.announce("Building binaries", level=3) | ||
|
|
||
| self.spawn(['cmake', '--build', self.build_temp, | ||
| '--config', config]) | ||
|
|
||
| # Build finished, now copy the files into the copy directory | ||
| # The copy directory is the parent directory of the extension (.pyd) | ||
|
|
||
| self.announce("Moving built python module", level=3) | ||
|
|
||
| bin_dir = os.path.join(build_dir, 'dltpy', 'native') | ||
| self.distribution.bin_dir = bin_dir | ||
|
|
||
| pyd_path = [os.path.join(bin_dir, _pyd) for _pyd in | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also,
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its probably because the libraries have the ending |
||
| os.listdir(bin_dir) if | ||
| os.path.isfile(os.path.join(bin_dir, _pyd)) and | ||
| os.path.splitext(_pyd)[0].startswith('dltreader_native') and | ||
| os.path.splitext(_pyd)[1] in [".pyd", ".so"]][0] | ||
|
|
||
| shutil.move(pyd_path, extension_path) | ||
|
|
||
| setup( | ||
| name='dltpy', | ||
| version='0.3.6.6', | ||
| description='DLT log reader', | ||
| long_description=Path('README.md').read_text(), | ||
| long_description=pathlib.Path('README.md').read_text(), | ||
| long_description_content_type="text/markdown", | ||
| author='Vladimir Shapranov', | ||
| author_email='equidamoid@gmail.com', | ||
| url='https://github.com/Equidamoid/dltpy', | ||
| packages=find_packages(), | ||
| ext_modules=[CMakeExtension('dltpy/native/native_dltfile')], | ||
| ext_modules=[CMakeExtension('dltpy/native/dltreader_native')], | ||
| cmdclass={'build_ext': build_ext_cmake,}, | ||
| entry_points={ | ||
| 'console_scripts': [ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried using the
pybind11_add_modulemacro from pybind11? https://pybind11.readthedocs.io/en/master/compiling.html#pybind11-add-moduleIt could be that it will solve the problem without adding platform-specific code here (I'd try it myself, but can't test it for windows at all...).