Skip to content

Commit

Permalink
build: update dependencies
Browse files Browse the repository at this point in the history
A pretty major change including a lot of refactoring.

- New versions of the folllowing tools:
    - Conan 2
    - Ubuntu 24.04
    - LLVM 18
- Clean up deprecations (e.g. removed FetchContent_Populate)
- Refactor the CMake files with comments added
- Bump multiple dependencies, adapt to their new API
- Migrated to conanfile.py
- Use CMake presets (Fixes anydistro#7)
  • Loading branch information
LordTermor committed Sep 11, 2024
1 parent ae2ef17 commit 80f8493
Show file tree
Hide file tree
Showing 23 changed files with 382 additions and 339 deletions.
5 changes: 2 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"clang-format.executable": "clang-format-17",
"clangd.path": "clangd-17",
"lldb-dap.executable-path": "/bin/lldb-vscode-17"
"clangd.path": "clangd-18",
"lldb-dap.executable-path": "/bin/lldb-dap-18"
}
56 changes: 16 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
################################################################################
# CMake Configuration: Set up project and compiler settings
################################################################################
cmake_minimum_required(VERSION 3.23)
project(bxt CXX)
project(bxt C CXX)

list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
Expand All @@ -9,49 +12,22 @@ set(CMAKE_CXX_STANDARD 23)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Wall -Wextra")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
set(FETCHCONTENT_QUIET FALSE)

include(FetchContent)
################################################################################
# Dependencies: Fetch and configure external libraries not available in Conan
################################################################################
include("${CMAKE_SOURCE_DIR}/cmake/bundled-deps.cmake")

FetchContent_Declare(
lmdbxx
GIT_REPOSITORY https://github.com/hoytech/lmdbxx
GIT_TAG b12d1b12f4c9793aef8bed03d07ecbf789e810b4
)
FetchContent_MakeAvailable(lmdbxx)
################################################################################
# Dependencies: Configure dependencies available via Conan
################################################################################
include("${CMAKE_SOURCE_DIR}/cmake/deps.cmake")

FetchContent_Declare(
event-bus
GIT_REPOSITORY https://github.com/gelldur/EventBus.git
GIT_TAG v3.0.3
)

FetchContent_GetProperties(event-bus)
if(NOT event-bus_POPULATED)
FetchContent_Populate(event-bus)
add_subdirectory(${event-bus_SOURCE_DIR}/lib ${event-bus_BINARY_DIR} EXCLUDE_FROM_ALL)
endif(NOT event-bus_POPULATED)

FetchContent_Declare(
reflect-cpp
GIT_REPOSITORY https://github.com/getml/reflect-cpp.git
GIT_TAG v0.10.0
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(reflect-cpp)

if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake"
TLS_VERIFY ON)
endif()

include("${CMAKE_BINARY_DIR}/conan.cmake")
conan_cmake_run(CONANFILE conanfile.txt
BASIC_SETUP
PROFILE default
BUILD missing)

################################################################################
# Project Structure: Add subdirectories for different components
################################################################################
add_subdirectory(daemon)
add_subdirectory(web)
add_subdirectory(dbcli)
43 changes: 43 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"patch": 0
},
"configurePresets": [
{
"name": "base",
"generator": "Ninja",
"hidden": true,
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "/cmake-conan/conan_provider.cmake"
}
},
{
"name": "debug",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "release",
"configurePreset": "release"
}
]
}
158 changes: 109 additions & 49 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,75 +1,135 @@
#syntax=docker/dockerfile:1.9
################################################################################
# Base Stage: Prepare all dependencies and tools
FROM ubuntu:22.04 as base

