xinetzone opened a new issue, #199:
URL: https://github.com/apache/tvm-ffi/issues/199

   
   
   ### Background
   
   The current “Build from Source” documentation for Windows only lists MSVC 
(Visual Studio 2019/2022, x64) as the supported toolchain. There is no guidance 
on how to build tvm-ffi with Clang/LLVM together with Ninja and CMake. I would 
like to avoid installing the very large Visual Studio/MSVC environment and 
instead use a lighter setup with Clang/LLVM and Ninja.
   
   ---
   
   ### Motivation
   
   - **Lightweight development environment:** Use LLVM (Clang/LLD) + Ninja + 
CMake without requiring the full Visual Studio installation.  
   - **Cross-platform consistency:** Reuse the same Clang/Ninja workflow across 
Linux, macOS, and Windows.  
   - **Simplified CI/CD:** Easier to maintain smaller toolchains (LLVM, Ninja, 
CMake) in containers or self-hosted runners.
   
   ---
   
   ### Goals and scenarios
   
   - On Windows 10/11 x64, build and install tvm-ffi using:
     - **CMake 3.18+, Ninja**
     - **LLVM/Clang (clang++)**, preferably linking with **lld**
     - Either via **pip + scikit-build-core** for the Python package, or just 
the **C/C++ shared library**  
   - Avoid requiring a full MSVC/Visual Studio installation. If MSVC runtime or 
Windows SDK is unavoidable, use the smallest possible installation (e.g. VS 
Build Tools only).
   
   ---
   
   ### Approaches tried
   
   #### A. Pure Clang/LLVM (MinGW-w64 UCRT) + Ninja
   
   - Environment:
     - Install LLVM (clang, lld), Ninja, CMake.
     - Install MinGW-w64 (UCRT, e.g. MSYS2 `ucrt64`) for C/C++ runtime and 
Windows headers.
   - Build commands:
     ```bash
     cmake -B build_cpp -G Ninja ^
       -DCMAKE_BUILD_TYPE=RelWithDebInfo ^
       -DCMAKE_C_COMPILER=clang ^
       -DCMAKE_CXX_COMPILER=clang++ ^
       -DCMAKE_CXX_STANDARD=17 ^
       -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" ^
       -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld"
   
     cmake --build build_cpp --parallel --target tvm_ffi_shared
     cmake --install build_cpp --prefix dist
     ```
   - Expected output: `dist/include/` and `dist/lib/` (same as official docs).  
   - Issues:
     - Need to confirm tvm-ffi compatibility with MinGW-w64 UCRT (exception 
handling, FFI registry, DLPack ABI behavior).  
     - If Windows-specific APIs or MSVCRT assumptions exist, may cause 
incompatibility.
   
   #### B. clang-cl + Ninja (with minimal VS Build Tools/Windows SDK)
   
   - Environment:
     - Install LLVM (clang-cl), Ninja, CMake.
     - Install minimal VS Build Tools (just MSVC runtime + Windows SDK) or 
reuse existing SDK.
   - Build commands:
     ```bash
     cmake -B build_cpp -G Ninja ^
       -DCMAKE_BUILD_TYPE=RelWithDebInfo ^
       -DCMAKE_C_COMPILER=clang-cl ^
       -DCMAKE_CXX_COMPILER=clang-cl ^
       -DCMAKE_CXX_STANDARD=17
   
     cmake --build build_cpp --parallel --config RelWithDebInfo --target 
tvm_ffi_shared
     cmake --install build_cpp --config RelWithDebInfo --prefix dist
     ```
   - Pros: Keeps MSVC ABI compatibility while using Clang frontend; Ninja 
generator is simple.  
   - Cons: Still requires some MSVC/SDK installation, though smaller than full 
VS.
   
   #### C. Python package build (scikit-build-core) with Clang/Ninja
   
   - Command:
     ```bash
     set CMAKE_GENERATOR=Ninja
     pip install --reinstall --verbose -e . ^
       --config-settings cmake.define.CMAKE_C_COMPILER=clang ^
       --config-settings cmake.define.CMAKE_CXX_COMPILER=clang++ ^
       --config-settings cmake.define.CMAKE_CXX_STANDARD=17 ^
       --config-settings cmake.define.CMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" ^
       --config-settings cmake.define.CMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld" ^
       --config-settings cmake.define.TVM_FFI_ATTACH_DEBUG_SYMBOLS=ON
     ```
   - Verification:
     ```bash
     python -c "import tvm_ffi; print(tvm_ffi.__version__)"
     tvm-ffi-config -h
     ```
   - Risk: scikit-build-core may default to MSVC on Windows and ignore manual 
compiler settings, requiring a toolchain file to enforce Clang.
   
   ---
   
   ### Obstacles and open questions
   
   - **Docs restrict Windows to MSVC:** No mention of Clang/LLVM workflows or 
known limitations.  
   - **ABI/runtime compatibility:**  
     - MinGW-w64 (UCRT) vs MSVC C++ ABI (exceptions, RTTI, etc.) may affect FFI 
object model and cross-boundary exception handling.  
     - clang-cl path is safer ABI-wise but still needs MSVC/SDK.  
   - **CMake generator differences:** Docs note VS generators need `--config`, 
while Ninja uses `-DCMAKE_BUILD_TYPE`. Easy to misconfigure when switching 
toolchains.  
   - **Python editable installs:** Docs warn that C++/Cython changes aren’t 
automatically reflected. Any extra caveats when using Clang/Ninja?
   
   ---
   
   ### Requested support
   
   - **Documentation updates:**  
     1. Add a Windows “Clang/LLVM + Ninja” section, covering both:  
        - Pure MinGW-w64 (UCRT) + Clang/LLD  
        - clang-cl + minimal VS Build Tools  
        Include tested CMake options and note limitations (ABI, exceptions, 
DLPack).  
     2. Clarify generator/build-type differences (Ninja vs VS).  
   - **CI matrix expansion:** Add Windows + Clang + Ninja builds/tests for both 
Python package and C/C++ shared library.  
   - **Minimal dependency guidance:** If MSVC/SDK is required, provide a 
minimal component list for VS Build Tools.
   
   ---
   
   ### References
   
   - Official tvm-ffi repository and docs.  
   - Python packaging guide (FFI registration, exception handling, object 
model).  
   - Build from source guide (currently Windows=MSVC only, with Ninja/VS 
generator notes).
   
   ---
   
   Would you like me to polish this further into a ready-to-post GitHub issue 
(with concise wording and Markdown formatting tuned for maintainers), or keep 
it as a detailed draft for your own editing?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to