Skip to content

Commit 4ede2e5

Browse files
davidlionkirkrodriguesBill-hbrhbr
authored
feat(taskfile): Add more build tasks and rename others according to latest conventions: (#70)
- Change tasks to support building a subset of libraries through `ystdlib_LIBRARIES`. - Add tasks for building debug and release versions. - Add tasks for building examples. - Rename tasks to begin with the verb. Co-authored-by: kirkrodrigues <[email protected]> Co-authored-by: Bingran Hu <[email protected]>
1 parent 753e815 commit 4ede2e5

17 files changed

+435
-174
lines changed

.gersemirc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
definitions:
55
- "cmake/ystdlib-helpers.cmake"
6-
- "build/deps/Catch2/Catch2-src/extras/Catch.cmake"
6+
- "build/deps/Catch2-src/extras/Catch.cmake"
77
line_length: 100
88
list_expansion: "favour-expansion"

.github/workflows/code-linting-checks.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ jobs:
3737
shell: "bash"
3838
run: "npm install -g @go-task/cli"
3939

40+
- name: "Install uv"
41+
shell: "bash"
42+
run: |-
43+
curl \
44+
--fail \
45+
--location \
46+
--silent \
47+
--show-error \
48+
https://astral.sh/uv/0.8.4/install.sh \
49+
| sh
50+
4051
- name: "Run lint task"
4152
shell: "bash"
4253
run: "task lint:check"

.github/workflows/unit-tests.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
- "macos-15"
2626
- "ubuntu-22.04"
2727
- "ubuntu-24.04"
28+
build_type:
29+
- "debug"
30+
- "release"
2831
runs-on: "${{matrix.os}}"
2932
steps:
3033
- uses: "actions/checkout@v4"
@@ -45,7 +48,7 @@ jobs:
4548
brew install coreutils
4649
brew install llvm@16
4750
48-
- name: "Run unit tests"
51+
- name: "Run unit tests and examples"
4952
env: >-
5053
${{
5154
'macos-14' == matrix.os
@@ -55,4 +58,8 @@ jobs:
5558
}')
5659
|| fromJson('{}')
5760
}}
58-
run: "task test-all"
61+
# Currently unit tests rely on cassert and fail to compile in release mode.
62+
run: |-
63+
task test:run-debug
64+
task examples:build-${{matrix.build_type}}
65+
./build/examples/${{matrix.build_type}}/linking-tests

README.md

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Follow the steps below to develop and contribute to the project.
4343
* CMake 3.23 or higher
4444
* Python 3.10 or higher
4545
* [Task] 3.40.0 or higher
46+
* [uv] 0.7.10 or higher
4647
4748
## Set up
4849
Initialize and update submodules:
@@ -52,33 +53,32 @@ git submodule update --init --recursive
5253
5354
If you want to open the project in an IDE, run the following command to install any necessary
5455
dependencies from source:
56+
5557
```shell
5658
task deps:install-all
5759
```
5860

5961
## Building
6062

