Skip to content

Commit

Permalink
feat: Add Bazel and first ci
Browse files Browse the repository at this point in the history
  • Loading branch information
0-Sacha committed Apr 30, 2024
1 parent 0403a9a commit aa5b279
Show file tree
Hide file tree
Showing 50 changed files with 1,370 additions and 1,054 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: "ProjectCore"
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: ProjectCore

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
13 changes: 9 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@

# bazel
MODULE.bazel.lock
bazel-bin
bazel-out
bazel-littleecs
bazel-testlogs

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

# Make
Makefile
*.make

# VSCode
.vscode

# VSCode
# bin
bin
bin-int

Expand Down
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": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22000.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
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"],
)
17 changes: 17 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
""

# buildifier: disable=module-docstring
module(
name = "littleecs",
version = "0.1",
repo_name = "com_sacha_littleecs",
)

bazel_dep(name = "rules_cc", version = "0.0.9")

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "ProjectCore",
urls = [ "https://github.com/0-Sacha/ProjectCore/archive/refs/heads/dev.zip" ],
strip_prefix = "ProjectCore-dev"
)
18 changes: 18 additions & 0 deletions buildbuddy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins:
- repo: buildbuddy-io/plugins
path: open-invocation
- repo: siggisim/theme-modern
- repo: buildbuddy-io/plugins
path: notify

actions:
- name: "BuildBuddy Workflows"
triggers:
push:
branches:
- "*"
pull_request:
branches:
- "*"
bazel_commands:
- "test --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_RBEKEY_WINDOWS_WSL //..."
23 changes: 23 additions & 0 deletions src/LittleECS/Core/CompilerInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#ifndef LECS_DO_NOT_USE_DEFAULT_MACRO
#if defined(__clang__)
#define LECS_COMPILER_CLANG
#elif defined(__GNUC__) || defined(__GNUG__)
#define LECS_COMPILER_GCC
#elif defined(_MSC_VER)
#define LECS_COMPILER_MSVC
#endif

#ifdef LECS_COMPILER_MSVC
#ifdef _DEBUG
#define LECS_DEBUG
#endif
#endif

#if defined(LECS_COMPILER_CLANG) || defined(LECS_COMPILER_GCC)
#if !defined(NDEBUG)
#define LECS_DEBUG
#endif
#endif
#endif
43 changes: 43 additions & 0 deletions src/LittleECS/Core/Core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include "CompilerInfo.h"

#include <utility>

#ifdef LECS_DEBUG
#define LECS_LOGGER_ENABLE
#define LECS_ASSERT_ENABLE
#endif

#ifdef LECS_ASSERT_ENABLE
#define LECS_LOGGER_ENABLE
#endif

#ifdef LECS_LOGGER_ENABLE
#ifdef LECS_USE_PROJECTCORE
#include "UseProjectCore.h"
#endif

#define LECS_TRACE(...) // TODO: ?
#define LECS_INFO(...) // TODO: ?
#define LECS_WARN(...) // TODO: ?
#define LECS_ERROR(...) // TODO: ?
#define LECS_FATAL(...) // TODO: ?
#else
#define LECS_TRACE(...)
#define LECS_INFO(...)
#define LECS_WARN(...)
#define LECS_ERROR(...)
#define LECS_FATAL(...)
#endif

#ifdef LECS_ASSERT_ENABLE
#ifdef LECS_COMPILER_MSVC
#define LECS_ASSERT(x, ...) if(!(x)) { LECS_FATAL("ASSERT FAILED! : " #x __VA_ARGS__); __debugbreak(); }
#else
#include <csignal>
#define LECS_ASSERT(x, ...) if(!(x)) { LECS_FATAL("ASSERT FAILED! : " #x __VA_ARGS__); std::raise(SIGINT); }
#endif
#else
#define LECS_ASSERT(...)
#endif
Loading

0 comments on commit aa5b279

Please sign in to comment.