Skip to content
Merged
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
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on:
pull_request:
branches:
- '**'

env:
CTEST_OUTPUT_ON_FAILURE: true

jobs:
build-sim:
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 Simulith
run: |
make build-sim

build-test:
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
62 changes: 34 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
# 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)

# Find ZeroMQ via pkg-config
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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
37 changes: 24 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion test/Dockerfile.director
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/Dockerfile.server
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM tryspace-lab:latest
FROM tryspaceorg/tryspace-lab:latest

# Copy built FSW files into the image
COPY build /app
Expand Down