Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
black-desk committed Jan 21, 2025
1 parent d576be0 commit 632370c
Show file tree
Hide file tree
Showing 89 changed files with 3,311 additions and 4,469 deletions.
129 changes: 87 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
cmake_minimum_required(VERSION 3.11.4) # for RHEL 8

# Let's place extra cmake scripts in /cmake directory
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

project(
linyaps-box
VERSION 1.3.4
DESCRIPTION "A simple OCI runtime for desktop applications."
HOMEPAGE_URL "https://github.com/OpenAtom-Linyaps/linyaps-box"
LANGUAGES CXX)

# Extra cmake scripts of this project placed in /cmake directory
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# ==============================================================================
# Build options
# ==============================================================================

option(linyaps-box_STATIC "Build statically-linked binary." OFF)
option(linyaps-box_STATIC "Build linyaps-box as statically-linked binary." OFF)

set(linyaps-box_ENABLE_SECCOMP_DEFAULT ON)
if(linyaps-box_STATIC)
set(linyaps-box_ENABLE_SECCOMP_DEFAULT OFF)
endif()

option(linyaps-box_ENABLE_SECCOMP "Enable seccomp support."
option(linyaps-box_ENABLE_SECCOMP "Build linyaps-box with seccomp support."
${linyaps-box_ENABLE_SECCOMP_DEFAULT})

if(linyaps-box_STATIC AND linyaps-box_ENABLE_SECCOMP)
Expand Down Expand Up @@ -54,40 +56,71 @@ set(linyaps-box_CPACK_PACKAGING_INSTALL_PREFIX
"/opt/org.openatom.linyaps-box"
CACHE STRING "Install prefix for package generated by CPack.")

set(linyaps-box_CLONE_CHILD_STACK_SIZE
"(1 << 20)"
CACHE STRING
"Size of child stack in bytes when using clone to create container.")

set(linyaps-box_STACK_GROWTH_DOWN
true
CACHE BOOL "The stack grows down.")

# ==============================================================================

set(linyaps-box_LIBRARY linyaps-box)
set(linyaps-box_LIBRARY_SOURCE
./src/container/container.cpp
./src/container/container.h
./src/container/helper.cpp
./src/container/helper.h
./src/container/mount
./src/container/mount/filesystem_driver.cpp
./src/container/mount/filesystem_driver.h
./src/container/mount/host_mount.cpp
./src/container/mount/host_mount.h
./src/container/seccomp.cpp
./src/container/seccomp.h
./src/util/common.cpp
./src/util/common.h
./src/util/debug
./src/util/debug/debug.cpp
./src/util/debug/debug.h
./src/util/filesystem.cpp
./src/util/filesystem.h
./src/util/json.h
./src/util/logger.cpp
./src/util/logger.h
./src/util/macro.h
./src/util/message_reader.cpp
./src/util/message_reader.h
./src/util/oci_runtime.h
./src/util/platform.cpp
./src/util/platform.h
./src/util/semaphore.cpp
./src/util/semaphore.h
./src/util/util.h)
./src/linyaps_box/app.cpp
./src/linyaps_box/app.h
./src/linyaps_box/command/exec.cpp
./src/linyaps_box/command/exec.h
./src/linyaps_box/command/kill.cpp
./src/linyaps_box/command/kill.h
./src/linyaps_box/command/list.cpp
./src/linyaps_box/command/list.h
./src/linyaps_box/command/options.cpp
./src/linyaps_box/command/options.h
./src/linyaps_box/command/run.cpp
./src/linyaps_box/command/run.h
./src/linyaps_box/config.cpp
./src/linyaps_box/config.h
./src/linyaps_box/container.cpp
./src/linyaps_box/container.h
./src/linyaps_box/container_ref.cpp
./src/linyaps_box/container_ref.h
./src/linyaps_box/container_status.cpp
./src/linyaps_box/container_status.h
./src/linyaps_box/impl/json_printer.cpp
./src/linyaps_box/impl/json_printer.h
./src/linyaps_box/impl/status_directory.cpp
./src/linyaps_box/impl/status_directory.h
./src/linyaps_box/impl/table_printer.cpp
./src/linyaps_box/impl/table_printer.h
./src/linyaps_box/interface.cpp
./src/linyaps_box/interface.h
./src/linyaps_box/printer.cpp
./src/linyaps_box/printer.h
./src/linyaps_box/runtime.cpp
./src/linyaps_box/runtime.h
./src/linyaps_box/status_directory.cpp
./src/linyaps_box/status_directory.h
./src/linyaps_box/utils/atomic_write.cpp
./src/linyaps_box/utils/atomic_write.h
./src/linyaps_box/utils/socketpair.cpp
./src/linyaps_box/utils/socketpair.h
./src/linyaps_box/utils/file_describer.cpp
./src/linyaps_box/utils/file_describer.h
./src/linyaps_box/utils/fstat.cpp
./src/linyaps_box/utils/fstat.h
./src/linyaps_box/utils/open_file.cpp
./src/linyaps_box/utils/open_file.h
./src/linyaps_box/utils/mknod.cpp
./src/linyaps_box/utils/mknod.h
./src/linyaps_box/utils/mkdir.cpp
./src/linyaps_box/utils/mkdir.h
./src/linyaps_box/utils/touch.cpp
./src/linyaps_box/utils/touch.h
./src/linyaps_box/utils/semver.cpp
./src/linyaps_box/utils/semver.h)
set(linyaps-box_LIBRARY_LINK_LIBRARIES)
set(linyaps-box_LIBRARY_INCLUDE_DIRS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")

Expand All @@ -101,12 +134,25 @@ find_package(nlohmann_json 3.5.0 REQUIRED)
list(APPEND linyaps-box_LIBRARY_LINK_LIBRARIES PUBLIC
nlohmann_json::nlohmann_json)

find_package(CLI11 REQUIRED)
list(APPEND linyaps-box_LIBRARY_LINK_LIBRARIES PUBLIC CLI11::CLI11)

add_library("${linyaps-box_LIBRARY}" ${linyaps-box_LIBRARY_SOURCE})
target_include_directories("${linyaps-box_LIBRARY}"
${linyaps-box_LIBRARY_INCLUDE_DIRS})
target_link_libraries("${linyaps-box_LIBRARY}"
${linyaps-box_LIBRARY_LINK_LIBRARIES})
target_compile_features("${linyaps-box_LIBRARY}" PUBLIC cxx_std_17)
set_property(TARGET "${linyaps-box_LIBRARY}" PROPERTY CXX_STANDARD 17)
set_property(TARGET "${linyaps-box_LIBRARY}" PROPERTY CXX_EXTENSIONS OFF)
set_property(TARGET "${linyaps-box_LIBRARY}" PROPERTY CXX_STANDARD_REQUIRED ON)

target_compile_definitions(
"${linyaps-box_LIBRARY}"
PRIVATE
"LINYAPS_BOX_CLONE_CHILD_STACK_SIZE=${linyaps-box_CLONE_CHILD_STACK_SIZE}"
PRIVATE "LINYAPS_BOX_STACK_GROWTH_DOWN=${linyaps-box_STACK_GROWTH_DOWN}")

if(linyaps-box_ENABLE_SECCOMP)
target_compile_definitions("${linyaps-box_LIBRARY}"
PUBLIC LINYAPS_BOX_ENABLE_SECCOMP)
Expand All @@ -126,8 +172,6 @@ if(linyaps-box_ENABLE_COVERAGE)
FATAL_ERROR "Coverage is not supported for ${CMAKE_CXX_COMPILER_ID}.")
endif()
endif()
set_property(TARGET "${linyaps-box_LIBRARY}" PROPERTY CXX_STANDARD 17)
set_property(TARGET "${linyaps-box_LIBRARY}" PROPERTY CXX_STANDARD_REQUIRED ON)

