Skip to content

Commit

Permalink
Enable windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
1yefuwang1 committed Jun 30, 2024
1 parent e851d14 commit 37697e2
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 42 deletions.
29 changes: 17 additions & 12 deletions .github/workflows/build-wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,39 @@ jobs:
strategy:
matrix:
# os: [ubuntu-latest, windows-latest, macos-13, macos-14]
os: [ubuntu-latest, macos-13, macos-14]
# os: [ubuntu-latest, macos-13, macos-14]
os: [windows-latest]

steps:
- uses: actions/checkout@v4

# Used to host cibuildwheel
- uses: actions/setup-python@v5

- name: setup devcmd
if: ${{ matrix.os == 'windows-latest' }}
# NOTE: this is necessary to correctly find and use cl.exe
uses: ilammy/msvc-dev-cmd@v1.13.0
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.19.1 pipx pytest apsw numpy

- name: Install linux deps
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt-get install zip -y
- uses: ilammy/msvc-dev-cmd@v1

- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v2

- name: Setup Ninja
uses: seanmiddleditch/gha-setup-ninja@v5

- name: Bootstrap vcpkg
run: |
git submodule update --init --recursive
python bootstrap_vcpkg.py
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.19.1
- name: build release
shell: bash
run: |
sh build_release.sh

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
run: pipx run cibuildwheel --output-dir wheelhouse
env:
MACOSX_DEPLOYMENT_TARGET: '10.15' # 10.15 is the minimum version that fully supports c++17

Expand Down
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)

if (WIN32)
set(VCPKG_TARGET_TRIPLET "x64-windows-static-md")
message(STATUS "VCPKG_TARGET_TRIPLET on windows: ${VCPKG_TARGET_TRIPLET}")
endif(WIN32)

project(vectorlite VERSION 0.1.0 LANGUAGES CXX)

configure_file(src/version.h.in version.h)
Expand Down Expand Up @@ -31,12 +36,13 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
endif ()

add_library(vectorlite SHARED src/vectorlite.cpp src/virtual_table.cpp src/vector.cpp src/util.cpp src/vector_space.cpp src/index_options.cpp src/sqlite_functions.cpp src/constraint.cpp)
# remove the lib prefix to make the shared library name consistent on all platforms.
set_target_properties(vectorlite PROPERTIES PREFIX "")
target_include_directories(vectorlite PUBLIC ${RAPIDJSON_INCLUDE_DIRS} ${HNSWLIB_INCLUDE_DIRS} ${PROJECT_BINARY_DIR})
target_link_libraries(vectorlite PRIVATE unofficial::sqlite3::sqlite3 absl::status absl::statusor absl::strings re2::re2)
# copy the shared library to the python package to make running integration tests easier
add_custom_command(TARGET vectorlite POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vectorlite> ${PROJECT_SOURCE_DIR}/vectorlite_py/$<TARGET_FILE_NAME:vectorlite>)