RUN apt-get update --yes && apt-get install --yes ca-certificates curl gnupg \
&& echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" > /etc/apt/sources.list.d/llvm.list \
&& curl --silent --location https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
&& mkdir -p /etc/apt/keyrings \
&& curl --silent --location https://apt.kitware.com/keys/kitware-archive-latest.asc | gpg --dearmor -o /usr/share/keyrings/kitware-archive-keyring.gpg \
&& echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | tee /etc/apt/sources.list.d/kitware.list >/dev/null \
&& apt-get update --yes \
&& apt-get install --yes build-essential git cmake libssl-dev pip ninja-build lldb-17 clangd-17 clang-format-17 clang-17 libc++-17-dev libc++abi-17-dev nodejs zstd unzip \
&& rm -rf /var/lib/apt/lists/*

RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 100 && \
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 100 && \
update-alternatives --install /usr/bin/cc cc /usr/bin/clang-17 100 && \
update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-17 100 && \
update-alternatives --set clang /usr/bin/clang-17 && \
update-alternatives --set clang++ /usr/bin/clang++-17 && \
update-alternatives --set cc /usr/bin/clang-17 && \
update-alternatives --set c++ /usr/bin/clang++-17

RUN pip install conan==1.63.0 \
&& conan profile new default --detect \
&& conan profile update settings.compiler=clang default \
&& conan profile update settings.compiler.version=17 default \
&& conan profile update settings.compiler.libcxx=libc++ default
################################################################################
FROM ubuntu:24.04 as base

ENV DEBIAN_FRONTEND=noninteractive
RUN <<EOF
apt-get update --yes
apt-get install --yes \
ca-certificates \
curl \
gnupg
mkdir -p /etc/apt/keyrings
curl --silent --location https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor -o /etc/apt/keyrings/llvm-archive-keyring.gpg
curl --silent --location https://apt.kitware.com/keys/kitware-archive-latest.asc | gpg --dearmor -o /etc/apt/keyrings/kitware-archive-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/noble/ llvm-toolchain-noble-18 main" > /etc/apt/sources.list.d/llvm.list
echo "deb [signed-by=/etc/apt/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main" > /etc/apt/sources.list.d/kitware.list
apt-get update --yes
apt-get install --yes \
build-essential \
clang-18 \
clang-format-18 \
clangd-18 \
cmake \
curl \
git \
gnupg \
libc++-18-dev \
libc++abi-18-dev \
libssl-dev \
lldb-18 \
ninja-build \
nodejs \
pipx \
unzip \
zstd
rm -rf /var/lib/apt/lists/*
EOF

RUN <<EOF
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-18 100
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-18 100
update-alternatives --install /usr/bin/cc cc /usr/bin/clang-18 100
update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-18 100
update-alternatives --set clang /usr/bin/clang-18
update-alternatives --set clang++ /usr/bin/clang++-18
update-alternatives --set cc /usr/bin/clang-18
update-alternatives --set c++ /usr/bin/clang++-18
EOF

ENV PATH="/root/.bun/bin:/root/.local/bin:${PATH}"

RUN pipx install conan==2.7.0

RUN conan profile detect --force --name default && \
cat <<EOF >> /root/.conan2/profiles/default
compiler=clang
compiler.version=18
compiler.libcxx=libc++
compiler.cppstd=23
EOF

RUN git clone https://github.com/conan-io/cmake-conan.git -b develop2 /cmake-conan

RUN curl -fsSL https://bun.sh/install | bash

ENV PATH="/root/.bun/bin:${PATH}"

COPY conanfile.txt /conan/
COPY conanfile.py /conan/

################################################################################
# Development Stage: Set up the development environment
################################################################################
FROM base as development

RUN conan install /conan -pr=default -s build_type=Debug --build=missing -g txt -of /conan
EXPOSE 8080
RUN conan install /conan -pr=/root/.conan2/profiles/default -s build_type=Debug --build=missing -of /conan
# for main application
EXPOSE 8080
# for web server
EXPOSE 3000

################################################################################
# Production Build Stage: Build the application for production
################################################################################
FROM base as production-build

RUN conan install /conan -pr=default -s build_type=Release --build=missing -g txt -of /conan
RUN pipx ensurepath && conan install /conan -pr=default -s build_type=Release --build=missing -of /conan
COPY ./ /src

RUN cmake -B/build -S/src -DCMAKE_BUILD_TYPE=Release -G Ninja \
&& cmake --build /build \
&& cp /src/configs/box.yml /build/bin/ \
&& cp /src/configs/config.toml /build/bin/
RUN <<EOF
cmake -B/build -S/src -DCMAKE_BUILD_TYPE=Release --preset release
cmake --build /build
EOF

################################################################################
# Production Stage: Set up the environment for running the application
FROM ubuntu:22.04 as production

RUN apt-get update --yes \
&& apt-get install --yes ca-certificates curl gnupg \
&& echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" > /etc/apt/sources.list.d/llvm.list \
&& curl --silent --location https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
&& apt-get update && apt-get install --yes bzip2 xz-utils zlib1g liblz4-1 zstd libc++1-17 libc++abi1-17 \
&& rm -rf /var/lib/apt/lists/*
################################################################################
FROM ubuntu:24.04 as production

RUN <<EOF
apt-get update --yes
apt-get install --yes \
ca-certificates \
curl \
gnupg
mkdir -p /etc/apt/keyrings
curl --silent --location https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor -o /etc/apt/keyrings/llvm-archive-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" > /etc/apt/sources.list.d/llvm.list
apt-get update --yes
apt-get install --yes \
bzip2 \
libc++1-18 \
libc++abi1-18 \
liblz4-1 \
xz-utils \
zlib1g \
zstd
rm -rf /var/lib/apt/lists/*
EOF

COPY --from=production-build /build/bin /app

RUN mkdir -p /app/persistence/ && \
adduser --disabled-password --gecos '' bxt \
&& chown -R bxt:bxt /app \
&& chmod 755 /app

RUN <<EOF
mkdir -p /app/persistence/
adduser --disabled-password --gecos '' bxt
chown -R bxt:bxt /app
chmod 755 /app
EOF

USER bxt

ENV LD_LIBRARY_PATH=/app/libs/
ENV LD_LIBRARY_PATH=/app/lib/
WORKDIR /app
EXPOSE 8080
CMD ["/app/bxtd"]
8 changes: 8 additions & 0 deletions cmake/FindBun.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
################################################################################
# Bun Configuration: Find Bun executable and set up related functions
################################################################################

set(_prev "${BUN_EXECUTABLE}")
find_program(BUN_EXECUTABLE bun DOC "Path to Bun, the all-in-one JavaScript runtime")

Expand All @@ -13,6 +17,10 @@ else()
endif()
endif()

################################################################################
# Bun Utility Functions: Define functions for running Bun commands
################################################################################

function(bun_run_command cmd working_dir)
message(STATUS "Running command: ${BUN_EXECUTABLE} ${cmd} at ${working_dir}")
execute_process(
Expand Down
51 changes: 0 additions & 51 deletions cmake/FindYarn.cmake

This file was deleted.

Loading

0 comments on commit 80f8493

Please sign in to comment.