# ==============================================================================

Expand All @@ -146,6 +190,7 @@ if(linyaps-box_STATIC)
endif()
target_compile_features("${linyaps-box_APP}" PRIVATE cxx_std_17)
set_property(TARGET "${linyaps-box_APP}" PROPERTY CXX_STANDARD 17)
set_property(TARGET "${linyaps-box_APP}" PROPERTY CXX_EXTENSIONS OFF)
set_property(TARGET "${linyaps-box_APP}" PROPERTY CXX_STANDARD_REQUIRED ON)

# ==============================================================================
Expand All @@ -170,9 +215,10 @@ endif()

enable_testing()

include(GoogleTest)

set(linyaps-box_UNIT_TESTS ll-box-ut)
set(linyaps-box_UNIT_TESTS_SOURCE ./tests/ll-box-ut/src/oci_test.cpp
./tests/ll-box-ut/src/seccomp_test.cpp)
set(linyaps-box_UNIT_TESTS_SOURCE ./tests/ll-box-ut/src/test.cpp)
set(linyaps-box_UNIT_TESTS_LINK_LIBRARIES PRIVATE "${linyaps-box_LIBRARY}")
set(linyaps-box_UNIT_TESTS_SOURCE_INCLUDE_DIRS
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/tests/ll-box-ut/src")
Expand All @@ -192,17 +238,16 @@ target_link_libraries("${linyaps-box_UNIT_TESTS}"
${linyaps-box_UNIT_TESTS_LINK_LIBRARIES})
target_compile_features("${linyaps-box_UNIT_TESTS}" PRIVATE cxx_std_17)
set_property(TARGET "${linyaps-box_UNIT_TESTS}" PROPERTY CXX_STANDARD 17)
set_property(TARGET "${linyaps-box_UNIT_TESTS}" PROPERTY CXX_EXTENSIONS OFF)
set_property(TARGET "${linyaps-box_UNIT_TESTS}" PROPERTY CXX_STANDARD_REQUIRED
ON)

include(GoogleTest)

set(GTEST_DISCOVER_TESTS_ARGS "${linyaps-box_UNIT_TESTS}" WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/tests/ll-box-ut")

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND GTEST_DISCOVER_TESTS_ARGS PROPERTIES ENVIRONMENT
"LLVM_PROFILE_FILE=${CMAKE_CURRENT_BINARY_DIR}/default.profraw")
"LLVM_PROFILE_FILE=/dev/null")
endif()

