added CMakeLists.txt
 
@@ -0,0 +1,85 @@
1
+ cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
2
+ project(hnswlib_nif C CXX)
3
+
4
+ if(NOT DEFINED PRIV_DIR)
5
+ if(DEFINED MIX_APP_PATH AND NOT "${MIX_APP_PATH}" STREQUAL "")
6
+ if(WIN32)
7
+ string(REPLACE "\\" "/" MIX_APP_PATH "${MIX_APP_PATH}")
8
+ endif()
9
+ set(PRIV_DIR "${MIX_APP_PATH}/priv")
10
+ else()
11
+ set(PRIV_DIR "${CMAKE_CURRENT_SOURCE_DIR}/priv")
12
+ endif()
13
+ endif()
14
+ message(STATUS "Using PRIV_DIR: ${PRIV_DIR}")
15
+
16
+ if(DEFINED ERTS_INCLUDE_DIR AND NOT "${ERTS_INCLUDE_DIR}" STREQUAL "")
17
+ set(ERTS_INCLUDE_DIR "${ERTS_INCLUDE_DIR}")
18
+ else()
19
+ set(ERTS_INCLUDE_DIR_ONE_LINER "erl -noshell -eval \"io:format('~ts/erts-~ts/include/', [code:root_dir(), erlang:system_info(version)]), halt().\"")
20
+ if(WIN32)
21
+ execute_process(COMMAND powershell -command "${ERTS_INCLUDE_DIR_ONE_LINER}" OUTPUT_VARIABLE ERTS_INCLUDE_DIR)
22
+ else()
23
+ execute_process(COMMAND bash -c "${ERTS_INCLUDE_DIR_ONE_LINER}" OUTPUT_VARIABLE ERTS_INCLUDE_DIR)
24
+ endif()
25
+ set(ERTS_INCLUDE_DIR "${ERTS_INCLUDE_DIR}")
26
+ endif()
27
+ message(STATUS "Using ERTS_INCLUDE_DIR: ${ERTS_INCLUDE_DIR}")
28
+
29
+ if(UNIX AND APPLE)
30
+ set(CMAKE_SHARED_LINKER_FLAGS "-flat_namespace -undefined suppress -undefined dynamic_lookup")
31
+ endif()
32
+
33
+ set(CMAKE_CXX_STANDARD 14)
34
+ if(DEFINED ENV{TARGET_GCC_FLAGS})
35
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{TARGET_GCC_FLAGS}")
36
+ endif()
37
+
38
+ message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
39
+
40
+ if(WIN32)
41
+ string(REPLACE "\\" "/" C_SRC "${C_SRC}")
42
+ endif()
43
+ set(SOURCE_FILES
44
+ "${C_SRC}/nif_utils.cpp"
45
+ "${C_SRC}/hnswlib_nif.cpp"
46
+ )
47
+
48
+ include_directories("${ERTS_INCLUDE_DIR}")
49
+ include_directories("${HNSWLIB_SRC}")
50
+
51
+ add_library(hnswlib_nif SHARED
52
+ ${SOURCE_FILES}
53
+ )
54
+ install(
55
+ TARGETS hnswlib_nif
56
+ RUNTIME DESTINATION "${PRIV_DIR}"
57
+ )
58
+
59
+ set_target_properties(hnswlib_nif PROPERTIES PREFIX "")
60
+ if(NOT WIN32)
61
+ set_target_properties(hnswlib_nif PROPERTIES SUFFIX ".so")
62
+ endif()
63
+ set_target_properties(hnswlib_nif PROPERTIES
64
+ INSTALL_RPATH_USE_LINK_PATH TRUE
65
+ BUILD_WITH_INSTALL_RPATH TRUE
66
+ )
67
+
68
+ if(UNIX AND NOT APPLE)
69
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-but-set-variable -Wno-reorder")
70
+ elseif(UNIX AND APPLE)
71
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-reorder-ctor")
72
+ set(CMAKE_SHARED_LINKER_FLAGS "-flat_namespace -undefined suppress -undefined dynamic_lookup")
73
+ endif()
74
+
75
+ if(WIN32)
76
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4996 /wd4267 /wd4068")
77
+ else()
78
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
79
+ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
80
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g3")
81
+ else()
82
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
83
+ endif()
84
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers -Wno-deprecated-declarations")
85
+ endif()
changed Makefile
 