61-
The library can be built directly using [CMake](#using-cmake) or indirectly using
62-
[Task](#using-task).
63+
The library can be built via [Task](#building-using-task) or directly with
64+
[CMake](#building-using-cmake).
6365

64-
### Using Task
66+
### <a id="building-using-task" />Using Task
6567

66-
To build all targets:
67-
```shell
68-
task build:all
69-
```
68+
To build all libraries:
7069

71-
To build an executable containing all unit tests:
7270
```shell
73-
task build:unit-test-all
71+
task ystdlib:build-release
7472
```
7573

76-
To build an executable containing a single library's unit tests:
74+
To build a subset of libraries, set the [`ystdlib_LIBRARIES` parameter](#ystdlib_libraries). For
75+
example:
76+
7777
```shell
78-
task build:unit-test-<lib_name>
78+
task ystdlib:build-release ystdlib_LIBRARIES="containers;io_interface"
7979
```
8080

81-
### Using CMake
81+
### <a id="building-using-cmake" />Using CMake
8282

8383
To build all libraries, run:
8484

@@ -87,37 +87,57 @@ cmake -S . -B ./build
8787
cmake --build ./build
8888
```
8989

90-
To build a subset of libraries, set the variable `ystdlib_LIBRARIES` to a semicolon-separated (`;`)
91-
list of library names. The library names match their [directory name in src/](./src/ystdlib). For
90+
To build a subset of libraries, set the [`ystdlib_LIBRARIES` parameter](#ystdlib_libraries). For
9291
example:
9392

9493
```shell
9594
cmake -S . -B ./build -Dystdlib_LIBRARIES="containers;io_interface"
9695
cmake --build ./build
9796
```
9897

99-
> [!NOTE]
100-
> Internal dependencies of the libraries you choose will be automatically built, even if you don't
101-
> explicitly specify them. In the example, specifying `io_interface` automatically adds
102-
> `wrapped_facade_headers` to the build.
103-
10498
## Installing
10599

106-
After [building](#building), install with:
100+
The library can be installed via [Task](#installing-using-task) or directly with
101+
[CMake](#installing-using-cmake).
102+
103+
### <a id="installing-using-task" />Using Task
104+
105+
To build and install all libraries, run:
106+
107+
```shell
108+
task ystdlib:install-release INSTALL_PREFIX="$HOME/.local"
109+
```
110+
111+
To build and install a subset of libraries, set the
112+
[`ystdlib_LIBRARIES` parameter](#ystdlib_libraries). For example:
113+
114+
```shell
115+
task ystdlib:install-release \
116+
INSTALL_PREFIX="$HOME/.local" \
117+
ystdlib_LIBRARIES="containers;io_interface"
118+
```
119+
120+
### <a id="installing-using-cmake" />Using CMake
121+
122+
After [building](#building-using-cmake), to install all built libraries, run:
107123

108124
```shell
109125
cmake --install "./build" --prefix "$HOME/.local"
110126
```
111127

112128
## Testing
129+
113130
To build and run all unit tests:
131+
114132
```shell
115-
task test-all
133+
task test:run-debug
116134
```
117135

118-
To build and run unit tests for a specific library:
136+
To build and run unit tests for a subset of libraries, set the
137+
[`ystdlib_LIBRARIES` parameter](#ystdlib_libraries). For example:
138+
119139
```shell
120-
task test-<lib_name>
140+
task test:run-debug ystdlib_LIBRARIES="containers;io_interface"
121141
```
122142

123143
When generating a testing target, the CMake variable `BUILD_TESTING` is followed (unless overruled
@@ -144,4 +164,39 @@ task -a
144164
```
145165
Look for all tasks under the `lint` namespace (identified by the `lint:` prefix).
146166

167+
## Build and install parameters
168+
169+
The following parameters are common between multiple tasks and CMake.
170+
171+
### `ystdlib_LIBRARIES`
172+
173+
The parameter/variable `ystdlib_LIBRARIES` can be used to target a subset of libraries, by setting
174+
it to a semicolon-separated (`;`) list of library names. The library names match their
175+
[directory name in `src/`](./src/ystdlib).
176+
177+
> [!NOTE]
178+
> Internal dependencies of the libraries you choose will be automatically built, even if you don't
179+
> explicitly specify them. In the following examples, specifying `io_interface` automatically adds
180+
> `wrapped_facade_headers` to the build.
181+
182+
#### Using Task
183+
184+
Set by adding it after the task name. For example:
185+
186+
```shell
187+
task ystdlib:build-release ystdlib_LIBRARIES="containers;io_interface"
188+
```
189+
190+
Not all tasks support `ystdlib_LIBRARIES`. You can check if a task supports it by reading its
191+
description (run `task -a` to view all tasks and descriptions).
192+
193+
#### Using CMake
194+
195+
Set using the `-D` flag in the generation step. For example:
196+
197+
```shell
198+
cmake -S . -B ./build -Dystdlib_LIBRARIES="containers;io_interface"
199+
```
200+
147201
[Task]: https://taskfile.dev
202+
[uv]: https://docs.astral.sh/uv

examples/README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,33 @@ This directory contains example programs that demonstrate how to use the ystdlib
55
The example program `linking-tests` references all of ystdlib's library targets to ensure they can
66
be installed and linked correctly.
77

8-
## Requirements
8+
## Building
9+
10+
### Using Task
11+
12+
#### Requirements
13+
14+
See the [ystdlib Requirements section](../README.md#requirements).
15+
16+
#### Commands
17+
18+
```shell
19+
# debug build
20+
task examples:build-debug
21+
22+
# release build
23+
task examples:build-release
24+
```
25+
26+
### Using CMake
27+
28+
#### Requirements
929

1030
[Build](../README.md#building) and [install](../README.md#installing) ystdlib. The commands below
1131
assume you've built and installed ystdlib to `./build/examples/ystdlib`. If you installed it to a
1232
different location, adjust the paths accordingly.
1333

14-
## Building
34+
#### Commands
1535

1636
```shell
1737
cmake -S "./examples" -B "./build/examples" -Dystdlib_ROOT="./build/examples/ystdlib"

taskfile.yaml

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@ set: ["u", "pipefail"]
44
shopt: ["globstar"]
55

66
includes:
7-
build: "./taskfiles/build.yaml"
87
deps: "./taskfiles/deps.yaml"
8+
examples: "./taskfiles/examples.yaml"
99
lint: "./taskfiles/lint.yaml"
10-
utils: "tools/yscope-dev-utils/exports/taskfiles/utils/utils.yaml"
10+
test: "./taskfiles/test.yaml"
11+
ystdlib: "./taskfiles/ystdlib.yaml"
1112

1213
vars:
13-
G_BUILD_DIR: "{{.ROOT_DIR}}/build"
14-
G_CPP_SRC_DIR: "{{.ROOT_DIR}}/src"
15-
G_DEPS_DIR: "{{.G_BUILD_DIR}}/deps"
16-
17-
# These should be kept in-sync with its usage in CMakeLists.txt
18-
G_DEPS_CMAKE_SETTINGS_DIR: "{{.G_DEPS_DIR}}/cmake-settings"
19-
G_DEPS_CMAKE_SETTINGS_FILE: "{{.G_DEPS_CMAKE_SETTINGS_DIR}}/all.cmake"
14+
# General variables
15+
# This must match the package name in CMakeLists.txt.
16+
G_CMAKE_PACKAGE_NAME: "ystdlib"
2017

21-
G_TEST_BIN_DIR: "{{.G_BUILD_DIR}}/testbin"
22-
G_TEST_TARGET_SUFFIXES:
23-
- "all"
24-
- "containers"
25-
- "error_handling"
26-
- "wrapped_facade_headers"
18+
# Build directories
19+
G_BUILD_DIR: "{{.ROOT_DIR}}/build"
20+
G_EXAMPLES_BUILD_DIR: "{{.G_BUILD_DIR}}/examples"
21+
G_EXAMPLES_DEBUG_BUILD_DIR: "{{.G_EXAMPLES_BUILD_DIR}}/debug"
22+
G_EXAMPLES_RELEASE_BUILD_DIR: "{{.G_EXAMPLES_BUILD_DIR}}/release"
23+
G_YSTDLIB_BUILD_DIR: "{{.G_BUILD_DIR}}/{{.G_CMAKE_PACKAGE_NAME}}"
24+
G_YSTDLIB_DEBUG_BUILD_DIR: "{{.G_YSTDLIB_BUILD_DIR}}/debug"
25+
G_YSTDLIB_RELEASE_BUILD_DIR: "{{.G_YSTDLIB_BUILD_DIR}}/release"
2726

2827
tasks:
2928
clean:
@@ -37,13 +36,3 @@ tasks:
3736
run: "once"
3837
cmds:
3938
- "mkdir -p '{{.G_BUILD_DIR}}'"
40-
41-
test-*:
42-
desc: "Runs unit tests for the specified test target."
43-
vars:
44-
TEST_TARGET: >-
45-
{{printf "unit-test-%s" (index .MATCH 0)}}
46-
deps:
47-
- "build:{{.TEST_TARGET}}"
48-
cmds:
49-
- "{{.G_TEST_BIN_DIR}}/{{.TEST_TARGET}}"

taskfiles/build.yaml

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)