Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesaorson committed Dec 31, 2024
0 parents commit 3b89802
Show file tree
Hide file tree
Showing 26 changed files with 609 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI build

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
build_type:
- Release
compiler:
- gcc
- clang
include:
- os: macos-latest
compiler: clang
cpp_compiler: clang++
- os: ubuntu-latest
compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
compiler: clang
cpp_compiler: clang++

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: true

- name: Setup
run: |
echo ${HOME}/.local/bin >> ${GITHUB_PATH}
make setup
- name: Configure
run: make configure

- name: Build
run: make build

- name: Test
run: make test

- name: Run
run: make run
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint
on:
pull_request:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup
run: |
echo ${HOME}/.local/bin >> ${GITHUB_PATH}
make setup
- name: Build
run: |
make configure
- name: Lint
run: |
make lint
15 changes: 15 additions & 0 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Mirror
on:
push:
branches: main
workflow_dispatch:

jobs:
mirror:
runs-on: ubuntu-latest

steps:
- uses: jamesaorson/composite-git-mirror@main
with:
target-git-url: git@git.sr.ht:~exokomodo/${{ github.event.repository.name }}
ssh-private-key: ${{ secrets.SRHT_SSH_PRIVATE_KEY }}
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Compiled Object files
**/.DS_Store
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# Editors
.idea/*.xml

# Build output
build/*
!**/.gitkeep
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "test/lib/catch2"]
path = test/lib/catch2
url = https://github.com/catchorg/Catch2.git
branch = devel
21 changes: 21 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configurations": [
{
"name": "default",
"includePath": [
"${workspaceFolder}/include",
"${workspaceFolder}/test/lib/catch2/src",
"${workspaceFolder}/build/test/lib/catch2/generated-includes"
],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"intelliSenseMode": "macos-clang-x64",
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17"
}
],
"version": 4
}
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cmake-tools",
"twxs.cmake",
"ms-vscode.makefile-tools"
]
}
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.31)

project(exosourcing
LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})

set(INCLUDE_DIR_exo ${PROJECT_SOURCE_DIR}/include)

add_subdirectory(src)

# Don't even look at tests if we're not top level
if(NOT PROJECT_IS_TOP_LEVEL)
return()
endif()
include(CTest)
add_subdirectory(test)
106 changes: 106 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
SHELL := /bin/bash
.SHELLFLAGS = -e -c
.DEFAULT_GOAL := help
.ONESHELL:

UNAME_S := $(shell uname -s)

NO_GENERATE_TEMPLATES ?= 0
RELEASE_KIND ?= debug

ifeq ($(UNAME_S),Linux)
CC := gcc
endif
ifeq ($(UNAME_S),Darwin)
CC := clang
endif

export PATH := "$(shell pwd)/bin:$(PATH)"

BUILD_DIR := ./build
BINARY := $(shell pwd)/build/src/demo
TEST_BINARY := $(shell pwd)/build/test/tests

.PHONY: configure
configure: ## Configure default candidate
cmake -B$(BUILD_DIR) -S.

.PHONY: configure/debug
configure/debug: ## Configure debug candidate
$(MAKE) configure RELEASE_KIND=debug

.PHONY: configure/release
configure/release: ## Configure release candidate
$(MAKE) configure RELEASE_KIND=release

.PHONY: build
build: configure ## Build default candidate
cmake --build $(BUILD_DIR)

.PHONY: build/debug
build/debug: ## Build debug candidate
$(MAKE) build RELEASE_KIND=debug

.PHONY: build/release
build/release: ## Build release candidate
$(MAKE) build RELEASE_KIND=release

.PHONY: test
test: $(TEST_BINARY) ## Run test binary
$<

.PHONY: run
run: $(BINARY) ## Run binary
$<

.PHONY: run/debug
run/debug: ## Run debug candidate
$(MAKE) build RELEASE_KIND=debug

.PHONY: run/release
run/release: ## Run release candidate
$(MAKE) build RELEASE_KIND=release

.PHONY: setup
setup: ./scripts/setup ## Setup dependencies for system
@$<

SOURCE_FILES := $(shell find ./src -type f -name '*.cpp')
HEADER_FILES := $(shell find ./src -type f -name '*.h')

.PHONY: format
format: ## Format the C/C++ code
@echo $(SOURCE_FILES) $(HEADER_FILES) | xargs clang-format -i

.PHONY: lint
lint: ## Lint the C/C++ code
@BAD_FILES=$(shell mktemp)
echo "[clang-format] BEGIN"
echo $(SOURCE_FILES) $(HEADER_FILES) | xargs -I {} $(SHELL) -c 'clang-format --dry-run --Werror {} || echo {}' >> $${BAD_FILES}
if [[ -s $${BAD_FILES} ]]; then
echo "[clang-format] Found formatting errors"
cat $${BAD_FILES}
else
echo "[clang-format] No formatting errors"
fi
echo "[clang-format] END"
echo "[clang-tidy] BEGIN"
$(MAKE) tidy
echo "[clang-tidy] END"
if [[ -s $${BAD_FILES} ]]; then
exit 1
fi

.PHONY: tidy
tidy: ## Tidy the C/C++ code
@clang-tidy $(SOURCE_FILES) $(HEADER_FILES)

.PHONY: version
version: ## Version info
$(MAKE) --version
$(CC) --version
$(MAKE) run/version

.PHONY: help
help: ## Displays help info
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Exosourcing
1 change: 1 addition & 0 deletions compile_commands.json
Empty file added docs/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions include/exo/event.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <chrono>

namespace exo {
template<typename T>
struct Event {
T data;

bool operator==(const Event<T>& other) const {
return this->data == other.data;
}
};

template<typename T>
Event<T> make_event(T data) {
return {
.data = data,
};
}
}
40 changes: 40 additions & 0 deletions include/exo/store.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <vector>

#include <exo/event.hpp>

namespace exo {
// NOTE: Forward declare all friend types
template<typename T>
struct MemoryStoreInspector;

template<typename T>
struct Store {
bool emplace_back(const exo::Event<T> event);
};

template<typename T>
struct MemoryStore : exo::Store<T> {
friend struct exo::MemoryStoreInspector<T>;

bool emplace_back(const exo::Event<T> event) {
try {
this->events.emplace_back(event);
} catch (const std::exception& e) {
return false;
}
return true;
}

protected:
// NOTE: Using a std::vector, since we always `emplace_back`,
// allowing for guaranteed O(1) insertion
std::vector<Event<T>> events;
};

template<typename T>
exo::MemoryStore<T> make_memory_store() {
return {};
}
}
Loading

0 comments on commit 3b89802

Please sign in to comment.