2021-01-11 18:35:54 +08:00
#!/bin/bash
2021-10-09 18:01:27 +08:00
# Licensed to the LF AI & Data foundation under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2021-01-11 18:35:54 +08:00
SOURCE = ${ BASH_SOURCE [0] }
while [ -h $SOURCE ] ; do # resolve $SOURCE until the file is no longer a symlink
DIR = $( cd -P $( dirname $SOURCE ) && pwd )
SOURCE = $( readlink $SOURCE )
[ [ $SOURCE != /* ] ] && SOURCE = $DIR /$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR = $( cd -P $( dirname $SOURCE ) && pwd )
2021-01-14 15:12:08 +08:00
CMAKE_BUILD = ${ DIR } /../cwrapper_rocksdb_build
OUTPUT_LIB = ${ DIR } /../internal/kv/rocksdb/cwrapper/output
2021-01-11 18:35:54 +08:00
SRC_DIR = ${ DIR } /../internal/kv/rocksdb/cwrapper
2021-01-14 15:12:08 +08:00
if [ ! -d ${ CMAKE_BUILD } ] ; then
mkdir ${ CMAKE_BUILD }
fi
2021-01-11 18:35:54 +08:00
2021-01-14 15:12:08 +08:00
if [ ! -d ${ OUTPUT_LIB } ] ; then
mkdir ${ OUTPUT_LIB }
2021-01-11 18:35:54 +08:00
fi
BUILD_TYPE = "Debug"
2021-01-14 15:12:08 +08:00
CUSTOM_THIRDPARTY_PATH = ""
2022-04-14 19:57:34 +08:00
EMBEDDED_MILVUS = "OFF"
2021-01-11 18:35:54 +08:00
2022-04-14 19:57:34 +08:00
while getopts "t:h:f:b" arg; do
2021-01-11 18:35:54 +08:00
case $arg in
2021-01-14 15:12:08 +08:00
f)
CUSTOM_THIRDPARTY_PATH = $OPTARG
; ;
2021-01-11 18:35:54 +08:00
t)
BUILD_TYPE = $OPTARG # BUILD_TYPE
; ;
h) # help
echo " -t: build type(default: Debug)
2021-01-14 15:12:08 +08:00
-f: custom thirdparty path( default: "" )
2021-01-11 18:35:54 +08:00
-h: help
2022-04-14 19:57:34 +08:00
-b: build embedded milvus( default: OFF)
2021-01-11 18:35:54 +08:00
"
exit 0
; ;
2022-04-14 19:57:34 +08:00
b)
EMBEDDED_MILVUS = "ON"
; ;
2021-01-11 18:35:54 +08:00
?)
echo "ERROR! unknown argument"
exit 1
; ;
esac
done
echo "BUILD_TYPE: " $BUILD_TYPE
2021-01-14 15:12:08 +08:00
echo "CUSTOM_THIRDPARTY_PATH: " $CUSTOM_THIRDPARTY_PATH
2021-01-11 18:35:54 +08:00
2021-01-14 15:12:08 +08:00
pushd ${ CMAKE_BUILD }
2021-01-11 18:35:54 +08:00
CMAKE_CMD = " cmake \
2022-02-09 14:27:46 +08:00
-DCMAKE_BUILD_TYPE= ${ BUILD_TYPE } \
2021-01-14 15:12:08 +08:00
-DCMAKE_INSTALL_PREFIX= ${ OUTPUT_LIB } \
2022-04-14 19:57:34 +08:00
-DEMBEDDED_MILVUS= ${ EMBEDDED_MILVUS } \
2021-01-14 15:12:08 +08:00
-DCUSTOM_THIRDPARTY_DOWNLOAD_PATH= ${ CUSTOM_THIRDPARTY_PATH } ${ SRC_DIR } "
2021-01-11 18:35:54 +08:00
2022-02-09 14:27:46 +08:00
unameOut = " $( uname -s) "
2021-01-11 18:35:54 +08:00
if [ [ ! ${ jobs +1 } ] ] ; then
2022-02-09 14:27:46 +08:00
case " ${ unameOut } " in
Linux*) jobs = $( nproc) ; ;
Darwin*) jobs = $( sysctl -n hw.physicalcpu) ; ;
*) echo " UNKNOWN: ${ unameOut } " ; exit 0;
esac
2021-01-11 18:35:54 +08:00
fi
2022-02-09 14:27:46 +08:00
2022-03-17 17:17:22 +08:00
if [ " $MSYSTEM " = = "MINGW64" ] ; then
echo Using system rocksdb
else
echo ${ CMAKE_CMD }
${ CMAKE_CMD }
make -j ${ jobs }
fi
2021-07-08 15:43:45 +08:00
go env -w CGO_CFLAGS = " -I ${ OUTPUT_LIB } /include "
2022-02-09 14:27:46 +08:00
ldflags = ""
2021-07-08 15:43:45 +08:00
if [ -f " ${ OUTPUT_LIB } /lib/librocksdb.a " ] ; then
2022-02-09 14:27:46 +08:00
case " ${ unameOut } " in
Linux*) ldflags = " -L ${ OUTPUT_LIB } /lib -l:librocksdb.a -lstdc++ -lm -lz " ; ;
Darwin*) ldflags = " -L ${ OUTPUT_LIB } /lib -lrocksdb -stdlib=libc++ -lm -lz -lbz2 -ldl " ; ;
*) echo " UNKNOWN: ${ unameOut } " ; exit 0;
esac
2021-07-08 15:43:45 +08:00
else
2022-02-09 14:27:46 +08:00
case " ${ unameOut } " in
Linux*) ldflags = " -L ${ OUTPUT_LIB } /lib64 -l:librocksdb.a -lstdc++ -lm -lz " ; ;
Darwin*) ldflags = " -L ${ OUTPUT_LIB } /lib64 -lrocksdb -stdlib=libc++ -lm -lz -lbz2 -ldl " ; ;
*) echo " UNKNOWN: ${ unameOut } " ; exit 0;
esac
fi
2022-03-17 17:17:22 +08:00
if [ " $MSYSTEM " = = "MINGW64" ] ; then
ldflags = " -L ${ OUTPUT_LIB } /lib -lrocksdb -lstdc++ -lm -lz -lshlwapi -lrpcrt4 "
fi
2022-02-09 14:27:46 +08:00
if [ [ $( arch) = = 'arm64' ] ] ; then
go env -w GOARCH = arm64
2021-07-08 15:43:45 +08:00
fi
2022-02-09 14:27:46 +08:00
go env -w CGO_LDFLAGS = " $ldflags " && GO111MODULE = on
2022-03-17 17:17:22 +08:00
2021-07-08 15:43:45 +08:00
go get github.com/tecbot/gorocksdb