Skip to content

Commit 8ddbc72

Browse files
reximyuI4140mikmart0x152aprogrammerlexi
committed
Release v1.23.0
Introduce new API for running commands (by @rexim, @programmerlexi, @0x152a) - Add nob_cmd_run() - Add nob_cmd_run_opt() - Add struct Nob_Cmd_Opt - Add nob_procs_flush() - Add nob_nprocs() Deprecate old API for running commands. (by @rexim) We do not plan to delete this API any time, but we believe that the new one is more convenient. - Deprecate struct Nob_Cmd_Redirect{} (it's not explicitly marked with NOB_DEPRECATED, but functions that use it are) - Turn nob_cmd_run_async() into a function (otherwise it's not deprecatable with NOB_DEPRECATED) - Deprecate nob_cmd_run_async() - Deprecate nob_cmd_run_async_and_reset() - Deprecate nob_cmd_run_async_redirect() - Deprecate nob_cmd_run_async_redirect_and_reset() - Deprecate nob_cmd_run_sync() - Deprecate nob_cmd_run_sync_and_reset() - Deprecate nob_cmd_run_sync_redirect() - Deprecate nob_cmd_run_sync_redirect_and_reset() - Deprecate nob_procs_append_with_flush() - Deprecate nob_procs_wait_and_reset() Introduce deprecation mechanism (by @yuI4140, @rexim) By default, deprecation warnings are not reported. You have to #define NOB_WARN_DEPRECATED to enable them. - Add NOB_DEPRECATED() - Add NOB_WARN_DEPRECATED Add NOB_DECLTYPE_CAST() for C++-compatible casting of allocation results (by @rexim) Introduce basic performance measuring mechanism (By @mikmart) - Add nob_nanos_since_unspecified_epoch() - Add NOB_NANOS_PER_SEC Co-authored-by: yuI4140 <[email protected]> Co-authored-by: Mikko Marttila <[email protected]> Co-authored-by: 0x152a <[email protected]> Co-authored-by: programmerlexi <[email protected]>
1 parent 8d04ee8 commit 8ddbc72

File tree

19 files changed

+689
-196
lines changed

19 files changed

+689
-196
lines changed

.github/workflows/nob.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ jobs:
4646
# https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#create-your-own-command-prompt-shortcut
4747
run: |
4848
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
49-
cl.exe ${{ matrix.hotreload }} /Fe:nob nob.c
49+
cl.exe /Fe:nob nob.c
5050
nob.exe
5151
- name: Build how_to-s
5252
shell: cmd
5353
run: |
5454
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
5555
cd how_to/
56-
cl.exe ${{ matrix.hotreload }} /Fe:nob nob.c
56+
cl.exe /Fe:nob nob.c
5757
nob.exe

how_to/001_basic_usage/nob.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ int main(int argc, char **argv)
5353
nob_cmd_append(&cmd, "cl", "-I.", "-o", BUILD_FOLDER"hello", SRC_FOLDER"hello.c");
5454
#endif // _MSC_VER
5555

56-
// Let's execute the command synchronously, that is it will be blocked until it's finished.
57-
if (!nob_cmd_run_sync(cmd)) return 1;
58-
// Reset the cmd array so you can use it again for another command
59-
cmd.count = 0;
56+
// Let's execute the command.
57+
if (!nob_cmd_run(&cmd)) return 1;
58+
// nob_cmd_run() automatically resets the cmd array, so you can nob_cmd_append() more strings
59+
// into it.
6060

6161
// nob.h ships with a bunch of nob_cc_* macros that try abstract away the specific compiler.
6262
// They are verify basic and not particularly flexible, but you can redefine them if you need to
@@ -65,9 +65,7 @@ int main(int argc, char **argv)
6565
nob_cc_flags(&cmd);
6666
nob_cc_output(&cmd, BUILD_FOLDER "foo");
6767
nob_cc_inputs(&cmd, SRC_FOLDER "foo.c");
68-
69-
// nob_cmd_run_sync_and_reset() resets the cmd for you automatically
70-
if (!nob_cmd_run_sync_and_reset(&cmd)) return 1;
68+
if (!nob_cmd_run(&cmd)) return 1;
7169

