Skip to content

Commit 773e5eb

Browse files
Bazel: general improvements.
Improve the Bazel build. Attempt to fix previous errors recorded while trying to publish ftxui in the Bazel Central Registry: - bazelbuild/bazel-central-registry#4485 - https://buildkite.com/bazel/bcr-presubmit/builds/13601#01968b61-f5b2-4d16-94d0-c87a03a1a23b Test against "recent" platforms ------------------------------- Previously, I got the error: ``` gcc: error: unrecognized command line option '-std-c++20'; did you mean '-std-c++2a'? ``` This was due to using old distribution like ubuntu 2004. Test against newer platforms only to avoid GCC version<-9.x.y Downgrade gtest version. ------------------------ I suspect this caused the Bazel Central Registry error: ``` file:///workdir/modules/googletest/1.15.2/MODULE.bazel:68:20: name 'use_repo_rule' is not defined ``` I hoped using a lower version will fix the issue. Tag gtest as dev_dependency --------------------------- Presumably, this should avoid dependants to fetch it? Enable --features-layering_check -------------------------------- Aka clang `-Wprivate-header`. Fix the encountered errors. Use clang in the CI ------------------- The CI was defining clang/gcc in the matrix, but was not using it. Fix the bug.
1 parent add5f40 commit 773e5eb

File tree

7 files changed

+106
-38
lines changed

7 files changed

+106
-38
lines changed

.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build --features=layering_check

.bcr/presubmit.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
matrix:
2+
# Note that gcc 9 and earlier aren't supported due to using --std=c++2a
3+
# instead of --std=c++20
24
platform:
3-
- centos7
4-
- debian10
5-
- ubuntu2004
5+
- debian11
6+
- ubuntu2024
67
- macos
8+
- macos-arm64
79
- windows
8-
bazel: [6.x, 7.x, 8.x]
10+
bazel:
11+
#- 6.x -> Build fails with bazel 6.x
12+
- 7.x
13+
- 8.x
914
tasks:
1015
verify_targets:
1116
name: Build and test.

.github/workflows/build.yaml

+9-5
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ jobs:
2020
matrix:
2121
include:
2222
- os: ubuntu-latest
23-
compiler: gcc
23+
compiler: g++
2424

2525
- os: ubuntu-latest
26-
compiler: llvm
26+
compiler: clang++
2727

2828
- os: macos-latest
29-
compiler: llvm
29+
compiler: g++
3030

3131
- os: macos-latest
32-
compiler: gcc
32+
compiler: clang++
3333

3434
- os: windows-latest
3535
compiler: cl
@@ -40,10 +40,14 @@ jobs:
4040
uses: actions/checkout@v3
4141

4242
- name: "Build with Bazel"
43+
env:
44+
CC: ${{ matrix.compiler }}
4345
run: bazel build ...
4446

4547
- name: "Tests with Bazel"
46-
run: bazel run tests
48+
env:
49+
CC: ${{ matrix.compiler }}
50+
run: bazel test --test_output=all ...
4751

4852
test_cmake:
4953
name: "CMake, ${{ matrix.compiler }}, ${{ matrix.os }}"

BUILD.bazel

+37-17
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@ load(":bazel/ftxui.bzl", "cpp20")
1616
load(":bazel/ftxui.bzl", "windows_copts")
1717
load(":bazel/ftxui.bzl", "pthread_linkopts")
1818

19-
package(default_visibility = ["//visibility:public"])
19+
# A meta target depending on all of the ftxui submodules.
20+
# Note that component depends on dom and screen, so ftxui is just an alias for
21+
# component.
22+
# ┌component──┐
23+
# │┌dom──────┐│
24+
# ││┌screen─┐││
25+
# └┴┴───────┴┴┘
26+
alias(name = "ftxui", actual = ":component")
2027

