Skip to content

Commit

Permalink
Clean-up build-related code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhuighuy committed Nov 24, 2024
1 parent 3bac090 commit 6a7be63
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 49 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,3 @@ Build and run tests on Ubuntu and macOS under all build configurations.

Build and run tests on Ubuntu under _Coverage_ configuration, run SonarCloud
analysis and upload coverage reports to Codecov and SonarCloud.

## `docker.yaml`

[![Docker](https://github.com/Jhuighuy/TitSolver/actions/workflows/docker.yml/badge.svg)](https://github.com/Jhuighuy/TitSolver/actions/workflows/docker.yml)

Build Docker image containing development environment for `amd64` and `arm64`.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"files.watcherExclude": {
"**/.cache/**": true,
"**/dist/**": true,
"**/output/**": true,
"**/compile_flags.txt": true,
"**/node_modules/**": true
Expand Down
3 changes: 2 additions & 1 deletion build/build-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export TEST_OUTPUT_DIR="$SOURCE_DIR/output/test_output"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Terminal width.
export COLUMNS=$((tty -s && tput cols) || echo 80)
COLUMNS=$( (tty -s && tput cols) || echo 80)
export COLUMNS

# Print a separator.
echo-separator() {
Expand Down
2 changes: 1 addition & 1 deletion build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ parse-args() {
--compiler) COMPILER="$2"; shift 2;;
--compiler=*) COMPILER="${1#*=}"; shift 1;;
--vcpkg-root) VCPKG_ROOT="$2"; shift 2;;
--vcpkg-root=*) VCPKG_ROOT="${1#*=}"; shift 2;;
--vcpkg-root=*) VCPKG_ROOT="${1#*=}"; shift 1;;
--dry) DRY=true; shift;;
--) EXTRA_ARGS=("${@:2}"); break;;
# Help.
Expand Down
22 changes: 12 additions & 10 deletions build/setup-ci-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LLVM_VERSION=${LLVM_VERSION:-18}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