@@ -6,6 +6,17 @@ PRIV_DIR = $(MIX_APP_PATH)/priv
6
6
NIF_SO = $(PRIV_DIR)/hnswlib_nif.so
7
7
HNSWLIB_SRC = $(shell pwd)/3rd_party/hnswlib
8
8
C_SRC = $(shell pwd)/c_src
9
+
10
+ ifdef CC_PRECOMPILER_CURRENT_TARGET
11
+ ifeq ($(findstring darwin, $(CC_PRECOMPILER_CURRENT_TARGET)), darwin)
12
+ ifeq ($(findstring aarch64, $(CC_PRECOMPILER_CURRENT_TARGET)), aarch64)
13
+ CMAKE_CONFIGURE_FLAGS=-D CMAKE_OSX_ARCHITECTURES=arm64
14
+ else
15
+ CMAKE_CONFIGURE_FLAGS=-D CMAKE_OSX_ARCHITECTURES=x86_64
16
+ endif
17
+ endif
18
+ endif
19
+
9
20
ifdef CMAKE_TOOLCHAIN_FILE
10
21
CMAKE_CONFIGURE_FLAGS=-D CMAKE_TOOLCHAIN_FILE="$(CMAKE_TOOLCHAIN_FILE)"
11
22
endif
changed checksum.exs
 