21-
# A meta target that depends on all the ftxui sub modules.
22-
alias(
23-
name = "ftxui",
24-
# Note that :component depends on :dom, which depends on :screen. Bazel
25-
# doesn't really support "public" and "private" dependencies. They are all
26-
# public. This is equivalent to depending on all the submodules.
27-
actual = ":component",
28-
visibility = ["//visibility:public"],
29-
)
30-
31-
# ftxui:screen is a module that provides a screen buffer and color management
28+
# @ftxui:screen is a module that provides a screen buffer and color management
3229
# for terminal applications. A screen is a 2D array of cells, each cell can
3330
# contain a glyph, a color, and other attributes. The library also provides
3431
# functions to manipulate the screen.
@@ -60,7 +57,7 @@ ftxui_cc_library(
6057
],
6158
)
6259

63-
# ftxui:dom is a library that provides a way to create and manipulate a
60+
# @ftxui:dom is a library that provides a way to create and manipulate a
6461
# "document" that can be rendered to a screen. The document is a tree of nodes.
6562
# Nodes can be text, layouts, or various decorators. Users needs to compose
6663
# nodes to create a document. A document is responsive to the size of the
@@ -130,7 +127,7 @@ ftxui_cc_library(
130127
deps = [":screen"],
131128
)
132129

133-
# ftxui:component is a library to create "dynamic" component renderering and
130+
# @ftxui:component is a library to create "dynamic" component renderering and
134131
# updating a ftxui::dom document on the screen. It is a higher level API than
135132
# ftxui:dom.
136133
#
@@ -167,6 +164,13 @@ ftxui_cc_library(
167164
"src/ftxui/component/terminal_input_parser.hpp",
168165
"src/ftxui/component/util.cpp",
169166
"src/ftxui/component/window.cpp",
167+
168+
# Private header from ftxui:dom.
169+
"src/ftxui/dom/node_decorator.hpp",
170+
171+
# Private header from ftxui:screen.
172+
"src/ftxui/screen/string_internal.hpp",
173+
"src/ftxui/screen/util.hpp",
170174
],
171175
hdrs = [
172176
"include/ftxui/component/animation.hpp",
@@ -182,7 +186,10 @@ ftxui_cc_library(
182186
"include/ftxui/component/task.hpp",
183187
],
184188
linkopts = pthread_linkopts(),
185-
deps = [":dom"],
189+
deps = [
190+
":dom",
191+
":screen",
192+
],
186193
)
187194

