Class: FFI::Clang::MswinArgs
Overview
MSVC-specific clang configuration. Discovers libclang and system include paths from the Visual Studio installation:
-
Find the VS installation path via vswhere.exe
-
Call vcvarsall.bat to set up the MSVC developer environment
-
Run clang-cl -v -E -x c++ NUL in that environment
-
Parse the “#include <…> search starts here:” block from the output
-
Inject each discovered path as -I into parse_translation_unit
Constant Summary collapse
- VSWHERE =
"C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe"
Instance Attribute Summary
Attributes inherited from Args
Instance Method Summary collapse
-
#post_load(library) ⇒ Object
Pin libclang in memory so Windows will not unload it at exit.
Methods inherited from Args
#command_line_args, create, #libclang_paths, #resource_dir
Instance Method Details
#post_load(library) ⇒ Object
Pin libclang in memory so Windows will not unload it at exit.
LLVM’s rpmalloc allocator registers Fiber Local Storage (FLS) callbacks via FlsAlloc but does not call FlsFree on DLL_PROCESS_DETACH (LLVM bug #154361, fixed in LLVM 22.1.0 by github.com/llvm/llvm-project/pull/171465). Pinning with GET_MODULE_HANDLE_EX_FLAG_PIN prevents the unload so the FLS callbacks remain valid through process shutdown.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ffi/clang/args/mswin.rb', line 29 def post_load(library) symbol = library.find_symbol("clang_getClangVersion") return unless symbol kernel32 = FFI::DynamicLibrary.open("kernel32", 0) get_module_handle_ex_w = kernel32.find_function("GetModuleHandleExW") return unless get_module_handle_ex_w get_module_handle_ex_flag_from_address = 0x4 get_module_handle_ex_flag_pin = 0x1 flags = get_module_handle_ex_flag_from_address | get_module_handle_ex_flag_pin handle_out = FFI::MemoryPointer.new(:pointer) pin = FFI::Function.new(:bool, [:uint, :pointer, :pointer], get_module_handle_ex_w) pin.call(flags, symbol, handle_out) end |