Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions packages/f/faiss/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
package("faiss")

set_homepage("https://github.com/facebookresearch/faiss/")
set_description("A library for efficient similarity search and clustering of dense vectors.")
set_license("MIT")

add_urls("https://github.com/facebookresearch/faiss/archive/refs/tags/$(version).tar.gz",
"https://github.com/facebookresearch/faiss.git")
add_versions("v1.7.0", "f86d346ac9f409ee30abe37e52f6cce366b7f60d3924d65719f40aa07ceb4bec")
add_versions("v1.12.0", "561376d1a44771bf1230fabeef9c81643468009b45a585382cf38d3a7a94990a")

add_configs("gpu", {description = "Enable support for GPU indexes.", default = false, type = "boolean"})
add_configs("gpu_static", {description = "Link GPU libraries statically.", default = false, type = "boolean"})
add_configs("mkl", {description = "Enable MKL.", default = false, type = "boolean"})
add_configs("python", {description = "Build Python extension.", default = false, type = "boolean"})
add_configs("c_api", {description = "Build C API.", default = false, type = "boolean"})
add_configs("lto", {description = "Enable Link-Time optimization.", default = false, type = "boolean"})
Copy link
Contributor

@star-hengxing star-hengxing Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is built-in config, you can check xrepo info zlib.


add_deps("cmake")
add_deps("cuda", {system = true, optional = true})
add_deps("mkl", "cuda", {system = true, optional = true})
if is_plat("linux") then
add_syslinks("pthread")
end
on_load("windows|x64", "linux", function (package)
if not find_package("mkl") then

add_deps("cmake", "openmp")
on_load(function (package)
if package:config("gpu") then
package:add("deps", "cuda")
end
if package:config("mkl") then
package:add("deps", "mkl", {system = true, optional = true})
else
package:add("deps", "openblas")
end
end)

on_install("windows|x64", "linux", function (package)
io.replace("CMakeLists.txt", "add_subdirectory(demos)", "", {plain = true})
io.replace("CMakeLists.txt", "add_subdirectory(tutorial/cpp)", "", {plain = true})
local configs = {"-DFAISS_ENABLE_PYTHON=OFF", "-DBUILD_TESTING=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DFAISS_ENABLE_GPU=" .. (package:dep("cuda"):exists() and "ON" or "OFF"))
on_install("windows|x64", "linux", "macosx", function (package)
local configs = {
"-DBUILD_TESTING=OFF",
"-DFAISS_ENABLE_EXTRAS=OFF",
}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DFAISS_ENABLE_GPU=" .. (package:config("gpu") and "ON" or "OFF"))
table.insert(configs, "-DFAISS_GPU_STATIC=" .. (package:config("gpu_static") and "ON" or "OFF"))
table.insert(configs, "-DFAISS_ENABLE_MKL=" .. (package:config("mkl") and "ON" or "OFF"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The logic for enabling MKL is currently incorrect. It only checks package:config("mkl"), which defaults to true. If the MKL library is not found on the system, on_load correctly adds openblas as a fallback. However, on_install will still pass -DFAISS_ENABLE_MKL=ON to CMake. This will cause the build to fail because faiss's build system will be unable to find the MKL library.

The condition should also check if the MKL package is actually found using find_package("mkl") before enabling the corresponding CMake option.

        table.insert(configs, "-DFAISS_ENABLE_MKL=" .. (find_package("mkl") and package:config("mkl") and "ON" or "OFF"))

table.insert(configs, "-DFAISS_ENABLE_PYTHON=" .. (package:config("python") and "ON" or "OFF"))
table.insert(configs, "-DFAISS_ENABLE_C_API=" .. (package:config("c_api") and "ON" or "OFF"))
table.insert(configs, "-DFAISS_ENABLE_LTO=" .. (package:config("lto") and "ON" or "OFF"))
import("package.tools.cmake").install(package, configs)
end)

on_test(function (package)
assert(package:has_cxxtypes("faiss::MultiIndexQuantizer", {configs = {languages = "c++11"}, includes = "faiss/IndexPQ.h"}))
assert(package:has_cxxtypes("faiss::MultiIndexQuantizer", {configs = {languages = "c++17"}, includes = "faiss/IndexPQ.h"}))
end)
Loading