Skip to content

Commit

Permalink
Add Docker-based builder script (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitbuda committed May 21, 2023
1 parent 717bbbd commit a5718f6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
49 changes: 49 additions & 0 deletions build-generic-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$SCRIPT_DIR"

docker_name="mgconsole_build_generic_linux"
toolchain_url="https://s3-eu-west-1.amazonaws.com/deps.memgraph.io/toolchain-v4/toolchain-v4-binaries-centos-7-x86_64.tar.gz"
toolchain_tar_gz="$(basename $toolchain_url)"
memgraph_repo="https://github.com/memgraph/memgraph.git"
setup_toolchain_cmd="cd /memgraph/environment/os && \
./centos-7.sh check TOOLCHAIN_RUN_DEPS || \
./centos-7.sh install TOOLCHAIN_RUN_DEPS"
setup_memgraph_cmd="cd /memgraph/environment/os && \
./centos-7.sh check MEMGRAPH_BUILD_DEPS || \
./centos-7.sh install MEMGRAPH_BUILD_DEPS"
mgconsole_build_cmd="source /opt/toolchain-v4/activate && \
mkdir -p /mgconsole/build && cd /mgconsole/build && \
cmake -DCMAKE_BUILD_TYPE=Release .. && make -j"

if [ ! "$(docker info)" ]; then
echo "ERROR: Docker is required"
exit 1
fi

if [ ! "$(docker ps -q -f name=$docker_name)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$docker_name)" ]; then
echo "Cleanup of the old exited mgconsole build container..."
docker rm $docker_name
fi
docker run -d --network host --name "$docker_name" centos:7 sleep infinity
fi
echo "The mgconsole build container is active!"

docker_exec () {
cmd="$1"
docker exec -it "$docker_name" bash -c "$cmd"
}

docker_exec "mkdir -p /mgconsole"
docker cp -q "$PROJECT_ROOT/." "$docker_name:/mgconsole/"
docker_exec "rm -rf /mgconsole/build/*"
docker_exec "yum install -y wget git"
docker_exec "[ ! -f /$toolchain_tar_gz ] && wget -O /$toolchain_tar_gz $toolchain_url"
docker_exec "[ ! -d /opt/toolchain-v4/ ] && tar -xzf /$toolchain_tar_gz -C /opt"
docker_exec "[ ! -d /memgraph/ ] && git clone $memgraph_repo"
docker_exec "$setup_toolchain_cmd"
docker_exec "$setup_memgraph_cmd"
docker_exec "$mgconsole_build_cmd"
mkdir -p "$PROJECT_ROOT/build/generic"
docker cp -q "$docker_name:/mgconsole/build/src/mgconsole" "$PROJECT_ROOT/build/generic/"
7 changes: 2 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ if(MGCONSOLE_ON_WINDOWS)
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lws2_32")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")
elseif(MGCONSOLE_ON_LINUX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
# -no-pie -> https://stackoverflow.com/questions/46827433/g-compile-error-rodata-can-not-be-used-when-making-a-shared-object-recomp
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -no-pie")
endif()

if(MGCONSOLE_ON_LINUX)
Expand All @@ -63,7 +64,6 @@ ExternalProject_Add(gflags-proj
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
INSTALL_DIR "${PROJECT_BINARY_DIR}/gflags")

ExternalProject_Get_Property(gflags-proj install_dir)
Expand Down Expand Up @@ -121,20 +121,17 @@ target_include_directories(mgconsole
${MGCLIENT_INCLUDE_DIRS}
${REPLXX_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(mgconsole
PRIVATE
${GFLAGS_LIBRARY}
utils
${MGCLIENT_LIBRARY}
${OPENSSL_LIBRARIES})

if(MGCONSOLE_ON_WINDOWS)
target_link_libraries(mgconsole PRIVATE shlwapi)
endif()

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/version.hpp")

install(TARGETS mgconsole
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
4 changes: 3 additions & 1 deletion src/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
ExternalProject_Add(replxx-proj
PREFIX replxx
GIT_REPOSITORY https://github.com/AmokHuginnsson/replxx.git
GIT_TAG release-0.0.3
GIT_TAG release-0.0.4
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DREPLXX_BUILD_EXAMPLES=OFF"
"-DBUILD_SHARED_LIBS=OFF"
INSTALL_DIR "${PROJECT_BINARY_DIR}/replxx")

if(CMAKE_BUILD_TYPE_LOWERCASE STREQUAL "debug")
Expand Down

0 comments on commit a5718f6

Please sign in to comment.