diff --git a/cython/.gitignore b/cython/.gitignore new file mode 100644 index 00000000..61c8abbd --- /dev/null +++ b/cython/.gitignore @@ -0,0 +1,20 @@ +slvs.py +python_solvespace/*.cpp +*.o* +*.def +*.lib +*.so +*.pyd +*.a +*.cxx + +*__pycache__* +*obj* + +*.eric6project* +*.e4p +*.e4q +*.e6t +*.ui + +.DS_Store diff --git a/cython/python_solvespace/__init__.pxd b/cython/python_solvespace/__init__.pxd new file mode 100644 index 00000000..8d1c8b69 --- /dev/null +++ b/cython/python_solvespace/__init__.pxd @@ -0,0 +1 @@ + diff --git a/cython/setup.py b/cython/setup.py index dd44e7c8..e83f34ae 100644 --- a/cython/setup.py +++ b/cython/setup.py @@ -10,7 +10,9 @@ __email__ = "pyslvs@gmail.com" import os import re import codecs +from textwrap import dedent from setuptools import setup, Extension, find_packages +from setuptools.command.build_ext import build_ext from platform import system from distutils import sysconfig @@ -22,6 +24,11 @@ ver = sysconfig.get_config_var('VERSION') lib = sysconfig.get_config_var('BINDIR') +def write(doc, *parts): + with codecs.open(os.path.join(here, *parts), 'w') as f: + f.write(doc) + + def read(*parts): with codecs.open(os.path.join(here, *parts), 'r') as f: return f.read() @@ -77,10 +84,24 @@ if system() == 'Windows': macros.append(('WIN32', None)) # Platform sources - sources.append(platform_path + 'w32util.cpp') + sources.append(platform_path + 'utilwin.cpp') sources.append(platform_path + 'platform.cpp') else: - sources.append(platform_path + 'unixutil.cpp') + sources.append(platform_path + 'utilunix.cpp') + + +class Build(build_ext): + def run(self): + # Generate "config.h", actually not used. + config_h = src_path + "config.h" + write(dedent(f"""\ + #ifndef SOLVESPACE_CONFIG_H + #define SOLVESPACE_CONFIG_H + #endif + """), config_h) + super(Build, self).run() + os.remove(config_h) + setup( name="python_solvespace", @@ -92,13 +113,14 @@ setup( url="https://github.com/solvespace/solvespace", packages=find_packages(exclude=('tests',)), ext_modules=[Extension( - "slvs", + "python_solvespace.slvs", sources, language="c++", include_dirs=[include_path, src_path, platform_path], define_macros=macros, extra_compile_args=compile_args )], + cmdclass={'build_ext': Build}, python_requires=">=3.6", setup_requires=[ 'setuptools', diff --git a/src/platform/platform.cpp b/src/platform/platform.cpp index ab08828d..80ffd7f3 100644 --- a/src/platform/platform.cpp +++ b/src/platform/platform.cpp @@ -458,7 +458,7 @@ bool WriteFile(const Platform::Path &filename, const std::string &data) { #if defined(WIN32) const void *LoadResource(const std::string &name, size_t *size) { - HRSRC hres = FindResourceW(NULL, Widen(name).c_str(), RT_RCDATA); + HRSRC hres = FindResourceW(NULL, Widen(name).c_str(), (LPWSTR)RT_RCDATA); ssassert(hres != NULL, "Cannot find resource"); HGLOBAL res = ::LoadResource(NULL, hres); ssassert(res != NULL, "Cannot load resource");