From 4199c0262bbb5cb30833f39bc111bba5442e5623 Mon Sep 17 00:00:00 2001 From: jonassibbesen Date: Wed, 22 Mar 2023 15:30:03 +0100 Subject: [PATCH 1/6] add build static option --- CMakeLists.txt | 165 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 108 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fffc59..fd31225 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,16 @@ project(rpvg) set(CMAKE_CXX_STANDARD 14) +set(BUILD_STATIC 0 CACHE BOOL "Build static version") + +if(${BUILD_STATIC} EQUAL 1) + + set(Protobuf_USE_STATIC_LIBS ON) + set(BUILD_SHARED_LIBS OFF) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + +endif(${BUILD_STATIC} EQUAL 1) + find_package(OpenMP REQUIRED) find_package(Protobuf REQUIRED) @@ -50,27 +60,6 @@ ExternalProject_Add(libvgio-proj set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) -add_library(xg - deps/xg/src/xg.cpp -) - -add_library(${PROJECT_NAME} - src/fragment_length_dist.cpp - src/paths_index.cpp - src/alignment_path.cpp - src/alignment_path_finder.cpp - src/path_clusters.cpp - src/read_path_probabilities.cpp - src/path_estimator.cpp - src/path_posterior_estimator.cpp - src/path_abundance_estimator.cpp - src/threaded_output_writer.cpp - src/io/register_libvg_io.cpp - src/io/register_loader_saver_gbwt.cpp - src/io/register_loader_saver_r_index.cpp - src/io/register_loader_saver_xg.cpp -) - include_directories( ${HTSlib_INCLUDE_DIRS} ${Protobuf_INCLUDE_DIRS} @@ -93,13 +82,16 @@ include_directories( ) link_directories( - ${HTSlib_LIBRARY_DIRS} ${PROJECT_SOURCE_DIR}/deps/sdsl-lite/lib ${PROJECT_SOURCE_DIR}/deps/gbwt/lib ${PROJECT_SOURCE_DIR}/deps/libvgio ${PROJECT_SOURCE_DIR}/deps/libvgio/handlegraph-prefix/lib ) +add_library(xg + deps/xg/src/xg.cpp +) + target_link_libraries(xg sdsl handlegraph @@ -107,8 +99,62 @@ target_link_libraries(xg divsufsort64 ) +add_dependencies(xg gbwt-proj) +add_dependencies(xg libvgio-proj) + +set(SOURCE_FILES + src/fragment_length_dist.cpp + src/paths_index.cpp + src/alignment_path.cpp + src/alignment_path_finder.cpp + src/path_clusters.cpp + src/read_path_probabilities.cpp + src/path_estimator.cpp + src/path_posterior_estimator.cpp + src/path_abundance_estimator.cpp + src/threaded_output_writer.cpp + src/io/register_libvg_io.cpp + src/io/register_loader_saver_gbwt.cpp + src/io/register_loader_saver_r_index.cpp + src/io/register_loader_saver_xg.cpp +) + +if(${BUILD_STATIC} EQUAL 0) + + link_directories( + ${HTSlib_LIBRARY_DIRS} + ) + + add_library(${PROJECT_NAME} + ${SOURCE_FILES} + ) + + target_link_libraries(${PROJECT_NAME} + ${HTSlib_LIBRARIES} + ) + +else(${BUILD_STATIC} EQUAL 0) + + message(STATUS "Building static version") + + link_directories( + ${HTSlib_STATIC_LIBRARY_DIRS} + ) + + add_executable(${PROJECT_NAME} + src/main.cpp + ${SOURCE_FILES} + ) + + target_link_libraries(${PROJECT_NAME} + ${HTSlib_STATIC_LIBRARIES} + ) + + set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++") + +endif(${BUILD_STATIC} EQUAL 0) + target_link_libraries(${PROJECT_NAME} - ${HTSlib_LIBRARIES} ${PROTOBUF_LIBRARIES} sdsl gbwt @@ -119,9 +165,6 @@ target_link_libraries(${PROJECT_NAME} xg ) -add_dependencies(xg gbwt-proj) -add_dependencies(xg libvgio-proj) - add_dependencies(${PROJECT_NAME} gbwt-proj) add_dependencies(${PROJECT_NAME} libvgio-proj) add_dependencies(${PROJECT_NAME} xg) @@ -140,34 +183,42 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") endif() -add_executable(${PROJECT_NAME}-bin src/main.cpp) -target_link_libraries(${PROJECT_NAME}-bin ${PROJECT_NAME}) - -set_target_properties(${PROJECT_NAME}-bin PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) - -add_executable(${PROJECT_NAME}-tests - src/tests/main_test.cpp - src/tests/fragment_length_dist_test.cpp - src/tests/paths_index_test.cpp - src/tests/alignment_path_test.cpp - src/tests/alignment_path_finder_test.cpp - src/tests/read_path_probabilities_test.cpp - src/tests/path_clusters_test.cpp - src/tests/path_abundance_estimator_test.cpp -) - -include_directories( - ${PROJECT_SOURCE_DIR}/deps/catch2/single_include -) - -target_link_libraries(${PROJECT_NAME}-tests - ${PROJECT_NAME} -) - -enable_testing() - -add_test( - NAME ${PROJECT_NAME}-tests - COMMAND ${PROJECT_NAME}-tests -) - +if(${BUILD_STATIC} EQUAL 0) + + add_executable(${PROJECT_NAME}-bin + src/main.cpp + ) + + target_link_libraries(${PROJECT_NAME}-bin + ${PROJECT_NAME} + ) + + set_target_properties(${PROJECT_NAME}-bin PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) + + add_executable(${PROJECT_NAME}-tests + src/tests/main_test.cpp + src/tests/fragment_length_dist_test.cpp + src/tests/paths_index_test.cpp + src/tests/alignment_path_test.cpp + src/tests/alignment_path_finder_test.cpp + src/tests/read_path_probabilities_test.cpp + src/tests/path_clusters_test.cpp + src/tests/path_abundance_estimator_test.cpp + ) + + include_directories( + ${PROJECT_SOURCE_DIR}/deps/catch2/single_include + ) + + target_link_libraries(${PROJECT_NAME}-tests + ${PROJECT_NAME} + ) + + enable_testing() + + add_test( + NAME ${PROJECT_NAME}-tests + COMMAND ${PROJECT_NAME}-tests + ) + +endif(${BUILD_STATIC} EQUAL 0) From 17e622a8b83b5288ee99d4df6e7043411b465d3b Mon Sep 17 00:00:00 2001 From: jonassibbesen Date: Wed, 22 Mar 2023 15:30:41 +0100 Subject: [PATCH 2/6] add docker file with static rpvg build --- Dockerfile.static | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Dockerfile.static diff --git a/Dockerfile.static b/Dockerfile.static new file mode 100644 index 0000000..12f2b97 --- /dev/null +++ b/Dockerfile.static @@ -0,0 +1,45 @@ +FROM mirror.gcr.io/library/ubuntu:20.04 + +MAINTAINER jsibbese@ucsc.edu + +WORKDIR /home + +### Install essential tools (including protobuf and jansson) + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends wget git autoconf automake make cmake gcc g++ pkg-config protobuf-compiler libprotoc-dev libprotobuf-dev libjansson-dev && \ + rm -rf /var/lib/apt/lists/* + +### Install htslib + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends perl zlib1g-dev libbz2-dev liblzma-dev libssl-dev && \ + rm -rf /var/lib/apt/lists/* + +RUN wget --no-check-certificate https://github.com/samtools/htslib/releases/download/1.16/htslib-1.16.tar.bz2 && \ + tar -xvjf htslib-1.16.tar.bz2 && \ + cd htslib-1.16 && \ + ./configure --disable-s3 --disable-gcs --disable-libcurl --disable-plugins && \ + make install && \ + cd .. && \ + rm -r * + +### Get rpvg + +RUN GIT_SSL_NO_VERIFY=true git clone --recursive https://github.com/jonassibbesen/rpvg.git + +### Set target CPU architecture + +RUN cd rpvg && \ + sed -i 's/march=native/march=nehalem/g' CMakeLists.txt deps/sdsl-lite/CMakeLists.txt + +### Compile rpvg + +RUN cd rpvg && \ + mkdir build && \ + cd build && \ + cmake -DBUILD_STATIC=1 .. && \ + make && \ + cd ../../ && \ + mv rpvg/bin/rpvg /usr/bin/ && \ + rm -r * From 0a676a759d354b2d2afb3b88be6cbf85b9058169 Mon Sep 17 00:00:00 2001 From: jonassibbesen Date: Wed, 22 Mar 2023 16:37:57 +0100 Subject: [PATCH 3/6] update maintainer in Dockerfiles --- Dockerfile | 2 +- Dockerfile.static | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8a2b69a..04caab7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM mirror.gcr.io/library/ubuntu:20.04 -MAINTAINER jsibbese@ucsc.edu +MAINTAINER https://github.com/jonassibbesen WORKDIR /home diff --git a/Dockerfile.static b/Dockerfile.static index 12f2b97..053e64d 100644 --- a/Dockerfile.static +++ b/Dockerfile.static @@ -1,6 +1,6 @@ FROM mirror.gcr.io/library/ubuntu:20.04 -MAINTAINER jsibbese@ucsc.edu +MAINTAINER https://github.com/jonassibbesen WORKDIR /home From 8bb683a78f35b06a837802967c4e884ef01fb7fb Mon Sep 17 00:00:00 2001 From: jonassibbesen Date: Wed, 22 Mar 2023 16:38:41 +0100 Subject: [PATCH 4/6] switch branch in static Dockerfile --- Dockerfile.static | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile.static b/Dockerfile.static index 053e64d..afeec8b 100644 --- a/Dockerfile.static +++ b/Dockerfile.static @@ -26,7 +26,9 @@ RUN wget --no-check-certificate https://github.com/samtools/htslib/releases/down ### Get rpvg -RUN GIT_SSL_NO_VERIFY=true git clone --recursive https://github.com/jonassibbesen/rpvg.git +RUN GIT_SSL_NO_VERIFY=true git clone --recursive https://github.com/jonassibbesen/rpvg.git && \ + cd rpvg && \ + git checkout static-build ### Set target CPU architecture From b24e84748a7c62ec68a7248d4c93d0a3a22997a0 Mon Sep 17 00:00:00 2001 From: jonassibbesen Date: Fri, 24 Mar 2023 13:47:43 +0100 Subject: [PATCH 5/6] use main branch in static Dockerfile --- Dockerfile.static | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile.static b/Dockerfile.static index afeec8b..053e64d 100644 --- a/Dockerfile.static +++ b/Dockerfile.static @@ -26,9 +26,7 @@ RUN wget --no-check-certificate https://github.com/samtools/htslib/releases/down ### Get rpvg -RUN GIT_SSL_NO_VERIFY=true git clone --recursive https://github.com/jonassibbesen/rpvg.git && \ - cd rpvg && \ - git checkout static-build +RUN GIT_SSL_NO_VERIFY=true git clone --recursive https://github.com/jonassibbesen/rpvg.git ### Set target CPU architecture From de1c2ab1a7d96279840c6e364bde0b04bed73c0a Mon Sep 17 00:00:00 2001 From: jonassibbesen Date: Fri, 24 Mar 2023 14:07:25 +0100 Subject: [PATCH 6/6] create static binary in Dockerfile --- Dockerfile | 8 ++++---- Dockerfile.static | 45 --------------------------------------------- 2 files changed, 4 insertions(+), 49 deletions(-) delete mode 100644 Dockerfile.static diff --git a/Dockerfile b/Dockerfile index 04caab7..053e64d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,13 +13,13 @@ RUN apt-get update && \ ### Install htslib RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends perl zlib1g-dev libbz2-dev liblzma-dev libcurl4-gnutls-dev libssl-dev && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends perl zlib1g-dev libbz2-dev liblzma-dev libssl-dev && \ rm -rf /var/lib/apt/lists/* RUN wget --no-check-certificate https://github.com/samtools/htslib/releases/download/1.16/htslib-1.16.tar.bz2 && \ tar -xvjf htslib-1.16.tar.bz2 && \ cd htslib-1.16 && \ - ./configure && \ + ./configure --disable-s3 --disable-gcs --disable-libcurl --disable-plugins && \ make install && \ cd .. && \ rm -r * @@ -38,8 +38,8 @@ RUN cd rpvg && \ RUN cd rpvg && \ mkdir build && \ cd build && \ - cmake .. && \ + cmake -DBUILD_STATIC=1 .. && \ make && \ cd ../../ && \ mv rpvg/bin/rpvg /usr/bin/ && \ - unlink rpvg/deps/libvgio/vg + rm -r * diff --git a/Dockerfile.static b/Dockerfile.static deleted file mode 100644 index 053e64d..0000000 --- a/Dockerfile.static +++ /dev/null @@ -1,45 +0,0 @@ -FROM mirror.gcr.io/library/ubuntu:20.04 - -MAINTAINER https://github.com/jonassibbesen - -WORKDIR /home - -### Install essential tools (including protobuf and jansson) - -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends wget git autoconf automake make cmake gcc g++ pkg-config protobuf-compiler libprotoc-dev libprotobuf-dev libjansson-dev && \ - rm -rf /var/lib/apt/lists/* - -### Install htslib - -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends perl zlib1g-dev libbz2-dev liblzma-dev libssl-dev && \ - rm -rf /var/lib/apt/lists/* - -RUN wget --no-check-certificate https://github.com/samtools/htslib/releases/download/1.16/htslib-1.16.tar.bz2 && \ - tar -xvjf htslib-1.16.tar.bz2 && \ - cd htslib-1.16 && \ - ./configure --disable-s3 --disable-gcs --disable-libcurl --disable-plugins && \ - make install && \ - cd .. && \ - rm -r * - -### Get rpvg - -RUN GIT_SSL_NO_VERIFY=true git clone --recursive https://github.com/jonassibbesen/rpvg.git - -### Set target CPU architecture - -RUN cd rpvg && \ - sed -i 's/march=native/march=nehalem/g' CMakeLists.txt deps/sdsl-lite/CMakeLists.txt - -### Compile rpvg - -RUN cd rpvg && \ - mkdir build && \ - cd build && \ - cmake -DBUILD_STATIC=1 .. && \ - make && \ - cd ../../ && \ - mv rpvg/bin/rpvg /usr/bin/ && \ - rm -r *