Skip to content

Commit 6cc1ecc

Browse files
avara1986juanjux
andauthored
chore: fast build environment variables [backport 2.21] (#12736)
Backport #12509 to 2.21. ## Description - Adds `DD_FAST_BUILD` which, if present, should halve the time to build the project (in my machine, 146 seconds without to 69 seconds without sccache) or be 4x faster if previously catched with sccache (44 seconds to 10) by exchanging some optimizations (disable abseil lib in IAST, -O0) for better build time. To be used for development and CI (CI config is also modified to use this env var, except for the `main` branch to catch corner cases that could happen only when optimized). - Adds `DD_COMPILE_ABSEIL` which, is present and "0" will disable the compilation of abseil in the native module independently of the release mode (currently is compiled by default if in `Release` mode only; this behavior will continue if `DD_COMPILE_ABSEIL` is not present). - Add a new "build" section in `docs/configuration.rst` with these two environment vars plus two that were not documented. - Fix an error in the documentation of `DD_COMPILE_DEBUG` (it enables `Debug` mode, not `RelWithDebInfo` as stated, and does it for all native extensions not only pyx ones). I will add an option to compile with `RelWithDebInfo` in a further PR. Signed-off-by: Juanjo Alvarez <[email protected]>## Checklist - [X] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: Juanjo Alvarez Martinez <[email protected]>
1 parent 9093b3c commit 6cc1ecc

File tree

10 files changed

+192
-144
lines changed

10 files changed

+192
-144
lines changed

.circleci/config.templ.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,14 @@ jobs:
394394
- run:
395395
name: "Generate base virtual environments."
396396
# DEV: riot list -i tracer lists all supported Python versions
397-
command: "riot list -i tracer | circleci tests split | xargs -I PY riot -P -v generate --python=PY"
397+
command: |
398+
if [ "$CIRCLE_BRANCH" = "main" ]; then
399+
export DD_FAST_BUILD=0
400+
else
401+
export DD_FAST_BUILD=1
402+
fi
403+
echo "DD_FAST_BUILD is set to $DD_FAST_BUILD"
404+
riot list -i tracer | circleci tests split | xargs -I PY riot -P -v generate --python=PY
398405
environment:
399406
CMAKE_BUILD_PARALLEL_LEVEL: 12
400407
PIP_VERBOSE: 1

.gitlab/tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ include:
3939
echo "Running hatch env: ${env}:test"
4040
hatch run ${env}:test
4141
done
42+
variables:
43+
CMAKE_BUILD_PARALLEL_LEVEL = "12"
44+
CARGO_BUILD_JOBS = "12"
45+
DD_FAST_BUILD = "1"
46+
4247

4348

4449
.test_base_hatch_snapshot:

.riot/requirements/1fe8dd2.txt

Lines changed: 0 additions & 83 deletions
This file was deleted.

.riot/requirements/6bec1ec.txt

Lines changed: 0 additions & 31 deletions
This file was deleted.

ddtrace/appsec/_iast/_taint_tracking/CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,23 @@ else()
3030
endif(BUILD_MACOS)
3131
unset(BUILD_MACOS CACHE)
3232

33-
if(CMAKE_BUILD_TYPE STREQUAL "Release")
34-
message("Release mode: using abseil")
33+
# Check the DD_COMPILE_ABSEIL environment variable and build type
34+
if(DEFINED ENV{DD_COMPILE_ABSEIL} AND ("$ENV{DD_COMPILE_ABSEIL}" STREQUAL "0" OR "$ENV{DD_COMPILE_ABSEIL}" STREQUAL
35+
"false"))
36+
37+
message("==============================================================")
38+
message("WARNING: DD_COMPILE_ABSEIL set to 0 or false: not using abseil")
39+
message("==============================================================")
40+
add_definitions(-DDONT_COMPILE_ABSEIL) # Define DONT_COMPILE_ABSEIL preprocessor variable
41+
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
42+
message("=====================================")
43+
message("WARNING: Debug mode: not using abseil")
44+
message("=====================================")
45+
add_definitions(-DDONT_COMPILE_ABSEIL) # Define DONT_COMPILE_ABSEIL preprocessor variable
46+
else()
47+
message("Release mode: using abseil (DD_COMPILE_ABSEIL unset or not 0/false)")
3548
FetchContent_Declare(absl URL "https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.1.zip")
3649
FetchContent_MakeAvailable(absl)
37-
else()
38-
message("Debug mode: not using abseil")
3950
endif()
4051

4152
include_directories(".")
@@ -81,7 +92,9 @@ set_target_properties(_native PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRE
8192

8293
# target_link_libraries(_native PRIVATE ${ICU_LIBS})
8394

84-
if(CMAKE_BUILD_TYPE STREQUAL "Release")
95+
if(CMAKE_BUILD_TYPE STREQUAL "Release"
96+
AND NOT (DEFINED ENV{DD_COMPILE_ABSEIL} AND ("$ENV{DD_COMPILE_ABSEIL}" STREQUAL "0" OR "$ENV{DD_COMPILE_ABSEIL}"
97+
STREQUAL "false")))
8598
target_link_libraries(${APP_NAME} PRIVATE absl::node_hash_map)
8699
endif()
87100

ddtrace/appsec/_iast/_taint_tracking/TaintTracking/TaintRange.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ class TaintedObject;
1919
// Alias
2020
using TaintedObjectPtr = shared_ptr<TaintedObject>;
2121

22-
#ifdef NDEBUG // Decide wether to use abseil
23-
22+
// Use Abseil only if NDEBUG is set and DONT_COMPILE_ABSEIL is not set
23+
#if defined(NDEBUG) && !defined(DONT_COMPILE_ABSEIL)
2424
#include "absl/container/node_hash_map.h"
2525
using TaintRangeMapType = absl::node_hash_map<uintptr_t, std::pair<Py_hash_t, TaintedObjectPtr>>;
26-
2726
#else
28-
2927
#include <unordered_map>
30-
using TaintRangeMapType = std::map<uintptr_t, std::pair<Py_hash_t, TaintedObjectPtr>>;
31-
32-
#endif // NDEBUG
28+
using TaintRangeMapType = std::unordered_map<uintptr_t, std::pair<Py_hash_t, TaintedObjectPtr>>;
29+
#endif
3330

3431
using TaintRangeMapTypePtr = shared_ptr<TaintRangeMapType>;
3532
// using TaintRangeMapTypePtr = TaintRangeMapType*;

ddtrace/appsec/_iast/_taint_tracking/tests/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ file(GLOB TEST_SOURCES "*.cpp" "*.hpp")
1111
add_executable(native_tests ${TEST_SOURCES} ${SOURCE_FILES} ${HEADER_FILES})
1212

1313
set(NATIVE_TEST_LIBRARIES gtest gtest_main ${PYTHON_LIBRARIES} pybind11::module)
14-
if(CMAKE_BUILD_TYPE STREQUAL "Release")
14+
15+
if(CMAKE_BUILD_TYPE STREQUAL "Release"
16+
AND NOT (DEFINED ENV{DD_COMPILE_ABSEIL} AND ("$ENV{DD_COMPILE_ABSEIL}" STREQUAL "0" OR "$ENV{DD_COMPILE_ABSEIL}"
17+
STREQUAL "false")))
1518
list(APPEND NATIVE_TEST_LIBRARIES absl::node_hash_map)
1619
endif()
1720

hatch.toml

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ DD_CIVISIBILITY_AGENTLESS_ENABLED = "1"
185185
DD_CIVISIBILITY_CODE_COVERAGE_ENABLED = "1"
186186
DD_CIVISIBILITY_ITR_ENABLED = "1"
187187
DD_PATCH_MODULES = "unittest:false"
188-
CMAKE_BUILD_PARALLEL_LEVEL = "12"
189-
190188

191189
## ASM Django
192190

@@ -323,6 +321,35 @@ test = [
323321
[[envs.appsec_iast_packages.matrix]]
324322
python = ["3.9", "3.10", "3.11", "3.12"]
325323

324+
## ASM iast_tdd_propagation
325+
326+
[envs.iast_tdd_propagation]
327+
template = "iast_tdd_propagation"
328+
dependencies = [
329+
"pytest",
330+
"pytest-cov",
331+
"requests",
332+
"hypothesis",
333+
"flask",
334+
"pycryptodome",
335+
"sqlalchemy~=2.0.23",
336+
"pony",
337+
"aiosqlite",
338+
"tortoise-orm",
339+
"peewee",
340+
"aiosqlite",
341+
]
342+
343+
[envs.iast_tdd_propagation.scripts]
344+
test = [
345+
"uname -a",
346+
"pip freeze",
347+
"DD_CIVISIBILITY_ITR_ENABLED=0 DD_IAST_REQUEST_SAMPLING=100 DD_IAST_DEDUPLICATION_ENABLED=false python -m pytest tests/appsec/iast_tdd_propagation",
348+
]
349+
350+
[[envs.iast_tdd_propagation.matrix]]
351+
python = ["3.9", "3.10", "3.11", "3.12", "3.13"]
352+
326353
## ASM appsec_integrations_django
327354

328355
[envs.appsec_integrations_django]
@@ -399,6 +426,50 @@ flask = ["~=2.2"]
399426
python = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
400427
flask = ["~=3.0"]
401428

429+
[[envs.appsec_integrations_flask.matrix]]
430+
# werkzeug 3.1 drops support for py3.8
431+
python = ["3.11", "3.12", "3.13"]
432+
flask = ["~=3.1"]
433+
werkzeug = ["~=3.1"]
434+
435+
## ASM appsec_integrations_fastapi
436+
437+
[envs.appsec_integrations_fastapi]
438+
template = "appsec_integrations_fastapi"
439+
dependencies = [
440+
"pytest",
441+
"pytest-cov",
442+
"requests",
443+
"hypothesis",
444+
"python-multipart",
445+
"jinja2",
446+
"httpx<0.28.0",
447+
"anyio{matrix:anyio:}",
448+
"fastapi{matrix:fastapi}"
449+
]
450+
451+
[envs.appsec_integrations_fastapi.scripts]
452+
test = [
453+
"uname -a",
454+
"pip freeze",
455+
"DD_TRACE_AGENT_URL=\"http://testagent:9126\" DD_CIVISIBILITY_ITR_ENABLED=0 DD_IAST_REQUEST_SAMPLING=100 DD_IAST_DEDUPLICATION_ENABLED=false python -m pytest -vvv {args:tests/appsec/integrations/fastapi_tests/}",
456+
]
457+
458+
459+
# if you add or remove a version here, please also update the parallelism parameter
460+
# in .circleci/config.templ.yml
461+
[[envs.appsec_integrations_fastapi.matrix]]
462+
python = ["3.8", "3.10", "3.13"]
463+
fastapi = ["==0.86.0"]
464+
anyio = ["==3.7.1"]
465+
466+
[[envs.appsec_integrations_fastapi.matrix]]
467+
python = ["3.8", "3.10", "3.13"]
468+
fastapi = ["==0.94.1"]
469+
470+
[[envs.appsec_integrations_fastapi.matrix]]
471+
python = ["3.8", "3.10", "3.13"]
472+
fastapi = ["~=0.114.2"]
402473

403474

404475
## ASM FastAPI
@@ -441,7 +512,6 @@ fastapi = ["==0.94.1"]
441512
python = ["3.8", "3.10", "3.13"]
442513
fastapi = ["~=0.114.2"]
443514

444-
445515
## ASM Appsec Aggregated Leak Testing
446516

447517
[envs.appsec_aggregated_leak_testing]
@@ -457,9 +527,9 @@ dependencies = [
457527
"pydantic-settings",
458528
]
459529

460-
[envs.appsec_aggregated_leak_testing.env-vars]
461-
CMAKE_BUILD_PARALLEL_LEVEL = "12"
530+
[envs.iast_aggregated_leak_testing.env-vars]
462531
DD_IAST_ENABLED = "true"
532+
_DD_IAST_PATCH_MODULES = "scripts.iast"
463533

464534
[envs.appsec_aggregated_leak_testing.scripts]
465535
test = [
@@ -622,7 +692,6 @@ dependencies = [
622692

623693
[evs.selenium.env-vars]
624694
DD_AGENT_TRACER_URL = "9126"
625-
CMAKE_BUILD_PARALLEL_LEVEL = "12"
626695

627696
[envs.selenium.scripts]
628697
test = [

riotfile.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,10 +2937,10 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
29372937
},
29382938
venvs=[
29392939
# Python 3.8
2940-
Venv(
2941-
pys=["3.8"],
2942-
pkgs={"greenlet": "==3.1.0"},
2943-
),
2940+
# Venv(
2941+
# pys=["3.8"],
2942+
# pkgs={"greenlet": "==3.1.0"},
2943+
# ),
29442944
# Python 3.9+
29452945
Venv(
29462946
pys=select_pys(min_version="3.9"),
@@ -2961,7 +2961,10 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
29612961
pkgs={"vcrpy": latest, "pytest-asyncio": "==0.21.1"},
29622962
venvs=[
29632963
Venv(pys="3.7"),
2964-
Venv(pys=select_pys(min_version="3.8"), pkgs={"ragas": "==0.1.21", "langchain": latest}),
2964+
Venv(
2965+
pys=select_pys(min_version="3.8", max_version="3.12"),
2966+
pkgs={"ragas": "==0.1.21", "langchain": latest},
2967+
),
29652968
],
29662969
),
29672970
Venv(

0 commit comments

Comments
 (0)