Skip to content

Commit 7b12070

Browse files
committed
Add more comments to the basic_usage example
1 parent c730879 commit 7b12070

File tree

2 files changed

+25
-32
lines changed

2 files changed

+25
-32
lines changed

README.md

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,4 @@ You know all these BS movements that supposedly remove the root cause of your pr
3838

3939
## How to use the library in your own project
4040

41-
The only file you need from here is [nob.h](https://raw.githubusercontent.com/tsoding/nob.h/refs/heads/main/nob.h). Just copy-paste it to your project and start using it.
42-
43-
```c
44-
// nob.c
45-
#define NOB_IMPLEMENTATION
46-
#include "nob.h"
47-
48-
int main(int argc, char **argv)
49-
{
50-
NOB_GO_REBUILD_URSELF(argc, argv);
51-
Nob_Cmd cmd = {0};
52-
nob_cmd_append(&cmd, "cc", "-Wall", "-Wextra", "-o", "main", "main.c");
53-
if (!nob_cmd_run_sync(cmd)) return 1;
54-
return 0;
55-
}
56-
```
57-
58-
```console
59-
$ cc -o nob nob.c
60-
$ ./nob
61-
```
62-
63-
The `nob` automatically rebuilds itself if `nob.c` is modified thanks to the `NOB_GO_REBUILD_URSELF` macro (don't forget to check out how it all works in [nob.h](./nob.h)). Explore [./tests/](./tests/) and [./how_to/](./how_to/) folders.
41+
The only file you need from here is [nob.h](https://raw.githubusercontent.com/tsoding/nob.h/refs/heads/main/nob.h). Just copy-paste it to your project and start using it. See [how_to/](how_to/) folder for examples.

how_to/001_basic_usage/nob.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// This is your build script. You only need to "bootstrap" it once with `cc -o nob nob.c` (you can
2-
// call it whatever actually) or `cl nob.c` on MSVC and thanks to NOB_GO_REBUILD_URSELF (see below).
3-
// After that every time you run the `nob` executable if it detects that you modifed nob.c it will
4-
// rebuild itself automatically
1+
// This is your build script. You only need to "bootstrap" it once with `cc -o nob nob.c`
2+
// (you can call the executable whatever actually) or `cl nob.c` on MSVC. After that every
3+
// time you run the `nob` executable if it detects that you modifed nob.c it will rebuild
4+
// itself automatically thanks to NOB_GO_REBUILD_URSELF (see below)
55

66
// nob.h is an stb-style library https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
77
// What that means is that it's a single file that acts both like .c and .h files, but by default
@@ -14,26 +14,41 @@
1414
// and Autotools is that the codebases that use them naturally rot. That is if you do not actively update
1515
// your build scripts, they may not work with the latest version of the build tools. Here we basically
1616
// include the entirety of the source code of the tool along with the code base. It will never get
17-
// outdated.
17+
// outdated (unless you got no standard compliant C compiler lying around, but at that point why are
18+
// you trying to build a C project?)
1819
//
1920
// (In these examples we actually symlinking nob.h, but this is to keep nob.h-s synced among all the
2021
// examples)
2122
#include "nob.h"
2223

23-
// TODO: add more comments in here
24-
24+
// Some folder paths that we use throughout the build process.
2525
#define BUILD_FOLDER "build/"
2626
#define SRC_FOLDER "src/"
2727

2828
int main(int argc, char **argv)
2929
{
30+
// This line enables the self-rebuilding. It detects when nob.c is updated and auto rebuilds it then
31+
// runs it again.
3032
NOB_GO_REBUILD_URSELF(argc, argv);
3133

32-
Nob_Cmd cmd = {0};
33-
34+
// It's better to keep all the building artifacts in a separate build folder. Let's create it if it
35+
// does not exist yet.
36+
//
37+
// Majority of the nob command return bool which indicates whether operation has failed or not (true -
38+
// success, false - failure). If the operation returned false you don't need to log anything, the
39+
// convention is usually that the function logs what happened to itself. Just do
40+
// `if (!nob_function()) return;`
3441
if (!nob_mkdir_if_not_exists(BUILD_FOLDER)) return 1;
42+
43+
// The working horse of nob is the Nob_Cmd structure. It's a Dynamic Array of strings which represent
44+
// command line that you want to execute.
45+
Nob_Cmd cmd = {0};
46+
// Let's append the command line arguments
3547
nob_cmd_append(&cmd, "cc", "-Wall", "-Wextra", "-o", BUILD_FOLDER"main", SRC_FOLDER"main.c");
48+
// Let's execute the command synchronously, that is it will be blocked until it's finished.
3649
if (!nob_cmd_run_sync(cmd)) return 1;
3750

51+
// TODO: add more examples in here
52+
3853
return 0;
3954
}

0 commit comments

Comments
 (0)