Skip to content

Commit 8fbcbf6

Browse files
committed
Merge branch 'pr/84' into feature/test-on-c++
2 parents 1d0c74f + a257c56 commit 8fbcbf6

File tree

12 files changed

+202
-169
lines changed

12 files changed

+202
-169
lines changed

.github/workflows/nob.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ jobs:
5252
# https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#create-your-own-command-prompt-shortcut
5353
run: |
5454
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
55-
cl.exe ${{ matrix.hotreload }} ${{ matrix.standard }} /Fe:nob nob.c
55+
cl.exe ${{ matrix.standard }} /Fe:nob nob.c
5656
nob.exe
5757
- name: Build how_to-s
5858
shell: cmd
5959
run: |
6060
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
6161
cd how_to/
62-
cl.exe ${{ matrix.hotreload }} ${{ matrix.standard }} /Fe:nob nob.c
62+
cl.exe ${{ matrix.standard }} /Fe:nob nob.c
6363
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ int main(int argc, char **argv)
1919
nob_cc_flags(&cmd);
2020
nob_cc_output(&cmd, BUILD_FOLDER"foo");
2121
nob_cc_inputs(&cmd, SRC_FOLDER"foo.c");
22-
da_append(&procs, cmd_run_async_and_reset(&cmd));
22+
if (!cmd_run(&cmd, .async = &procs)) return 1;
2323

2424
nob_cc(&cmd);
2525
nob_cc_flags(&cmd);
2626
nob_cc_output(&cmd, BUILD_FOLDER"bar");
2727
nob_cc_inputs(&cmd, SRC_FOLDER"bar.c");
28-
da_append(&procs, cmd_run_async_and_reset(&cmd));
28+
if (!cmd_run(&cmd, .async = &procs)) return 1;
2929

3030
nob_cc(&cmd);
3131
nob_cc_flags(&cmd);
3232
nob_cc_output(&cmd, BUILD_FOLDER"baz");
3333
nob_cc_inputs(&cmd, SRC_FOLDER"baz.c");
34-
da_append(&procs, cmd_run_async_and_reset(&cmd));
34+
if (!cmd_run(&cmd, .async = &procs)) return 1;
3535

3636
// Wait on all the async processes to finish
3737
if (!procs_wait_and_reset(&procs)) return 1;

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ int main(int argc, char **argv)
3636
nob_cmd_append(&cmd, "-I.", "-I" BUILD_FOLDER, "-I" SRC_BUILD_FOLDER); // -I is usually the same across all compilers
3737
nob_cc_output(&cmd, output_path);
3838
nob_cc_inputs(&cmd, input_path);
39-
if (!cmd_run_sync_and_reset(&cmd)) return 1;
39+
if (!cmd_run(&cmd)) return 1;
4040

4141
cmd_append(&cmd, output_path);
42-
if (!cmd_run_sync_and_reset(&cmd)) return 1;
42+
if (!cmd_run(&cmd)) return 1;
4343

4444
return 0;
4545
}

how_to/010_nob_two_stage/src_build/nob_configed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ int main(void)
2020
nob_cmd_append(&cmd, "-I"BUILD_FOLDER, "-I.");
2121
nob_cc_output(&cmd, output_path);
2222
nob_cc_inputs(&cmd, input_path);
23-
if (!cmd_run_sync_and_reset(&cmd)) return 1;
23+
if (!cmd_run(&cmd)) return 1;
2424
return 0;
2525
}

how_to/nob.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ int main(int argc, char **argv)
2525
nob_cc(&cmd);
2626
nob_cc_output(&cmd, "./nob");
2727
nob_cc_inputs(&cmd, "nob.c");
28-
if (!cmd_run_sync_and_reset(&cmd)) return 1;
28+
if (!cmd_run(&cmd)) return 1;
2929

3030
cmd_append(&cmd, "./nob");
31-
if (!cmd_run_sync_and_reset(&cmd)) return 1;
31+
if (!cmd_run(&cmd)) return 1;
3232
if (!set_current_dir("..")) return 1;
3333
temp_rewind(mark);
3434
}

nob.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ bool build_and_run_test(Cmd *cmd, const char *test_name)
3636
nob_cc_flags(cmd);
3737
nob_cc_output(cmd, bin_path);
3838
nob_cc_inputs(cmd, src_path);
39-
if (!cmd_run_sync_and_reset(cmd)) return false;
39+
if (!cmd_run(cmd)) return false;
4040

4141
const char *test_cwd_path = temp_sprintf("%s%s%s.cwd", BUILD_FOLDER, TESTS_FOLDER, test_name);
4242
if (!mkdir_if_not_exists(test_cwd_path)) return false;
4343
if (!set_current_dir(test_cwd_path)) return false;
4444
cmd_append(cmd, temp_sprintf("../%s", test_name));
45-
if (!cmd_run_sync_and_reset(cmd)) return false;
45+
if (!cmd_run(cmd)) return false;
4646
if (!set_current_dir("../../../")) return false;
4747

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

0 commit comments

Comments
 (0)