Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub CI on Windows #30

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/nob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,22 @@ jobs:
run: ${{ matrix.cc }} -o nob nob.c
- name: Run nob
run: ./nob
windows:
runs-on: windows-latest
steps:
- name: Clone GIT repo
uses: actions/checkout@v4
- name: Build nob
shell: cmd
# cl.exe isn't available as-is in Github images because they don't want
# to, so we need to pull env vars ourselves. Refs:
# https://github.com/actions/runner-images/issues/6205#issuecomment-1241573412
# https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#create-your-own-command-prompt-shortcut
run: |
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
cl.exe ${{ matrix.hotreload }} -o nob.exe nob.c
- name: Run nob
shell: cmd
run: |
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
nob.exe
3 changes: 1 addition & 2 deletions nob.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ bool build_and_run_test(Cmd *cmd, const char *test_name)
{
const char *bin_path = temp_sprintf("%s%s", BUILD_FOLDER TESTS_FOLDER, test_name);
const char *src_path = temp_sprintf("%s%s.c", TESTS_FOLDER, test_name);
cmd_append(cmd, "cc", "-Wall", "-Wextra", "-Wswitch-enum", "-I.", "-o", bin_path, src_path);
if (!cmd_run_sync_and_reset(cmd)) return false;
if (!build_exec(cmd, bin_path, src_path)) return false;
cmd_append(cmd, bin_path);
if (!cmd_run_sync_and_reset(cmd)) return false;
nob_log(INFO, "--- %s finished ---", bin_path);
Expand Down
14 changes: 11 additions & 3 deletions shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@
#define TESTS_FOLDER "tests/"
#define TOOLS_FOLDER "tools/"

bool build_exec(Cmd *cmd, const char *bin_path, const char *src_path)
{
#ifdef _MSC_VER
cmd_append(cmd, "cl", "-I.", "-o", bin_path, src_path);
#else
cmd_append(cmd, "cc", "-Wall", "-Wextra", "-Wswitch-enum", "-I.", "-o", bin_path, src_path);
#endif // _MSC_VER
return cmd_run_sync_and_reset(cmd);
}

// Tests are allowed to build the tools they may need for their testing
// The tools are single C files residing in TOOLS_FOLDER
bool build_tool(Cmd *cmd, const char *tool_name)
{
const char *tool_src = temp_sprintf("%s%s.c", TOOLS_FOLDER, tool_name);
const char *tool_bin = temp_sprintf("%s%s", BUILD_FOLDER TOOLS_FOLDER, tool_name);
cmd_append(cmd, "cc", "-Wall", "-Wextra", "-Wswitch-enum", "-I.", "-o", tool_bin, tool_src);
if (!cmd_run_sync_and_reset(cmd)) return false;
return true;
return build_exec(cmd, tool_bin, tool_src);
}

#endif // SHARED_H_