From 97b88f0259162676942d9182354d72b759d3a74b Mon Sep 17 00:00:00 2001 From: "Lucas, John P." Date: Thu, 14 Aug 2025 11:17:03 -0400 Subject: [PATCH 1/2] [tryspaceorg/tryspace-lab#14] Updates to use public container, cleanup make / cmake, and add CI; --- .github/workflows/ci.yml | 42 +++++++++++++++++++++++++++ CMakeLists.txt | 62 ++++++++++++++++++++++------------------ Makefile | 37 +++++++++++++++--------- test/Dockerfile.director | 2 +- test/Dockerfile.server | 2 +- 5 files changed, 102 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..48cedc1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI + +on: + pull_request: + branches: + - '**' + +env: + CTEST_OUTPUT_ON_FAILURE: true + +jobs: + setup: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install GNU Make + run: sudo apt-get update && sudo apt-get install -y \ + build-essential \ + cmake \ + libzmq3-dev \ + make \ + pkg-config + + build-sim: + needs: setup + runs-on: ubuntu-latest + steps: + - name: Build Simulith + run: | + make build-sim + + build-test: + needs: setup + runs-on: ubuntu-latest + steps: + - name: Build Test + run: | + make build-test diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d2e5d0..e9c62e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,11 @@ +# Simulith CMake configuration cmake_minimum_required(VERSION 3.25) -project(Simulith C) +project(Simulith VERSION 0.0 LANGUAGES C) +# Enable compile_commands.json for IDEs and static analysis +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Set C standard set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) @@ -8,27 +13,19 @@ set(CMAKE_C_STANDARD_REQUIRED ON) find_package(PkgConfig REQUIRED) pkg_check_modules(ZeroMQ REQUIRED libzmq) -# Compiler flags +# Global compiler flags (applied to all targets) if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") + add_compile_options(-Wall -Werror) endif() - # Create Unity library with specific compiler flags and always build with -fPIC add_library(unity STATIC unity/unity.c) set_target_properties(unity PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(unity PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/unity) if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") target_compile_options(unity PRIVATE -Wno-float-equal) endif() -include_directories( - include - unity - 42/Include - 42/Kit/Include - ${ZeroMQ_INCLUDE_DIRS} -) - # Simulith library sources set(SIMULITH_SOURCES src/simulith_common.c @@ -43,7 +40,19 @@ set(SIMULITH_SOURCES src/simulith_uart.c ) -# 42 Core library sources (excluding main, GUI, and app-specific files) +# Build Simulith static library with -fPIC, used by HWLIB +add_library(simulith STATIC ${SIMULITH_SOURCES}) +set_target_properties(simulith PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(simulith PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/unity + ${CMAKE_CURRENT_SOURCE_DIR}/42/Include + ${CMAKE_CURRENT_SOURCE_DIR}/42/Kit/Include + ${ZeroMQ_INCLUDE_DIRS} +) +target_link_libraries(simulith PUBLIC ${ZeroMQ_LIBRARIES}) + +# Build 42 as a library set(FORTYTWO_SOURCES 42/Source/42exec.c 42/Source/42init.c @@ -82,16 +91,13 @@ set(FORTYTWO_SOURCES # - gmseckit.c, glkit.c (optional dependencies) ) - -# Build Simulith static library with -fPIC -add_library(simulith STATIC ${SIMULITH_SOURCES}) -set_target_properties(simulith PROPERTIES POSITION_INDEPENDENT_CODE ON) -target_link_libraries(simulith ${ZeroMQ_LIBRARIES}) - - -# Build 42 static library with -fPIC +# Build 42 as a library add_library(fortytwo STATIC ${FORTYTWO_SOURCES}) set_target_properties(fortytwo PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(fortytwo PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/42/Include + ${CMAKE_CURRENT_SOURCE_DIR}/42/Kit/Include +) target_compile_definitions(fortytwo PRIVATE __linux__ # Set platform define _GNU_SOURCE # Enable GNU extensions @@ -116,9 +122,8 @@ if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") endif() # Build Simulith director (dynamically loads components) -add_executable(simulith_director_standalone - src/simulith_director.c) -target_link_libraries(simulith_director_standalone simulith fortytwo ${ZeroMQ_LIBRARIES} dl m) +add_executable(simulith_director_standalone src/simulith_director.c) +target_link_libraries(simulith_director_standalone PRIVATE simulith fortytwo ${ZeroMQ_LIBRARIES} dl m) if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") # Handle warnings for director due to 42 integration target_compile_options(simulith_director_standalone PRIVATE @@ -130,10 +135,11 @@ endif() # Build Simulith server standalone add_executable(simulith_server_standalone - src/simulith_common.c - src/simulith_server.c - src/simulith_server_standalone.c) -target_link_libraries(simulith_server_standalone ${ZeroMQ_LIBRARIES}) + src/simulith_common.c + src/simulith_server.c + src/simulith_server_standalone.c) +target_link_libraries(simulith_server_standalone PRIVATE simulith ${ZeroMQ_LIBRARIES}) + # Optionally add tests subdirectory option(BUILD_SIMULITH_TESTS "Build Simulith tests" OFF) diff --git a/Makefile b/Makefile index 36d49bc..187cbcf 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,27 @@ # Makefile for TrySpace Simulith development -.PHONY: all build clean debug director server start stop test +.PHONY: build clean debug director server stop test export BUILDDIR ?= $(CURDIR)/build export TOPDIR ?= $(CURDIR)/.. -export BUILD_IMAGE_NAME ?= tryspace-lab +export BUILD_IMAGE ?= tryspaceorg/tryspace-lab +export CONTAINER_NAME ?= tryspace-lab export RUNTIME_DIRECTOR_NAME ?= tryspace-director export RUNTIME_SERVER_NAME ?= tryspace-server # Commands -all: build - build: - docker run --rm -it -v $(TOPDIR):$(TOPDIR) --user $(shell id -u):$(shell id -g) --name $(RUNTIME_SERVER_NAME) -w $(CURDIR) $(BUILD_IMAGE_NAME) make -j build-sim + docker run --rm -v $(TOPDIR):$(TOPDIR) --user $(shell id -u):$(shell id -g) --name $(CONTAINER_NAME) -w $(CURDIR) $(BUILD_IMAGE) make -j build-sim -build-sim: +build-director: mkdir -p $(BUILDDIR) - cd $(BUILDDIR) && cmake -DBUILD_SIMULITH_TESTS=ON .. - $(MAKE) --no-print-directory -C $(BUILDDIR) + cd $(BUILDDIR) && cmake .. + $(MAKE) --no-print-directory -C $(BUILDDIR) simulith_director_standalone + +build-server: + mkdir -p $(BUILDDIR) + cd $(BUILDDIR) && cmake .. + $(MAKE) --no-print-directory -C $(BUILDDIR) simulith_server_standalone # Create components directory and copy shared libraries mkdir -p $(BUILDDIR)/components cp $(BUILDDIR)/*.so $(BUILDDIR)/components/ 2>/dev/null || true @@ -26,11 +30,21 @@ build-sim: cp -r 42/InOut $(BUILDDIR)/ 2>/dev/null || true cp -r 42/Model $(BUILDDIR)/ 2>/dev/null || true +build-sim: + $(MAKE) build-director + $(MAKE) build-server + +build-test: + mkdir -p $(BUILDDIR) + cd $(BUILDDIR) && cmake .. -DBUILD_SIMULITH_TESTS=ON + $(MAKE) --no-print-directory -C $(BUILDDIR) + cd $(BUILDDIR) && $(MAKE) test + clean: rm -rf $(BUILDDIR) debug: - docker run --rm -it -v $(TOPDIR):$(TOPDIR) --user $(shell id -u):$(shell id -g) --name $(RUNTIME_DIRECTOR_NAME) -w $(CURDIR) $(RUNTIME_DIRECTOR_NAME) /bin/bash + docker run --rm -it -v $(TOPDIR):$(TOPDIR) --user $(shell id -u):$(shell id -g) --name $(CONTAINER_NAME) -w $(CURDIR) $(BUILD_IMAGE) /bin/bash director: $(MAKE) clean build @@ -40,11 +54,8 @@ server: $(MAKE) clean build docker build -t $(RUNTIME_SERVER_NAME) -f test/Dockerfile.server . -start: - docker run --rm -it --name $(RUNTIME_SERVER_NAME) $(RUNTIME_SERVER_NAME) ./simulith_server_standalone - stop: docker ps --filter name=tryspace-* | xargs docker stop test: - docker run --rm -it -v $(CURDIR):$(CURDIR) --name $(RUNTIME_SERVER_NAME) --user $(shell id -u):$(shell id -g) -w $(BUILDDIR) $(BUILD_IMAGE_NAME) make test + docker run --rm -v $(TOPDIR):$(TOPDIR) --user $(shell id -u):$(shell id -g) --name $(CONTAINER_NAME) -w $(CURDIR) $(BUILD_IMAGE) make -j build-test diff --git a/test/Dockerfile.director b/test/Dockerfile.director index 1d80f03..0e2f8f0 100644 --- a/test/Dockerfile.director +++ b/test/Dockerfile.director @@ -1,4 +1,4 @@ -FROM tryspace-lab:latest +FROM tryspaceorg/tryspace-lab:latest # Copy built simulith director and components COPY ./build/simulith_director_standalone /app/simulith_director_standalone diff --git a/test/Dockerfile.server b/test/Dockerfile.server index 1e7a3f7..92b40fc 100644 --- a/test/Dockerfile.server +++ b/test/Dockerfile.server @@ -1,4 +1,4 @@ -FROM tryspace-lab:latest +FROM tryspaceorg/tryspace-lab:latest # Copy built FSW files into the image COPY build /app From 796e1a2c29cfd9dc1510cfe3c859e0063226573d Mon Sep 17 00:00:00 2001 From: "Lucas, John P." Date: Thu, 14 Aug 2025 11:25:17 -0400 Subject: [PATCH 2/2] [tryspaceorg/tryspace-lab#14] Updates in ci.yml to use public container; --- .github/workflows/ci.yml | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48cedc1..66763b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,34 +9,30 @@ env: CTEST_OUTPUT_ON_FAILURE: true jobs: - setup: + build-sim: runs-on: ubuntu-latest + container: + image: tryspaceorg/tryspace-lab steps: - name: Checkout repository uses: actions/checkout@v4 with: submodules: recursive - - - name: Install GNU Make - run: sudo apt-get update && sudo apt-get install -y \ - build-essential \ - cmake \ - libzmq3-dev \ - make \ - pkg-config - - build-sim: - needs: setup - runs-on: ubuntu-latest - steps: + fetch-depth: 1 - name: Build Simulith run: | make build-sim build-test: - needs: setup runs-on: ubuntu-latest + container: + image: tryspaceorg/tryspace-lab steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 1 - name: Build Test run: | make build-test