Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Docker build on linux/arm64 #45

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ENV CC="$C_COMPILER"
ENV CXX="$CXX_COMPILER"

# Install b2 using Conan
RUN printf '[requires]\nb2/4.10.1\n[options]\nb2*:toolset=%s' \
RUN printf '[requires]\nb2/5.2.1\n[options]\nb2*:toolset=%s' \
"$(basename "$(which "$CC")")" | cut -f 1 -d - > /tmp/conanfile.txt

RUN conan install /tmp/conanfile.txt \
Expand Down Expand Up @@ -92,6 +92,7 @@ RUN cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="$build_dir" \
-DENABLE_DEVELOPER_MODE=OFF \
-DCMAKE_INSTALL_PREFIX="$staging_dir" \
-DNCHG_ENABLE_TESTING=OFF \
-DGIT_RETRIEVED_STATE=true \
-DGIT_TAG="$GIT_TAG" \
-DGIT_IS_DIRTY="$GIT_IS_DIRTY" \
Expand All @@ -103,7 +104,7 @@ RUN cmake -DCMAKE_BUILD_TYPE=Release \

# Build and install project
RUN cmake --build "$build_dir" -t NCHG -j "$(nproc)" \
&& cmake --install "$build_dir" --component Runtime \
&& cmake --install "$build_dir" --component Runtime \
&& rm -rf "$build_dir/include" "$build_dir/lib"

ARG FINAL_BASE_IMAGE
Expand Down
9 changes: 9 additions & 0 deletions src/nchg/include/nchg/tools/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@

namespace nchg {
namespace internal {

#ifdef __cpp_lib_constexpr_string
[[nodiscard]] constexpr std::string strip_leading_zero(std::string s) {
#else
[[nodiscard]] inline std::string strip_leading_zero(std::string s) {
#endif
if (s.front() != '0') {
return s;
}
Expand All @@ -35,7 +40,11 @@ namespace internal {
} // namespace internal

template <typename Duration>
#ifdef __cpp_lib_constexpr_string
[[nodiscard]] constexpr std::string format_duration(const Duration& duration) {
#else
[[nodiscard]] inline std::string format_duration(const Duration& duration) {
#endif
if (duration < std::chrono::microseconds(1)) {
return fmt::to_string(std::chrono::duration_cast<std::chrono::nanoseconds>(duration));
}
Expand Down
28 changes: 17 additions & 11 deletions utils/devel/build_dockerfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ set -o pipefail

IMAGE_NAME='nchg'

if [ "$(uname)" == "Darwin" ]; then
BUILD_USER="$USER"
else
BUILD_USER='root'
fi

GIT_HASH="$(git rev-parse HEAD)"
GIT_SHORT_HASH="$(git rev-parse --short HEAD)"
GIT_TAG="$(git for-each-ref 'refs/tags/v*.*.*' --count 1 --sort=-v:refname --format "%(refname:short)" --points-at HEAD)"
CREATION_DATE="$(date --iso-8601)"
GIT_TAG="$(git for-each-ref 'refs/tags/v*.*.*' --count 1 --sort=-v:refname --format "%(refname:short)" --points-at HEAD)"
CREATION_DATE="$(date -I)"

if [[ $(git status --porcelain -uno) ]]; then
GIT_IS_DIRTY=1
Expand All @@ -48,21 +54,21 @@ fi

2>&1 echo "Building \"$IMAGE_NAME:$IMAGE_TAG\"..."

sudo docker pull docker.io/library/ubuntu:22.04
FINAL_BASE_IMAGE_DIGEST="$(sudo docker inspect --format='{{index .RepoDigests 0}}' docker.io/library/ubuntu:22.04 | grep -o '[[:alnum:]:]\+$')"
sudo -u "$BUILD_USER" docker pull docker.io/library/ubuntu:22.04
FINAL_BASE_IMAGE_DIGEST="$(sudo -u "$BUILD_USER" docker inspect --format='{{index .RepoDigests 0}}' docker.io/library/ubuntu:22.04 | grep -o '[[:alnum:]:]\+$')"

BUILD_BASE_IMAGE='ghcr.io/paulsengroup/ci-docker-images/ubuntu-22.04-cxx-clang-18:latest'
BUILD_BASE_IMAGE='ghcr.io/paulsengroup/ci-docker-images/ubuntu-22.04-cxx-clang-19:latest'

sudo docker pull "$BUILD_BASE_IMAGE"
sudo -u "$BUILD_USER" docker pull "$BUILD_BASE_IMAGE"

# sudo docker buildx build --platform linux/amd64,linux/arm64 \
sudo docker buildx build --platform linux/amd64 \
# sudo -u "$BUILD_USER" docker buildx build --platform linux/amd64,linux/arm64 \
sudo -u "$BUILD_USER" docker buildx build --platform linux/amd64 \
--build-arg "BUILD_BASE_IMAGE=$BUILD_BASE_IMAGE" \
--build-arg "FINAL_BASE_IMAGE=docker.io/library/ubuntu" \
--build-arg "FINAL_BASE_IMAGE_TAG=22.04" \
--build-arg "FINAL_BASE_IMAGE_DIGEST=$FINAL_BASE_IMAGE_DIGEST" \
--build-arg "C_COMPILER=clang-18" \
--build-arg "CXX_COMPILER=clang++-18" \
--build-arg "C_COMPILER=clang-19" \
--build-arg "CXX_COMPILER=clang++-19" \
--build-arg "GIT_HASH=$GIT_HASH" \
--build-arg "GIT_SHORT_HASH=$GIT_SHORT_HASH" \
--build-arg "GIT_TAG=$GIT_TAG" \
Expand All @@ -73,5 +79,5 @@ sudo docker buildx build --platform linux/amd64 \
-t "$IMAGE_NAME:$IMAGE_TAG" \
"$(git rev-parse --show-toplevel)"

# sudo singularity build -F "${img_name}_v${ver}.sif" \
# sudo -u "$BUILD_USER" singularity build -F "${img_name}_v${ver}.sif" \
# "docker-daemon://${img_name}:${ver}"