FROM quay.io/pypa/manylinux_2_28_x86_64:2024-02-08-a1b4ddc as build

RUN dnf update -y && dnf install -y ninja-build hwloc-devel && dnf clean all
# Setup gcc 11 (to be compatible with concrete-compiler image)
RUN dnf install -y gcc-toolset-11 && dnf clean all
ENV CC_COMPILER=/opt/rh/gcc-toolset-11/root/usr/bin/gcc
ENV CXX_COMPILER=/opt/rh/gcc-toolset-11/root/usr/bin/c++
# Add a non-root user and group
RUN groupadd -g 10001 grp02 && \
    useradd -u 10000 -g grp02 usr01 && \
    chown -R usr01:grp02 /boost_1_71_0 /hpx
# Switch to the non-root user
USER usr01:grp02
# Install boost
ADD https://boostorg.jfrog.io/artifactory/main/release/1.71.0/source/boost_1_71_0.tar.gz /boost_1_71_0.tar.gz
RUN tar -xzvf /boost_1_71_0.tar.gz
WORKDIR /boost_1_71_0
RUN ./bootstrap.sh && ./b2 --with-filesystem install
# Build HPX
RUN git clone https://github.com/STEllAR-GROUP/hpx.git /hpx
WORKDIR /hpx
RUN git checkout v1.9.1
# empty HPX_WITH_MAX_CPU_COUNT = dynamic
# ref https://github.com/STEllAR-GROUP/hpx/blob/1.7.1/CMakeLists.txt#L759
WORKDIR /hpx/build
RUN cmake \
	-DCMAKE_C_COMPILER=${CC_COMPILER} \
	-DCMAKE_CXX_COMPILER=${CXX_COMPILER} \
	-DHPX_WITH_MAX_CPU_COUNT="" \
	-DHPX_WITH_FETCH_ASIO=on \
	-DHPX_FILESYSTEM_WITH_BOOST_FILESYSTEM_COMPATIBILITY=ON \
	-DHPX_WITH_MALLOC=system .. \
	&& make -j2

FROM scratch
COPY --from=build /hpx/ /hpx/
