Skip to content

Commit

Permalink
compile with pkg-config
Browse files Browse the repository at this point in the history
Signed-off-by: shaoting-huang <[email protected]>
  • Loading branch information
shaoting-huang committed Jan 17, 2025
1 parent 9e53927 commit 0d60d5d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ jobs:

- name: Run cpp tests
run: cd cpp/build/Release/test && ./milvus_test

- name: Package cpp
run: cd cpp && make package

- name: Run tests
run: cd go && make && make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ go/.idea/*
compile_commands.json
CMakeUserPresets.json
.vscode/*
go/internal/core/output/*
16 changes: 14 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,26 @@ if (WITH_BENCHMARK)
add_subdirectory(benchmark)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/milvus-storage.pc.in "${CMAKE_CURRENT_BINARY_DIR}/milvus-storage.pc" @ONLY)
function(add_pkg_config module)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/${module}.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${module}.pc
@ONLY
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${module}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/"
)
endfunction()


add_pkg_config(libstorage)

install(TARGETS milvus-storage
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
message( "install cmake install libdir: ${CMAKE_CURRENT_SOURCE_DIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/milvus-storage.pc" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/build/Release/")

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

Expand Down
2 changes: 1 addition & 1 deletion cpp/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,4 @@ def package_info(self):
)
self.cpp_info.components["libstorage"].set_property(
"pkg_config_name", "libstorage"
)
)
2 changes: 1 addition & 1 deletion cpp/src/milvus-storage.pc.in → cpp/src/libstorage.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Name: Milvus Storage
Description: Milvus Storage
Version: @PROJECT_VERSION@

Libs: -L${libdir} -lmilvus-storage
Libs: -L${libdir} -lmilvus-storage -Wl,-rpath,"${libdir}"
Cflags: -I${includedir}
24 changes: 7 additions & 17 deletions go/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
include ../cpp/build/conanbuildinfo.mak

MILVUS_STORAGE_ROOT = $(abspath $(CURDIR)/..)
MILVUS_STORAGE_INCLUDE_DIR = $(abspath $(MILVUS_STORAGE_ROOT)/cpp/include)
MILVUS_STORAGE_LD_DIR = $(abspath $(MILVUS_STORAGE_ROOT)/cpp/build/Release)

CFLAGS += $(CONAN_CFLAGS)
CXXFLAGS += $(CONAN_CXXFLAGS)
INCLUDE_DIRS = $(CONAN_INCLUDE_DIRS_ARROW) $(MILVUS_STORAGE_INCLUDE_DIR)
CPPFLAGS += $(addprefix -I, $(INCLUDE_DIRS))
LDFLAGS += $(addprefix -L, $(MILVUS_STORAGE_LD_DIR)) -Wl,-rpath,$(MILVUS_STORAGE_LD_DIR)
MILVUS_STORAGE_LD_DIR = $(abspath $(CURDIR)/build/Release)

.EXPORT_ALL_VARIABLES:
.PHONY: build test proto

build:
@echo "CPPFLAGS: $(CPPFLAGS)"
@echo "LDFLAGS: $(LDFLAGS)"
@echo "CGO_CFLAGS: $(CGO_CFLAGS)"
@echo "CGO_LDFLAGS: $(CGO_LDFLAGS)"
@. $(PWD)/scripts/setenv.sh && \
CGO_CFLAGS="$(CPPFLAGS)" CGO_LDFLAGS="$(LDFLAGS) -lmilvus-storage" go build ./...
CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build ./...

test:
@. $(PWD)/scripts/setenv.sh && LD_LIBRARY_PATH=$(MILVUS_STORAGE_LD_DIR):$$LD_LIBRARY_PATH \
CGO_CFLAGS="$(CPPFLAGS)" \
CGO_LDFLAGS="$(LDFLAGS) -lmilvus-storage" \
@. $(PWD)/scripts/setenv.sh && \
CGO_CFLAGS="$(CGO_CFLAGS)" \
CGO_LDFLAGS="$(CGO_LDFLAGS)" \
go test -count=1 -timeout 30s ./... -gcflags "all=-N -l" -o gdb/

proto:
Expand Down
6 changes: 3 additions & 3 deletions go/packed/packed_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
package packed

/*
#cgo pkg-config: milvus-storage
#cgo pkg-config: libstorage, arrow
#include <stdlib.h>
#include "milvus-storage/packed/reader_c.h"
#include "arrow/c/abi.h"
#include "arrow/c/helpers.h"
#include <arrow/c/abi.h>
#include <arrow/c/helpers.h>
*/
import "C"

Expand Down
6 changes: 3 additions & 3 deletions go/packed/packed_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
package packed

/*
#cgo pkg-config: milvus-storage
#cgo pkg-config: libstorage, arrow
#include <stdlib.h>
#include "milvus-storage/packed/writer_c.h"
#include "arrow/c/abi.h"
#include "arrow/c/helpers.h"
#include <arrow/c/abi.h>
#include <arrow/c/helpers.h>
*/
import "C"

Expand Down
13 changes: 12 additions & 1 deletion go/scripts/setenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@ unameOut="$(uname -s)"

ROOT_DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"

PKG_CONFIG_DIR="$ROOT_DIR/go/internal/core/output/lib/pkgconfig"

conan install milvus-storage/0.1.0@milvus/testing --install-folder $PKG_CONFIG_DIR -g pkg_config --build=missing

ARROW_PC_FILE="$PKG_CONFIG_DIR/arrow.pc"
if [ ! -f "$ARROW_PC_FILE" ]; then
echo "Error: $ARROW_PC_FILE not found."
exit 1
fi
sed -i '/^Requires:/c\Requires:' "$ARROW_PC_FILE"

# Update PKG_CONFIG_PATH
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${ROOT_DIR}/cpp/build/Release/"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:$PKG_CONFIG_DIR"

0 comments on commit 0d60d5d

Please sign in to comment.