188195
# FTXUI's tests
@@ -205,7 +212,6 @@ cc_test(
205212
"src/ftxui/component/resizable_split_test.cpp",
206213
"src/ftxui/component/slider_test.cpp",
207214
"src/ftxui/component/terminal_input_parser_test.cpp",
208-
"src/ftxui/component/terminal_input_parser_test_fuzzer.cpp",
209215
"src/ftxui/component/toggle_test.cpp",
210216
"src/ftxui/dom/blink_test.cpp",
211217
"src/ftxui/dom/bold_test.cpp",
@@ -233,6 +239,17 @@ cc_test(
233239
"src/ftxui/screen/string_test.cpp",
234240
"src/ftxui/util/ref_test.cpp",
235241

242+
# Private header from ftxui:screen for string_test.cpp.
243+
"src/ftxui/screen/string_internal.hpp",
244+
245+
# Private header from ftxui::component for
246+
# terminal_input_parser_test.cpp.
247+
"src/ftxui/component/terminal_input_parser.hpp",
248+
249+
# Private header from ftxui::dom for
250+
# flexbox_helper_test.cpp.
251+
"src/ftxui/dom/flexbox_helper.hpp",
252+
236253
# TODO: Enable the two tests timing out with Bazel:
237254
# - "src/ftxui/component/screen_interactive_test.cpp",
238255
# - "src/ftxui/dom/selection_test.cpp",
@@ -243,7 +260,10 @@ cc_test(
243260
],
244261
copts = cpp20() + windows_copts(),
245262
deps = [
246-
"//:ftxui",
263+
":screen",
264+
":dom",
265+
":component",
266+
"@googletest//:gtest",
247267
"@googletest//:gtest_main",
248268
],
249269
)

MODULE.bazel

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# FTXUI Module.
2-
module(name = "ftxui", version = "6.1.8", compatibility_level = 6)
1+
# FTXUI module.
2+
module(
3+
name = "ftxui",
4+
version = "6.1.8",
5+
compatibility_level = 6,
6+
)
37

4-
# Build deps.
8+
# Build dependencies.
59
bazel_dep(name = "rules_cc", version = "0.1.1")
6-
bazel_dep(name = "platforms", version = "0.0.11")
10+
bazel_dep(name = "platforms", version = "0.0.10")
711

8-
# Test deps.
9-
bazel_dep(name = "googletest", version = "1.16.0.bcr.1")
12+
# Test dependencies.
13+
bazel_dep(name = "googletest", version = "1.14.0.bcr.1", dev_dependency = True)

bazel/ftxui.bzl

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ftxui_common.bzl
22

33
load("@rules_cc//cc:defs.bzl", "cc_library")
4+
load("@rules_cc//cc:defs.bzl", "cc_binary")
45

56
def cpp17():
67
return select({
@@ -45,7 +46,8 @@ def windows_copts():
4546
# This
4647
# - Replace missing font symbols by others.
4748
# - Reduce screen position pooling frequency to deals against a Microsoft
48-
# race condition. This was fixed in 2020, but clients never not updated.
49+
# race condition. This was fixed in 2020, but clients are still using
50+
# old versions.
4951
# - https://github.com/microsoft/terminal/pull/7583
5052
# - https://github.com/ArthurSonzogni/FTXUI/issues/136
5153
"-DFTXUI_MICROSOFT_TERMINAL_FALLBACK",
@@ -71,8 +73,8 @@ def pthread_linkopts():
7173

7274
def ftxui_cc_library(
7375
name,
74-
srcs,
75-
hdrs,
76+
srcs = [],
77+
hdrs = [],
7678
linkopts = [],
7779
deps = []):
7880

@@ -93,7 +95,8 @@ def ftxui_cc_library(
9395
)
9496

9597
# Compile all the examples in the examples/ directory.
96-
# This is useful to check the Bazel is synchronized with CMake definitions.
98+
# This is useful to check the Bazel is always synchronized against CMake
99+
# definitions.
97100
def generate_examples():
98101
cpp_files = native.glob(["examples/**/*.cpp"])
99102

@@ -107,9 +110,13 @@ def generate_examples():
107110
# Turn "examples/component/button.cpp" → "example_component_button"
108111
name = src.replace("/", "_").replace(".cpp", "")
109112

110-
native.cc_binary(
113+
cc_binary(
111114
name = name,
112115
srcs = [src],
113-
deps = ["//:component"],
116+
deps = [
117+
":component",
118+
":dom",
119+
":screen",
120+
],
114121
copts = cpp20() + windows_copts(),
115122
)

tools/test_bazel.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This script tests the project with different versions of Bazel and compilers
2+
# locally. This avoids waiting on the CI to run the tests.
3+
4+
# Version
5+
# -------
6+
# - Version >= 7 are supported
7+
# - Version <= 6 fail with the error:
8+
# ERROR: Analysis of target '//:component' failed; build aborted: no such
9+
# package '@rules_cc//cc/compiler': BUILD file not found in directory
10+
# 'cc/compiler' of external repository @rules_cc. Add a BUILD file to a
11+
# directory to mark it as a package.
12+
#
13+
14+
for ver in \
15+
"7.0.0" \
16+
"8.0.0"
17+
do
18+
for cc in \
19+
"gcc" \
20+
"clang"
21+
do
22+
echo "=== Testing with Bazel ${ver} with ${cc} ==="
23+
USE_BAZEL_VERSION=${ver} CC=${cc} bazel clean --expunge
24+
USE_BAZEL_VERSION=${ver} CC=${cc} bazel build //...
25+
USE_BAZEL_VERSION=${ver} CC=${cc} bazel test //...
26+
done
27+
done

0 commit comments

Comments
 (0)