Skip to content
Open
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
22 changes: 22 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04
FROM mcr.microsoft.com/devcontainers/cpp:dev-ubuntu-24.04

ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"

# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/

RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh

# [Optional] Uncomment this section to install additional vcpkg ports.
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install clangd"

# [Optional] Uncomment this section to install additional packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
RUN apt update && export DEBIAN_FRONTEND=noninteractive && apt -y install clangd-19 clang-tidy-19 python3-pip
RUN update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-19 100
RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-19 100
21 changes: 21 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile"
},
"containerEnv": {
"CLIPPY_BACKEND_PATH": "${containerWorkspaceFolder}/build/test"
},
"customizations": {
"vscode": {
"extensions": [
"llvm-vs-code-extensions.vscode-clangd",
"ms-python.python"
// add other extensions as needed
]
}
},
//"postCreateCommand": "pip install --break-system-packages -r ${containerWorkspaceFolder}/test/requirements.txt"
}
59 changes: 59 additions & 0 deletions .devcontainer/reinstall-cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
set -e

CMAKE_VERSION=${1:-"none"}

if [ "${CMAKE_VERSION}" = "none" ]; then
echo "No CMake version specified, skipping CMake reinstallation"
exit 0
fi

# Cleanup temporary directory and associated files when exiting the script.
cleanup() {
EXIT_CODE=$?
set +e
if [[ -n "${TMP_DIR}" ]]; then
echo "Executing cleanup of tmp files"
rm -Rf "${TMP_DIR}"
fi
exit $EXIT_CODE
}
trap cleanup EXIT


echo "Installing CMake..."
apt-get -y purge --auto-remove cmake
mkdir -p /opt/cmake

architecture=$(dpkg --print-architecture)
case "${architecture}" in
arm64)
ARCH=aarch64 ;;
amd64)
ARCH=x86_64 ;;
*)
echo "Unsupported architecture ${architecture}."
exit 1
;;
esac

CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)

echo "${TMP_DIR}"
cd "${TMP_DIR}"

curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O

sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license

ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
__pycache__
**/build
venv
*.core
build
setup.cfg
.vscode
*.egg-info
.coverage
**/attic
build
*/.cache
99 changes: 99 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Copyright 2020 Lawrence Livermore National Security, LLC and other CLIPPy
# Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: MIT


cmake_minimum_required(VERSION 3.26)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(ALLOW_DUPLICATE_CUSTOM_TARGETS TRUE)

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()

project(CLIPPy
VERSION 0.5
DESCRIPTION "Command Line Interface Plus Python"
LANGUAGES CXX)

include(FetchContent)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Only do these if this is the main project, and not if it is included through add_subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Let's ensure -std=c++xx instead of -std=g++xx
set(CMAKE_CXX_EXTENSIONS OFF)

# Let's nicely support folders in IDE's
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Testing only available if this is the main app
# Note this needs to be done in the main CMakeLists
# since it calls enable_testing, which must be in the
# main CMakeLists.
# include(CTest)

# Docs only available if this is the main app
find_package(Doxygen)
if(Doxygen_FOUND)
#add_subdirectory(docs)
else()
message(STATUS "Doxygen not found, not building docs")
endif()
endif()


#
# Boost
# Download and build Boost::json
set(BOOST_URL
"https://github.com/boostorg/boost/releases/download/boost-1.87.0/boost-1.87.0-cmake.tar.gz"
CACHE STRING "URL to fetch Boost tarball")


set(BOOST_INCLUDE_LIBRARIES json lexical_cast range)
set(BUILD_SHARED_LIBS ON)
FetchContent_Declare(
Boost
URL ${BOOST_URL})
FetchContent_MakeAvailable(Boost)


#
# JSONLogic
set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/boost-install) # needed for jsonlogic

FetchContent_Declare(jsonlogic
GIT_REPOSITORY https://github.com/LLNL/jsonlogic.git
GIT_TAG v0.2.0
SOURCE_SUBDIR cpp
)
# set(jsonlogic_INCLUDE_DIR ${jsonlogic_SOURCE_DIR}/cpp/include/jsonlogic)
FetchContent_MakeAvailable(jsonlogic)
message(STATUS "jsonlogic source dir: ${jsonlogic_SOURCE_DIR}")



### Require out-of-source builds
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(FATAL_ERROR "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.")
endif()

include_directories("${PROJECT_SOURCE_DIR}/include")

option(TEST_WITH_SLURM "Run tests with Slurm" OFF)

# Testing & examples are only available if this is the main app
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
message(STATUS "adding test subdir")
add_subdirectory(test)
# Example codes are here.
#add_subdirectory(examples)
endif()
11 changes: 11 additions & 0 deletions cpp/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 3,
"configurePresets": [
{
"name": "cfg",
"generator": "Ninja",
"sourceDir": "src",
"binaryDir": "build"
}
]
}
22 changes: 22 additions & 0 deletions cpp/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# C++ Examples using CLIPPy
This directory contains a series of examples of using CLIPPy for command
line configuration.


**NOTE:** These examples are trivial and are used for illustration and testing
purposes. In no way are we advocating sorting strings externally to
Python, for example.


