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

[WIP] build pysam on Windows #964

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ addopts = -s -v
testpaths = pysam tests
pep8maxlinelength = 120
pep8ignore = E402

[build]
compiler=mingw32
[build_ext]
compiler=mingw32
39 changes: 25 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import subprocess
import sys
import sysconfig
import distutils
from contextlib import contextmanager
from setuptools import setup
from cy_build import CyExtension as Extension, cy_build_ext as build_ext
Expand All @@ -54,7 +55,7 @@ def run_configure(option):
sys.stdout.flush()
try:
retcode = subprocess.call(
" ".join(("./configure", option)),
" ".join(("sh ./configure", option)),
shell=True)
if retcode != 0:
return False
Expand Down Expand Up @@ -242,7 +243,7 @@ def get_pysam_version():
for key, value in htslib_make_options.items():
print ("# pysam: htslib_config {}={}".format(key, value))

external_htslib_libraries = ['z']
external_htslib_libraries = ['z', 'regex', 'tre', 'intl', 'iconv']
if "LIBS" in htslib_make_options:
external_htslib_libraries.extend(
[re.sub("^-l", "", x) for x in htslib_make_options["LIBS"].split(" ") if x.strip()])
Expand Down Expand Up @@ -319,7 +320,7 @@ def get_pysam_version():

#######################################################
# Windows compatibility - untested
if platform.system() == 'Windows':
if False:
include_os = ['win32']
os_c_files = ['win32/getopt.c']
extra_compile_args = []
Expand All @@ -338,20 +339,27 @@ def get_pysam_version():

define_macros = []

suffix = sysconfig.get_config_var('EXT_SUFFIX')
suffix = distutils.sysconfig.get_config_var('EXT_SUFFIX')
if not suffix:
suffix = sysconfig.get_config_var('SO')
suffix = distutils.sysconfig.get_config_var('SO')

internal_htslib_libraries = [
os.path.splitext("chtslib{}".format(suffix))[0]]
":libchtslib{}".format(suffix)]
internal_samtools_libraries = [
os.path.splitext("csamtools{}".format(suffix))[0],
os.path.splitext("cbcftools{}".format(suffix))[0],
":libcsamtools{}".format(suffix),
":libcbcftools{}".format(suffix),
]
internal_pysamutil_libraries = [
os.path.splitext("cutils{}".format(suffix))[0]]
":libcutils{}".format(suffix)]

libraries_for_pysam_module = external_htslib_libraries + internal_htslib_libraries + internal_pysamutil_libraries
external_htslib_objects = []
for lib in external_htslib_libraries:
if lib != "ws2_32":
external_htslib_objects.append("C:/msys64/mingw64/lib/lib{}.a".format(lib))

internal_htslib_libraries.append("ws2_32")

libraries_for_pysam_module = internal_htslib_libraries + internal_pysamutil_libraries

# Order of modules matters in order to make sure that dependencies are resolved.
# The structures of dependencies is as follows:
Expand All @@ -367,17 +375,19 @@ def get_pysam_version():
modules = [
dict(name="pysam.libchtslib",
sources=[source_pattern % "htslib", "pysam/htslib_util.c"] + shared_htslib_sources + os_c_files,
libraries=external_htslib_libraries),
extra_link_args=["-Wl,--export-all-symbols"]),
dict(name="pysam.libcsamtools",
sources=[source_pattern % "samtools"] + glob.glob(os.path.join("samtools", "*.pysam.c")) +
[os.path.join("samtools", "lz4", "lz4.c")] + htslib_sources + os_c_files,
libraries=external_htslib_libraries + internal_htslib_libraries),
libraries=internal_htslib_libraries,
extra_link_args=["-Wl,--export-all-symbols"]),
dict(name="pysam.libcbcftools",
sources=[source_pattern % "bcftools"] + glob.glob(os.path.join("bcftools", "*.pysam.c")) + htslib_sources + os_c_files,
libraries=external_htslib_libraries + internal_htslib_libraries),
libraries=internal_htslib_libraries,
extra_link_args=["-Wl,--export-all-symbols"]),
dict(name="pysam.libcutils",
sources=[source_pattern % "utils", "pysam/pysam_util.c"] + htslib_sources + os_c_files,
libraries=external_htslib_libraries + internal_htslib_libraries + internal_samtools_libraries),
libraries=internal_htslib_libraries + internal_samtools_libraries),
dict(name="pysam.libcalignmentfile",
sources=[source_pattern % "alignmentfile"] + htslib_sources + os_c_files,
libraries=libraries_for_pysam_module),
Expand Down Expand Up @@ -413,6 +423,7 @@ def get_pysam_version():
define_macros=define_macros,
# for out-of-tree compilation, use absolute paths
library_dirs=[os.path.abspath(x) for x in ["pysam"] + htslib_library_dirs],
extra_objects=external_htslib_objects,
include_dirs=[os.path.abspath(x) for x in htslib_include_dirs + \
["samtools", "samtools/lz4", "bcftools", "pysam", "."] + include_os])

Expand Down