7270
return 0;
7371
}

how_to/005_parallel_build/nob.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define NOB_IMPLEMENTATION
22
#define NOB_STRIP_PREFIX
3+
#define NOB_WARN_DEPRECATED
34
#include "nob.h"
45

56
#define BUILD_FOLDER "build/"
@@ -14,29 +15,28 @@ int main(int argc, char **argv)
1415

1516
if (!mkdir_if_not_exists(BUILD_FOLDER)) return 1;
1617

17-
// Spawn three async processes collecting them to procs dynamic array
18-
nob_cc(&cmd);
19-
nob_cc_flags(&cmd);
20-
nob_cc_output(&cmd, BUILD_FOLDER"foo");
21-
nob_cc_inputs(&cmd, SRC_FOLDER"foo.c");
22-
da_append(&procs, cmd_run_async_and_reset(&cmd));
23-
24-
nob_cc(&cmd);
25-
nob_cc_flags(&cmd);
26-
nob_cc_output(&cmd, BUILD_FOLDER"bar");
27-
nob_cc_inputs(&cmd, SRC_FOLDER"bar.c");
28-
da_append(&procs, cmd_run_async_and_reset(&cmd));
29-
30-
nob_cc(&cmd);
31-
nob_cc_flags(&cmd);
32-
nob_cc_output(&cmd, BUILD_FOLDER"baz");
33-
nob_cc_inputs(&cmd, SRC_FOLDER"baz.c");
34-
da_append(&procs, cmd_run_async_and_reset(&cmd));
35-
36-
// Wait on all the async processes to finish
37-
if (!procs_wait_and_reset(&procs)) return 1;
38-
39-
// TODO: add some examples with nob_procs_append_with_flush()
18+
static struct {
19+
const char *bin_path;
20+
const char *src_path;
21+
} targets[] = {
22+
{ .bin_path = BUILD_FOLDER"foo", .src_path = SRC_FOLDER"foo.c" },
23+
{ .bin_path = BUILD_FOLDER"bar", .src_path = SRC_FOLDER"bar.c" },
24+
{ .bin_path = BUILD_FOLDER"baz", .src_path = SRC_FOLDER"baz.c" },
25+
};
26+
27+
// Spawn one async process per target collecting them to procs dynamic array
28+
for (size_t i = 0; i < ARRAY_LEN(targets); ++i) {
29+
nob_cc(&cmd);
30+
nob_cc_flags(&cmd);
31+
nob_cc_output(&cmd, targets[i].bin_path);
32+
nob_cc_inputs(&cmd, targets[i].src_path);
33+
if (!cmd_run(&cmd, .async = &procs)) return 1;
34+
}
35+
36+
// Wait on all the async processes to finish and reset procs dynamic array to 0
37+
if (!procs_flush(&procs)) return 1;
38+
39+
// TODO: add some examples with .max_procs
4040

4141
return 0;
4242
}

how_to/010_nob_two_stage/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Two Stage Build
22

3-
Quite often when your project grows big enough you end up wanting to configure the build of your application: different sets of enabled features, compilation flags, etc. The recommended approach to this in nob is to setup Two Stage Build system. That is [nob.c](./nob.c) does not do any actual work except generating initial `./build/config.h` and building `./src_build/nob_configed.c` (which `#include`-s the `./build/config.h` file) and then running it.
3+
Quite often when your project grows big enough you end up wanting to configure the build of your application: different sets of enabled features, compilation flags, etc. The recommended approach to this in nob is to setup Two Stage Build system. That is [nob.c](./nob.c) does not do any actual work except generating initial `./build/config.h` and building `./src_build/nob_configed.c` (which `#include`-s the `./build/config.h` file) and then running it.
44

55
Exact details of the setup is up to your. Here we present just one way of doing it. In fact you have a freedom to do as many stages of your build as you want, analysing your environment in all sorts of different ways (you literally have a system programming language at your disposal). The whole point of nob is that you bootstrap it ONLY with `cc -o nob nob.c` (no additional flags or actions should be required form the user) and the rest is taken care of by your C code.
66