enforce-ci() {
[[ ! -z "$GITHUB_RUN_ID" ]] && return
[[ -n "$GITHUB_RUN_ID" ]] && return
echo "This script must be run in a GitHub CI environment!"
exit 1
}
Expand All @@ -41,11 +41,13 @@ setup-macos() {
pnpm \
sphinx-doc \
|| true # Linking may fail if the package is already installed.
local LLVM_PATH="$(brew --prefix llvm@$LLVM_VERSION)/bin"
local LLVM_PATH
LLVM_PATH="$(brew --prefix "llvm@$LLVM_VERSION")/bin"
ln -s "$LLVM_PATH/clang++" "$LLVM_PATH/clang++-$LLVM_VERSION"
echo "$LLVM_PATH" >> $GITHUB_PATH
local SPHINX_PATH="$(brew --prefix sphinx-doc)/bin"
echo "$SPHINX_PATH" >> $GITHUB_PATH
echo "$LLVM_PATH" >> "$GITHUB_PATH"
local SPHINX_PATH
SPHINX_PATH="$(brew --prefix sphinx-doc)/bin"
echo "$SPHINX_PATH" >> "$GITHUB_PATH"
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -54,7 +56,7 @@ setup-ubuntu() {
sudo apt -qq update
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh $LLVM_VERSION
sudo ./llvm.sh "$LLVM_VERSION"
sudo apt -qq install \
"clang-$LLVM_VERSION" \
"clang-tidy-$LLVM_VERSION" \
Expand All @@ -79,12 +81,12 @@ install-python-tools() {
install-vcpkg() {
export VCPKG_ROOT="$HOME/vcpkg"
export VCPKG_DEFAULT_BINARY_CACHE="$HOME/vcpkg_cache"
echo "VCPKG_ROOT=$VCPKG_ROOT" >> $GITHUB_ENV
echo "VCPKG_DEFAULT_BINARY_CACHE=$VCPKG_DEFAULT_BINARY_CACHE" >> $GITHUB_ENV
echo "VCPKG_ROOT=$VCPKG_ROOT" >> "$GITHUB_ENV"
echo "VCPKG_DEFAULT_BINARY_CACHE=$VCPKG_DEFAULT_BINARY_CACHE" >> "$GITHUB_ENV"
# Note: we cannot use `--depth=1` here, vcpgk requires the baseline commit.
git clone https://github.com/microsoft/vcpkg.git $VCPKG_ROOT
git clone https://github.com/microsoft/vcpkg.git "$VCPKG_ROOT"
"$VCPKG_ROOT/bootstrap-vcpkg.sh"
mkdir -p $VCPKG_DEFAULT_BINARY_CACHE || true # Ignore if it already exists.
mkdir -p "$VCPKG_DEFAULT_BINARY_CACHE" || true # Ignore if it already exists.
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 2 additions & 0 deletions build/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

source "$(dirname "$0")/build-utils.sh" || exit $?
JOBS=$(($(get-num-cpus) + 1))
EXTRA_ARGS=()
CTEST_EXE="${CTEST_EXE:-ctest}"

usage() {
Expand Down Expand Up @@ -64,6 +65,7 @@ run-tests() {
# Exclude long tests if the flag is not set.
[ ! "$TIT_LONG_TESTS" ] && CTEST_ARGS+=("--exclude-regex" "\[long\]")

[ "${EXTRA_ARGS[@]}" ] && CTEST_ARGS=("${CTEST_ARGS[@]}" "${EXTRA_ARGS[@]}")
(cd "$TEST_DIR" && "${CTEST_ARGS[@]}") || exit $?
}

Expand Down
6 changes: 4 additions & 2 deletions cmake/clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set(CLANG_MIN_VERSION "18.1.8")
# Define warnings and diagnostics options.
set(
CLANG_WARNINGS
# Treat warnings as errors.
-Werror
# Enable most of the commonly used warning options.
-Wall
-Wextra
Expand Down Expand Up @@ -138,8 +140,8 @@ set(
# Use link time optimizations?
#
# Note: This is experimental and may significantly decrease performance!
set(GNU_USE_LTO FALSE)
if(GNU_USE_LTO)
set(CLANG_USE_LTO FALSE)
if(CLANG_USE_LTO)
message(WARNING "Link-time optimizations support is experimental!")
list(APPEND CLANG_OPTIMIZE_OPTIONS -flto)
endif()
Expand Down
20 changes: 14 additions & 6 deletions cmake/clang_tidy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ function(enable_clang_tidy TARGET_OR_ALIAS)
-std=c++23
)

# Get the source directory and sources of the target.
set(ALL_STAMPS)
# Get the binary, source directory and sources of the target.
get_target_property(TARGET_BINARY_DIR ${TARGET} BINARY_DIR)
get_target_property(TARGET_SOURCE_DIR ${TARGET} SOURCE_DIR)
get_target_property(TARGET_SOURCES ${TARGET} SOURCES)
if(NOT TARGET_SOURCES)
Expand All @@ -82,28 +82,36 @@ function(enable_clang_tidy TARGET_OR_ALIAS)
endif()

# Loop through the target sources and call clang-tidy.
set(ALL_STAMPS)
foreach(SOURCE ${TARGET_SOURCES})
# Skip non-C/C++ files.
is_cpp_file("${SOURCE}" SOURCE_IS_CPP)
if(NOT SOURCE_IS_CPP)
message(WARNING "clang-tidy: a skipping non C/C++ file: '${SOURCE}'.")
message(WARNING "clang-tidy: skipping a non C/C++ file: '${SOURCE}'.")
continue()
endif()

# Create a stamp.
string(REPLACE "/" "_" STAMP "${SOURCE}.tidy_stamp")
set(STAMP "${TARGET_BINARY_DIR}/${STAMP}")
list(APPEND ALL_STAMPS "${STAMP}")

# Execute clang-tidy and update a stamp file on success.
# (wrapped with chronic to avoid annoying `N warnings generated` messages).
set(SOURCE_PATH "${TARGET_SOURCE_DIR}/${SOURCE}")
cmake_path(
RELATIVE_PATH SOURCE_PATH
BASE_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE RELATIVE_SOURCE_PATH
)
add_custom_command(
COMMENT "Analyzing ${SOURCE_PATH}"
COMMENT "Analyzing ${RELATIVE_SOURCE_PATH}"
OUTPUT "${STAMP}"
COMMAND
"${CHRONIC_EXE}"
"${CLANG_TIDY_EXE}" "${SOURCE_PATH}"
${CLANG_TIDY_ARGS} -- ${CLANG_TIDY_COMPILE_ARGS}
"${CLANG_TIDY_EXE}"
"${SOURCE_PATH}"
${CLANG_TIDY_ARGS} -- ${CLANG_TIDY_COMPILE_ARGS}
COMMAND
"${CMAKE_COMMAND}" -E touch "${STAMP}"
DEPENDS "${SOURCE_PATH}"
Expand Down
3 changes: 3 additions & 0 deletions cmake/clangd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function(write_compile_flags SAMPLE_TARGET)
-std=c++23
)

# Remove `-Werror` from the compile flags, as it breaks clangd.
list(REMOVE_ITEM CLANG_COMPILE_ARGS "-Werror")

# Write the compile flags to a file, each on a new line.
add_custom_target(
"${CMAKE_PROJECT_NAME}_clangd_compile_flags"
Expand Down
17 changes: 13 additions & 4 deletions cmake/pnpm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

include_guard()
include(utils)

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -39,9 +38,14 @@ function(add_pnpm_target TARGET)

# Run PNPM install.
set(TARGET_NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/node_modules")
cmake_path(
RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR
BASE_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE RELATIVE_SOURCE_DIR
)
add_custom_command(
COMMENT
"Installing dependencies for PNPM package ${CMAKE_CURRENT_SOURCE_DIR}"
"Installing dependencies for PNPM package ${RELATIVE_SOURCE_DIR}"
COMMAND "${CHRONIC_EXE}" "${PNPM_EXE}" install
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS "${TARGET_PACKAGE}"
Expand All @@ -64,7 +68,7 @@ function(add_pnpm_target TARGET)

# Run PNPM build.
add_custom_command(
COMMENT "Building PNPM package ${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Building PNPM package ${RELATIVE_SOURCE_DIR}"
COMMAND
"${CMAKE_COMMAND}" -E env "PNPM_OUTPUT_DIR=${TARGET_OUTPUT_DIR}"
"${CHRONIC_EXE}" "${PNPM_EXE}" run build
Expand Down Expand Up @@ -136,8 +140,13 @@ function(lint_pnpm_target TARGET)

# Run the PNPM lint.
set(STAMP "${TARGET_BINARY_DIR}/${TARGET}.pnpm_lint_stamp")
cmake_path(
RELATIVE_PATH TARGET_SOURCE_DIR
BASE_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE RELATIVE_SOURCE_DIR
)
add_custom_command(
COMMENT "Linting PNPM package ${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Linting PNPM package ${RELATIVE_SOURCE_DIR}"
COMMAND "${CHRONIC_EXE}" "${PNPM_EXE}" run lint
COMMAND "${CMAKE_COMMAND}" -E touch "${STAMP}"
WORKING_DIRECTORY "${TARGET_SOURCE_DIR}"
Expand Down
11 changes: 9 additions & 2 deletions cmake/sphinx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ function(add_sphinx_target TARGET)
)

# Run sphinx-build.
cmake_path(
RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR
BASE_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE RELATIVE_SOURCE_DIR
)
add_custom_command(
COMMENT "Building Sphinx target ${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Building Sphinx target ${RELATIVE_SOURCE_DIR}"
OUTPUT ${TARGET_OUTPUT}
COMMAND
"${CMAKE_COMMAND}"
Expand Down Expand Up @@ -119,7 +124,9 @@ function(install_sphinx_target)
# Install the documentation.
foreach(FILE ${TARGET_OUTPUT})
# Get the directory of the file relative to the output directory,
# and prepend the installation destination.
# and append it to the installation destination. This is needed to
# properly handle the hierarchy of the files, otherwise CMake will
# install all the files in the destination directory in a flat manner.
get_filename_component(FILE_DIR "${FILE}" DIRECTORY)
cmake_path(
RELATIVE_PATH
Expand Down
27 changes: 15 additions & 12 deletions cmake/tit_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ include(utils)
# Common target name prefix.
set(TARGET_NAME_PREFIX "tit")

#
# Make a target name.
#
function(make_target_name NAME RESULT_VAR)
if(NAME MATCHES "^${TARGET_NAME_PREFIX}")
set(${RESULT_VAR} "${NAME}" PARENT_SCOPE)
else()
set(${RESULT_VAR} "${TARGET_NAME_PREFIX}_${NAME}" PARENT_SCOPE)
endif()
endfunction()

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#
Expand Down Expand Up @@ -100,11 +111,7 @@ function(add_tit_library)
endif()

# Create the library and the alias.
if(LIB_NAME MATCHES "^${TARGET_NAME_PREFIX}")
set(LIB_TARGET "${LIB_NAME}")
else()
set(LIB_TARGET "${TARGET_NAME_PREFIX}_${LIB_NAME}")
endif()
make_target_name(${LIB_NAME} LIB_TARGET)
set(LIB_TARGET_ALIAS "${TARGET_NAME_PREFIX}::${LIB_NAME}")
add_library(${LIB_TARGET} ${LIB_TYPE} ${LIB_SOURCES})
add_library(${LIB_TARGET_ALIAS} ALIAS ${LIB_TARGET})
Expand Down Expand Up @@ -147,11 +154,7 @@ function(add_tit_executable)
endif()

# Create the executable and the alias.
if(EXE_NAME MATCHES "^${TARGET_NAME_PREFIX}")
set(EXE_TARGET "${EXE_NAME}")
else()
set(EXE_TARGET "${TARGET_NAME_PREFIX}_${EXE_NAME}")
endif()
make_target_name(${EXE_NAME} EXE_TARGET)
set(EXE_TARGET_ALIAS "${TARGET_NAME_PREFIX}::${EXE_NAME}")
add_executable(${EXE_TARGET} ${EXE_SOURCES})
add_executable(${EXE_TARGET_ALIAS} ALIAS ${EXE_TARGET})
Expand Down Expand Up @@ -184,7 +187,7 @@ function(add_tit_webapp)
endif()

# Create the target.
set(WEBAPP_TARGET "${TARGET_NAME_PREFIX}_${WEBAPP_NAME}")
make_target_name(${WEBAPP_NAME} WEBAPP_TARGET)
add_pnpm_target(${WEBAPP_TARGET})

# Install the target.
Expand Down Expand Up @@ -212,7 +215,7 @@ function(add_tit_documentation)
endif()

# Create the target.
set(DOC_TARGET "${TARGET_NAME_PREFIX}_${MAN_NAME}")
make_target_name(${DOC_NAME} DOC_TARGET)
add_sphinx_target(${DOC_TARGET})

# Install the target.
Expand Down
2 changes: 1 addition & 1 deletion source/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `tit`
# `source`

This folder contains all the solver's source code.
2 changes: 1 addition & 1 deletion source/titfront/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default tseslint.config(
],
files: ["**/*.{ts,tsx}"],
languageOptions: {
ecmaVersion: 2020,
ecmaVersion: 2023,
globals: globals.browser,
parserOptions: {
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
Expand Down
4 changes: 1 addition & 3 deletions source/titfront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.2.1",
"three": "^0.165.0"
"react-icons": "^5.2.1"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/node": "^18.3.12",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/three": "^0.170.0",
"@vitejs/plugin-react": "^4.3.3",
"autoprefixer": "^10.4.20",
"eslint": "^9.13.0",
Expand Down

0 comments on commit 6a7be63

Please sign in to comment.