-
Notifications
You must be signed in to change notification settings - Fork 416
/
setup.py
670 lines (577 loc) · 26.4 KB
/
setup.py
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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
import hashlib
import os
import platform
import re
import shutil
import subprocess
import sys
import sysconfig
import tarfile
import cmake
from setuptools_rust import Binding
from setuptools_rust import RustExtension
from setuptools import Extension, find_packages, setup # isort: skip
from setuptools.command.build_ext import build_ext # isort: skip
from setuptools.command.build_py import build_py as BuildPyCommand # isort: skip
from pathlib import Path # isort: skip
from pkg_resources import get_build_platform # isort: skip
from distutils.command.clean import clean as CleanCommand # isort: skip
try:
# ORDER MATTERS
# Import this after setuptools or it will fail
from Cython.Build import cythonize # noqa: I100
import Cython.Distutils
except ImportError:
raise ImportError(
"Failed to import Cython modules. This can happen under versions of pip older than 18 that don't "
"support installing build requirements during setup. If you're using pip, make sure it's a "
"version >=18.\nSee the quickstart documentation for more information:\n"
"https://ddtrace.readthedocs.io/en/stable/installation_quickstart.html"
)
from urllib.error import HTTPError
from urllib.request import urlretrieve
HERE = Path(__file__).resolve().parent
DEBUG_COMPILE = "DD_COMPILE_DEBUG" in os.environ
SCCACHE_COMPILE = os.getenv("DD_USE_SCCACHE", "0").lower() in ("1", "yes", "on", "true")
IS_PYSTON = hasattr(sys, "pyston_version_info")
IS_EDITABLE = False # Set to True if the package is being installed in editable mode
LIBDDWAF_DOWNLOAD_DIR = HERE / "ddtrace" / "appsec" / "_ddwaf" / "libddwaf"
IAST_DIR = HERE / "ddtrace" / "appsec" / "_iast" / "_taint_tracking"
DDUP_DIR = HERE / "ddtrace" / "internal" / "datadog" / "profiling" / "ddup"
CRASHTRACKER_DIR = HERE / "ddtrace" / "internal" / "datadog" / "profiling" / "crashtracker"
STACK_V2_DIR = HERE / "ddtrace" / "internal" / "datadog" / "profiling" / "stack_v2"
BUILD_PROFILING_NATIVE_TESTS = os.getenv("DD_PROFILING_NATIVE_TESTS", "0").lower() in ("1", "yes", "on", "true")
CURRENT_OS = platform.system()
LIBDDWAF_VERSION = "1.22.0"
# DEV: update this accordingly when src/core upgrades libdatadog dependency.
# libdatadog v14.1.0 requires rust 1.76.
RUST_MINIMUM_VERSION = "1.76"
# Set macOS SDK default deployment target to 10.14 for C++17 support (if unset, may default to 10.9)
if CURRENT_OS == "Darwin":
os.environ.setdefault("MACOSX_DEPLOYMENT_TARGET", "10.14")
def interpose_sccache():
"""
Injects sccache into the relevant build commands if it's allowed and we think it'll work
"""
if not SCCACHE_COMPILE:
return
# Check for sccache. We don't do multi-step failover (e.g., if ${SCCACHE_PATH} is set, but the binary is invalid)
sccache_path = Path(os.getenv("SCCACHE_PATH", shutil.which("sccache")))
if sccache_path.is_file() and os.access(sccache_path, os.X_OK):
# Both the cmake and rust toolchains allow the caller to interpose sccache into the compiler commands, but this
# misses calls from native extension builds. So we do the normal Rust thing, but modify CC and CXX to point to
# a wrapper
os.environ["DD_SCCACHE_PATH"] = str(sccache_path.resolve())
os.environ["RUSTC_WRAPPER"] = str(sccache_path.resolve())
cc_path = next(
(shutil.which(cmd) for cmd in [os.getenv("CC", ""), "cc", "gcc", "clang"] if shutil.which(cmd)), None
)
if cc_path:
os.environ["DD_CC_OLD"] = cc_path
os.environ["CC"] = str(HERE / "scripts" / "cc_wrapper.sh")
cxx_path = next(
(shutil.which(cmd) for cmd in [os.getenv("CXX", ""), "c++", "g++", "clang++"] if shutil.which(cmd)), None
)
if cxx_path:
os.environ["DD_CXX_OLD"] = cxx_path
os.environ["CXX"] = str(HERE / "scripts" / "cxx_wrapper.sh")
def verify_checksum_from_file(sha256_filename, filename):
# sha256 File format is ``checksum`` followed by two whitespaces, then ``filename`` then ``\n``
expected_checksum, expected_filename = list(filter(None, open(sha256_filename, "r").read().strip().split(" ")))
actual_checksum = hashlib.sha256(open(filename, "rb").read()).hexdigest()
try:
assert expected_filename.endswith(filename)
assert expected_checksum == actual_checksum
except AssertionError:
print("Checksum verification error: Checksum and/or filename don't match:")
print("expected checksum: %s" % expected_checksum)
print("actual checksum: %s" % actual_checksum)
print("expected filename: %s" % expected_filename)
print("actual filename: %s" % filename)
sys.exit(1)
def verify_checksum_from_hash(expected_checksum, filename):
# sha256 File format is ``checksum`` followed by two whitespaces, then ``filename`` then ``\n``
actual_checksum = hashlib.sha256(open(filename, "rb").read()).hexdigest()
try:
assert expected_checksum == actual_checksum
except AssertionError:
print("Checksum verification error: Checksum mismatch:")
print("expected checksum: %s" % expected_checksum)
print("actual checksum: %s" % actual_checksum)
sys.exit(1)
def load_module_from_project_file(mod_name, fname):
"""
Helper used to load a module from a file in this project
DEV: Loading this way will by-pass loading all parent modules
e.g. importing `ddtrace.vendor.psutil.setup` will load `ddtrace/__init__.py`
which has side effects like loading the tracer
"""
fpath = HERE / fname
import importlib.util
spec = importlib.util.spec_from_file_location(mod_name, fpath)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
def is_64_bit_python():
return sys.maxsize > (1 << 32)
class LibraryDownload:
name = None
download_dir = None
version = None
url_root = None
available_releases = None
expected_checksums = None
translate_suffix = None
@classmethod
def download_artifacts(cls):
suffixes = cls.translate_suffix[CURRENT_OS]
download_dir = Path(cls.download_dir)
download_dir.mkdir(parents=True, exist_ok=True) # No need to check if it exists
# If the directory is nonempty, assume we're done
if any(download_dir.iterdir()):
return
for arch in cls.available_releases[CURRENT_OS]:
if CURRENT_OS == "Linux" and not get_build_platform().endswith(arch):
# We cannot include the dynamic libraries for other architectures here.
continue
elif CURRENT_OS == "Darwin":
# Detect build type for macos:
# https://github.com/pypa/cibuildwheel/blob/main/cibuildwheel/macos.py#L250
target_platform = os.getenv("PLAT")
# Darwin Universal2 should bundle both architectures
if not target_platform.endswith(("universal2", arch)):
continue
elif CURRENT_OS == "Windows" and (not is_64_bit_python() != arch.endswith("32")):
# Win32 can be built on a 64-bit machine so build_platform may not be relevant
continue
arch_dir = download_dir / arch
# If the directory for the architecture exists and is nonempty, assume we're done
if arch_dir.is_dir() and any(arch_dir.iterdir()):
continue
archive_dir = cls.get_package_name(arch, CURRENT_OS)
archive_name = cls.get_archive_name(arch, CURRENT_OS)
download_address = "%s/%s/%s" % (
cls.url_root,
cls.version,
archive_name,
)
try:
filename, http_response = urlretrieve(download_address, archive_name)
except HTTPError as e:
print("No archive found for dynamic library {}: {}".format(cls.name, archive_dir))
raise e
# Verify checksum of downloaded file
if cls.expected_checksums is None:
sha256_address = download_address + ".sha256"
sha256_filename, http_response = urlretrieve(sha256_address, archive_name + ".sha256")
verify_checksum_from_file(sha256_filename, filename)
else:
expected_checksum = cls.expected_checksums[CURRENT_OS][arch]
verify_checksum_from_hash(expected_checksum, filename)
# Open the tarfile first to get the files needed.
# This could be solved with "r:gz" mode, that allows random access
# but that approach does not work on Windows
with tarfile.open(filename, "r|gz", errorlevel=2) as tar:
dynfiles = [c for c in tar.getmembers() if c.name.endswith(suffixes)]
with tarfile.open(filename, "r|gz", errorlevel=2) as tar:
tar.extractall(members=dynfiles, path=HERE)
Path(HERE / archive_dir).rename(arch_dir)
# Rename <name>.xxx to lib<name>.xxx so the filename is the same for every OS
lib_dir = arch_dir / "lib"
for suffix in suffixes:
original_file = lib_dir / "{}{}".format(cls.name, suffix)
if original_file.exists():
renamed_file = lib_dir / "lib{}{}".format(cls.name, suffix)
original_file.rename(renamed_file)
Path(filename).unlink()
@classmethod
def run(cls):
cls.download_artifacts()
@classmethod
def get_archive_name(cls, arch, os):
return cls.get_package_name(arch, os) + ".tar.gz"
class LibDDWafDownload(LibraryDownload):
name = "ddwaf"
download_dir = LIBDDWAF_DOWNLOAD_DIR
version = LIBDDWAF_VERSION
url_root = "https://github.com/DataDog/libddwaf/releases/download"
available_releases = {
"Windows": ["win32", "x64"],
"Darwin": ["arm64", "x86_64"],
"Linux": ["aarch64", "x86_64"],
}
translate_suffix = {"Windows": (".dll",), "Darwin": (".dylib",), "Linux": (".so",)}
@classmethod
def get_package_name(cls, arch, opsys):
archive_dir = "lib%s-%s-%s-%s" % (cls.name, cls.version, opsys.lower(), arch)
return archive_dir
@classmethod
def get_archive_name(cls, arch, opsys):
os_name = opsys.lower()
if os_name == "linux":
archive_dir = "lib%s-%s-%s-linux-musl.tar.gz" % (cls.name, cls.version, arch)
else:
archive_dir = "lib%s-%s-%s-%s.tar.gz" % (cls.name, cls.version, os_name, arch)
return archive_dir
class LibraryDownloader(BuildPyCommand):
def run(self):
# The setuptools docs indicate the `editable_mode` attribute of the build_py command class
# is set to True when the package is being installed in editable mode, which we need to know
# for some extensions
global IS_EDITABLE
if self.editable_mode:
IS_EDITABLE = True
CleanLibraries.remove_artifacts()
LibDDWafDownload.run()
BuildPyCommand.run(self)
class CleanLibraries(CleanCommand):
@staticmethod
def remove_artifacts():
shutil.rmtree(LIBDDWAF_DOWNLOAD_DIR, True)
shutil.rmtree(IAST_DIR / "*.so", True)
def run(self):
CleanLibraries.remove_artifacts()
CleanCommand.run(self)
class CMakeBuild(build_ext):
@staticmethod
def try_strip_symbols(so_file):
if CURRENT_OS == "Linux" and shutil.which("strip") is not None:
try:
subprocess.run(["strip", "-g", so_file], check=True)
except subprocess.CalledProcessError as e:
print(
"WARNING: stripping '{}' returned non-zero exit status ({}), ignoring".format(so_file, e.returncode)
)
except Exception as e:
print(
"WARNING: An error occurred while stripping the symbols from '{}', ignoring: {}".format(so_file, e)
)
def build_extension(self, ext):
if isinstance(ext, CMakeExtension):
try:
self.build_extension_cmake(ext)
except subprocess.CalledProcessError as e:
print("WARNING: Command '{}' returned non-zero exit status {}.".format(e.cmd, e.returncode))
if ext.optional:
return
raise
except Exception as e:
print("WARNING: An error occurred while building the CMake extension {}, {}.".format(ext.name, e))
if ext.optional:
return
raise
else:
super().build_extension(ext)
if not DEBUG_COMPILE:
try:
self.try_strip_symbols(self.get_ext_fullpath(ext.name))
except Exception as e:
print(f"WARNING: An error occurred while building the extension: {e}")
def build_extension_cmake(self, ext):
# Define the build and output directories
output_dir = Path(self.get_ext_fullpath(ext.name)).parent.resolve()
extension_basename = Path(self.get_ext_fullpath(ext.name)).name
# We derive the cmake build directory from the output directory, but put it in
# a sibling directory to avoid polluting the final package
cmake_build_dir = Path(self.build_lib.replace("lib.", "cmake."), ext.name).resolve()
cmake_build_dir.mkdir(parents=True, exist_ok=True)
# Which commands are passed to _every_ cmake invocation
cmake_args = ext.cmake_args or []
cmake_args += [
"-S{}".format(ext.source_dir), # cmake>=3.13
"-B{}".format(cmake_build_dir), # cmake>=3.13
"-DPython3_ROOT_DIR={}".format(sysconfig.get_config_var("prefix")),
"-DPYTHON_EXECUTABLE={}".format(sys.executable),
"-DCMAKE_BUILD_TYPE={}".format(ext.build_type),
"-DLIB_INSTALL_DIR={}".format(output_dir),
"-DEXTENSION_NAME={}".format(extension_basename),
]
if BUILD_PROFILING_NATIVE_TESTS:
cmake_args += ["-DBUILD_TESTING=ON"]
# If it's been enabled, also propagate sccache to the CMake build. We have to manually set the default CC/CXX
# compilers here, because otherwise the way we wrap sccache will conflict with the CMake wrappers
sccache_path = os.getenv("DD_SCCACHE_PATH")
if sccache_path:
cmake_args += [
"-DCMAKE_C_COMPILER={}".format(os.getenv("DD_CC_OLD", shutil.which("cc"))),
"-DCMAKE_C_COMPILER_LAUNCHER={}".format(sccache_path),
"-DCMAKE_CXX_COMPILER={}".format(os.getenv("DD_CXX_OLD", shutil.which("c++"))),
"-DCMAKE_CXX_COMPILER_LAUNCHER={}".format(sccache_path),
]
# If this is an inplace build, propagate this fact to CMake in case it's helpful
# In particular, this is needed for build products which are not otherwise managed
# by setuptools/distutils
if IS_EDITABLE:
# the INPLACE_LIB_INSTALL_DIR should be the source dir of the extension
cmake_args.append("-DINPLACE_LIB_INSTALL_DIR={}".format(ext.source_dir))
# Arguments to the cmake --build command
build_args = ext.build_args or []
build_args += ["--config {}".format(ext.build_type)]
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
# CMAKE_BUILD_PARALLEL_LEVEL works across all generators
# self.parallel is a Python 3 only way to set parallel jobs by hand
# using -j in the build_ext call, not supported by pip or PyPA-build.
# DEV: -j is supported in CMake 3.12+ only.
if hasattr(self, "parallel") and self.parallel:
build_args += ["-j{}".format(self.parallel)]
# Arguments to cmake --install command
install_args = ext.install_args or []
install_args += ["--config {}".format(ext.build_type)]
# platform/version-specific arguments--may go into cmake, build, or install as needed
if CURRENT_OS == "Windows":
cmake_args += [
"-A{}".format("x64" if platform.architecture()[0] == "64bit" else "Win32"),
]
if CURRENT_OS == "Darwin" and sys.version_info >= (3, 8, 0):
# Cross-compile support for macOS - respect ARCHFLAGS if set
# Darwin Universal2 should bundle both architectures
# This is currently specific to IAST and requires cmakefile support
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
if archs:
cmake_args += [
"-DBUILD_MACOS=ON",
"-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs)),
]
cmake_command = (
Path(cmake.CMAKE_BIN_DIR) / "cmake"
).resolve() # explicitly use the cmake provided by the cmake package
subprocess.run([cmake_command, *cmake_args], cwd=cmake_build_dir, check=True)
subprocess.run([cmake_command, "--build", ".", *build_args], cwd=cmake_build_dir, check=True)
subprocess.run([cmake_command, "--install", ".", *install_args], cwd=cmake_build_dir, check=True)
class CMakeExtension(Extension):
def __init__(
self,
name,
source_dir=".",
cmake_args=[],
build_args=[],
install_args=[],
build_type=None,
optional=True, # By default, extensions are optional
):
super().__init__(name, sources=[])
self.source_dir = source_dir
self.cmake_args = cmake_args or []
self.build_args = build_args or []
self.install_args = install_args or []
self.build_type = build_type or "Debug" if DEBUG_COMPILE else "Release"
self.optional = optional # If True, cmake errors are ignored
def check_rust_toolchain():
try:
rustc_res = subprocess.run(["rustc", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cargo_res = subprocess.run(["cargo", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if rustc_res.returncode != 0:
raise EnvironmentError("rustc required to build Rust extensions")
if cargo_res.returncode != 0:
raise EnvironmentError("cargo required to build Rust extensions")
# Now check valid minimum versions. These are hardcoded for now, but should be canonized in some other way
rustc_ver = rustc_res.stdout.decode().split(" ")[1]
cargo_ver = cargo_res.stdout.decode().split(" ")[1]
if rustc_ver < RUST_MINIMUM_VERSION:
raise EnvironmentError(f"rustc version {RUST_MINIMUM_VERSION} or later required, {rustc_ver} found")
if cargo_ver < RUST_MINIMUM_VERSION:
raise EnvironmentError(f"cargo version {RUST_MINIMUM_VERSION} or later required, {cargo_ver} found")
except FileNotFoundError:
raise EnvironmentError("Rust toolchain not found. Please install Rust from https://rustup.rs/")
# Before adding any extensions, check that system pre-requisites are satisfied
try:
check_rust_toolchain()
except EnvironmentError as e:
print(f"{e}")
sys.exit(1)
def get_exts_for(name):
try:
mod = load_module_from_project_file(
"ddtrace.vendor.{}.setup".format(name), "ddtrace/vendor/{}/setup.py".format(name)
)
return mod.get_extensions()
except Exception as e:
print("WARNING: Failed to load %s extensions, skipping: %s" % (name, e))
return []
if sys.byteorder == "big":
encoding_macros = [("__BIG_ENDIAN__", "1")]
else:
encoding_macros = [("__LITTLE_ENDIAN__", "1")]
if CURRENT_OS == "Windows":
encoding_libraries = ["ws2_32"]
extra_compile_args = []
debug_compile_args = []
else:
linux = CURRENT_OS == "Linux"
encoding_libraries = []
extra_compile_args = ["-DPy_BUILD_CORE"]
if DEBUG_COMPILE:
if linux:
debug_compile_args = ["-g", "-O0", "-Wall", "-Wextra", "-Wpedantic"]
else:
debug_compile_args = [
"-g",
"-O0",
"-Wall",
"-Wextra",
"-Wpedantic",
# Cython is not deprecation-proof
"-Wno-deprecated-declarations",
]
else:
debug_compile_args = []
if not IS_PYSTON:
ext_modules = [
Extension(
"ddtrace.profiling.collector._memalloc",
sources=[
"ddtrace/profiling/collector/_memalloc.c",
"ddtrace/profiling/collector/_memalloc_tb.c",
"ddtrace/profiling/collector/_memalloc_heap.c",
"ddtrace/profiling/collector/_memalloc_reentrant.c",
],
extra_compile_args=debug_compile_args + ["-D_POSIX_C_SOURCE=200809L", "-std=c11"]
if CURRENT_OS != "Windows"
else ["/std:c11"],
),
Extension(
"ddtrace.internal._threads",
sources=["ddtrace/internal/_threads.cpp"],
extra_compile_args=["-std=c++17", "-Wall", "-Wextra"] if CURRENT_OS != "Windows" else ["/std:c++20", "/MT"],
),
]
if platform.system() not in ("Windows", ""):
ext_modules.append(
Extension(
"ddtrace.appsec._iast._stacktrace",
# Sort source files for reproducibility
sources=[
"ddtrace/appsec/_iast/_stacktrace.c",
],
extra_compile_args=extra_compile_args + debug_compile_args,
)
)
ext_modules.append(CMakeExtension("ddtrace.appsec._iast._taint_tracking._native", source_dir=IAST_DIR))
if (
platform.system() == "Linux" or (platform.system() == "Darwin" and platform.machine() == "arm64")
) and is_64_bit_python():
ext_modules.append(
CMakeExtension(
"ddtrace.internal.datadog.profiling.ddup._ddup",
source_dir=DDUP_DIR,
optional=False,
)
)
ext_modules.append(
CMakeExtension(
"ddtrace.internal.datadog.profiling.crashtracker._crashtracker",
source_dir=CRASHTRACKER_DIR,
optional=False,
)
)
# Echion doesn't build on 3.7, so just skip it outright for now
if sys.version_info >= (3, 8) and sys.version_info < (3, 13):
ext_modules.append(
CMakeExtension(
"ddtrace.internal.datadog.profiling.stack_v2._stack_v2",
source_dir=STACK_V2_DIR,
optional=False,
),
)
else:
ext_modules = []
interpose_sccache()
setup(
name="ddtrace",
packages=find_packages(exclude=["tests*", "benchmarks*", "scripts*"]),
package_data={
"ddtrace": ["py.typed"],
"ddtrace.appsec": ["rules.json"],
"ddtrace.appsec._ddwaf": ["libddwaf/*/lib/libddwaf.*"],
"ddtrace.appsec._iast._taint_tracking": ["CMakeLists.txt"],
"ddtrace.internal.datadog.profiling": (
["libdd_wrapper*.*"] + ["ddtrace/internal/datadog/profiling/test/*"] if BUILD_PROFILING_NATIVE_TESTS else []
),
"ddtrace.internal.datadog.profiling.crashtracker": ["crashtracker_exe*"],
},
zip_safe=False,
# enum34 is an enum backport for earlier versions of python
# funcsigs backport required for vendored debtcollector
cmdclass={
"build_ext": CMakeBuild,
"build_py": LibraryDownloader,
"clean": CleanLibraries,
},
setup_requires=["setuptools_scm[toml]>=4", "cython", "cmake>=3.24.2,<3.28", "setuptools-rust"],
ext_modules=ext_modules
+ cythonize(
[
Cython.Distutils.Extension(
"ddtrace.internal._rand",
sources=["ddtrace/internal/_rand.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.internal._tagset",
sources=["ddtrace/internal/_tagset.pyx"],
language="c",
),
Extension(
"ddtrace.internal._encoding",
["ddtrace/internal/_encoding.pyx"],
include_dirs=["."],
libraries=encoding_libraries,
define_macros=encoding_macros,
),
Cython.Distutils.Extension(
"ddtrace.profiling.collector.stack",
sources=["ddtrace/profiling/collector/stack.pyx"],
language="c",
# cython generated code errors on build in toolchains that are strict about int->ptr conversion
# OTOH, the MSVC toolchain is different. In a perfect world we'd deduce the underlying toolchain and
# emit the right flags, but as a compromise we assume Windows implies MSVC and everything else is on a
# GNU-like toolchain
extra_compile_args=extra_compile_args + (["-Wno-int-conversion"] if CURRENT_OS != "Windows" else []),
),
Cython.Distutils.Extension(
"ddtrace.profiling.collector._traceback",
sources=["ddtrace/profiling/collector/_traceback.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.profiling._threading",
sources=["ddtrace/profiling/_threading.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.profiling.collector._task",
sources=["ddtrace/profiling/collector/_task.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.profiling.exporter.pprof",
sources=["ddtrace/profiling/exporter/pprof.pyx"],
language="c",
),
Cython.Distutils.Extension(
"ddtrace.profiling._build",
sources=["ddtrace/profiling/_build.pyx"],
language="c",
),
],
compile_time_env={
"PY_MAJOR_VERSION": sys.version_info.major,
"PY_MINOR_VERSION": sys.version_info.minor,
"PY_MICRO_VERSION": sys.version_info.micro,
"PY_VERSION_HEX": sys.hexversion,
},
force=True,
annotate=os.getenv("_DD_CYTHON_ANNOTATE") == "1",
compiler_directives={"language_level": "3"},
)
+ get_exts_for("psutil"),
rust_extensions=[
RustExtension(
"ddtrace.internal.core._core",
path="src/core/Cargo.toml",
py_limited_api="auto",
binding=Binding.PyO3,
debug=os.getenv("_DD_RUSTC_DEBUG") == "1",
),
],
)