diff --git a/releasenotes/notes/native-heap-gotter-opt-in-wheel-build-8f3a2c1d9e4b5a07.yaml b/releasenotes/notes/native-heap-gotter-opt-in-wheel-build-8f3a2c1d9e4b5a07.yaml new file mode 100644 index 00000000000..b43bff54970 --- /dev/null +++ b/releasenotes/notes/native-heap-gotter-opt-in-wheel-build-8f3a2c1d9e4b5a07.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + profiling: ``libdd_heap_gotter`` is now included in Linux wheels only when the + wheel is built with ``DD_PROFILING_NATIVE_HEAP_ENABLED=1``. Default packaging + builds omit the cdylib. Musllinux and Alpine sdist builds always skip the + gotter cargo build even when that env var is set. diff --git a/setup.py b/setup.py index 24b68870d8d..e85497cf958 100644 --- a/setup.py +++ b/setup.py @@ -130,27 +130,41 @@ CARGO_TARGET_DIR = NATIVE_CRATE.absolute() / f"target{sys.version_info.major}.{sys.version_info.minor}" DD_CARGO_ARGS = shlex.split(os.getenv("DD_CARGO_ARGS", "")) -BUILD_PROFILING_NATIVE_TESTS = os.getenv("DD_PROFILING_NATIVE_TESTS", "0").lower() in ("1", "yes", "on", "true") + +def _env_truthy(name: str, default: str = "0") -> bool: + return os.getenv(name, default).lower() in ("1", "yes", "on", "true") + + +BUILD_PROFILING_NATIVE_TESTS = _env_truthy("DD_PROFILING_NATIVE_TESTS") + + +def is_musl_libc() -> bool: + """True when this interpreter is a musl (Alpine / musllinux) build. + + The heap-gotter cdylib is built and tested only on manylinux (glibc) in CI; + skip building on musllinux because cargo builds fail there. + """ + return any( + "musl" in (sysconfig.get_config_var(k) or "") + for k in ("SOABI", "EXT_SUFFIX", "BUILD_GNU_TYPE", "HOST_GNU_TYPE", "MULTIARCH") + ) + # Opt-in build of the native heap-gotter cdylib. # Off by default so normal builds don't pay the extra cargo fetch/compile and # mainline wheels don't ship the artifact until it GA's. # Same env var as runtime arming (ProfilingConfigNativeHeap.enabled); setup.py # reads it via os.getenv during the package build, independent of DDConfig. -BUILD_NATIVE_HEAP_GOTTER: bool = os.getenv("DD_PROFILING_NATIVE_HEAP_ENABLED", "0").lower() in ( - "1", - "yes", - "on", - "true", -) +# Musl is always a no-op even when the env is set (see is_musl_libc). +if _env_truthy("DD_PROFILING_NATIVE_HEAP_ENABLED") and is_musl_libc(): + print( + "WARNING: DD_PROFILING_NATIVE_HEAP_ENABLED is set but the native heap-gotter " + "cdylib is only built on manylinux (glibc); skipping on musllinux." + ) +BUILD_NATIVE_HEAP_GOTTER: bool = _env_truthy("DD_PROFILING_NATIVE_HEAP_ENABLED") and not is_musl_libc() # Keep the staged cdylib unstripped when building with the upstream test-support # feature (hook-hit counter for e2e / integration tests). -BUILD_NATIVE_HEAP_GOTTER_TEST_SUPPORT: bool = os.getenv("DD_PROFILING_NATIVE_HEAP_TEST_SUPPORT", "0").lower() in ( - "1", - "yes", - "on", - "true", -) +BUILD_NATIVE_HEAP_GOTTER_TEST_SUPPORT = _env_truthy("DD_PROFILING_NATIVE_HEAP_TEST_SUPPORT") CURRENT_OS = platform.system() SERVERLESS_BUILD = os.getenv("DD_SERVERLESS_BUILD", "0").lower() in ("1", "yes", "on", "true")