-
Notifications
You must be signed in to change notification settings - Fork 6
Install Pysvf from Scratch
This document describes how to build SVF-Python from scratch on a Mac/Linux. If you can’t use a pre-built wheel due to environment, network, or other constraints, follow these steps to compile and install the package locally.
Note: These instructions assume macOS with the standard Apple Clang toolchain. Some details may vary based on your Xcode or Command Line Tools setup.
-
macOS Toolchain
- Xcode or the Command Line Tools installed. You can verify by running:
xcode-select --install
- Xcode or the Command Line Tools installed. You can verify by running:
-
Python 3.8 – 3.13
- Make sure
python3is installed. If using [Homebrew](https://brew.sh/), you can install an up-to-date Python:brew install python
- Alternatively, you can install multiple Python version via
pyenvand setup your virtual env.
- Make sure
-
Pip / Wheel / Setuptools
- It’s often helpful to have the latest versions:
python3 -m pip install --upgrade pybind11 pip setuptools wheel
- It’s often helpful to have the latest versions:
-
Git
- Ensure you have Git installed (macOS usually has it by default).
Clone the SVF Python repository:
git clone https://github.com/SVF-tools/SVF
cd SVFthen build the SVF library: Release build
bash build.sh sharedOr Debug build
bash bash build.sh shared debugThen we can see the libSvfLLVM.so and libSvfCore.so under Release-build/lib(or Debug-build/lib).
And we can see these environment variables:
SVF_DIR=/path/to/SVF
LLVM_DIR=/path/to/SVF/llvm-16.0.0.obj
Z3_DIR=/path/to/SVF/z3.objThen clone the SVF-Python repository:
git clone https://github.com/SVF-tools/SVF-Python.git
cd SVF-PythonWe should make sure these variables.
-
SVF_DIRpoints to the SVF directory, which should be given by the previous step. -
LLVM_DIRpoints to the LLVM directory, which should be given by the previous step. -
Z3_DIRpoints to the Z3 directory, which should be given by the previous step. -
PYBIND11_DIRpoints to the pybind11 directory, which ispython3 -m pybind11 --cmakedir. -
CMAKE_BUILD_TYPEis the build type, which can beReleaseorDebug, default isRelease. It should be the same as the build type of SVF.
Inside the SVF-Python directory:
-
Clean Up (If Rebuilding)
If you’ve attempted a previous build, remove cached directories:rm -rf build dist pysvf.egg-info
-
Adjust
setup.py- Open the script in a text editor.
- Update the Python binary path and version, if needed:
you can set your version number.
version="0.0.0" - Confirm it points to the correct
python3interpreter on your system.
-
Run the Build Script
SVF_DIR=${SVF_DIR} LLVM_DIR=${LLVM_DIR} Z3_DIR=${Z3_DIR} bash build.shOnce the build is finished:
- Check the generated file name in
dist/. - Install it via
pip:python3 -m pip install dist/YOUR_SVF_PYTHON.whl
If installation completes without errors, you should have pysvf available in your Python environment.
- Change to
test_cases:cd test_cases - Run the test script:
python3 test.py
- If everything is set up correctly, you’ll see output related to ICFG (e.g.,
CallICFGNode,RetICFGNode, etc.) from the example bitcode.
Unlike the pip install pre-built wheels from Pypi, it has no dependency installation process. You should see a bunch of output from ICFGNode from the bitcodes.
.... [Other output
CallICFGNode45 {fun: main{ "ln": 21, "cl": 5, "fl": "src/ae_assert_tests/BASIC_array_2d_0-0.c" }}
call void @svf_assert(i1 noundef zeroext %cmp), !dbg !47 CallICFGNode: { "ln": 21, "cl": 5, "fl": "src/ae_assert_tests/BASIC_array_2d_0-0.c" }
RetICFGNode46 {fun: main{ "ln": 21, "cl": 5, "fl": "src/ae_assert_tests/BASIC_array_2d_0-0.c" }}
call void @svf_assert(i1 noundef zeroext %cmp), !dbg !47 RetICFGNode: { "ln": 21, "cl": 5, "fl": "src/ae_assert_tests/BASIC_array_2d_0-0.c" }
IntraICFGNode47 {fun: main{ "ln": 22, "cl": 5, "fl": "src/ae_assert_tests/BASIC_array_2d_0-0.c" }}
ret i32 0, !dbg !48 { "ln": 22, "cl": 5, "fl": "src/ae_assert_tests/BASIC_array_2d_0-0.c" }
-
Missing or Incompatible CMake
If the build fails, verify your CMake version (cmake --version). -
Command Line Tools
Make sure you installed Xcode or Command Line Tools; missing compilers often cause build issues. -
Python Development Headers
If you see errors about missing headers, ensure the correct Python dev headers are installed. (On Homebrew Python, this is usually included by default.)
With the above steps, you can build and install SVF-Python on macOS. Once installed, you can import pysvf in your scripts and start using SVF’s static analysis capabilities.
For more in-depth usage, refer to:
- Official SVF Documentation
- The
pysvfAPI reference in the repository