Skip to content

Commit b307a17

Browse files
Bazel: general improvements. (#1043)
* 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 ``` Specifying using bazelmod fixes the issue. Thanks @robinlinden 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 4604adb commit b307a17

File tree

7 files changed

+135
-72
lines changed

7 files changed

+135
-72
lines changed

.bazelrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build --features=layering_check
2+
build --enable_bzlmod
3+
4+
build --enable_platform_specific_config
5+
build:linux --cxxopt=-std=c++20
6+
build:macos --cxxopt=-std=c++20
7+
build:windows --cxxopt=-std:c++20

.bcr/presubmit.yml

+29-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
matrix:
2-
platform:
3-
- centos7
4-
- debian10
5-
- ubuntu2004
6-
- macos
7-
- windows
8-
bazel: [6.x, 7.x, 8.x]
2+
bazel:
3+
- 7.x
4+
- 8.x
5+
- rolling
6+
unix_platform:
7+
- debian11
8+
- ubuntu2204
9+
- macos
10+
- macos_arm64
11+
win_platform:
12+
- windows
13+
914
tasks:
10-
verify_targets:
11-
name: Build and test.
12-
platform: ${{ platform }}
15+
16+
unix_test:
17+
name: Verify build targets on Unix
18+
platform: ${{ unix_platform }}
1319
bazel: ${{ bazel }}
20+
build_flags:
21+
- --cxxopt=-std=c++20
1422
build_targets:
15-
- '@ftxui//:ftxui'
16-
- '@ftxui//:screen'
1723
- '@ftxui//:dom'
1824
- '@ftxui//:component'
19-
test_targets:
20-
- '@ftxui//:tests'
25+
- '@ftxui//:screen'
2126

27+
windows_test:
28+
name: Verify build targets
29+
platform: ${{ win_platform }}
30+
bazel: ${{ bazel }}
31+
build_flags:
32+
- --cxxopt=/std:c++20
33+
build_targets:
34+
- '@ftxui//:dom'
35+
- '@ftxui//:component'
36+
- '@ftxui//:screen'

.github/workflows/build.yaml

+18-7
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,47 @@ on:
1414
jobs:
1515

1616
test_bazel:
17-
name: "Bazel, ${{ matrix.compiler }}, ${{ matrix.os }}"
17+
name: "Bazel, ${{ matrix.cxx }}, ${{ matrix.os }}"
1818
strategy:
1919
fail-fast: false
2020
matrix:
2121
include:
2222
- os: ubuntu-latest
23-
compiler: gcc
23+
cxx: g++
24+
cc: gcc
2425

2526
- os: ubuntu-latest
26-
compiler: llvm
27+
cxx: clang++
28+
cc: clang
2729

2830
- os: macos-latest
29-
compiler: llvm
31+
cxx: g++
32+
cc: gcc
3033

3134
- os: macos-latest
32-
compiler: gcc
35+
cxx: clang++
36+
cc: clang
3337

3438
- os: windows-latest
35-
compiler: cl
39+
cxx: cl
40+
cc: cl
3641

3742
runs-on: ${{ matrix.os }}
3843
steps:
3944
- name: "Checkout repository"
4045
uses: actions/checkout@v3
4146

4247
- name: "Build with Bazel"
48+
env:
49+
CC: ${{ matrix.cc }}
50+
CXX: ${{ matrix.cxx }}
4351
run: bazel build ...
4452

4553
- name: "Tests with Bazel"
46-
run: bazel run tests
54+
env:
55+
CC: ${{ matrix.cc }}
56+
CXX: ${{ matrix.cxx }}
57+
run: bazel test --test_output=all ...
4758

4859
test_cmake:
4960
name: "CMake, ${{ matrix.compiler }}, ${{ matrix.os }}"

BUILD.bazel

+38-19
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,19 @@
1212
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
1313
load(":bazel/ftxui.bzl", "ftxui_cc_library")
1414
load(":bazel/ftxui.bzl", "generate_examples")
15-
load(":bazel/ftxui.bzl", "cpp20")
1615
load(":bazel/ftxui.bzl", "windows_copts")
1716
load(":bazel/ftxui.bzl", "pthread_linkopts")
1817

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

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
27+
# @ftxui:screen is a module that provides a screen buffer and color management
3228
# for terminal applications. A screen is a 2D array of cells, each cell can
3329
# contain a glyph, a color, and other attributes. The library also provides
3430
# functions to manipulate the screen.
@@ -60,7 +56,7 @@ ftxui_cc_library(
6056
],
6157
)
6258

63-
# ftxui:dom is a library that provides a way to create and manipulate a
59+
# @ftxui:dom is a library that provides a way to create and manipulate a
6460
# "document" that can be rendered to a screen. The document is a tree of nodes.
6561
# Nodes can be text, layouts, or various decorators. Users needs to compose
6662
# nodes to create a document. A document is responsive to the size of the
@@ -130,7 +126,7 @@ ftxui_cc_library(
130126
deps = [":screen"],
131127
)
132128

133-
# ftxui:component is a library to create "dynamic" component renderering and
129+
# @ftxui:component is a library to create "dynamic" component renderering and
134130
# updating a ftxui::dom document on the screen. It is a higher level API than
135131
# ftxui:dom.
136132
#
@@ -167,6 +163,13 @@ ftxui_cc_library(
167163
"src/ftxui/component/terminal_input_parser.hpp",
168164
"src/ftxui/component/util.cpp",
169165
"src/ftxui/component/window.cpp",
166+
167+
# Private header from ftxui:dom.
168+
"src/ftxui/dom/node_decorator.hpp",
169+
170+
# Private header from ftxui:screen.
171+
"src/ftxui/screen/string_internal.hpp",
172+
"src/ftxui/screen/util.hpp",
170173
],
171174
hdrs = [
172175
"include/ftxui/component/animation.hpp",
@@ -182,7 +185,10 @@ ftxui_cc_library(
182185
"include/ftxui/component/task.hpp",
183186
],
184187
linkopts = pthread_linkopts(),
185-
deps = [":dom"],
188+
deps = [
189+
":dom",
190+
":screen",
191+
],
186192
)
187193

188194
# FTXUI's tests
@@ -205,7 +211,6 @@ cc_test(
205211
"src/ftxui/component/resizable_split_test.cpp",
206212
"src/ftxui/component/slider_test.cpp",
207213
"src/ftxui/component/terminal_input_parser_test.cpp",
208-
"src/ftxui/component/terminal_input_parser_test_fuzzer.cpp",
209214
"src/ftxui/component/toggle_test.cpp",
210215
"src/ftxui/dom/blink_test.cpp",
211216
"src/ftxui/dom/bold_test.cpp",
@@ -233,6 +238,17 @@ cc_test(
233238
"src/ftxui/screen/string_test.cpp",
234239
"src/ftxui/util/ref_test.cpp",
235240

241+
# Private header from ftxui:screen for string_test.cpp.
242+
"src/ftxui/screen/string_internal.hpp",
243+
244+
# Private header from ftxui::component for
245+
# terminal_input_parser_test.cpp.
246+
"src/ftxui/component/terminal_input_parser.hpp",
247+
248+
# Private header from ftxui::dom for
249+
# flexbox_helper_test.cpp.
250+
"src/ftxui/dom/flexbox_helper.hpp",
251+
236252
# TODO: Enable the two tests timing out with Bazel:
237253
# - "src/ftxui/component/screen_interactive_test.cpp",
238254
# - "src/ftxui/dom/selection_test.cpp",
@@ -241,9 +257,12 @@ cc_test(
241257
"include",
242258
"src",
243259
],
244-
copts = cpp20() + windows_copts(),
260+
copts = windows_copts(),
245261
deps = [
246-
"//:ftxui",
262+
":screen",
263+
":dom",
264+
":component",
265+
"@googletest//:gtest",
247266
"@googletest//:gtest_main",
248267
],
249268
)

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

+15-26
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
# ftxui_common.bzl
22

33
load("@rules_cc//cc:defs.bzl", "cc_library")
4-
5-
def cpp17():
6-
return select({
7-
"@rules_cc//cc/compiler:msvc-cl": ["/std:c++17"],
8-
"@rules_cc//cc/compiler:clang-cl": ["/std:c++17"],
9-
"@rules_cc//cc/compiler:clang": ["-std=c++17"],
10-
"@rules_cc//cc/compiler:gcc": ["-std=c++17"],
11-
"//conditions:default": ["-std=c++17"],
12-
})
13-
14-
def cpp20():
15-
return select({
16-
"@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"],
17-
"@rules_cc//cc/compiler:clang-cl": ["/std:c++20"],
18-
"@rules_cc//cc/compiler:clang": ["-std=c++20"],
19-
"@rules_cc//cc/compiler:gcc": ["-std=c++20"],
20-
"//conditions:default": ["-std=c++20"],
21-
})
4+
load("@rules_cc//cc:defs.bzl", "cc_binary")
225

236
# Microsoft terminal is a bit buggy ¯\_(ツ)_/¯ and MSVC uses bad defaults.
247
def windows_copts():
@@ -45,7 +28,8 @@ def windows_copts():
4528
# This
4629
# - Replace missing font symbols by others.
4730
# - Reduce screen position pooling frequency to deals against a Microsoft
48-
# race condition. This was fixed in 2020, but clients never not updated.
31+
# race condition. This was fixed in 2020, but clients are still using
32+
# old versions.
4933
# - https://github.com/microsoft/terminal/pull/7583
5034
# - https://github.com/ArthurSonzogni/FTXUI/issues/136
5135
"-DFTXUI_MICROSOFT_TERMINAL_FALLBACK",
@@ -71,8 +55,8 @@ def pthread_linkopts():
7155

7256
def ftxui_cc_library(
7357
name,
74-
srcs,
75-
hdrs,
58+
srcs = [],
59+
hdrs = [],
7660
linkopts = [],
7761
deps = []):
7862

@@ -88,12 +72,13 @@ def ftxui_cc_library(
8872
"include",
8973
"src",
9074
],
91-
copts = cpp17() + windows_copts(),
75+
copts = windows_copts(),
9276
visibility = ["//visibility:public"],
9377
)
9478

9579
# Compile all the examples in the examples/ directory.
96-
# This is useful to check the Bazel is synchronized with CMake definitions.
80+
# This is useful to check the Bazel is always synchronized against CMake
81+
# definitions.
9782
def generate_examples():
9883
cpp_files = native.glob(["examples/**/*.cpp"])
9984

@@ -107,9 +92,13 @@ def generate_examples():
10792
# Turn "examples/component/button.cpp" → "example_component_button"
10893
name = src.replace("/", "_").replace(".cpp", "")
10994

110-
native.cc_binary(
95+
cc_binary(
11196
name = name,
11297
srcs = [src],
113-
deps = ["//:component"],
114-
copts = cpp20() + windows_copts(),
98+
deps = [
99+
":component",
100+
":dom",
101+
":screen",
102+
],
103+
copts = windows_copts(),
115104
)

tools/test_bazel.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
for ver in \
5+
"6.0.0" \
6+
"7.0.0" \
7+
"8.0.0"
8+
do
9+
for cc in \
10+
"gcc" \
11+
"clang"
12+
do
13+
echo "=== Testing with Bazel ${ver} with ${cc} ==="
14+
USE_BAZEL_VERSION=${ver} CC=${cc} bazel clean --expunge
15+
USE_BAZEL_VERSION=${ver} CC=${cc} bazel build //...
16+
USE_BAZEL_VERSION=${ver} CC=${cc} bazel test //...
17+
done
18+
done

0 commit comments

Comments
 (0)