@@ -1,22 +1,22 @@
1
1
%{
2
- "hnswlib-nif-2.16-aarch64-apple-darwin-0.1.1.tar.gz" => "sha256:efd52b720cc3f0f84bd701e9583b953a8474284658a73573969b71ba3c41d45b",
3
- "hnswlib-nif-2.16-aarch64-linux-gnu-0.1.1.tar.gz" => "sha256:3f95a8e6f1bebfc1a917fa63d3e9d42ad00fee18770e0f2eb25e8151ceeee09e",
4
- "hnswlib-nif-2.16-armv7l-linux-gnueabihf-0.1.1.tar.gz" => "sha256:3f95a8e6f1bebfc1a917fa63d3e9d42ad00fee18770e0f2eb25e8151ceeee09e",
5
- "hnswlib-nif-2.16-i686-linux-gnu-0.1.1.tar.gz" => "sha256:3f95a8e6f1bebfc1a917fa63d3e9d42ad00fee18770e0f2eb25e8151ceeee09e",
6
- "hnswlib-nif-2.16-powerpc64le-linux-gnu-0.1.1.tar.gz" => "sha256:3f95a8e6f1bebfc1a917fa63d3e9d42ad00fee18770e0f2eb25e8151ceeee09e",
7
- "hnswlib-nif-2.16-riscv64-linux-gnu-0.1.1.tar.gz" => "sha256:3f95a8e6f1bebfc1a917fa63d3e9d42ad00fee18770e0f2eb25e8151ceeee09e",
8
- "hnswlib-nif-2.16-s390x-linux-gnu-0.1.1.tar.gz" => "sha256:3f95a8e6f1bebfc1a917fa63d3e9d42ad00fee18770e0f2eb25e8151ceeee09e",
9
- "hnswlib-nif-2.16-x86_64-apple-darwin-0.1.1.tar.gz" => "sha256:9202f8f767c9fcd8d177b7da1bf06841fe9d246653a579ca2799391d742cefec",
10
- "hnswlib-nif-2.16-x86_64-linux-gnu-0.1.1.tar.gz" => "sha256:3f95a8e6f1bebfc1a917fa63d3e9d42ad00fee18770e0f2eb25e8151ceeee09e",
11
- "hnswlib-nif-2.16-x86_64-windows-msvc-0.1.1.tar.gz" => "sha256:45f549bb16472f2aae74ebf1126d9e636668621be9f87fa1e6b28fd75112ac05",
12
- "hnswlib-nif-2.17-aarch64-apple-darwin-0.1.1.tar.gz" => "sha256:1962525c16ada97b654b816e6fb87339480ae52859f0ee4a9d882e4eda153789",
13
- "hnswlib-nif-2.17-aarch64-linux-gnu-0.1.1.tar.gz" => "sha256:e4071b06684c8d15d009705ae33f6bbf7eb1b51441bbecee57684878f57bcf0e",
14
- "hnswlib-nif-2.17-armv7l-linux-gnueabihf-0.1.1.tar.gz" => "sha256:e4071b06684c8d15d009705ae33f6bbf7eb1b51441bbecee57684878f57bcf0e",
15
- "hnswlib-nif-2.17-i686-linux-gnu-0.1.1.tar.gz" => "sha256:e4071b06684c8d15d009705ae33f6bbf7eb1b51441bbecee57684878f57bcf0e",
16
- "hnswlib-nif-2.17-powerpc64le-linux-gnu-0.1.1.tar.gz" => "sha256:e4071b06684c8d15d009705ae33f6bbf7eb1b51441bbecee57684878f57bcf0e",
17
- "hnswlib-nif-2.17-riscv64-linux-gnu-0.1.1.tar.gz" => "sha256:e4071b06684c8d15d009705ae33f6bbf7eb1b51441bbecee57684878f57bcf0e",
18
- "hnswlib-nif-2.17-s390x-linux-gnu-0.1.1.tar.gz" => "sha256:e4071b06684c8d15d009705ae33f6bbf7eb1b51441bbecee57684878f57bcf0e",
19
- "hnswlib-nif-2.17-x86_64-apple-darwin-0.1.1.tar.gz" => "sha256:1962525c16ada97b654b816e6fb87339480ae52859f0ee4a9d882e4eda153789",
20
- "hnswlib-nif-2.17-x86_64-linux-gnu-0.1.1.tar.gz" => "sha256:e4071b06684c8d15d009705ae33f6bbf7eb1b51441bbecee57684878f57bcf0e",
21
- "hnswlib-nif-2.17-x86_64-windows-msvc-0.1.1.tar.gz" => "sha256:0f988ee6e0a048b3db251510508f96b1e60b6fb4b5b3fcc50b5ab7f63675ba4f",
2
+ "hnswlib-nif-2.16-aarch64-apple-darwin-0.1.2.tar.gz" => "sha256:070c882464ee735d6d0e402dec297d44cab4a8891d903241d6b7f4db10c6d070",
3
+ "hnswlib-nif-2.16-aarch64-linux-gnu-0.1.2.tar.gz" => "sha256:18c65a452ef5d9fb43b7a2eec1ea5d08e68a736a1aaff0284d23c9eedc039f06",
4
+ "hnswlib-nif-2.16-armv7l-linux-gnueabihf-0.1.2.tar.gz" => "sha256:18c65a452ef5d9fb43b7a2eec1ea5d08e68a736a1aaff0284d23c9eedc039f06",
5
+ "hnswlib-nif-2.16-i686-linux-gnu-0.1.2.tar.gz" => "sha256:18c65a452ef5d9fb43b7a2eec1ea5d08e68a736a1aaff0284d23c9eedc039f06",
6
+ "hnswlib-nif-2.16-powerpc64le-linux-gnu-0.1.2.tar.gz" => "sha256:18c65a452ef5d9fb43b7a2eec1ea5d08e68a736a1aaff0284d23c9eedc039f06",
7
+ "hnswlib-nif-2.16-riscv64-linux-gnu-0.1.2.tar.gz" => "sha256:18c65a452ef5d9fb43b7a2eec1ea5d08e68a736a1aaff0284d23c9eedc039f06",
8
+ "hnswlib-nif-2.16-s390x-linux-gnu-0.1.2.tar.gz" => "sha256:18c65a452ef5d9fb43b7a2eec1ea5d08e68a736a1aaff0284d23c9eedc039f06",
9
+ "hnswlib-nif-2.16-x86_64-apple-darwin-0.1.2.tar.gz" => "sha256:9004ba9d0d6d96273f05a3436bad8afd30900435300438a517fbbc908af211fb",
10
+ "hnswlib-nif-2.16-x86_64-linux-gnu-0.1.2.tar.gz" => "sha256:18c65a452ef5d9fb43b7a2eec1ea5d08e68a736a1aaff0284d23c9eedc039f06",
11
+ "hnswlib-nif-2.16-x86_64-windows-msvc-0.1.2.tar.gz" => "sha256:1fa027a5a9c628b7884cc7197c04c06e7dc10cfc58ee720802ee1e864d736d50",
12
+ "hnswlib-nif-2.17-aarch64-apple-darwin-0.1.2.tar.gz" => "sha256:df8b1b144a60c54a548d2b4fbfaf81ce48bd0b70833eac3624f383ddb779927b",
13
+ "hnswlib-nif-2.17-aarch64-linux-gnu-0.1.2.tar.gz" => "sha256:fff35b7e2b004f78c72d31707277678b1a2103ecc67a80fabaed92b8b36780bc",
14
+ "hnswlib-nif-2.17-armv7l-linux-gnueabihf-0.1.2.tar.gz" => "sha256:fff35b7e2b004f78c72d31707277678b1a2103ecc67a80fabaed92b8b36780bc",
15
+ "hnswlib-nif-2.17-i686-linux-gnu-0.1.2.tar.gz" => "sha256:fff35b7e2b004f78c72d31707277678b1a2103ecc67a80fabaed92b8b36780bc",
16
+ "hnswlib-nif-2.17-powerpc64le-linux-gnu-0.1.2.tar.gz" => "sha256:fff35b7e2b004f78c72d31707277678b1a2103ecc67a80fabaed92b8b36780bc",
17
+ "hnswlib-nif-2.17-riscv64-linux-gnu-0.1.2.tar.gz" => "sha256:fff35b7e2b004f78c72d31707277678b1a2103ecc67a80fabaed92b8b36780bc",
18
+ "hnswlib-nif-2.17-s390x-linux-gnu-0.1.2.tar.gz" => "sha256:fff35b7e2b004f78c72d31707277678b1a2103ecc67a80fabaed92b8b36780bc",
19
+ "hnswlib-nif-2.17-x86_64-apple-darwin-0.1.2.tar.gz" => "sha256:3def681c4af5df5d0e2e8d4296498b4f56fad0f63f3fd58f765b857142525f9f",
20
+ "hnswlib-nif-2.17-x86_64-linux-gnu-0.1.2.tar.gz" => "sha256:23b44c914cec81386fc0d1ea44e9673e78bcadaf23b6053203f0da616980bcd0",
21
+ "hnswlib-nif-2.17-x86_64-windows-msvc-0.1.2.tar.gz" => "sha256:402dd20cea31276d922e6262c8d9c07619d6feab3a78959d534d06a6884b294b",
22
22
}
changed hex_metadata.config
 
