Răsfoiți Sursa

Merge pull request #13 from tsoding/4

(#4) Enable MSVC build on CI
Alexey Kutepov 4 ani în urmă
părinte
comite
0fa391dfdf
3 a modificat fișierele cu 62 adăugiri și 23 ștergeri
  1. 26 4
      .github/workflows/ci.yml
  2. 35 5
      nobuild.c
  3. 1 14
      nobuild.h

+ 26 - 4
.github/workflows/ci.yml

@@ -9,10 +9,14 @@ jobs:
     runs-on: ubuntu-18.04
     steps:
       - uses: actions/checkout@v1
+      - name: install 3rd party things
+        run: |
+          sudo apt-get update
+          sudo apt-get install valgrind
       - name: build everything
         run: |
           $CC -o nobuild nobuild.c
-          ./nobuild run
+          ./nobuild valgrind
         env:
           CC: gcc
           CXX: g++
@@ -20,10 +24,14 @@ jobs:
     runs-on: ubuntu-18.04
     steps:
       - uses: actions/checkout@v1
+      - name: install 3rd party things
+        run: |
+          sudo apt-get update
+          sudo apt-get install valgrind
       - name: build everything
         run: |
           $CC -o nobuild nobuild.c
-          ./nobuild run
+          ./nobuild valgrind
         env:
           CC: clang
           CXX: clang++
@@ -38,5 +46,19 @@ jobs:
         env:
           CC: clang
           CXX: clang++
-# TODO(#4): there is no CI for windows
-# TODO(#21): there is no CI build for FreeBSD
+  build-windows-msvc:
+    runs-on: windows-2019
+    steps:
+      - name: force LF
+        shell: cmd
+        run: |
+          git config --global core.autocrlf input
+      - uses: actions/checkout@v1
+        # this runs vcvarsall for us, so we get the MSVC toolchain in PATH.
+      - uses: seanmiddleditch/gha-setup-vsdevenv@master
+      - name: build everything
+        shell: cmd
+        # this replaces default PowerShell, which can't fail the build
+        run: |
+          cl.exe nobuild.c
+          .\nobuild.exe run

+ 35 - 5
nobuild.c

@@ -2,19 +2,25 @@
 #include "./nobuild.h"
 
 #define CFLAGS "-Wall", "-Wextra", "-std=c11", "-pedantic", "-ggdb"
+#define CSV_FILE_PATH "./csv/stress-copy.csv"
 
-int main(int argc, char **argv)
+const char *cc(void)
 {
-    GO_REBUILD_URSELF(argc, argv);
+    const char *result = getenv("CC");
+    return result ? result : "cc";
+}
 
-    // CMD("clang", CFLAGS, "-fsanitize=memory", "-o", "minicel", "src/main.c");
-    CMD("gcc", CFLAGS, "-o", "minicel", "src/main.c");
+int posix_main(int argc, char **argv)
+{
+    CMD(cc(), CFLAGS, "-o", "minicel", "src/main.c");
 
     if (argc > 1) {
         if (strcmp(argv[1], "run") == 0) {
-            CMD("./minicel", "./csv/stress-copy.csv");
+            CMD("./minicel", CSV_FILE_PATH);
         } else if (strcmp(argv[1], "gdb") == 0) {
             CMD("gdb", "./minicel");
+        } else if (strcmp(argv[1], "valgrind") == 0) {
+            CMD("valgrind", "--error-exitcode=1", "./minicel", CSV_FILE_PATH);
         } else {
             PANIC("%s is unknown subcommand", argv[1]);
         }
@@ -22,3 +28,27 @@ int main(int argc, char **argv)
 
     return 0;
 }
+
+int msvc_main(int argc, char **argv)
+{
+    CMD("cl.exe", "/Feminicel", "src/main.c");
+    if (argc > 1) {
+        if (strcmp(argv[1], "run") == 0) {
+            CMD(".\\minicel.exe", CSV_FILE_PATH);
+        } else {
+            PANIC("%s is unknown subcommand", argv[1]);
+        }
+    }
+    return 0;
+}
+
+int main(int argc, char **argv)
+{
+    GO_REBUILD_URSELF(argc, argv);
+
+#ifndef _WIN32
+    return posix_main(argc, argv);
+#else
+    return msvc_main(argc, argv);
+#endif
+}

+ 1 - 14
nobuild.h

@@ -72,7 +72,6 @@ int closedir(DIR *dirp);
 #endif  // MINIRENT_H_
 // minirent.h HEADER END ////////////////////////////////////////
 
-// TODO(#28): use GetLastErrorAsString everywhere on Windows error reporting
 LPSTR GetLastErrorAsString(void);
 
 #endif  // _WIN32
@@ -138,8 +137,6 @@ typedef struct {
     size_t count;
 } Cmd_Array;
 
-// TODO(#1): no way to disable echo in nobuild scripts
-// TODO(#2): no way to ignore fails
 #define CMD(...)                                        \
     do {                                                \
         Cmd cmd = {                                     \
@@ -162,7 +159,6 @@ typedef struct {
     Cstr_Array args;
 } Chain_Token;
 
-// TODO(#17): IN and OUT are already taken by WinAPI
 #define IN(path) \
     (Chain_Token) { \
         .type = CHAIN_TOKEN_IN, \
@@ -181,7 +177,6 @@ typedef struct {
         .args = cstr_array_make(__VA_ARGS__, NULL) \
     }
 
-// TODO(#20): pipes do not allow redirecting stderr
 typedef struct {
     Cstr input_filepath;
     Cmd_Array cmds;
@@ -192,7 +187,6 @@ Chain chain_build_from_tokens(Chain_Token first, ...);
 void chain_run_sync(Chain chain);
 void chain_echo(Chain chain);
 
-// TODO(#15): PIPE does not report where exactly a syntactic error has happened
 #define CHAIN(...)                                                      \
     do {                                                                \
         Chain chain = chain_build_from_tokens(__VA_ARGS__, (Chain_Token) {0}); \
@@ -200,7 +194,6 @@ void chain_echo(Chain chain);
         chain_run_sync(chain);                                          \
     } while(0)
 
-// TODO(#29): REBUILD_URSELF does not distinguish MSVC and MinGW setups on Windows
 #ifndef REBUILD_URSELF
 #  if _WIN32
 #    define REBUILD_URSELF(binary_path, source_path) CMD("cl.exe", source_path)
@@ -225,6 +218,7 @@ void chain_echo(Chain chain);
                     .count = argc,                                     \
                 },                                                     \
             };                                                         \
+            INFO("CMD: %s", cmd_show(cmd));                            \
             cmd_run_sync(cmd);                                         \
             exit(0);                                                   \
         }                                                              \
@@ -661,10 +655,6 @@ void pid_wait(Pid pid)
 
 Cstr cmd_show(Cmd cmd)
 {
-    // TODO(#31): cmd_show does not render the command line properly
-    // - No string literals when arguments contains space
-    // - No escaping of special characters
-    // - Etc.
     return cstr_array_join(" ", cmd.line);
 }
 
@@ -679,7 +669,6 @@ Pid cmd_run_async(Cmd cmd, Fd *fdin, Fd *fdout)
     // NOTE: theoretically setting NULL to std handles should not be a problem
     // https://docs.microsoft.com/en-us/windows/console/getstdhandle?redirectedfrom=MSDN#attachdetach-behavior
     siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
-    // TODO(#32): check for errors in GetStdHandle
     siStartInfo.hStdOutput = fdout ? *fdout : GetStdHandle(STD_OUTPUT_HANDLE);
     siStartInfo.hStdInput = fdin ? *fdin : GetStdHandle(STD_INPUT_HANDLE);
     siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
@@ -690,8 +679,6 @@ Pid cmd_run_async(Cmd cmd, Fd *fdin, Fd *fdout)
     BOOL bSuccess =
         CreateProcess(
             NULL,
-            // TODO(#33): cmd_run_async on Windows does not render command line properly
-            // It may require wrapping some arguments with double-quotes if they contains spaces, etc.
             cstr_array_join(" ", cmd.line),
             NULL,
             NULL,