-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSConstruct
More file actions
642 lines (563 loc) · 20.1 KB
/
SConstruct
File metadata and controls
642 lines (563 loc) · 20.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
#! /usr/bin/env python3
# Copyright (C) 2017, 2019-2020 FIUBioRG
# SPDX-License-Identifier: MIT
#
# Application constructor/compiler configuration
#
# @TODO: Test portability with Windows systems using MSVC
# @TODO: Merge variable assignments
# @TODO: Test portability with Mac OSX
#
# -*-python-*-
from glob import glob
from os import environ, getenv
from os.path import relpath, abspath
import logging
import os
import re
import subprocess
import sys
from build_config import *
from build_support import *
from resolve_requirements import resolve_and_install
if sys.version_info.major < 3:
logging.error("Python3 is required to run this Sconstruct")
# The current SConstruct does not support Windows variants
if sys.platform.startswith("windows"):
logging.error("Windows is currently not supported")
Exit(1)
###################################################################
# Add Commndline Options to our Scons build
#
# We assume with-* options to be False for common plugins UNLESS the enduser
# specifies True. For CUDA, we assume False since CUDA availability is not
# expected on most end-user systems.
AddOption(
"--prefix",
dest="prefix",
type="string",
nargs=1,
action="store",
metavar="DIR",
default="/usr/local",
help="PREFIX for local installations",
)
AddOption(
"--with-cuda",
dest="with-cuda",
action="store_true",
default=False,
help="Enable CUDA plugin compilation",
)
AddOption(
"--gpu-architecture",
dest="gpu_arch",
type="string",
nargs=1,
action="store",
metavar="ARCH",
default="sm_35",
help="Specify the name of the class of NVIDIA 'virtual' GPU architecture for which the CUDA input files must be compiled"
)
AddOption(
"--without-python",
dest="without-python",
action="store_true",
default=False,
help="Disable Python plugin compilation",
)
AddOption(
"--without-perl",
dest="without-perl",
action="store_true",
default=False,
help="Disable Perl plugin compilation",
)
AddOption(
"--without-r",
dest="without-r",
action="store_true",
default=False,
help="Disable R plugin compilation",
)
AddOption(
"--without-java",
dest="without-java",
action="store_true",
default=False,
help="Disable Java plugin support",
)
AddOption(
"--with-rust",
dest="with-rust",
action="store_true",
default=False,
help="Enable experimental support for Rust language plugins"
)
AddOption(
"--r-include-dir",
dest="r-include-dir",
action="store",
default="/usr/local/lib/R/include",
help="Set the include directory for the R installation on the system"
)
AddOption(
"--r-lib-dir",
dest="r-lib-dir",
action="store",
default="/usr/local/lib/R/lib",
help="Set the lib directory for the R installation on the system"
)
###################################################################
# Gets the environment variables set by the user on the OS level or
# defaults to 'sane' values.
###################################################################
###################################################################
# Gets the environment variables set by the user on the OS level or
# defaults to 'sane' values.
###################################################################
env = Environment(
ENV=environ,
CC=getenv("CC", "cc"),
CXX=getenv("CXX", "c++"),
CPPDEFINES=["HAVE_PYTHON"],
SHCCFLAGS=["-fpermissive", "-fPIC", "-I.", "-O2"],
SHCXXFLAGS=["-std=c++11", "-fPIC", "-I.", "-O2"],
CCFLAGS=["-fpermissive", "-fPIC", "-I.", "-O2"],
CXXFLAGS=["-std=c++11", "-fPIC", "-O2"],
CPPPATH=include_search_path,
#LIBPATH=lib_search_path,
LICENSE=["MIT"],
SHLIBPREFIX=""
)
if not sys.platform.startswith("darwin"):
env.Append(LINKFLAGS=["-rdynamic"])
env.Append(LIBS=["rt"])
else:
env.Append(CCFLAGS=['-DAPPLE'])
if platform_id == "alpine":
env.Append(CPPDEFINES=["__MUSL__"])
###################################################################
###################################################################
# Either clean folders from previous Scons runs or begin assembling
# `PluMA` and its associated plugins
if env.GetOption("clean"):
env.Clean("python", [Glob("./**/__pycache__"),])
env.Clean(
"default",
[
Glob(".scon*"),
relpath("config.log"),
relpath(".perlconfig.txt"),
relpath("pluma"),
Glob('PluGen/*.o'),
relpath('PluGen/plugen'),
relpath("./obj"),
relpath("./lib"),
Glob("perm*.txt"),
Glob("asp_py_*tab.py"),
Glob("*.out"),
Glob("*.err"),
relpath("derep.fasta"),
Glob("logs/*.log.txt"),
Glob("pvals.*.txt"),
#relpath("pythonds"),
Glob("*.pdf"),
Glob("*.so"),
relpath("tmp"),
Glob("*_wrap.cxx"),
relpath("PerlPluMA.pm"),
relpath("PyPluMA.py"),
relpath("RPluMA.R"),
relpath("__pycache__"),
Glob("*.pyc"),
relpath(".venv"),
relpath("requirements-plugins.txt"),
],
)
env.Clean("all", ["python", "default"])
else:
envPluginCuda = None
###################################################################
# Check for headers, libraries, and build sub-environments
# for plugins.
###################################################################
config = Configure(env, custom_tests={"CheckPerl": CheckPerl})
if not config.CheckCC():
Exit(1)
if not config.CheckCXX():
Exit(1)
if not config.CheckSHCXX():
Exit(1)
libs = [
"m",
"pthread",
"dl",
"crypt",
"pcre",
"rt",
"c",
]
for lib in libs:
if not config.CheckLib(lib):
Exit(1)
config.CheckProg("swig")
if not env.GetOption("without-python"):
config.CheckProg("python3-config")
config.CheckProg("python3")
#config.env.ParseConfig("/usr/bin/python3-config --includes --ldflags")
config.env.ParseConfig("/usr/share/python3.14/bin/python3-config --includes --ldflags")
config.env.Append(LIBS=["util"])
if sys.version_info[0] == "2":
logging.warning(
"!! Version of Python <= Python3.0 are now EOL. Please update to Python3"
)
if not env.GetOption("without-perl"):
config.CheckProg("perl")
if not config.CheckPerl():
logging.error("!! Could not find a valid `perl` installation`")
Exit(1)
else:
config.env.ParseConfig("perl -MExtUtils::Embed -e ccopts -e ldopts")
if not config.CheckHeader("EXTERN.h"):
logging.error("!! Could not find `EXTERN.h`")
Exit(1)
config.env.AppendUnique(
CXXFLAGS=["-fno-strict-aliasing"],
CPPDEFINES=[
"LARGE_SOURCE",
"_FILE_OFFSET_BITS=64",
"HAVE_PERL",
"REENTRANT",
],
)
if sys.platform.startswith("darwin"):
config.env.Append(LIBS=["crypt", "nsl"])
config.env.Append(CPPDEFINES=["-DWITH_PERL"])
if not env.GetOption("without-r"):
if not config.CheckProg("R") or not config.CheckProg("Rscript"):
logging.error("!! Could not find a valid `R` installation`")
Exit(1)
else:
config.env.ParseConfig("pkg-config --cflags-only-I --libs-only-L libR")
config.env.AppendUnique(
LDFLAGS=["-Bsymbolic-functions", "-z,relro"], CPPDEFINES=["HAVE_R"]
)
config.env.AppendUnique(
CXXFLAGS=[
"-fno-gnu-unique",
"-fpermissive",
#"-fopenmp",
"--param=ssp-buffer-size=4",
"-Wformat",
"-Wformat-security",
"-Werror=format-security",
"-Wl,--export-dynamic",
],
CPPPATH=[
Dir("/usr/lib/R/library/Rcpp/include"),
Dir("/usr/lib/R/library/RInside/include"),
Dir('/usr/lib/R/site-library/RInside/include'),
Dir('/usr/lib/R/site-library/Rcpp/include'),
Dir("/usr/local/lib/R/library/Rcpp/include"),
Dir("/usr/local/lib/R/library/RInside/include"),
Dir('/usr/local/lib/R/site-library/RInside/include'),
Dir('/usr/local/lib/R/site-library/Rcpp/include'),
],
LIBPATH=[
Dir("/usr/lib/R/library/RInside/lib"),
Dir('/usr/lib/R/site-library/RInside/lib'),
Dir("/usr/local/lib/R/library/RInside/lib"),
Dir('/usr/local/lib/R/site-library/RInside/lib'),
],
LIBS=["R", "RInside"],
)
if getenv("R_INCLUDE_DIR"):
config.env.AppendUnique(
CPPATH=[
Dir(getenv("R_INCLUDE_DIR"))
]
)
if getenv("R_LIB_DIR"):
config.env.AppendUnique(
LIBPATH=[
Dir(getenv("R_LIB_DIR"))
]
)
if getenv("RINSIDE_LIB_DIR"):
config.env.AppendUnique(
LIBPATH=[
Dir(getenv("RINSIDE_LIB_DIR"))
]
)
if getenv("RINSIDE_INCLUDE_DIR"):
config.env.AppendUnique(
CPPPATH=[
Dir(getenv("RINSIDE_INCLUDE_DIR"))
]
)
if getenv("RCPP_INCLUDE_DIR"):
config.env.AppendUnique(
CPPPATH=[
Dir(getenv("RCPP_INCLUDE_DIR"))
]
)
config.env.Append(CPPDEFINES=["-DWITH_R"])
java_enabled = False
if not env.GetOption("without-java"):
java_home = getenv("JAVA_HOME")
if not java_home:
try:
javac_path = subprocess.check_output(
["which", "javac"], universal_newlines=True
).strip()
if javac_path:
java_home = os.path.dirname(os.path.dirname(os.path.realpath(javac_path)))
except (subprocess.CalledProcessError, FileNotFoundError):
java_home = None
if java_home and os.path.isdir(java_home):
include_dir = os.path.join(java_home, "include")
if sys.platform.startswith("linux"):
platform_dir = "linux"
elif sys.platform.startswith("darwin"):
platform_dir = "darwin"
elif sys.platform.startswith("win"):
platform_dir = "win32"
else:
platform_dir = sys.platform
cpp_paths = []
if os.path.isdir(include_dir):
cpp_paths.append(include_dir)
platform_include = os.path.join(include_dir, platform_dir)
if os.path.isdir(platform_include):
cpp_paths.append(platform_include)
if cpp_paths:
config.env.AppendUnique(CPPPATH=[Dir(path) for path in cpp_paths])
lib_dir = os.path.join(java_home, "lib", "server")
if not os.path.isdir(lib_dir):
lib_dir = os.path.join(java_home, "lib")
if os.path.isdir(lib_dir):
config.env.AppendUnique(LIBPATH=[Dir(lib_dir)])
libjvm_path = os.path.join(lib_dir, "libjvm.so")
libjvm_env = getenv("LIBJVM")
if (libjvm_env):
libjvm_path = libjvm_env
if os.path.isfile(libjvm_path):
config.env.AppendUnique(LIBPATH=[Dir("/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.472.b08-1.el8_10.x86_64/jre/lib/amd64/server/")])
config.env.Append(LIBS=["jvm"])
config.env.Append(CPPDEFINES=["HAVE_JAVA"])
java_enabled = True
elif config.CheckLib("jvm"):
config.env.Append(LIBS=["jvm"])
config.env.Append(CPPDEFINES=["HAVE_JAVA"])
java_enabled = True
else:
logging.warning(
"Java support requested but libjvm could not be linked."
)
else:
logging.warning("Java support requested but libjvm was not found.")
else:
logging.warning("Java support requested but JAVA_HOME/javac could not be resolved.")
if GetOption("with-rust"):
config.CheckProg("rustc")
config.CheckProg("cargo")
config.Finish()
if GetOption("with-cuda"):
envPluginCuda = Environment(
ENV=os.environ,
CUDA_PATH=[getenv("CUDA_PATH", "/usr/local/cuda")],
CUDA_SDK_PATH=[getenv("CUDA_SDK_PATH", "/usr/local/cuda")],
NVCCFLAGS=[
"-I" + os.getcwd(),
"--ptxas-options=-v",
"-std=c++14",
"-Xcompiler",
"-fPIC",
],
GPU_ARCH=GetOption('gpu_arch'),
)
configCuda = Configure(envPluginCuda)
configCuda.CheckProg("nvcc")
configCuda.CheckHeader("cuda.h")
configCuda.Finish()
# Export `envPlugin` and `envPluginCUDA`
Export("env")
Export("envPluginCuda")
if "-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1" in env['CCFLAGS']:
env['CCFLAGS'].remove("-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1")
print(env['CCFLAGS'])
###################################################################
# Regenerate wrappers for plugin languages
###################################################################
if not env.GetOption("without-python"):
env.Command(
"PyPluMA",
"src/PluginWrapper.i",
"swig -python -c++ -module $TARGET -o ${TARGET}_wrap.cxx $SOURCE"
)
if not env.GetOption("without-perl"):
env.Command(
"PerlPluMA",
"src/PluginWrapper.i",
"swig -perl5 -c++ -module $TARGET -o ${TARGET}_wrap.cxx $SOURCE"
)
if not env.GetOption("without-r"):
env.Command(
"RPluMA",
"src/PluginWrapper.i",
"swig -r -c++ -module $TARGET -o ${TARGET}_wrap.cxx $SOURCE"
)
###################################################################
# Execute compilation for our plugins.
# Note: CUDA is already prepared from the initial environment setup.
###################################################################
env.SharedObject(
source=SourcePath("PluMA.cxx"),
target=ObjectPath("PluMA.os"),
)
###################################################################
# PYTHON PLUGINS
env.SharedObject(
source="PyPluMA_wrap.cxx",
target=ObjectPath("PyPluMA_wrap.os"),
)
env.SharedLibrary(
source=[
ObjectPath("PyPluMA_wrap.os"),
ObjectPath("PluMA.os"),
],
target="_PyPluMA.so",
)
###################################################################
###################################################################
# PERL PLUGINS
env.SharedObject(
source="PerlPluMA_wrap.cxx",
target=ObjectPath("PerlPluMA_wrap.os"),
)
env.SharedLibrary(
source=[
ObjectPath("PluMA.os"),
ObjectPath("PerlPluMA_wrap.os"),
],
target="PerlPluMA.so",
)
###################################################################
# R PLUGINS
env.SharedObject(
source="RPluMA_wrap.cxx",
target=ObjectPath("RPluMA_wrap.os"),
)
env.SharedLibrary(
source=[
ObjectPath("PluMA.os"),
ObjectPath("RPluMA_wrap.os"),
],
target="RPluMA.so",
)
###################################################################
###################################################################
# Finally, compile!
###################################################################
env.Append(SHLIBPREFIX="lib")
###################################################################
# Assemble plugin path
pluginPath = glob("./plugins/*/")
###################################################################
###################################################################
# Resolve Python plugin dependencies into a shared venv.
# Scans plugins/*/requirements.txt, checks for version conflicts,
# and installs the merged set into .venv/ at the project root.
if not env.GetOption("without-python"):
resolve_and_install("plugins")
###################################################################
# # C++ Plugins
print("!! Compiling C++ Plugins")
for folder in pluginPath:
sconsScripts = Glob(folder + "/SConscript")
pluginListCXX = Glob(folder + "/*Plugin.cpp")
if len(sconsScripts) != 0:
for sconsScript in sconsScripts:
SConscript(sconsScripts, exports=toExport)
for plugin in pluginListCXX:
filesInPath = Glob(str(plugin.get_dir()) + "/*.cpp")
pluginName = plugin.get_path()
pluginName = pluginName.replace(".cpp", ".so")
env.SharedLibrary(
target=pluginName, source=filesInPath
)
###################################################################
#
# ###################################################################
if GetOption("with-cuda"):
print("!! Compiling CUDA Plugins")
envPluginCuda.AppendUnique(NVCCFLAGS=["-I"+os.getcwd()+"/src", '-std=c++14'])
for folder in pluginPath:
pluginListCU = Glob(folder+'/*Plugin.cu')
for plugin in pluginListCU:
pluginName = plugin.get_path()
pluginName = pluginName.replace(str(plugin.get_dir())+"/", "")
pluginName = pluginName.replace(".cu", ".so")
output = str(plugin.get_dir()) + "/lib" + pluginName
input = Glob(str(plugin.get_dir()) + "/*.cu", strings=True)
envPluginCuda.Command(
output,
input,
"nvcc -o $TARGET -std=c++14 -shared $NVCCFLAGS -arch=$GPU_ARCH $SOURCES"
)
###################################################################
# Main Executable & PluGen
env.Append(
LIBPATH=[LibPath(""),]
)
languages = Glob("src/languages/*.cxx")
for language in languages:
output = language.get_path().replace("src", "obj").replace(".cxx", ".os")
if "Perl" in output:
env.StaticObject(
LDFLAGS=[
[
subprocess.check_output(
"perl -MExtUtils::Embed -e ldopts",
universal_newlines=True,
shell=True,
encoding="utf8",
)
]
],
source=language,
target=output,
)
else:
env.StaticObject(
source=language,
target=output
)
plugenFiles = Glob(str(SourcePath("PluGen/*.cxx")))
env.Program("PluGen/plugen", Glob("src/PluGen/*.cxx"))
sourceFiles = Glob("src/*.cxx")
program_libs = [
"pthread",
"m",
"dl",
"crypt",
"c",
"python" + python_version,
"util",
"perl",
"R",
"RInside",
]
if java_enabled:
program_libs.append("jvm")
env.Program(
target="pluma",
source=[
SourcePath("main.cxx"),
SourcePath("PluginManager.cxx"),
languages,
],
LIBS=program_libs,
)
###################################################################