Skip to content

Commit b99ef50

Browse files
authored
Merge pull request #30 from tsoding/github-ci-windows
Add GitHub CI on Windows
2 parents 943f2d6 + f36a2a6 commit b99ef50

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

.github/workflows/nob.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,22 @@ jobs:
2323
run: ${{ matrix.cc }} -o nob nob.c
2424
- name: Run nob
2525
run: ./nob
26+
windows:
27+
runs-on: windows-latest
28+
steps:
29+
- name: Clone GIT repo
30+
uses: actions/checkout@v4
31+
- name: Build nob
32+
shell: cmd
33+
# cl.exe isn't available as-is in Github images because they don't want
34+
# to, so we need to pull env vars ourselves. Refs:
35+
# https://github.com/actions/runner-images/issues/6205#issuecomment-1241573412
36+
# https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#create-your-own-command-prompt-shortcut
37+
run: |
38+
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
39+
cl.exe ${{ matrix.hotreload }} -o nob.exe nob.c
40+
- name: Run nob
41+
shell: cmd
42+
run: |
43+
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
44+
nob.exe

nob.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ bool build_and_run_test(Cmd *cmd, const char *test_name)
1919
{
2020
const char *bin_path = temp_sprintf("%s%s", BUILD_FOLDER TESTS_FOLDER, test_name);
2121
const char *src_path = temp_sprintf("%s%s.c", TESTS_FOLDER, test_name);
22-
cmd_append(cmd, "cc", "-Wall", "-Wextra", "-Wswitch-enum", "-I.", "-o", bin_path, src_path);
23-
if (!cmd_run_sync_and_reset(cmd)) return false;
22+
if (!build_exec(cmd, bin_path, src_path)) return false;
2423
cmd_append(cmd, bin_path);
2524
if (!cmd_run_sync_and_reset(cmd)) return false;
2625
nob_log(INFO, "--- %s finished ---", bin_path);

shared.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@
77
#define TESTS_FOLDER "tests/"
88
#define TOOLS_FOLDER "tools/"
99

10+
bool build_exec(Cmd *cmd, const char *bin_path, const char *src_path)
11+
{
12+
#ifdef _MSC_VER
13+
cmd_append(cmd, "cl", "-I.", "-o", bin_path, src_path);
14+
#else
15+
cmd_append(cmd, "cc", "-Wall", "-Wextra", "-Wswitch-enum", "-I.", "-o", bin_path, src_path);
16+
#endif // _MSC_VER
17+
return cmd_run_sync_and_reset(cmd);
18+
}
19+
1020
// Tests are allowed to build the tools they may need for their testing
1121
// The tools are single C files residing in TOOLS_FOLDER
1222
bool build_tool(Cmd *cmd, const char *tool_name)
1323
{
1424
const char *tool_src = temp_sprintf("%s%s.c", TOOLS_FOLDER, tool_name);
1525
const char *tool_bin = temp_sprintf("%s%s", BUILD_FOLDER TOOLS_FOLDER, tool_name);
16-
cmd_append(cmd, "cc", "-Wall", "-Wextra", "-Wswitch-enum", "-I.", "-o", tool_bin, tool_src);
17-
if (!cmd_run_sync_and_reset(cmd)) return false;
18-
return true;
26+
return build_exec(cmd, tool_bin, tool_src);
1927
}
2028

2129
#endif // SHARED_H_

0 commit comments

Comments
 (0)