From a92d252da8e8125fd435812363bf0f7bcb521aef Mon Sep 17 00:00:00 2001 From: rexim Date: Tue, 4 Feb 2025 23:36:48 +0700 Subject: [PATCH 1/3] Add GitHub CI on Windows --- .github/workflows/nob.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/nob.yaml b/.github/workflows/nob.yaml index 30957b5..3c856ca 100644 --- a/.github/workflows/nob.yaml +++ b/.github/workflows/nob.yaml @@ -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 From 40b6a6a89c680e70f88b1cfd0a6e07f4cd4ac26f Mon Sep 17 00:00:00 2001 From: rexim Date: Tue, 4 Feb 2025 23:39:56 +0700 Subject: [PATCH 2/3] Port build_and_run_test() to msvc --- nob.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nob.c b/nob.c index d9e611b..c2349b3 100644 --- a/nob.c +++ b/nob.c @@ -19,7 +19,11 @@ 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); +#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 if (!cmd_run_sync_and_reset(cmd)) return false; cmd_append(cmd, bin_path); if (!cmd_run_sync_and_reset(cmd)) return false; From f36a2a6014d87b4269db6c4003b6986445edd9b6 Mon Sep 17 00:00:00 2001 From: rexim Date: Tue, 4 Feb 2025 23:45:13 +0700 Subject: [PATCH 3/3] Factor out build_exec() --- nob.c | 7 +------ shared.h | 14 +++++++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/nob.c b/nob.c index c2349b3..8dd346c 100644 --- a/nob.c +++ b/nob.c @@ -19,12 +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); -#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 - 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); diff --git a/shared.h b/shared.h index b1fb127..54ce96e 100644 --- a/shared.h +++ b/shared.h @@ -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_