Skip to content

Commit 3a68f40

Browse files
gnufedeavara1986juanjux
authored
chore(asm): avoid bundling unneeded ddwaf lib builds for other architectures (#5239)
Bundle only appropriate libddwaf builds into our ddtrace wheels ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) are followed. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Author is aware of the performance implications of this PR as reported in the benchmarks PR comment. ## Reviewer Checklist - [ ] Title is accurate. - [ ] No unnecessary changes are introduced. - [ ] Description motivates each change. - [ ] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Testing strategy adequately addresses listed risk(s). - [ ] Change is maintainable (easy to change, telemetry, documentation). - [ ] Release note makes sense to a user of the library. - [ ] Reviewer is aware of, and discussed the performance implications of this PR as reported in the benchmarks PR comment. --------- Co-authored-by: Alberto Vara <[email protected]> Co-authored-by: Juanjo Alvarez Martinez <[email protected]>
1 parent 63d8e56 commit 3a68f40

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

setup.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ def run_tests(self):
119119
sys.exit(errno)
120120

121121

122+
def is_64_bit_python():
123+
return sys.maxsize > (1 << 32)
124+
125+
126+
class CleanLibraries(CleanCommand):
127+
@staticmethod
128+
def remove_dynamic_library():
129+
shutil.rmtree(LIBDDWAF_DOWNLOAD_DIR, True)
130+
131+
def run(self):
132+
CleanLibraries.remove_dynamic_library()
133+
CleanCommand.run(self)
134+
135+
122136
class LibDDWaf_Download(BuildPyCommand):
123137
@staticmethod
124138
def download_dynamic_library():
@@ -138,11 +152,20 @@ def download_dynamic_library():
138152
if not os.path.isdir(LIBDDWAF_DOWNLOAD_DIR):
139153
os.makedirs(LIBDDWAF_DOWNLOAD_DIR)
140154

141-
build_platform = get_build_platform()
142155
for arch in AVAILABLE_RELEASES[CURRENT_OS]:
143-
if CURRENT_OS == "Darwin" and not build_platform.endswith(arch):
156+
if CURRENT_OS == "Linux" and not get_build_platform().endswith(arch):
144157
# We cannot include the dynamic libraries for other architectures here.
145158
continue
159+
elif CURRENT_OS == "Darwin":
160+
# Detect build type for macos:
161+
# https://github.com/pypa/cibuildwheel/blob/main/cibuildwheel/macos.py#L250
162+
target_platform = os.getenv("PLAT")
163+
# Darwin Universal2 should bundle both architectures
164+
if not target_platform.endswith(("universal2", arch)):
165+
continue
166+
elif CURRENT_OS == "Windows" and (not is_64_bit_python() != arch.endswith("32")):
167+
# Win32 can be built on a 64-bit machine so build_platform may not be relevant
168+
continue
146169

147170
arch_dir = os.path.join(LIBDDWAF_DOWNLOAD_DIR, arch)
148171

@@ -189,20 +212,11 @@ def download_dynamic_library():
189212
os.remove(filename)
190213

191214
def run(self):
215+
CleanLibraries.remove_dynamic_library()
192216
LibDDWaf_Download.download_dynamic_library()
193217
BuildPyCommand.run(self)
194218

195219

196-
class CleanLibraries(CleanCommand):
197-
@staticmethod
198-
def remove_dynamic_library():
199-
shutil.rmtree(LIBDDWAF_DOWNLOAD_DIR, True)
200-
201-
def run(self):
202-
CleanLibraries.remove_dynamic_library()
203-
CleanCommand.run(self)
204-
205-
206220
long_description = """
207221
# dd-trace-py
208222

0 commit comments

Comments
 (0)