include(GoogleTest)
enable_testing()
file(GLOB TEST_SOURCES src/*.cpp)
Expand All @@ -59,6 +65,11 @@ endif(OPTION_USE_AVX)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_libraries(vectorlite PRIVATE absl::log)
target_link_libraries(unit-test PRIVATE absl::log)
else()
if(MSVC)
target_compile_definitions(vectorlite PRIVATE NDEBUG)
target_compile_definitions(unit-test PRIVATE NDEBUG)
endif()
endif()

gtest_discover_tests(unit-test)
Expand Down
2 changes: 1 addition & 1 deletion build_release.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cmake --preset release && cmake --build build/release -j8 && ctest --test-dir build/release --output-on-failure && pytest vectorlite_py/test
cmake --preset release && cmake --build build/release -j8 && ctest --test-dir build/release --output-on-failure
2 changes: 1 addition & 1 deletion examples/knn_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create_connection():
# create connection to in-memory database
conn = apsw.Connection(':memory:') if use_apsw else sqlite3.connect(':memory:')
conn.enable_load_extension(True)
conn.load_extension('../build/release/libvectorlite.so')
conn.load_extension('../build/release/vectorlite.so')
return conn

conn = create_connection()
Expand Down
2 changes: 1 addition & 1 deletion integration_test/delete_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) {
const auto& vectors = GenerateRandomVectors();
rc = sqlite3_enable_load_extension(db, 1);
assert(rc == SQLITE_OK);
rc = sqlite3_load_extension(db, "build/dev/libvectorlite.so", "sqlite3_extension_init", &zErrMsg);
rc = sqlite3_load_extension(db, "build/dev/vectorlite.so", "sqlite3_extension_init", &zErrMsg);
if (rc != SQLITE_OK) {
std::cerr << "load extension failed: " << zErrMsg << std::endl;
sqlite3_free(zErrMsg);
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[build-system]
requires = ["setuptools>=59", "wheel", "cmake", "ninja"]
#cmake 3.29.6 doesn't work on windows
requires = ["setuptools>=59", "wheel"]

build-backend = "setuptools.build_meta"

[tool.cibuildwheel]
test-requires = ["pytest", "numpy", "apsw>=3.46"]
test-command = "pytest {project}/integration_test/python/test"
skip = ["*-win32", "*-manylinux_i686", "*musllinux*", "pp*", "cp36*", "cp37*", "cp38*"]
skip = ["*-win32", "*-win_arm64", "*-manylinux_i686", "*musllinux*", "pp*", "cp36*", "cp37*", "cp38*", "cp39*"]
46 changes: 23 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from pathlib import Path

from setuptools import Extension, setup
import cmake
# import cmake
import subprocess
import ninja
# import ninja

VERSION = '0.1.0'
PACKAGE_NAME = 'vectorlite_py'
Expand All @@ -19,38 +19,38 @@
machine = platform.machine()

print(f'Current platfrom: {system}, {machine}')
print(f'cmake bin dir: {cmake.CMAKE_BIN_DIR}. cwd: {os.getcwd()}')
cmake_path = os.path.join(cmake.CMAKE_BIN_DIR, 'cmake')
ctest_path = os.path.join(cmake.CMAKE_BIN_DIR, 'ctest')
ninja_path = os.path.join(ninja.BIN_DIR, 'ninja')
cmake_version = subprocess.run(['cmake', '--version'], check=True)
cmake_version.check_returncode()
# print(f'cmake bin dir: {cmake.CMAKE_BIN_DIR}. cwd: {os.getcwd()}')
# cmake_path = os.path.join(cmake.CMAKE_BIN_DIR, 'cmake')
# ctest_path = os.path.join(cmake.CMAKE_BIN_DIR, 'ctest')
# ninja_path = os.path.join(ninja.BIN_DIR, 'ninja')
# cmake_version = subprocess.run([cmake_path, '--version'], check=True)
# cmake_version.check_returncode()

class CMakeExtension(Extension):
def __init__(self, name: str) -> None:
super().__init__(name, sources=[])

def get_lib_name():
if system.lower() == 'linux':
return 'libvectorlite.so'
return 'vectorlite.so'
if system.lower() == 'darwin':
return 'libvectorlite.dylib'
return 'vectorlite.dylib'
if system.lower() == 'windows':
return 'libvectorlite.dll'
return 'vectorlite.dll'
raise ValueError(f'Unsupported platform: {system}')

class CMakeBuild(build_ext):
def build_extension(self, ext: CMakeExtension) -> None:
print(f'Building extension for {self.plat_name} {self.compiler.compiler_type}')
extra_args = []
if system.lower() == 'windows':
extra_args = ['-DCMAKE_CXX_COMPILER=cl', '-DCMAKE_C_COMPILER=cl']
configure = subprocess.run([cmake_path, '--preset', 'release', f'-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_path}', *extra_args])
configure.check_returncode()
# class CMakeBuild(build_ext):
# def build_extension(self, ext: CMakeExtension) -> None:
# print(f'Building extension for {self.plat_name} {self.compiler.compiler_type}')
# extra_args = []
# # if system.lower() == 'windows':
# # extra_args = ['-DCMAKE_CXX_COMPILER=cl', '-DCMAKE_C_COMPILER=cl']
# configure = subprocess.run([cmake_path, '--preset', 'release', f'-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_path}', *extra_args])
# configure.check_returncode()

subprocess.run([cmake_path, '--build', os.path.join('build', 'release'), '-j8'], check=True)
print(f'Running unit tests')
subprocess.run([ctest_path, '--test-dir', os.path.join('build', 'release'), '--rerun-failed', '--output-on-failure'], check=True)
# subprocess.run([cmake_path, '--build', os.path.join('build', 'release'), '-j8'], check=True)
# print(f'Running unit tests')
# subprocess.run([ctest_path, '--test-dir', os.path.join('build', 'release'), '--rerun-failed', '--output-on-failure'], check=True)

class CMakeInstallLib(install_lib):
def run(self):
Expand Down Expand Up @@ -87,7 +87,7 @@ def get_tag(self):
install_requires=[],
ext_modules=[CMakeExtension('vectorlite')],
cmdclass={
'build_ext': CMakeBuild,
# 'build_ext': CMakeBuild,
'install_lib': CMakeInstallLib,
'bdist_wheel': BuildAbiNoneWheel
}
Expand Down
2 changes: 1 addition & 1 deletion vectorlite_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__version__ = '0.1.0'

def vectorlite_path():
loadable_path = os.path.join(os.path.dirname(__file__), 'libvectorlite')
loadable_path = os.path.join(os.path.dirname(__file__), 'vectorlite')
return os.path.normpath(loadable_path)


Expand Down

0 comments on commit 37697e2

Please sign in to comment.