gtest_discover_tests(${GTEST_DISCOVER_TESTS_ARGS})
Expand Down
61 changes: 57 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,29 @@
"linyaps-box_ENABLE_CPACK": "ON"
}
},
{
"name": "static",
"displayName": "The static build profile",
"description": "The default configuration for produce static binary",
"binaryDir": "${sourceDir}/build-static",
"cacheVariables": {
"CMAKE_COLOR_DIAGNOSTICS": true,
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CXX_COMPILER_LAUNCHER": "$env{CMAKE_CXX_COMPILER_LAUNCHER}",
"CMAKE_CXX_CLANG_TIDY": "$env{CMAKE_CXX_CLANG_TIDY}",
"CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic -Werror -Os -fno-asynchronous-unwind-tables -fdata-sections -ffunction-sections -flto=auto $env{CXXFLAGS}",
"CMAKE_C_COMPILER_LAUNCHER": "$env{CMAKE_C_COMPILER_LAUNCHER}",
"CMAKE_C_CLANG_TIDY": "$env{CMAKE_C_CLANG_TIDY}",
"CMAKE_C_FLAGS": "-Wall -Wextra -Wpedantic -Werror -Os -fno-asynchronous-unwind-tables -fdata-sections -ffunction-sections -flto=auto $env{CFLAGS}",
"CMAKE_LINKER_TYPE": "$env{CMAKE_LINKER_TYPE}",
"CMAKE_EXE_LINKER_FLAGS_INIT": "-Wl,--gc-sections,--strip-all,--exclude-libs,ALL -flto=auto",
"linyaps-box_STATIC": true
}
},
{
"name": "ci",
"displayName": "The dev profile",
"description": "The default configuration for developers",
"displayName": "The CI profile",
"description": "The default configuration for CI",
"binaryDir": "${sourceDir}/build-ci",
"cacheVariables": {
"CMAKE_COLOR_DIAGNOSTICS": true,
Expand Down Expand Up @@ -74,6 +93,10 @@
{
"name": "ci",
"configurePreset": "ci"
},
{
"name": "static",
"configurePreset": "static"
}
],
"testPresets": [
Expand Down Expand Up @@ -109,6 +132,17 @@
"noTestsAction": "default",
"stopOnFailure": false
}
},
{
"name": "static",
"configurePreset": "static",
"output": {
"verbosity": "verbose"
},
"execution": {
"noTestsAction": "default",
"stopOnFailure": true
}
}
],
"workflowPresets": [
Expand Down Expand Up @@ -152,8 +186,8 @@
},
{
"name": "ci",
"displayName": "The default workflow for ci",
"description": "Configure, build then test with ci profile",
"displayName": "The default workflow for CI",
"description": "Configure, build then test with CI profile",
"steps": [
{
"type": "configure",
Expand All @@ -168,6 +202,25 @@
"name": "ci"
}
]
},
{
"name": "static",
"displayName": "The default workflow for static build",
"description": "Configure, build then test with static profile",
"steps": [
{
"type": "configure",
"name": "static"
},
{
"type": "build",
"name": "static"
},
{
"type": "test",
"name": "static"
}
]
}
]
}
Loading

0 comments on commit 632370c

Please sign in to comment.