how_to/010_nob_two_stage/nob.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define NOB_IMPLEMENTATION
22
#define NOB_STRIP_PREFIX
3+
#define NOB_WARN_DEPRECATED
34
#include "nob.h"
45
#include "src_build/folders.h"
56

@@ -36,10 +37,10 @@ int main(int argc, char **argv)
3637
nob_cmd_append(&cmd, "-I.", "-I"BUILD_FOLDER, "-I"SRC_BUILD_FOLDER); // -I is usually the same across all compilers
3738
nob_cc_output(&cmd, output_path);
3839
nob_cc_inputs(&cmd, input_path);
39-
if (!cmd_run_sync_and_reset(&cmd)) return 1;
40+
if (!cmd_run(&cmd)) return 1;
4041

4142
cmd_append(&cmd, output_path);
42-
if (!cmd_run_sync_and_reset(&cmd)) return 1;
43+
if (!cmd_run(&cmd)) return 1;
4344

4445
return 0;
4546
}

how_to/010_nob_two_stage/src_build/nob_configed.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define NOB_IMPLEMENTATION
22
#define NOB_STRIP_PREFIX
3+
#define NOB_WARN_DEPRECATED
34
#include "nob.h"
45
#include "config.h"
56
#include "folders.h"
@@ -20,6 +21,6 @@ int main(void)
2021
nob_cmd_append(&cmd, "-I"BUILD_FOLDER, "-I.");
2122
nob_cc_output(&cmd, output_path);
2223
nob_cc_inputs(&cmd, input_path);
23-
if (!cmd_run_sync_and_reset(&cmd)) return 1;
24+
if (!cmd_run(&cmd)) return 1;
2425
return 0;
2526
}

how_to/nob.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define NOB_IMPLEMENTATION
44
#define NOB_STRIP_PREFIX
55
#define NOB_EXPERIMENTAL_DELETE_OLD
6+
#define NOB_WARN_DEPRECATED
67
#include "../nob.h"
78

89
const char *examples[] = {
@@ -25,10 +26,10 @@ int main(int argc, char **argv)
2526
nob_cc(&cmd);
2627
nob_cc_output(&cmd, "./nob");
2728
nob_cc_inputs(&cmd, "nob.c");
28-
if (!cmd_run_sync_and_reset(&cmd)) return 1;
29+
if (!cmd_run(&cmd)) return 1;
2930

3031
cmd_append(&cmd, "./nob");
31-
if (!cmd_run_sync_and_reset(&cmd)) return 1;
32+
if (!cmd_run(&cmd)) return 1;
3233
if (!set_current_dir("..")) return 1;
3334
temp_rewind(mark);
3435
}

nob.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define NOB_IMPLEMENTATION
44
#define NOB_STRIP_PREFIX
55
#define NOB_EXPERIMENTAL_DELETE_OLD
6+
#define NOB_WARN_DEPRECATED
67
#include "nob.h"
78
#undef rename // Testing for backward compatibility after v1.20.6
89

@@ -36,13 +37,13 @@ bool build_and_run_test(Cmd *cmd, const char *test_name)
3637
nob_cc_flags(cmd);
3738
nob_cc_output(cmd, bin_path);
3839
nob_cc_inputs(cmd, src_path);
39-
if (!cmd_run_sync_and_reset(cmd)) return false;
40+
if (!cmd_run(cmd)) return false;
4041

4142
const char *test_cwd_path = temp_sprintf("%s%s%s.cwd", BUILD_FOLDER, TESTS_FOLDER, test_name);
4243
if (!mkdir_if_not_exists(test_cwd_path)) return false;
4344
if (!set_current_dir(test_cwd_path)) return false;
4445
cmd_append(cmd, temp_sprintf("../%s", test_name));
45-
if (!cmd_run_sync_and_reset(cmd)) return false;
46+
if (!cmd_run(cmd)) return false;
4647
if (!set_current_dir("../../../")) return false;
4748

4849
nob_log(INFO, "--- %s finished ---", bin_path);

0 commit comments

Comments
 (0)