diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d921eadb83..115e9dbcdd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -418,7 +418,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: build flecs - run: ${{ matrix.compiler }} flecs.c --shared -fPIC -pedantic -Wall -Wextra -Wno-unused-parameter -Werror -Wshadow -Wconversion -Wno-missing-field-initializers + run: ${{ matrix.compiler }} distr/flecs.c --shared -fPIC -pedantic -Wall -Wextra -Wno-unused-parameter -Werror -Wshadow -Wconversion -Wno-missing-field-initializers test-amalgamated: needs: build-linux diff --git a/.gitignore b/.gitignore index 254e269dad..0d0a8bebd7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,13 +7,9 @@ gcov *.pdb deps cmake-build-debug -bazel-bin -bazel-flecs -bazel-bazel -bazel-genfiles -bazel-out -bazel-testlogs +bazel-* **/CMakeFiles/* .vs out docs/html +MODULE.bazel.lock \ No newline at end of file diff --git a/BUILD b/BUILD index 760c455591..8aca0feccc 100644 --- a/BUILD +++ b/BUILD @@ -1,7 +1,7 @@ - cc_library( name = "flecs", visibility = ["//visibility:public"], + defines = ["flecs_EXPORTS"], srcs = glob(["src/**/*.c", "src/**/*.h", "src/**/*.inl"]), hdrs = glob(["include/**/*.h", "include/**/*.hpp", "include/**/*.inl"]), diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000000..927a638b2d --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,53 @@ +"A fast entity component system (ECS) for C & C++" +module(name = "flecs", version = "4.0.1") + +git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "bake", + remote = "https://github.com/SanderMertens/bake.git", + commit = "10c02123d6e3e200578128d73c3fa3bb996dff4f", + build_file_content = """ +cc_library( + name = "driver-test", + visibility = ["//visibility:public"], + deps = [":util", ":bake"], + defines = ["__BAKE__", "bake_test_EXPORTS"], + + srcs = glob(["drivers/test/src/**/*.c", "drivers/test/src/**/*.h"]), + hdrs = glob(["drivers/test/include/**/*.h"]), + includes = ["drivers/test/include"], +) + +cc_library( + name = "bake", + visibility = ["//visibility:public"], + deps = [":util"], + + srcs = glob(["src/*.c", "src/*.h"]), + hdrs = glob(["include/*.h", "include/bake/*.h"]), + includes = ["include"], +) + +cc_library( + name = "util", + visibility = ["//visibility:public"], + defines = ["__BAKE__", "_XOPEN_SOURCE=600", "bake_util_EXPORTS", "UT_IMPL"], + + linkopts = select({ + "@bazel_tools//src/conditions:windows": ["Dbghelp.lib", "Shell32.lib", "Shlwapi.lib"], + "//conditions:default": ["-lrt -lpthread -ldl"], + }), + + srcs = glob(["util/src/*.c"]) + select({ + "@bazel_tools//src/conditions:windows": glob(["util/src/win/*.c"]), + "//conditions:default": glob(["util/src/posix/*.c"]), + }), + hdrs = glob(["util/include/*.h", "util/include/bake-util/*.h"]) + select({ + "@bazel_tools//src/conditions:windows": glob(["util/include/bake-util/win/*.h"]), + "//conditions:default": glob(["util/include/bake-util/posix/*.h"]), + }), + includes = ["util/include"], +) +""", +) diff --git a/WORKSPACE b/WORKSPACE index 34536ebfa8..3f82cc7b4c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -49,4 +49,3 @@ cc_library( ) """ ) - diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 0000000000..00614f5b05 --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1 @@ +# Overrides WORKSPACE when building with bzlmod \ No newline at end of file diff --git a/flecs.c b/distr/flecs.c similarity index 100% rename from flecs.c rename to distr/flecs.c diff --git a/flecs.h b/distr/flecs.h similarity index 100% rename from flecs.h rename to distr/flecs.h diff --git a/examples/build/bazel/BUILD b/examples/build/bazel/BUILD deleted file mode 100644 index 64a660687a..0000000000 --- a/examples/build/bazel/BUILD +++ /dev/null @@ -1,7 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -cc_binary( - name = "example", - srcs = ["main.cpp"], - deps = ["@flecs//:flecs"] -) diff --git a/examples/build/bazel/MODULE.bazel b/examples/build/bazel/MODULE.bazel new file mode 100644 index 0000000000..25c04daacf --- /dev/null +++ b/examples/build/bazel/MODULE.bazel @@ -0,0 +1,10 @@ +"Example for using the flecs as a dependency using bazel" +module(name = "flecs_bazel_example", version = "1.0.0") + +bazel_dep(name = "rules_cc", version = "0.0.9") +bazel_dep(name = "flecs") +git_override( + module_name = "flecs", + remote = "https://github.com/SanderMertens/flecs.git", + commit = "02c8c2666b22ccce5706c8f16efaf813704fe31e", +) \ No newline at end of file diff --git a/examples/build/bazel/README.md b/examples/build/bazel/README.md index 7530998b72..4a117275e3 100644 --- a/examples/build/bazel/README.md +++ b/examples/build/bazel/README.md @@ -1,22 +1,22 @@ -You can include the flecs repository in your `WORKSPACE` with: +You can include the flecs repository in your `MODULE.bazel` with: ```bazel -git_repository( - name = "flecs", - remote = "https://github.com/SanderMertens/flecs", - commit = "f150d96ba9ea8be2b24dbf2217368c231cb17720", # v2.3.2+merge329 - shallow_since = "1615075784 -0800", +bazel_dep(name = "flecs") +git_override( + module_name = "flecs", + remote = "https://github.com/SanderMertens/flecs.git", + commit = "02c8c2666b22ccce5706c8f16efaf813704fe31e", ) ``` And then add it to your `BUILD` with: ```bazel - deps = ["@flecs//:flecs"] + deps = ["@flecs"] ``` This directory contains a complete example of this usage. To try it you can run the following from your terminal: ``` -bazel run example +bazel run //example ``` diff --git a/examples/build/bazel/WORKSPACE b/examples/build/bazel/WORKSPACE deleted file mode 100644 index 3d7dc46079..0000000000 --- a/examples/build/bazel/WORKSPACE +++ /dev/null @@ -1,8 +0,0 @@ -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") - -git_repository( - name = "flecs", - remote = "https://github.com/SanderMertens/flecs", - commit = "f150d96ba9ea8be2b24dbf2217368c231cb17720", # v2.3.2+merge329 - shallow_since = "1615075784 -0800", -) diff --git a/examples/build/bazel/example/BUILD b/examples/build/bazel/example/BUILD new file mode 100644 index 0000000000..cccd628b16 --- /dev/null +++ b/examples/build/bazel/example/BUILD @@ -0,0 +1,5 @@ +cc_binary( + name = "example", + srcs = ["main.cpp"], + deps = ["@flecs"] +) diff --git a/examples/build/bazel/main.cpp b/examples/build/bazel/example/main.cpp similarity index 100% rename from examples/build/bazel/main.cpp rename to examples/build/bazel/example/main.cpp diff --git a/project.json b/project.json index 752738c571..badfe5196b 100644 --- a/project.json +++ b/project.json @@ -4,7 +4,8 @@ "value": { "author": "Sander Mertens", "description": "Entity Component System written in C99/C++11", - "amalgamate": true + "amalgamate": true, + "amalgamate-path": "distr" }, "dependee": { "lang.c": { diff --git a/test/BUILD.bazel b/test/BUILD similarity index 100% rename from test/BUILD.bazel rename to test/BUILD