clang-tool-chain 1.1.5__py3-none-any.whl → 1.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,8 @@ from clang_tool_chain.env_utils import (
9
9
  )
10
10
  from clang_tool_chain.execution.sanitizer_env import (
11
11
  detect_sanitizers_from_flags,
12
+ get_all_sanitizer_runtime_dlls,
13
+ get_asan_runtime_dll,
12
14
  get_runtime_dll_paths,
13
15
  get_symbolizer_path,
14
16
  prepare_sanitizer_environment,
@@ -31,4 +33,6 @@ __all__ = [
31
33
  "get_runtime_dll_paths",
32
34
  "get_symbolizer_path",
33
35
  "detect_sanitizers_from_flags",
36
+ "get_asan_runtime_dll",
37
+ "get_all_sanitizer_runtime_dlls",
34
38
  ]
@@ -1,3 +1,3 @@
1
1
  """Version information for clang-tool-chain."""
2
2
 
3
- __version__ = "1.1.5"
3
+ __version__ = "1.1.6"
@@ -131,6 +131,168 @@ def get_runtime_dll_paths() -> list[str]:
131
131
  return paths
132
132
 
133
133
 
134
+ def get_asan_runtime_dll() -> Path | None:
135
+ """
136
+ Get the full path to the ASAN runtime DLL (Windows only).
137
+
138
+ This function locates the shared ASAN runtime DLL used when compiling
139
+ with -fsanitize=address -shared-libasan. The DLL must be accessible
140
+ at runtime for ASAN-instrumented executables to run.
141
+
142
+ This is particularly useful when running tests via build systems like
143
+ Meson that reset PATH and don't inherit ASAN DLL directories. By getting
144
+ the DLL path, consuming projects can copy it to their build directory
145
+ where the build system will automatically discover it.
146
+
147
+ Returns:
148
+ Path to libclang_rt.asan_dynamic-x86_64.dll (or ARM64 equivalent),
149
+ or None if not found or not on Windows.
150
+
151
+ Example:
152
+ >>> dll_path = get_asan_runtime_dll()
153
+ >>> if dll_path:
154
+ ... shutil.copy(dll_path, build_dir / dll_path.name)
155
+ ... # Now Meson tests will find the ASAN DLL in build_dir
156
+
157
+ Note:
158
+ This function ensures the toolchain is downloaded before searching.
159
+ The DLL is typically located in the MinGW sysroot bin directory:
160
+ ~/.clang-tool-chain/clang/win/x86_64/x86_64-w64-mingw32/bin/
161
+
162
+ See Also:
163
+ get_runtime_dll_paths: Returns directories containing runtime DLLs
164
+ prepare_sanitizer_environment: Adds DLL paths to PATH
165
+ """
166
+ if platform.system() != "Windows":
167
+ logger.debug("get_asan_runtime_dll: Not on Windows, returning None")
168
+ return None
169
+
170
+ try:
171
+ from clang_tool_chain.platform.detection import get_platform_binary_dir, get_platform_info
172
+
173
+ # Get platform info for sysroot lookup
174
+ _platform_name, arch = get_platform_info()
175
+
176
+ # Get the clang root directory
177
+ clang_bin_dir = get_platform_binary_dir()
178
+ clang_root = clang_bin_dir.parent
179
+
180
+ # Determine sysroot and DLL name based on architecture
181
+ if arch == "x86_64":
182
+ sysroot_name = "x86_64-w64-mingw32"
183
+ dll_name = "libclang_rt.asan_dynamic-x86_64.dll"
184
+ elif arch == "arm64":
185
+ sysroot_name = "aarch64-w64-mingw32"
186
+ dll_name = "libclang_rt.asan_dynamic-aarch64.dll"
187
+ else:
188
+ logger.debug(f"get_asan_runtime_dll: Unsupported architecture {arch}")
189
+ return None
190
+
191
+ # Check MinGW sysroot bin directory first (primary location)
192
+ sysroot_bin = clang_root / sysroot_name / "bin"
193
+ dll_path = sysroot_bin / dll_name
194
+ if dll_path.exists():
195
+ logger.debug(f"Found ASAN runtime DLL: {dll_path}")
196
+ return dll_path
197
+
198
+ # Fallback: check clang bin directory
199
+ dll_path = clang_bin_dir / dll_name
200
+ if dll_path.exists():
201
+ logger.debug(f"Found ASAN runtime DLL (fallback): {dll_path}")
202
+ return dll_path
203
+
204
+ # Try glob pattern for any ASAN DLL (version may vary)
205
+ for search_dir in [sysroot_bin, clang_bin_dir]:
206
+ if search_dir.exists():
207
+ for dll_file in search_dir.glob("libclang_rt.asan*.dll"):
208
+ logger.debug(f"Found ASAN runtime DLL (glob): {dll_file}")
209
+ return dll_file
210
+
211
+ logger.debug(f"ASAN runtime DLL not found in {sysroot_bin} or {clang_bin_dir}")
212
+ return None
213
+
214
+ except (ImportError, RuntimeError) as e:
215
+ logger.debug(f"Could not get ASAN runtime DLL path: {e}")
216
+ return None
217
+
218
+
219
+ def get_all_sanitizer_runtime_dlls() -> list[Path]:
220
+ """
221
+ Get all sanitizer runtime DLLs (Windows only).
222
+
223
+ This function locates all shared sanitizer runtime DLLs, including:
224
+ - Address Sanitizer (ASAN)
225
+ - Undefined Behavior Sanitizer (UBSAN)
226
+ - Thread Sanitizer (TSAN) - if available
227
+
228
+ This is useful for projects that want to copy all sanitizer DLLs to
229
+ their build directory to ensure all instrumented code can run.
230
+
231
+ Returns:
232
+ List of Paths to sanitizer runtime DLLs, or empty list if not
233
+ found or not on Windows.
234
+
235
+ Example:
236
+ >>> dlls = get_all_sanitizer_runtime_dlls()
237
+ >>> for dll in dlls:
238
+ ... shutil.copy(dll, build_dir / dll.name)
239
+
240
+ See Also:
241
+ get_asan_runtime_dll: Returns just the ASAN DLL path
242
+ """
243
+ if platform.system() != "Windows":
244
+ return []
245
+
246
+ dlls: list[Path] = []
247
+
248
+ try:
249
+ from clang_tool_chain.platform.detection import get_platform_binary_dir, get_platform_info
250
+
251
+ # Get platform info for sysroot lookup
252
+ _platform_name, arch = get_platform_info()
253
+
254
+ # Get the clang root directory
255
+ clang_bin_dir = get_platform_binary_dir()
256
+ clang_root = clang_bin_dir.parent
257
+
258
+ # Determine sysroot based on architecture
259
+ if arch == "x86_64":
260
+ sysroot_name = "x86_64-w64-mingw32"
261
+ elif arch == "arm64":
262
+ sysroot_name = "aarch64-w64-mingw32"
263
+ else:
264
+ return []
265
+
266
+ # Search directories
267
+ search_dirs = [
268
+ clang_root / sysroot_name / "bin",
269
+ clang_bin_dir,
270
+ ]
271
+
272
+ # Patterns for sanitizer DLLs
273
+ patterns = [
274
+ "libclang_rt.asan*.dll", # Address Sanitizer
275
+ "libclang_rt.ubsan*.dll", # Undefined Behavior Sanitizer
276
+ "libclang_rt.tsan*.dll", # Thread Sanitizer
277
+ "libclang_rt.lsan*.dll", # Leak Sanitizer (standalone)
278
+ ]
279
+
280
+ seen_names: set[str] = set()
281
+ for search_dir in search_dirs:
282
+ if search_dir.exists():
283
+ for pattern in patterns:
284
+ for dll_file in search_dir.glob(pattern):
285
+ if dll_file.name not in seen_names:
286
+ dlls.append(dll_file)
287
+ seen_names.add(dll_file.name)
288
+ logger.debug(f"Found sanitizer DLL: {dll_file}")
289
+
290
+ except (ImportError, RuntimeError) as e:
291
+ logger.debug(f"Could not get sanitizer runtime DLLs: {e}")
292
+
293
+ return dlls
294
+
295
+
134
296
  def detect_sanitizers_from_flags(compiler_flags: list[str]) -> tuple[bool, bool]:
135
297
  """
136
298
  Detect which sanitizers are enabled from compiler flags.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clang-tool-chain
3
- Version: 1.1.5
3
+ Version: 1.1.6
4
4
  Summary: Clang Tool Chain - C/C++ compilation toolchain utilities
5
5
  Project-URL: Homepage, https://github.com/zackees/clang-tool-chain
6
6
  Project-URL: Repository, https://github.com/zackees/clang-tool-chain
@@ -1,5 +1,5 @@
1
- clang_tool_chain/__init__.py,sha256=nLK5yA3seauLHvtQN3Qfe8_XLfbs8b-noek_3baRRZc,936
2
- clang_tool_chain/__version__.py,sha256=jG7OiD1U-R4k5RPrITUrVwY2AnwCm3EQkm__FP_IjMI,71
1
+ clang_tool_chain/__init__.py,sha256=TS-fHsqErYIes4VJyZExhRMQjveVv7i99T9JjHJPpas,1064
2
+ clang_tool_chain/__version__.py,sha256=YTx56JW89_upt38FX8hlUWfRFbv_i6nx3Au3Ysdk01M,71
3
3
  clang_tool_chain/archive.py,sha256=t3reh7cm5XP2rhTqfRIDAQZv5XQq7SsstyiROYg8wFA,27697
4
4
  clang_tool_chain/archive_cache.py,sha256=5ZmlwXIJZDcrDFkTbdgBQYN9sulGn0WyI6qwWqC4HEU,6806
5
5
  clang_tool_chain/checksums.py,sha256=KFXeAeDz5ZlcZVOxsHDpNDCrm9UDoJ8bMA4PeNhuzdA,9868
@@ -49,7 +49,7 @@ clang_tool_chain/execution/iwyu.py,sha256=bmP0d_PZObA1JfmFYp3qIOKCb7y32AWPm2_ReF
49
49
  clang_tool_chain/execution/lldb.py,sha256=VpxkWTPS6PsyskaKTALeziR5Z5NLwarW174Fm1SMX9k,20718
50
50
  clang_tool_chain/execution/nodejs_resolver.py,sha256=8QsJWvIfmt5mBDV7n0ypSjsPyXS-eZTizhBli937I-g,11172
51
51
  clang_tool_chain/execution/platform_executor.py,sha256=sF4GyW0ujy2EewG8y2Eo1gUWGzss5G5iIkv02w7-2_o,14362
52
- clang_tool_chain/execution/sanitizer_env.py,sha256=OE00wOEaLm-HIWL1fdjhQWEZ9D1hVN3bYfMxUEo8ZiQ,13364
52
+ clang_tool_chain/execution/sanitizer_env.py,sha256=DgmSKOOGd0JxoKJfLkT9pDFXIfm4C6IWtECeeRGc838,19269
53
53
  clang_tool_chain/installers/__init__.py,sha256=NAV5woPCEDKSbFr1UmfQsrg4Ua5UdghN4q7H3ymvRsg,279
54
54
  clang_tool_chain/installers/base.py,sha256=OS78bau9zoYPitmhla7pKsfCPEj-zLY0DkvVzjE31Tw,15437
55
55
  clang_tool_chain/installers/clang.py,sha256=rUtheVRF7mq_1YdmQ3XzIybrJqsHbm2Xf0cbhRbH7RQ,16994
@@ -71,8 +71,8 @@ clang_tool_chain/symbolizer/unwind_windows.h,sha256=XTWhJDv13AAMUPAzWCfRN7tO6EbN
71
71
  clang_tool_chain/testing/__init__.py,sha256=-sYqOOCuTV_u-MkmExrD4uKdTHG4RmMwR3D1kIG281Q,208
72
72
  clang_tool_chain/testing/diagnostic_runner.py,sha256=mnmFUEOQulY3-Ggu6hKVGZwjrKQNmV6kY80PRTUu2qU,5293
73
73
  clang_tool_chain/testing/diagnostic_tests.py,sha256=GmtKWrDcddZTpx9_yIKfhRAy6YOde8dj7SksCWVEME4,6019
74
- clang_tool_chain-1.1.5.dist-info/METADATA,sha256=V3_teL2iXVtyGp-CJKBjeYgC2UhYj0KlTXc2d9pWZtQ,60267
75
- clang_tool_chain-1.1.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
76
- clang_tool_chain-1.1.5.dist-info/entry_points.txt,sha256=N0a0OVPkCFbf6BisRkHj-m2TcZ-f1mqxfXxAHQxfrQg,2800
77
- clang_tool_chain-1.1.5.dist-info/licenses/LICENSE,sha256=51FO1oc2pZbQNI0v0_THnznnZIF4iFgawG1xnQ58kKo,10997
78
- clang_tool_chain-1.1.5.dist-info/RECORD,,
74
+ clang_tool_chain-1.1.6.dist-info/METADATA,sha256=fUCTpvTHpVserQz52zpkBTZVZD0KoZR-AMxA4r3vmhc,60267
75
+ clang_tool_chain-1.1.6.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
76
+ clang_tool_chain-1.1.6.dist-info/entry_points.txt,sha256=N0a0OVPkCFbf6BisRkHj-m2TcZ-f1mqxfXxAHQxfrQg,2800
77
+ clang_tool_chain-1.1.6.dist-info/licenses/LICENSE,sha256=51FO1oc2pZbQNI0v0_THnznnZIF4iFgawG1xnQ58kKo,10997
78
+ clang_tool_chain-1.1.6.dist-info/RECORD,,