From abf245045def3aec612af534f8142f9a94b62efb Mon Sep 17 00:00:00 2001 From: Kayuii <577738@qq.com> Date: Wed, 16 Jun 2021 16:37:38 +0800 Subject: [PATCH] Static Compilation With glibc --- CMakeLists.txt | 6 ++++++ Dockerfile | 4 ++-- README.md | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01a845fd9..3900a27b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,6 +138,12 @@ add_executable(ProofOfSpace ${BLAKE3_SRC} ) +option(BUILD_PROOF_OF_SPACE_STATICALLY "Build ProofOfSpace target statically" OFF) +IF (BUILD_PROOF_OF_SPACE_STATICALLY) + message("Statically build ProofOfSpace") + target_link_libraries(ProofOfSpace -static -Wl,--whole-archive -lrt -lpthread -Wl,--no-whole-archive) +ENDIF() + add_executable(RunTests tests/test-main.cpp tests/test.cpp diff --git a/Dockerfile b/Dockerfile index 1d6e76b2d..064a7a3eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM ubuntu:20.04 as builder ARG DEBIAN_FRONTEND=noninteractive +ARG BUILD_PROOF_OF_SPACE_STATICALLY=OFF RUN apt-get update -y @@ -20,7 +21,7 @@ COPY . . RUN mkdir -p build WORKDIR /app/build -RUN cmake ../ +RUN cmake -DBUILD_PROOF_OF_SPACE_STATICALLY=${BUILD_PROOF_OF_SPACE_STATICALLY} ../ RUN cmake --build . -- -j `nproc` @@ -29,4 +30,3 @@ FROM ubuntu:20.04 COPY --from=builder /app/build /app CMD ["/app/ProofOfSpace"] - diff --git a/README.md b/README.md index 87ff9570b..e031362d1 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,14 @@ cmake ../ cmake --build . -- -j 6 ``` +## Static Compilation With glibc +### Statically compile ProofOfSpace +```bash +mkdir -p build && cd build +cmake -DBUILD_PROOF_OF_SPACE_STATICALLY=ON ../ +cmake --build . -- -j 6 +``` + ### Run tests ```bash