## Examples

- [howdy.cpp](howdy.cpp): Example of String input and output
- [sum.cpp](sum.cpp): Example of Number input and output
- [sort_edges.cpp](sort_edges.cpp): Example of VectorIntInt input and output, also contains optional Boolean.
- [sort_strings.cpp](sort_strings.cpp): Example of VectorStrings input and output, also contains optional Boolean.
- [grumpy.cpp](grumpy.cpp): Example of exception throwing in C++ backend. Grumpy always throws a std::runtime_error()
- [dataframe](dataframe): Example with a dataframe class using freestanding clippy functions (clippy)
- [oo-dataframe](oo-dataframe): Example with a dataframe class using clippy objects (ooclippy)

## Building
Edit the `Makefile` as necessary and run `make`.
74 changes: 74 additions & 0 deletions cpp/examples/SimpleExamples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2020 Lawrence Livermore National Security, LLC and other CLIPPy
# Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: MIT

#
# This function adds an mpi example.
#
# Works with 3.11 and tested through 3.15 (not tested yet)
cmake_minimum_required(VERSION 3.14)
set(ALLOW_DUPLICATE_CUSTOM_TARGETS TRUE)

include(FetchContent)

find_package(Threads)
# PP: added because I got an error "Could NOT find Threads (missing: Threads_FOUND)"
# solution according to: https://github.com/alicevision/geogram/issues/2
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)

find_package(Boost 1.75 REQUIRED COMPONENTS)

#
# Metall
find_package(Metall QUIET)
if (NOT Metall_FOUND)
#set(METALL_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/metall-work)
set(METALL_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/metall-src)
set(METALL_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/metall-build)
set(METALL_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/metall-install)
FetchContent_Declare(Metall
GIT_REPOSITORY https://github.com/LLNL/metall.git
GIT_TAG v0.26
)
# SOURCE_DIR ${METALL_SOURCE_DIR}
# BINARY_DIR ${METALL_BUILD_DIR}
# CMAKE_ARGS -DINSTALL_HEADER_ONLY=ON -DCMAKE_INSTALL_PREFIX=${METALL_INSTALL_DIR}
# )
# set(METALL_INCLUDE_DIR ${METALL_INSTALL_DIR}/include)
FetchContent_MakeAvailable(Metall)
endif ()
function ( add_example example_name )
set(example_source "${example_name}.cpp")
set(example_exe "${example_name}")
add_executable(${example_exe} ${example_source})
target_include_directories(${example_exe} PRIVATE ${Boost_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/../include)
target_link_libraries(${example_exe} PRIVATE Metall)
target_link_libraries(${example_exe} PRIVATE stdc++fs Threads::Threads)
if (UNIX AND NOT APPLE)
target_link_libraries(${example_exe} PRIVATE rt)
endif ()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(SOURCES ${example_source} ${CMAKE_SOURCE_DIR}/../include/clippy/clippy.hpp} ${CMAKE_SOURCE_DIR}/../include/experimental/cxx-compat.hpp)
endfunction()

add_example(grumpy)
add_example(sort_edges)
add_example(sort_strings)
add_example(howdy)
add_example(sum)
add_example(return_tuple)
add_example(sort_string_edges)

add_subdirectory(wordcounter)
add_subdirectory(dataframe)
add_subdirectory(dataframe-load)
add_subdirectory(oo-howdy)
add_subdirectory(oo-dataframe)
#add_subdirectory(mpi)
#add_subdirectory(ygm)
add_subdirectory(logic)
16 changes: 16 additions & 0 deletions cpp/examples/SimpleExamples/grumpy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2019 Lawrence Livermore National Security, LLC and other Clippy
// Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: MIT

#include <clippy/clippy.hpp>

int main(int argc, char **argv) {
clippy::clippy clip("grumpy", "Always throws errors because he's Grumpy!");
if (clip.parse(argc, argv)) {
return 0;
}

throw std::runtime_error("I'm Grumpy!");
return 0;
}
18 changes: 18 additions & 0 deletions cpp/examples/SimpleExamples/howdy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2020 Lawrence Livermore National Security, LLC and other CLIPPy Project Developers.
// See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: MIT

#include <clippy/clippy.hpp>

int main(int argc, char **argv) {
clippy::clippy clip("howdy", "Formal Texan greeting.");
clip.add_required<std::string>("name", "Name to greet");
clip.returns<std::string>("The greeting");
if (clip.parse(argc, argv)) { return 0; }

auto name = clip.get<std::string>("name");

clip.to_return(std::string("Howdy, ") + name);
return 0;
}
18 changes: 18 additions & 0 deletions cpp/examples/SimpleExamples/return_tuple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2020 Lawrence Livermore National Security, LLC and other CLIPPy Project Developers.
// See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: MIT

#include <tuple>
#include <clippy/clippy.hpp>
#include <typeinfo>

int main(int argc, char **argv) {
clippy::clippy clip("return_tuple", "Always returns a tuple");

if (clip.parse(argc, argv)) { return 0; }

clip.to_return(std::make_tuple("foo", 42, 3.24));

return 0;
}
Loading
Loading