@@ -1,6 +1,6 @@
1
1
{<<"links">>,[{<<"GitHub">>,<<"https://github.com/elixir-nx/hnswlib">>}]}.
2
2
{<<"name">>,<<"hnswlib">>}.
3
- {<<"version">>,<<"0.1.1">>}.
3
+ {<<"version">>,<<"0.1.2">>}.
4
4
{<<"description">>,<<"Elixir binding for the hnswlib library">>}.
5
5
{<<"elixir">>,<<"~> 1.12">>}.
6
6
{<<"app">>,<<"hnswlib">>}.
 
@@ -14,7 +14,7 @@
14
14
<<"c_src/nif_utils.hpp">>,<<"lib">>,<<"lib/hnswlib_bfindex.ex">>,
15
15
<<"lib/hnswlib_index.ex">>,<<"lib/hnswlib_nif.ex">>,
16
16
<<"lib/hnswlib_helper.ex">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE">>,
17
- <<"Makefile">>,<<"checksum.exs">>]}.
17
+ <<"CMakeLists.txt">>,<<"Makefile">>,<<"checksum.exs">>]}.
18
18
{<<"licenses">>,[<<"Apache-2.0">>]}.
19
19
{<<"requirements">>,
20
20
[[{<<"name">>,<<"cc_precompiler">>},
changed lib/hnswlib_nif.ex
 
@@ -8,7 +8,7 @@ defmodule HNSWLib.Nif do
8
8
case :erlang.load_nif(nif_file, 0) do
9
9
:ok -> :ok
10
10
{:error, {:reload, _}} -> :ok
11
- {:error, reason} -> IO.puts("Failed to load nif: #{reason}")
11
+ {:error, reason} -> IO.puts("Failed to load nif: #{inspect(reason)}")
12
12
end
13
13
end
changed mix.exs
 
@@ -1,7 +1,7 @@
1
1
defmodule HNSWLib.MixProject do
2
2
use Mix.Project
3
3
4
- @version "0.1.1"
4
+ @version "0.1.2"
5
5
@github_url "https://github.com/elixir-nx/hnswlib"
6
6
7
7
def project do
 
@@ -52,7 +52,8 @@ defmodule HNSWLib.MixProject do
52
52
53
53
defp package() do
54
54
[
55
- files: ~w(3rd_party/hnswlib c_src lib mix.exs README* LICENSE* Makefile checksum.exs),
55
+ files:
56
+ ~w(3rd_party/hnswlib c_src lib mix.exs README* LICENSE* CMakeLists.txt Makefile checksum.exs),
56
57
licenses: ["Apache-2.0"],
57
58
links: %{"GitHub" => @github_url}
58
59
]