Skip to content

Commit 39028aa

Browse files
committed
Add parallel_build example
1 parent f9f2996 commit 39028aa

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nob
2+
nob.old
3+
build/

how_to/005_parallel_build/nob.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#define NOB_IMPLEMENTATION
2+
#define NOB_STRIP_PREFIX
3+
#include "nob.h"
4+
5+
#define BUILD_FOLDER "build/"
6+
#define SRC_FOLDER "src/"
7+
8+
int main(int argc, char **argv)
9+
{
10+
NOB_GO_REBUILD_URSELF(argc, argv);
11+
12+
Cmd cmd = {0};
13+
Procs procs = {0};
14+
15+
if (!mkdir_if_not_exists(BUILD_FOLDER)) return 1;
16+
17+
// Spawn three async processes collecting them to procs dynamic array
18+
cmd_append(&cmd, "cc", "-o", BUILD_FOLDER"foo", SRC_FOLDER"foo.c");
19+
da_append(&procs, cmd_run_async_and_reset(&cmd));
20+
cmd_append(&cmd, "cc", "-o", BUILD_FOLDER"bar", SRC_FOLDER"bar.c");
21+
da_append(&procs, cmd_run_async_and_reset(&cmd));
22+
cmd_append(&cmd, "cc", "-o", BUILD_FOLDER"baz", SRC_FOLDER"baz.c");
23+
da_append(&procs, cmd_run_async_and_reset(&cmd));
24+
25+
// Wait on all the async processes to finish
26+
if (!procs_wait_and_reset(&procs)) return 1;
27+
28+
// TODO: add some examples with nob_procs_append_with_flush()
29+
30+
return 0;
31+
}

how_to/005_parallel_build/nob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../nob.h
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
printf("Bar\n");
6+
return 0;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
printf("Baz\n");
6+
return 0;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
printf("Foo\n");
6+
return 0;
7+
}

0 commit comments

Comments
 (0)