From cbb9a830bd5daaae7dbea37e47f656a5afe73f18 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Thu, 5 Feb 2026 13:49:42 +0100 Subject: [PATCH 01/10] fix(shell): do not link OcreShell with OcreCore The application will select which Ocre API will be used as the backend for ocre-cli. So we add the OcreCore include directories only to OcreShell, and let the application decide when to link. Signed-off-by: Marco Casaroli --- src/samples/static_checks/posix/CMakeLists.txt | 5 ----- src/shell/CMakeLists.txt | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/samples/static_checks/posix/CMakeLists.txt b/src/samples/static_checks/posix/CMakeLists.txt index a0f08a5f..715f60a3 100644 --- a/src/samples/static_checks/posix/CMakeLists.txt +++ b/src/samples/static_checks/posix/CMakeLists.txt @@ -18,11 +18,6 @@ target_link_libraries(ocre_cmd OcreShell ) -target_link_libraries(OcreShell - PUBLIC - OcreCore -) - set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) target_link_libraries(ocre_cmd PRIVATE Threads::Threads) diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index a073075c..d6feb577 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -29,6 +29,10 @@ target_sources(OcreShell ) target_include_directories(OcreShell + PRIVATE + ../common/include + ../ocre/include + ../runtime/include PUBLIC include ) From e2f7d56edb501594dde81a732041c5e035c84aba Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Thu, 5 Feb 2026 23:08:37 +0100 Subject: [PATCH 02/10] fix(shell): create prints id even when non detached Since create does not start the container, it should print the id of the created container, even when it is non-detached. Signed-off-by: Marco Casaroli --- src/shell/container/create.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shell/container/create.c b/src/shell/container/create.c index 0a2af1fc..b1bc1b6e 100644 --- a/src/shell/container/create.c +++ b/src/shell/container/create.c @@ -230,7 +230,7 @@ int cmd_container_create_run(struct ocre_context *ctx, const char *argv0, int ar } } - if (detached) { + if (detached || !strcmp(argv[0], "create")) { const char *cid = ocre_container_get_id(container); fprintf(stdout, "%s\n", cid); From 8f85885c4f56ac933a794c03932ab1d129feceab Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Sat, 7 Feb 2026 13:57:18 +0100 Subject: [PATCH 03/10] feat(container): add function to get detached mode Sometimes we need to know if the container is in detached mode. We add this public function to the container API. Signed-off-by: Marco Casaroli --- src/ocre/container.c | 10 ++++++++++ src/ocre/include/ocre/container.h | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/ocre/container.c b/src/ocre/container.c index 5228ad39..748fedcd 100644 --- a/src/ocre/container.c +++ b/src/ocre/container.c @@ -710,3 +710,13 @@ const char *ocre_container_get_image(const struct ocre_container *container) return container->image; } + +bool ocre_container_is_detached(struct ocre_container *container) +{ + if (!container) { + LOG_ERR("Invalid container"); + return false; + } + + return container->detached; +} diff --git a/src/ocre/include/ocre/container.h b/src/ocre/include/ocre/container.h index 72540293..8f14b0cf 100644 --- a/src/ocre/include/ocre/container.h +++ b/src/ocre/include/ocre/container.h @@ -8,6 +8,8 @@ #ifndef OCRE_CONTAINER_H #define OCRE_CONTAINER_H +#include + /** * @brief The possible status of a container * @@ -165,4 +167,16 @@ int ocre_container_kill(struct ocre_container *container); */ int ocre_container_wait(struct ocre_container *container, int *status); +/** + * @brief Get detached mode + * @memberof ocre_container + * + * Detached containers run on background. + * + * @param container A pointer to the container to terminate + * + * @return true if container is detached, false otherwise + */ +bool ocre_container_is_detached(struct ocre_container *container); + #endif /* OCRE_CONTAINER_H */ From 4807db3ac6690e871cb764d950b47d7c68112828 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Sat, 7 Feb 2026 14:27:31 +0100 Subject: [PATCH 04/10] tests(context): container is detached function Signed-off-by: Marco Casaroli --- tests/system/context.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/system/context.c b/tests/system/context.c index cc3f1c7a..1b4e3722 100644 --- a/tests/system/context.c +++ b/tests/system/context.c @@ -508,6 +508,38 @@ void test_ocre_context_get_containers_ok(void) TEST_ASSERT_EQUAL_INT(0, ocre_context_get_containers(context, containers, 2)); } +void test_ocre_context_create_container_detached_mode(void) +{ + /* Create a valid detached container*/ + + struct ocre_container *detached_container = + ocre_context_create_container(context, "hello-world.wasm", "wamr/wasip1", NULL, true, NULL); + TEST_ASSERT_NOT_NULL(detached_container); + + /* Create a valid non-detached container*/ + + struct ocre_container *non_detached_container = + ocre_context_create_container(context, "hello-world.wasm", "wamr/wasip1", NULL, false, NULL); + TEST_ASSERT_NOT_NULL(non_detached_container); + + /* Check detached status */ + + TEST_ASSERT_TRUE(ocre_container_is_detached(detached_container)); + + /* Check non-detached status */ + + TEST_ASSERT_FALSE(ocre_container_is_detached(non_detached_container)); + + /* Check detached status from NULL should be false */ + + TEST_ASSERT_FALSE(ocre_container_is_detached(NULL)); + + /* Remove the containers */ + + TEST_ASSERT_EQUAL_INT(0, ocre_context_remove_container(context, detached_container)); + TEST_ASSERT_EQUAL_INT(0, ocre_context_remove_container(context, non_detached_container)); +} + int main(void) { UNITY_BEGIN(); @@ -523,6 +555,7 @@ int main(void) RUN_TEST(test_ocre_context_create_container_ok); RUN_TEST(test_ocre_context_create_container_null_runtime_ok); RUN_TEST(test_ocre_context_create_container_with_id_ok); + RUN_TEST(test_ocre_context_create_container_detached_mode); RUN_TEST(test_ocre_context_create_container_with_id_twice); RUN_TEST(test_ocre_context_create_container_and_forget); RUN_TEST(test_ocre_context_create_wait_remove); From 107089838bab23e5d1fc5bbeb104fb89015d3f3e Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Tue, 10 Feb 2026 13:39:07 +0100 Subject: [PATCH 05/10] build(sytem_test): link with OcreCommon Signed-off-by: Marco Casaroli --- tests/system/posix/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/system/posix/CMakeLists.txt b/tests/system/posix/CMakeLists.txt index 9fceee0f..051540b0 100644 --- a/tests/system/posix/CMakeLists.txt +++ b/tests/system/posix/CMakeLists.txt @@ -51,6 +51,7 @@ foreach(test ${OCRE_TESTS}) ) target_link_libraries(test_${test} + OcreCommon OcreCore Unity ) From 69971ad8bb31e5036037b275bba844669fe3aaa6 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Tue, 10 Feb 2026 14:42:39 +0100 Subject: [PATCH 06/10] refactor(version): move version to common As we will need it outside of OcreCore Signed-off-by: Marco Casaroli --- docs/BuildSystemLinux.md | 2 +- docs/BuildSystemZephyr.md | 2 +- docs/Versioning.md | 2 +- src/{ => common/include}/ocre/version.h | 0 src/ocre/ocre.c | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename src/{ => common/include}/ocre/version.h (100%) diff --git a/docs/BuildSystemLinux.md b/docs/BuildSystemLinux.md index af07c00a..d75b6ffd 100644 --- a/docs/BuildSystemLinux.md +++ b/docs/BuildSystemLinux.md @@ -17,7 +17,7 @@ This sections describes the build-time configuration honored by samples and test There are several components of the Ocre version that gets compiled in the project. -The file `src/ocre/version.h` includes the Ocre Library version string. +The file `src/common/version.h` includes the Ocre Library version string. While the file `commit_id.h` includes the commit ID of the Ocre Library. If this file is not present in the source tree, the file is generated during the build process and is stored in the build directory. If the file does not exist, and the source tree is not a valid git repository, the build will fail. diff --git a/docs/BuildSystemZephyr.md b/docs/BuildSystemZephyr.md index af992818..3367950c 100644 --- a/docs/BuildSystemZephyr.md +++ b/docs/BuildSystemZephyr.md @@ -81,7 +81,7 @@ This sections describes the build-time configuration required for Ocre to work. There are several components of the Ocre version that gets compiled in the project. -The file `src/ocre/version.h` includes the Ocre Library version string. +The file `src/common/version.h` includes the Ocre Library version string. While the file `commit_id.h` includes the commit ID of the Ocre Library. If this file is not present in the source tree, the file is generated during the build process and is stored in the build directory. If the file does not exist, and the source tree is not a valid git repository, the build will fail. diff --git a/docs/Versioning.md b/docs/Versioning.md index 4c7ded8f..1fe06463 100644 --- a/docs/Versioning.md +++ b/docs/Versioning.md @@ -4,7 +4,7 @@ There are several components of the Ocre version that gets compiled in the project. -The file `src/ocre/version.h` includes the Ocre Library version string. +The file `src/common/version.h` includes the Ocre Library version string. While the file `commit_id.h` includes the commit ID of the Ocre Library. If this file is not present in the source tree, the file is generated during the build process and is stored in the build directory. If the file does not exist, and the source tree is not a valid git repository, the build will fail. diff --git a/src/ocre/version.h b/src/common/include/ocre/version.h similarity index 100% rename from src/ocre/version.h rename to src/common/include/ocre/version.h diff --git a/src/ocre/ocre.c b/src/ocre/ocre.c index e134a31e..43789b61 100644 --- a/src/ocre/ocre.c +++ b/src/ocre/ocre.c @@ -24,7 +24,7 @@ #include "context.h" #include "util/rm_rf.h" -#include "version.h" +#include LOG_MODULE_REGISTER(ocre, CONFIG_OCRE_LOG_LEVEL); From 03b0b0ce848917452352a69433ef82d237bb9e5b Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Tue, 10 Feb 2026 14:58:04 +0100 Subject: [PATCH 07/10] refactor: move version to ocre/common and make it private Signed-off-by: Marco Casaroli --- src/common/CMakeLists.txt | 20 ++++++++++---------- src/common/common.c | 15 +++++++++++++++ src/common/include/ocre/common.h | 19 +++++++++++++++++++ src/common/{include/ocre => }/version.h | 0 src/ocre/include/ocre/library.h | 19 ------------------- src/ocre/ocre.c | 13 ------------- 6 files changed, 44 insertions(+), 42 deletions(-) rename src/common/{include/ocre => }/version.h (100%) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 70114ca8..a7690f1f 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -17,10 +17,9 @@ if(GIT_DIR) # Generate commit ID header file in source dir if we are in a git repository add_custom_command( - OUTPUT include/ocre/commit_id.h - COMMAND sh -c "mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/ocre" - COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/ocre/commit_id.h" - COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/ocre/commit_id.h" + OUTPUT include/commit_id.h + COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h" + COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM DEPENDS always_rebuild @@ -31,9 +30,9 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ocre) # Generate build info header file in binary dir for every build add_custom_command( - OUTPUT include/ocre/build_info.h - COMMAND sh -c "echo \"#define OCRE_BUILD_HOST_INFO \\\"$ENV{USER} @ $(uname -a)\\\"\" > include/ocre/build_info.h" - COMMAND sh -c "echo \"#define OCRE_BUILD_DATE \\\"$(date +'%Y-%m-%d %H:%M:%S %Z')\\\"\" >> include/ocre/build_info.h" + OUTPUT include/build_info.h + COMMAND sh -c "echo \"#define OCRE_BUILD_HOST_INFO \\\"$ENV{USER} @ $(uname -a)\\\"\" > include/build_info.h" + COMMAND sh -c "echo \"#define OCRE_BUILD_DATE \\\"$(date +'%Y-%m-%d %H:%M:%S %Z')\\\"\" >> include/build_info.h" VERBATIM DEPENDS always_rebuild ) @@ -50,12 +49,13 @@ add_library(OcreCommon) target_sources(OcreCommon PRIVATE common.c - include/ocre/build_info.h - include/ocre/commit_id.h + include/build_info.h + include/commit_id.h ) target_include_directories(OcreCommon + PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/include PUBLIC include - ${CMAKE_CURRENT_BINARY_DIR}/include ) diff --git a/src/common/common.c b/src/common/common.c index ec62c4e1..367117a5 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -2,6 +2,21 @@ #include #include +#include + +#include "version.h" +#include "build_info.h" +#include "commit_id.h" + +/* Constant build information */ + +const struct ocre_config ocre_build_configuration = { + .build_info = OCRE_BUILD_HOST_INFO, + .version = OCRE_VERSION_STRING, + .commit_id = GIT_COMMIT_ID, + .build_date = OCRE_BUILD_DATE, +}; + int ocre_is_valid_name(const char *id) { /* Cannot be NULL */ diff --git a/src/common/include/ocre/common.h b/src/common/include/ocre/common.h index 741c7b5e..ea139dc3 100644 --- a/src/common/include/ocre/common.h +++ b/src/common/include/ocre/common.h @@ -8,6 +8,25 @@ #ifndef OCRE_COMMON_H #define OCRE_COMMON_H +/** + * @brief Build configuration of the Ocre Library + * @headerfile ocre.h + * + * There should only be only one instance of this structure in the program. And it must be in constant read-only memory. + * It is set at build-time and should only be read-only to the user. + */ +struct ocre_config { + const char *version; /**< Version of the Ocre Library */ + const char *commit_id; /**< Commit ID of the build tree */ + const char *build_info; /**< Host build information */ + const char *build_date; /**< Build date */ +}; + +/** + * @brief The instance of configuration of the Ocre Library is constant and compiled-in. + */ +extern const struct ocre_config ocre_build_configuration; + /** * @brief Check if a container or image names is valid * @memberof ocre_context diff --git a/src/common/include/ocre/version.h b/src/common/version.h similarity index 100% rename from src/common/include/ocre/version.h rename to src/common/version.h diff --git a/src/ocre/include/ocre/library.h b/src/ocre/include/ocre/library.h index e792a244..b11ea8c5 100644 --- a/src/ocre/include/ocre/library.h +++ b/src/ocre/include/ocre/library.h @@ -10,25 +10,6 @@ #include -/** - * @brief Build configuration of the Ocre Library - * @headerfile ocre.h - * - * There should only be only one instance of this structure in the program. And it must be in constant read-only memory. - * It is set at build-time and should only be read-only to the user. - */ -struct ocre_config { - const char *version; /**< Version of the Ocre Library */ - const char *commit_id; /**< Commit ID of the build tree */ - const char *build_info; /**< Host build information */ - const char *build_date; /**< Build date */ -}; - -/** - * @brief The instance of configuration of the Ocre Library is constant and compiled-in. - */ -extern const struct ocre_config ocre_build_configuration; - /** * @class ocre_context * @headerfile ocre.h diff --git a/src/ocre/ocre.c b/src/ocre/ocre.c index 43789b61..b0240048 100644 --- a/src/ocre/ocre.c +++ b/src/ocre/ocre.c @@ -17,26 +17,13 @@ #include #include -#include #include -#include #include "context.h" #include "util/rm_rf.h" -#include - LOG_MODULE_REGISTER(ocre, CONFIG_OCRE_LOG_LEVEL); -/* Constant build information */ - -const struct ocre_config ocre_build_configuration = { - .build_info = OCRE_BUILD_HOST_INFO, - .version = OCRE_VERSION_STRING, - .commit_id = GIT_COMMIT_ID, - .build_date = OCRE_BUILD_DATE, -}; - /* List of runtimes */ struct runtime_node { From 33a24e7094aa8291ce26e33f03fb3b3592c1bcc6 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Wed, 18 Feb 2026 14:41:56 +0100 Subject: [PATCH 08/10] build(ocre): library visibility Signed-off-by: Marco Casaroli --- src/ocre/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ocre/CMakeLists.txt b/src/ocre/CMakeLists.txt index 00ea4e12..2427b362 100644 --- a/src/ocre/CMakeLists.txt +++ b/src/ocre/CMakeLists.txt @@ -16,11 +16,12 @@ target_sources(OcreCore ) target_link_libraries(OcreCore - PUBLIC + PRIVATE uthash OcrePlatform - OcreRuntime OcreRuntimeWamr + PUBLIC + OcreRuntime OcreCommon ) From 8e9742a146f844b223044b9c394b27b966201843 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Wed, 18 Feb 2026 16:46:03 +0100 Subject: [PATCH 09/10] build: add OcrePlatformBase Signed-off-by: Marco Casaroli --- src/platform/CMakeLists.txt | 11 +++++++++++ src/platform/posix/CMakeLists.txt | 8 +++++++- src/platform/zephyr/CMakeLists.txt | 6 ++++-- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/platform/CMakeLists.txt diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt new file mode 100644 index 00000000..d4c96065 --- /dev/null +++ b/src/platform/CMakeLists.txt @@ -0,0 +1,11 @@ +# @copyright Copyright (c) contributors to Project Ocre, +# which has been established as Project Ocre a Series of LF Projects, LLC +# +# SPDX-License-Identifier: Apache-2.0 + +add_library(OcrePlatformBase INTERFACE) + +target_include_directories(OcrePlatform + PUBLIC + include +) diff --git a/src/platform/posix/CMakeLists.txt b/src/platform/posix/CMakeLists.txt index 565c47c9..77612f46 100644 --- a/src/platform/posix/CMakeLists.txt +++ b/src/platform/posix/CMakeLists.txt @@ -14,8 +14,14 @@ target_sources(OcrePlatform lstat.c ) +add_subdirectory(.. OcrePlatformBase) + target_include_directories(OcrePlatform PUBLIC include - ../include +) + +target_link_libraries(OcrePlatform + PRIVATE + OcrePlatformBase ) diff --git a/src/platform/zephyr/CMakeLists.txt b/src/platform/zephyr/CMakeLists.txt index 943530aa..7e253296 100644 --- a/src/platform/zephyr/CMakeLists.txt +++ b/src/platform/zephyr/CMakeLists.txt @@ -12,13 +12,15 @@ target_sources(OcrePlatform lstat.c ) +add_subdirectory(.. OcrePlatformBase) + target_include_directories(OcrePlatform PUBLIC include - ../include ) target_link_libraries(OcrePlatform - PUBLIC + PRIVATE zephyr_interface + OcrePlatformBase ) From 202bcb0d6ec4905f369584ad9d1b66ad539c761a Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Wed, 18 Feb 2026 16:48:55 +0100 Subject: [PATCH 10/10] build: fix private exports Signed-off-by: Marco Casaroli --- src/runtime/wamr-wasip1/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/wamr-wasip1/CMakeLists.txt b/src/runtime/wamr-wasip1/CMakeLists.txt index 25286ba4..85106bb0 100644 --- a/src/runtime/wamr-wasip1/CMakeLists.txt +++ b/src/runtime/wamr-wasip1/CMakeLists.txt @@ -16,7 +16,7 @@ target_include_directories(OcreRuntimeWamr ) target_link_libraries(OcreRuntimeWamr - PUBLIC + PRIVATE OcreRuntime OcrePlatform OcreRuntimeAPI