Skip to main content

LLVM python binding

Project description

LLVMPY Meow!

Note this project is still in the very early stage, not even half completed.

Installation

pip install llvmpym

Additional notes for NixOS User

If you encounter issues like ImportError: libz.so.1: cannot open shared object file: No such file or directory when using this library
You can use the following command to inspect those shared libraries that are not founded.

ldd ./.venv/lib/python3.12/site-packages/llvmpym/llvmpym_ext.abi3.so

You can use the following command to give this library a quick run (if you miss libz.so.1 and libstdc++.so.6):

env LD_LIBRARY_PATH="$(nix path-info nixpkgs#zlib)/lib:$(nix path-info nixpkgs#stdenv.cc.cc.lib)/lib:$LD_LIBRARY_PATH" python ./main.py

Or using a shellHook in your devShell:

devShells = forAllSystems ({ pkgs }: {
  default = pkgs.mkShell {
      packages = with pkgs; [
        (python312.withPackages (ppkgs: with ppkgs; [
          pip
        ]))
      ];
      shellHook = ''
        export LD_LIBRARY_PATH="${pkgs.zlib}/lib:${pkgs.stdenv.cc.cc.lib.outPath}/lib:$LD_LIBRARY_PATH"
      '';
    };
});

Currently I haven't invested into how to solve the problem from its root. If you know how to solve it, please give it a hand. It would really be appreciated.

Build

Requirements

  • A C++17 compiler
  • CMake 3.20.0+
  • ninja (optional, if you want to follow the guide)
  • Python at least 3.12

Manual Build of LLVM

  1. Download llvm-project 18.1.8 release source code. LLVM release page.
  2. Extract the source code in a random directory such as ~/proj/probe/llvm-project. Here we set the path as <llvm-project-path> for later reference.
  3. Change directory into the this project (llvmpym).
  4. Do the following command to manually build llvm project
mkdir ./llvm-build
cd ./llvm-build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. -DCMAKE_INSTALL_INCLUDEDIR=include -G Ninja ~/proj/llvm/llvm-project_18.1.8/llvm/
cmake --build .
ninja install-llvm-headers

First time building this project

env SKBUILD_CMAKE_ARGS="-DLLVM_DIR=$(pwd)/llvm-build/cmake/modules/CMakeFiles" just

Enable nanobind Debug

If you are using just, then you can create an .env file at project root

SKBUILD_CMAKE_BUILD_TYPE=Debug

otherwise you need to expose it as an environment variable

Status

  • All functions that operates on lambda functions(function pointers) is not binded or handled correctly. Typically those parameters'(or returned value's) type name ends with Hanlder or Callback, e.g. LLVMDiagnosticHandler, LLVMYieldCallback.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llvmpym-0.0.2.tar.gz (56.4 kB view hashes)

Uploaded Source

Built Distributions

llvmpym-0.0.2-cp312-abi3-win_amd64.whl (1.8 MB view hashes)

Uploaded CPython 3.12+ Windows x86-64

llvmpym-0.0.2-cp312-abi3-manylinux_2_28_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.12+ manylinux: glibc 2.28+ x86-64

llvmpym-0.0.2-cp312-abi3-macosx_14_0_arm64.whl (13.0 MB view hashes)

Uploaded CPython 3.12+ macOS 14.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page