Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate bazel build to bzlmod #1301

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -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"]),
Expand Down
53 changes: 53 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
""",
)
1 change: 0 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ cc_library(
)
"""
)

1 change: 1 addition & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Overrides WORKSPACE when building with bzlmod
File renamed without changes.
File renamed without changes.
7 changes: 0 additions & 7 deletions examples/build/bazel/BUILD

This file was deleted.

10 changes: 10 additions & 0 deletions examples/build/bazel/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
16 changes: 8 additions & 8 deletions examples/build/bazel/README.md
Original file line number Diff line number Diff line change
@@ -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
```
8 changes: 0 additions & 8 deletions examples/build/bazel/WORKSPACE

This file was deleted.

5 changes: 5 additions & 0 deletions examples/build/bazel/example/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cc_binary(
name = "example",
srcs = ["main.cpp"],
deps = ["@flecs"]
)
File renamed without changes.
3 changes: 2 additions & 1 deletion project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
File renamed without changes.