From 762f5937848ad1610cbbb54ba8e21e1e106eec05 Mon Sep 17 00:00:00 2001 From: Bellier Sacha <69162022+0-Sacha@users.noreply.github.com> Date: Sat, 1 Jun 2024 23:25:59 +0200 Subject: [PATCH] Feature/bazel modules update (#3) - copts now handled by select to enable C++20 - Cleaner CI --- .bazelrc | 8 -------- .buildkite/linux_amd64.yml | 8 ++++---- .buildkite/windows_amd64.yml | 4 ++-- .github/workflows/LittleECS.yml | 12 ++++++------ .gitignore | 10 +++++----- BUILD | 16 ++++++++++++++-- Docs/Workflow.md | 7 +------ Examples/.bazelrc | 7 ------- Examples/README.md | 22 ++++++---------------- Examples/Workflow/BUILD | 4 ++++ Examples/Workflow/main.cpp | 5 +++-- MODULE.bazel | 3 ++- README.md | 2 -- WORKSPACE | 12 ++++++------ 14 files changed, 53 insertions(+), 67 deletions(-) diff --git a/.bazelrc b/.bazelrc index 9feacb2..4d9baff 100644 --- a/.bazelrc +++ b/.bazelrc @@ -6,13 +6,6 @@ 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 @@ -23,7 +16,6 @@ common:buildbuddy --bes_backend=grpcs://sacha.buildbuddy.io common:buildbuddy --remote_cache=grpcs://sacha.buildbuddy.io common:buildbuddy --remote_executor=grpcs://sacha.buildbuddy.io common:buildbuddy --experimental_remote_cache_compression -common:buildbuddy --jobs=50 common:buildbuddy --nolegacy_important_outputs common:buildbuddy --platforms=@buildbuddy_test//:buildbuddy_linux_x86_64 common:buildbuddy --extra_execution_platforms=@buildbuddy_test//:buildbuddy_linux_x86_64 diff --git a/.buildkite/linux_amd64.yml b/.buildkite/linux_amd64.yml index 6fec44b..decbd69 100644 --- a/.buildkite/linux_amd64.yml +++ b/.buildkite/linux_amd64.yml @@ -4,10 +4,10 @@ agents: 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 + - CC=gcc bazelisk build //:LittleECSTests + - CC=gcc bazelisk test //: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 \ No newline at end of file + - CC=clang bazelisk build //:LittleECSTests + - CC=clang bazelisk test //:LittleECSTests \ No newline at end of file diff --git a/.buildkite/windows_amd64.yml b/.buildkite/windows_amd64.yml index 75354c1..105f89d 100644 --- a/.buildkite/windows_amd64.yml +++ b/.buildkite/windows_amd64.yml @@ -4,5 +4,5 @@ agents: steps: - label: ":bazel: Build" commands: - - bazelisk build --config=microsoft_compiler_opts //:LittleECSTests - - bazelisk test --config=microsoft_compiler_opts //:LittleECSTests + - bazelisk build //:LittleECSTests + - bazelisk test //:LittleECSTests diff --git a/.github/workflows/LittleECS.yml b/.github/workflows/LittleECS.yml index 7bb512b..f95598f 100644 --- a/.github/workflows/LittleECS.yml +++ b/.github/workflows/LittleECS.yml @@ -20,9 +20,9 @@ jobs: path: "~/.cache/bazel" key: bazel - name: Building... - run: bazelisk build --config=microsoft_compiler_opts //:LittleECSTests + run: bazelisk build //:LittleECSTests - name: Testing... - run: bazelisk test --config=microsoft_compiler_opts //:LittleECSTests + run: bazelisk test //:LittleECSTests ubuntu-latest-gcc: runs-on: ubuntu-latest @@ -37,9 +37,9 @@ jobs: - name: Version run: gcc --version - name: Building... - run: CC=gcc bazelisk build --config=default_compiler_opts //:LittleECSTests + run: CC=gcc bazelisk build //:LittleECSTests - name: Testing... - run: CC=gcc bazelisk test --config=default_compiler_opts //:LittleECSTests + run: CC=gcc bazelisk test //:LittleECSTests ubuntu-latest-clang: runs-on: ubuntu-latest @@ -59,6 +59,6 @@ jobs: - name: Version run: clang --version - name: Building... - run: CC=clang++-17 bazelisk build --config=default_compiler_opts //:LittleECSTests + run: CC=clang++-17 bazelisk build //:LittleECSTests - name: Testing... - run: CC=clang++-17 bazelisk test --config=default_compiler_opts //:LittleECSTests + run: CC=clang++-17 bazelisk test //:LittleECSTests diff --git a/.gitignore b/.gitignore index df84819..0181326 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ - -# bazel +# Bazel MODULE.bazel.lock bazel-bin bazel-out @@ -16,11 +15,12 @@ bazel-testlogs *.vcxproj.filters *.vcxproj.user -# Make +# VSCode +.vscode + +# Premake Makefile *.make - -# bin bin bin-int diff --git a/BUILD b/BUILD index f1fe707..a85a38e 100644 --- a/BUILD +++ b/BUILD @@ -7,6 +7,10 @@ cc_library( srcs = glob([ "src/**/*.h" ]), hdrs = glob([ "src/**/*.h" ]), includes = [ "src/" ], + copts = select({ + "@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"], + "//conditions:default": ["-std=c++20"], + }), strip_include_prefix = "src", include_prefix = "LittleECS", linkstatic = True, @@ -15,18 +19,26 @@ cc_library( cc_test( name = "LittleECSTests", - includes = [ "src/" ], srcs = glob([ "Tests/**/*.h", "Tests/**/*.cpp" ], exclude=["Tests/Perf/**"]), + includes = [ "src/" ], defines = [ "LECS_USE_PROJECTCORE" ], + copts = select({ + "@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"], + "//conditions:default": ["-std=c++20"], + }), deps = [ "@ProjectCore//:ProjectCore", ":LittleECS" ], visibility = ["//visibility:public"], ) cc_test( name = "LittleECSTestsPerf", - includes = [ "src/" ], srcs = glob([ "Tests/**/*.h", "Tests/**/*.cpp" ]), + includes = [ "src/" ], defines = [ "LECS_USE_PROJECTCORE" ], + copts = select({ + "@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"], + "//conditions:default": ["-std=c++20"], + }), deps = [ "@ProjectCore//:ProjectCore", ":LittleECS" ], visibility = ["//visibility:public"], ) diff --git a/Docs/Workflow.md b/Docs/Workflow.md index 2e652cf..d0fc369 100644 --- a/Docs/Workflow.md +++ b/Docs/Workflow.md @@ -3,12 +3,7 @@ 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 + bazelisk run //Workflow:Workflow ``` diff --git a/Examples/.bazelrc b/Examples/.bazelrc index 4340403..39ef8d3 100644 --- a/Examples/.bazelrc +++ b/Examples/.bazelrc @@ -4,10 +4,3 @@ 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 diff --git a/Examples/README.md b/Examples/README.md index 3d3d4c4..0e97e3b 100644 --- a/Examples/README.md +++ b/Examples/README.md @@ -4,25 +4,15 @@ ##### Build and Run examples one by one (Recommended) Example with `//Workflow:Workflow` (see below for the list of example) -- On Windows, using msvc: - ``` - bazelisk run --config=msvc //Workflow:Workflow - ``` -- On Linux: (This `--config=linux` is not mandatory) - ``` - bazelisk run --config=linux //Workflow:Workflow - ``` +``` +bazelisk run //Workflow:Workflow +``` ##### Compile all examples, then run binaries To compile every example: -- On Windows, using msvc: - ``` - bazelisk build --config=msvc //... - ``` -- On Linux: (This `--config=linux` is not mandatory) - ``` - bazelisk build --config=linux //... - ``` +``` +bazelisk build //... +``` Then you can run a program with (example with `//Workflow:Workflow`, see below for the list of example) ``` diff --git a/Examples/Workflow/BUILD b/Examples/Workflow/BUILD index 4eef309..072516d 100644 --- a/Examples/Workflow/BUILD +++ b/Examples/Workflow/BUILD @@ -6,6 +6,10 @@ cc_binary( name = "Workflow", srcs = glob([ "*.h", "*.cpp" ]), defines = [ "LECS_USE_PROJECTCORE" ], + copts = select({ + "@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"], + "//conditions:default": ["-std=c++20"], + }), deps = [ "@ProjectCore//:ProjectCore", "@littleecs//:LittleECS" ], visibility = ["//visibility:public"], ) diff --git a/Examples/Workflow/main.cpp b/Examples/Workflow/main.cpp index 92a259d..39174b3 100644 --- a/Examples/Workflow/main.cpp +++ b/Examples/Workflow/main.cpp @@ -43,6 +43,7 @@ int main() registry.Add(alice, "Alice"); registry.Add(bob, "Bob"); + /****** Get Components ******/ std::cout << std::endl; Logger.Info("Alice's int: {}", registry.Get(alice)); @@ -53,8 +54,8 @@ int main() std::cout << std::endl; /** * To ForEach on a specific Component, use ForEachUniqueComponent. - * It takes an lambda which can contains optionally an `LECS::EntityId` as first parameter, in that case the entityId will be send to the lambda - * The component you want to loop over is take as an template argument, and the lambda can take the component as: + * It takes an lambda which can contains optionally an `LECS::EntityId` as first parameter, in that case the entityId will be sent to the lambda + * The component you want to loop over is took as an template argument, and the lambda can take the component as: * - value * - const value * - const reference diff --git a/MODULE.bazel b/MODULE.bazel index bc938cc..db2bba9 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -13,5 +13,6 @@ http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "ht http_archive( name = "ProjectCore", urls = [ "https://github.com/0-Sacha/ProjectCore/archive/refs/heads/dev.zip" ], - strip_prefix = "ProjectCore-dev" + strip_prefix = "ProjectCore-dev", + integrity = "sha256-28v/wuBCDSekQV03i9/2Tn+AR9hllqPdCOMYOvHBwmI=", ) diff --git a/README.md b/README.md index 63d038b..d7126bd 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,4 @@ It can be used using [Bazel](https://bazel.build/). A `cc_library` rule has been created: `@LittleECS//:LittleECS`. You need to add the module `littleecs` to your dependencies. -You will need at least to give an c++ standard to use (at least c++20) since no one have been forced. You can check the [bazelrc](.bazelrc) to see how you can add one. - Not Recommended: There is also a [Premake](https://premake.github.io/docs/using-premake) configuration, thought it is deprecated (and run on a wrapper of mine: [PremakeUtilities](https://github.com/0-Sacha/PremakeUtilities)). I keep it for my Game Engine [Blackbird](https://github.com/0-Sacha/Blackbird) which is using `Premake` as Build system. diff --git a/WORKSPACE b/WORKSPACE index 360da17..8da11b2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,16 +4,16 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "bazel_utilities", - strip_prefix = "bazel_utilities-d748d078d0bdd4e5fe9020e8011a46edb484525e", - urls = [ "https://github.com/0-Sacha/bazel_utilities/archive/d748d078d0bdd4e5fe9020e8011a46edb484525e.zip" ], - integrity = "sha256-qakyhHoLPrGK/3zD+dWIL7wGSjLwMX69TiSGA05Wu2c=", + strip_prefix = "bazel_utilities-efe15a48c3b063436d6deecaa14b811083035993", + urls = [ "https://github.com/0-Sacha/bazel_utilities/archive/efe15a48c3b063436d6deecaa14b811083035993.zip" ], + integrity = "sha256-g1BUGaQFSLywkzTqixQdQTdrJ25TlcqG6PZXoCK7Jrw=", ) http_archive( name = "bazel_buildbuddy", - strip_prefix = "bazel_buildbuddy-89937f1942a9271348c0963ef89fb67c240c3afd", - urls = [ "https://github.com/0-Sacha/bazel_buildbuddy/archive/89937f1942a9271348c0963ef89fb67c240c3afd.zip" ], - integrity = "sha256-M8sEkfNBjSivQhIRYRzCXIq7ix3w23UckP0z9T/L3II=", + strip_prefix = "bazel_buildbuddy-b0840cf378c4aef5750b5e8bc87aa2ad1aeb874f", + urls = [ "https://github.com/0-Sacha/bazel_buildbuddy/archive/b0840cf378c4aef5750b5e8bc87aa2ad1aeb874f.zip" ], + integrity = "sha256-Wvbu4LB7F3d42Xj/dQyaGjVEntf4U3DO+aku3zEZD4I=", ) load("@bazel_buildbuddy//:rules.bzl", "buildbuddy_toolchain")