openfhe-rs icon indicating copy to clipboard operation
openfhe-rs copied to clipboard

Dockerfile for developing this library on MAC M-Chip

Open HaroldGin931 opened this issue 1 year ago • 3 comments

Hey, I am trying to deploy this project on my Mac. Because the chip architecture is different, I can not build this project on my laptop. So I write a dockerfile to simulate the X86 env and now it works well, hope this can help you guys.

FROM --platform=linux/amd64 ubuntu:22.04

# Set environment variables
ENV CARGO_TERM_COLOR always

# Install necessary dependencies
RUN apt-get update && apt-get install -y \
    cmake \
    git \
    curl \
    build-essential \
    libssl-dev \
    pkg-config \
    sudo \
    gdb \
    lldb \
    libgmp-dev \
    libomp-dev

# Clone OpenFHE, build and install
RUN git clone https://github.com/openfheorg/openfhe-development.git && \
    cd openfhe-development && \
    git checkout v1.2.0 && \
    mkdir build && \
    cd build && \
    cmake -DBUILD_SHARED=ON .. && \
    make -j$(nproc) && \
    make install && \
    ldconfig

# Install Rust and debugging tools
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable
ENV PATH="/root/.cargo/bin:${PATH}"

# Clone OpenFHE-rs and build
RUN git clone https://github.com/fairmath/openfhe-rs.git && \
    cd openfhe-rs && \
    cargo build

# Set working directory
WORKDIR /workspace

# Add alias commands
RUN echo 'alias check-rust="rustc --version && cargo --version"' >> ~/.bashrc && \
    echo 'alias check-openfhe="make -C /openfhe-development/build/ testall"' >> ~/.bashrc && \
    echo 'alias check-openfhe-rs="cargo test --manifest-path /openfhe-rs/Cargo.toml -- --test-threads=1"' >> ~/.bashrc

# Make aliases effective immediately
RUN . ~/.bashrc

CMD ["bash"]

HaroldGin931 avatar Oct 16 '24 04:10 HaroldGin931

Hey thanks @HaroldGin931 for providing the dockerfile, I added line ENV DEBIAN_FRONTEND noninteractive otherwise it would stuck on asking the geographic area. I can build the image, but unfortunately it gives me linking error when I try to build openfhe-rs/crate_usage:

CXX include path:
    /openfhe-rs/crate_usage/target/debug/build/openfhe-54143b84db2888a8/out/cxxbridge/include
    /openfhe-rs/crate_usage/target/debug/build/openfhe-54143b84db2888a8/out/cxxbridge/crate


  error occurred: Command "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-I" "/openfhe-rs/crate_usage/target/debug/build/openfhe-54143b84db2888a8/out/cxxbridge/include" "-I" "/openfhe-rs/crate_usage/target/debug/build/openfhe-54143b84db2888a8/out/cxxbridge/crate" "-I" "/usr/local/include/openfhe" "-I" "/usr/local/include/openfhe/third-party/include" "-I" "/usr/local/include/openfhe/core" "-I" "/usr/local/include/openfhe/pke" "-I" "/usr/local/include/openfhe/binfhe" "-I" "./openfhe-development/install/include" "-I" "./openfhe-development/install/include/openfhe" "-I" "./openfhe-development/install/include/openfhe/third-party/include" "-I" "./openfhe-development/install/include/openfhe/core" "-I" "./openfhe-development/install/include/openfhe/pke" "-I" "./openfhe-development/install/include/openfhe/binfhe" "-Wall" "-Wextra" "-std=c++17" "-Wall" "-Werror" "-O3" "-fopenmp" "-Wno-parentheses" "-Wno-unused-parameter" "-Wno-missing-field-initializers" "-Wno-unused-function" "-o" "/openfhe-rs/crate_usage/target/debug/build/openfhe-54143b84db2888a8/out/75f31f28ec7a553a-lib.rs.o" "-c" "/openfhe-rs/crate_usage/target/debug/build/openfhe-54143b84db2888a8/out/cxxbridge/sources/openfhe/src/lib.rs.cc" with args c++ did not execute successfully (status code exit status: 1).

Do you know what might be the problem? Thanks in advance!

JacomoJ avatar Oct 18 '24 13:10 JacomoJ

@JacomoJ

I am not sure about your issue, can you provide me the setting of your docker engine and you laptops' chip arch? If using an M1 Mac, ensure Rosetta 2 is enabled to support x86_64 emulation Here is how I use this docker file, I hope it will help you.

  1. build the docker images docker build -t openfhe-rs -f .devcontainer/Dockerfile .
  2. Run the docker container docker run -it --rm --platform linux/amd64 -v $(pwd):/workspace -w /workspace openfhe-rs bash

The repo which commitment is"445bc396d77fc838e1c599b1fc4d2badd71fa931" is working well on my M1 chip, you can find it in the commit history.

HaroldGin931 avatar Oct 18 '24 15:10 HaroldGin931

@HaroldGin931 Thanks for the tips, unfortunately it does not work. I have an M1 Pro chip, and the docker has been configured with the following:

{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false
}

I tried to use the same commit with the same commands, still the crate crate_usage won't compile.

Btw, I saw that you are doing some cool stuff, if you want you can add me on discord by searching jacomoj and we can have some discussions about crypto.

JacomoJ avatar Oct 21 '24 10:10 JacomoJ