Skip to content

Commit

Permalink
feat: CI; Better project structure (#1)
Browse files Browse the repository at this point in the history
Add CI
Add Examples/ folder
Add a README
Cleaner project structure:
- Try to improve compile time with better inl/impl file management
  • Loading branch information
0-Sacha authored May 1, 2024
1 parent 0403a9a commit 026fe05
Show file tree
Hide file tree
Showing 70 changed files with 2,047 additions and 1,272 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Examples/
18 changes: 18 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Common
common --enable_platform_specific_config
common --incompatible_strict_action_env
common --toolchain_resolution_debug=all
common --show_timestamps
common --verbose_failures
test --test_output=errors

# Opts
common:linux --config=default_compiler_opts
common:msvc --config=microsoft_compiler_opts

common:default_compiler_opts --copt -std=c++20
common:microsoft_compiler_opts --copt /std:c++20

# BuildBuddy
common:linux --workspace_status_command=$(pwd)/.buildbuddy/workspace_status.sh
common:windows --workspace_status_command=.buildbuddy/workspace_status.bat
Empty file added .bazelversion
Empty file.
2 changes: 2 additions & 0 deletions .buildbuddy/workspace_status.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
call PowerShell -NoProfile -ExecutionPolicy Bypass -Command "%CD%\.buildbuddy\workspace_status.ps1"
33 changes: 33 additions & 0 deletions .buildbuddy/workspace_status.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This script will be run by Bazel when the building process starts to
# generate key-value information that represents the status of the
# workspace. The output should be like
#
# KEY1 VALUE1
# KEY2 VALUE2
#
# If the script exits with a non-zero code, it's considered as a failure
# and the output will be discarded.

$ErrorActionPreference = "Stop"

# Get the repository URL without credentials
$repo_url = (git config --get remote.origin.url) -replace '//.*?:.*?@', '//'
$repo_url = $repo_url -replace '^[email protected]:', 'https://github.com/'
$urrepo_urll = $repo_url -replace '\.git$'
Write-Output "REPO_URL $repo_url"

# Get the commit SHA
$commit_sha = git rev-parse HEAD
Write-Output "COMMIT_SHA $commit_sha"

# Get the current Git branch
$git_branch = git rev-parse --abbrev-ref HEAD
Write-Output "GIT_BRANCH $git_branch"

# Check if there are any modified files in the working directory
if (git diff-index --quiet HEAD) {
$git_tree_status = 'Clean'
} else {
$git_tree_status = 'Modified'
}
Write-Output "GIT_TREE_STATUS $git_tree_status"
31 changes: 31 additions & 0 deletions .buildbuddy/workspace_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# This script will be run bazel when building process starts to
# generate key-value information that represents the status of the
# workspace. The output should be like
#
# KEY1 VALUE1
# KEY2 VALUE2
#
# If the script exits with non-zero code, it's considered as a failure
# and the output will be discarded.

set -eo pipefail # exit immediately if any command fails.

function remove_url_credentials() {
which perl >/dev/null && perl -pe 's#//.*?:.*?@#//#' || cat
}

repo_url=$(git config --get remote.origin.url | remove_url_credentials)
repo_url=${repo_url/git@github.com:/https://github.com/}
repo_url=${repo_url%.git}
echo "REPO_URL $repo_url"

commit_sha=$(git rev-parse HEAD)
echo "COMMIT_SHA $commit_sha"

git_branch=$(git rev-parse --abbrev-ref HEAD)
echo "GIT_BRANCH $git_branch"

git_tree_status=$(git diff-index --quiet HEAD -- && echo 'Clean' || echo 'Modified')
echo "GIT_TREE_STATUS $git_tree_status"
13 changes: 13 additions & 0 deletions .buildkite/linux_amd64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
agents:
queue: "agent-runners-linux-amd64"

steps:
- label: ":bazel: Build and Test on gcc"
commands:
- CC=gcc bazelisk build --config=default_compiler_opts //:LittleECSTests
- CC=gcc bazelisk test --config=default_compiler_opts //:LittleECSTests

- label: ":bazel: Build and Test on Clang"
commands:
- CC=clang bazelisk build --config=default_compiler_opts //:LittleECSTests
- CC=clang bazelisk test --config=default_compiler_opts //:LittleECSTests
5 changes: 5 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
steps:
- label: ":pipeline: Launch Windows Pipeline"
command: "buildkite-agent pipeline upload .buildkite/windows_amd64.yml"
- label: ":pipeline: Launch Linux Pipeline"
command: "buildkite-agent pipeline upload .buildkite/linux_amd64.yml"
4 changes: 4 additions & 0 deletions .buildkite/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "LittleECS"
steps:
- label: ":pipeline: Launch Embbeded Pipeline"
command: "buildkite-agent pipeline upload .builkite/pipeline.yml"
8 changes: 8 additions & 0 deletions .buildkite/windows_amd64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
agents:
queue: "agent-runners-windows-amd64"

steps:
- label: ":bazel: Build"
commands:
- bazelisk build --config=microsoft_compiler_opts //:LittleECSTests
- bazelisk test --config=microsoft_compiler_opts //:LittleECSTests
64 changes: 64 additions & 0 deletions .github/workflows/LittleECS.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: LittleECS

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

jobs:
windows-latest-msvc:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: bazelbuild/setup-bazelisk@v3
- name: Mount bazel cache
uses: actions/cache@v4
with:
path: "~/.cache/bazel"
key: bazel
- name: Building...
run: bazelisk build --config=microsoft_compiler_opts //:LittleECSTests
- name: Testing...
run: bazelisk test --config=microsoft_compiler_opts //:LittleECSTests

ubuntu-latest-gcc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bazelbuild/setup-bazelisk@v3
- name: Mount bazel cache
uses: actions/cache@v4
with:
path: "~/.cache/bazel"
key: bazel
- name: Version
run: gcc --version
- name: Building...
run: CC=gcc bazelisk build --config=default_compiler_opts //:LittleECSTests
- name: Testing...
run: CC=gcc bazelisk test --config=default_compiler_opts //:LittleECSTests

ubuntu-latest-clang:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bazelbuild/setup-bazelisk@v3
- name: Mount bazel cache
uses: actions/cache@v4
with:
path: "~/.cache/bazel"
key: bazel
- name: Install clang
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 17
- name: Version
run: clang --version
- name: Building...
run: CC=clang++-17 bazelisk build --config=default_compiler_opts //:LittleECSTests
- name: Testing...
run: CC=clang++-17 bazelisk test --config=default_compiler_opts //:LittleECSTests
16 changes: 12 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@

# bazel
MODULE.bazel.lock
bazel-bin
bazel-out
bazel-littleecs
bazel-LittleECS
bazel-examples
bazel-Examples
bazel-testlogs

# VS
.vs
*.sln
*.vcxproj
*.vcxproj.filters
*.vcxproj.user

# Make
Makefile
*.make

# VSCode
.vscode

# VSCode
# bin
bin
bin-int

Expand Down
16 changes: 16 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"configurations": [
{
"name": "Default Windows",
"includePath": [
"src/",
"bazel-littleecs/external/_main~_repo_rules~ProjectCore/src/"
],
"cStandard": "c17",
"cppStandard": "c++20",
"compilerPath": "cl.exe",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
89 changes: 89 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"files.associations": {
"*.tpl": "starlark",
".bazelrc": "bat",
"algorithm": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"compare": "cpp",
"concepts": "cpp",
"exception": "cpp",
"filesystem": "cpp",
"format": "cpp",
"iomanip": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"memory": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"vector": "cpp",
"xhash": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp",
"future": "cpp",
"xlocale": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"deque": "cpp",
"coroutine": "cpp",
"resumable": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"locale": "cpp",
"map": "cpp",
"mutex": "cpp",
"queue": "cpp",
"ranges": "cpp",
"ratio": "cpp",
"set": "cpp",
"span": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"string": "cpp",
"thread": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xloctime": "cpp",
"xtree": "cpp"
}
}
32 changes: 32 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
""

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")

cc_library(
name = "LittleECS",
srcs = glob([ "src/**/*.h" ]),
hdrs = glob([ "src/**/*.h" ]),
includes = [ "src/" ],
strip_include_prefix = "src",
include_prefix = "LittleECS",
linkstatic = True,
visibility = ["//visibility:public"],
)

cc_test(
name = "LittleECSTests",
includes = [ "src/" ],
srcs = glob([ "Tests/**/*.h", "Tests/**/*.cpp" ], exclude=["Tests/Perf/**"]),
defines = [ "LECS_USE_PROJECTCORE" ],
deps = [ "@ProjectCore//:ProjectCore", ":LittleECS" ],
visibility = ["//visibility:public"],
)

cc_test(
name = "LittleECSTestsPerf",
includes = [ "src/" ],
srcs = glob([ "Tests/**/*.h", "Tests/**/*.cpp" ]),
defines = [ "LECS_USE_PROJECTCORE" ],
deps = [ "@ProjectCore//:ProjectCore", ":LittleECS" ],
visibility = ["//visibility:public"],
)
14 changes: 14 additions & 0 deletions Docs/Workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# LittleECS Workflow

This doc is tigtelly related to the [Workflow example](../Examples/Workflow/main.cpp)

To launch it, you can set your working directory to Examples/ and run:
- On Windows, using msvc:
```
bazelisk run --config=msvc //Workflow:Workflow
```
- On Linux: (This `--config=linux` is not mandatory)
```
bazelisk run --config=linux //Workflow:Workflow
```

13 changes: 13 additions & 0 deletions Examples/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Common
common --enable_platform_specific_config
common --incompatible_strict_action_env
common --show_timestamps
common --verbose_failures
test --test_output=errors

# Opts
common:linux --config=default_compiler_opts
common:msvc --config=microsoft_compiler_opts

common:default_compiler_opts --copt -std=c++20
common:microsoft_compiler_opts --copt /std:c++20
Loading

0 comments on commit 026fe05

Please sign in to comment.