31595a620094 — Leonard Ritter release-0.8 2 years ago
* fixed win32 build: have to build with gcc, not clang; static libraries must be linked in the right order
6 files changed, 118 insertions(+), 47 deletions(-)

A => doc/build_clang.txt
M genie.lua
M scopes.cpp
A => testing/test_clang.sc
M win32/realpath.c
M win32/stdlib_ex.h
A => doc/build_clang.txt +16 -0
@@ 0,0 1,16 @@ 
+Notes on building clang/LLVM libraries required for scopes on Windows:
+
+build with Visual Studio 2015
+
+unpack llvm to clang/llvm
+unpack clang to clang/llvm/tools/clang
+create clang/build
+cd clang/build
+cmake ../llvm -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_BUILD_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF
+open solution in vs 2015 and select release build
+from Tools, build only llvm-config
+build all from Libraries
+
+cmake ../llvm -G "MSYS Makefiles" -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_BUILD_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF
+make -j4
+-DCMAKE_INSTALL_PREFIX=...
  No newline at end of file

          
M genie.lua +74 -36
@@ 71,11 71,13 @@ local LLVM_CONFIG = toolpath("llvm-confi
 
 local LLVM_LDFLAGS = pkg_config(LLVM_CONFIG .. " --ldflags")
 local LLVM_CXXFLAGS = pkg_config(LLVM_CONFIG .. " --cxxflags")
-local LLVM_LIBS = pkg_config(LLVM_CONFIG .. " --libs engine passes option objcarcopts coverage support lto coroutines")
+local LLVM_LIBS = pkg_config(LLVM_CONFIG .. " --link-static --libs engine passes option objcarcopts coverage support lto coroutines")
 
-premake.gcc.cxx = CLANG_CXX
-premake.gcc.cc = CLANG_CC
-premake.gcc.llvm = true
+if not os.is("windows") then
+    premake.gcc.cxx = CLANG_CXX
+    premake.gcc.cc = CLANG_CC
+    premake.gcc.llvm = true
+end
 
 solution "scopes"
     location "build"

          
@@ 108,33 110,33 @@ project "scopes"
         "SCOPES_MAIN_CPP_IMPL",
     }
 
-    buildoptions_cpp {
-        "-std=c++11",
-        "-fno-rtti",
-        "-fno-exceptions",
-        "-ferror-limit=1",
-        "-pedantic",
-        "-Wall",
-        "-Wno-keyword-macro",
-    }
-
-    buildoptions_cpp(LLVM_CXXFLAGS)
+    configuration { "linux" }
+        buildoptions_cpp(LLVM_CXXFLAGS)
 
-    links {
-        "clangFrontend",
-        "clangDriver",
-        "clangSerialization",
-        "clangCodeGen",
-        "clangParse",
-        "clangSema",
-        "clangAnalysis",
-        "clangEdit",
-        "clangAST",
-        "clangLex",
-        "clangBasic"        
-    }
+        links {
+            "clangFrontend",
+            "clangDriver",
+            "clangSerialization",
+            "clangCodeGen",
+            "clangParse",
+            "clangSema",
+            "clangAnalysis",
+            "clangEdit",
+            "clangAST",
+            "clangLex",
+            "clangBasic"        
+        }
 
-    configuration { "linux" }
+        buildoptions_cpp {
+            "-std=c++11",
+            "-fno-rtti",
+            "-fno-exceptions",
+            "-ferror-limit=1",
+            "-pedantic",
+            "-Wall",
+            "-Wno-keyword-macro",
+        }
+    
         files {
             "external/minilibs/regexp.c"
         }

          
@@ 170,7 172,34 @@ project "scopes"
     
     configuration { "windows" }
         buildoptions_cpp {
-            "-Wno-unknown-warning-option",
+            "-D_GNU_SOURCE",
+            "-Wa,-mbig-obj",
+            "-std=gnu++11",
+            "-fno-exceptions",
+            "-fno-rtti",
+            "-D__STDC_CONSTANT_MACROS",
+            "-D__STDC_FORMAT_MACROS",
+            "-D__STDC_LIMIT_MACROS",
+        }
+
+        buildoptions_cpp {
+            "-Wall",
+        }
+
+        -- gcc-only options
+        buildoptions_cpp {
+            "-Wno-error=date-time",
+            "-fmax-errors=1",
+            "-Wno-vla",
+            "-Wno-enum-compare",
+            "-Wno-comment",
+            "-Wno-misleading-indentation",
+            "-Wno-pragmas",
+            "-Wno-return-type",
+            "-Wno-variadic-macros",
+        }
+    
+        buildoptions_cpp {
             "-Wno-unused-variable",
             "-Wno-unused-function",        
         }

          
@@ 196,15 225,25 @@ project "scopes"
         }
 
         links { 
-            "ffi", "ole32", "uuid", "version", "psapi"
+            "ffi", "uuid", "ole32", "psapi", "version", "stdc++",
         }
 
-        linkoptions { "-Wl,--allow-multiple-definition" }
         linkoptions(LLVM_LDFLAGS)
-        linkoptions { "-Wl,--whole-archive", "-Wl,--export-all-symbols" }
+        linkoptions {
+            "-lclangFrontend",
+            "-lclangDriver",
+            "-lclangSerialization",
+            "-lclangCodeGen",
+            "-lclangParse",
+            "-lclangSema",
+            "-lclangAnalysis",
+            "-lclangEdit",
+            "-lclangAST",
+            "-lclangLex",
+            "-lclangBasic"
+        }
         linkoptions(LLVM_LIBS)
-        linkoptions { "-Wl,--no-whole-archive" }
-        
+
         if os.is("windows") then
             local CP = toolpath("cp", MSYS_BIN_PATH)
 

          
@@ 214,7 253,6 @@ project "scopes"
                 CP .. " -v " .. dllpath("libgcc_s_seh-1") .. " " .. THISDIR,
                 CP .. " -v " .. dllpath("libstdc++-6") .. " " .. THISDIR,
                 CP .. " -v " .. dllpath("libwinpthread-1") .. " " .. THISDIR,
-                CP .. " -v " .. dllpath("LLVM") .. " " .. THISDIR,
             }
         end
     

          
M scopes.cpp +10 -8
@@ 3913,7 3913,7 @@ struct LexerParser {
             this->read_token();
             return Syntax::from(anchor,
                 List::from({ 
-                    Syntax::from(anchor, Symbol(KW_Quote)), 
+                    Any(Syntax::from(anchor, Symbol(KW_Quote))), 
                     parse_any() }));
         } else {
             location_error(format("unexpected token: %c (%i)",

          
@@ 3992,7 3992,7 @@ struct LexerParser {
     Any parse() {
         this->read_token();
         int lineno = 0;
-        bool escape = false;
+        //bool escape = false;
 
         const Anchor *anchor = this->anchor();
         ListBuilder builder(*this);

          
@@ 4001,7 4001,7 @@ struct LexerParser {
             if (this->token == tok_none) {
                 break;
             } else if (this->token == tok_escape) {
-                escape = true;
+                //escape = true;
                 this->read_token();
                 if (this->lineno <= lineno) {
                     location_error(String::from(

          
@@ 4014,7 4014,7 @@ struct LexerParser {
                         "indentation mismatch"));
                 }
 
-                escape = false;
+                //escape = false;
                 lineno = this->lineno;
                 // keep adding elements while we're in the same line
                 while ((this->token != tok_eof)

          
@@ 8161,13 8161,15 @@ static Any compile(Label *fn, uint64_t f
         if (LLVMCreateMCJITCompilerForModule(&ee, module, &opts,
             sizeof(opts), &errormsg)) {
             location_error(String::from_cstr(errormsg));
-        }
-
+        }        
+    } else {
+        LLVMAddModule(ee, module);
+    }
+
+    if (!disassembly_listener && (flags & CF_DumpDisassembly)) {
         llvm::ExecutionEngine *pEE = reinterpret_cast<llvm::ExecutionEngine*>(ee);
         disassembly_listener = new DisassemblyListener(pEE);
         pEE->RegisterJITEventListener(disassembly_listener);
-    } else {
-        LLVMAddModule(ee, module);
     }
 
 #if SCOPES_OPTIMIZE_ASSEMBLY

          
A => testing/test_clang.sc +12 -0
@@ 0,0 1,12 @@ 
+
+
+#fn testfunc (x y)
+    x * y
+let lib =
+    import-c "lib.c" "
+    int testfunc (int x, int y) {
+        return x * y;
+    }
+    " '()
+let testfunc = lib.testfunc
+assert ((testfunc 2 3) == 6)

          
M win32/realpath.c +5 -1
@@ 12,7 12,11 @@ I am placing this in the public domain f
 #include <errno.h>
 #include <sys/stat.h>
 
-char *realpath(const char *path, char resolved_path[PATH_MAX])
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
+char *realpath(const char *path, char *resolved_path)
 {
   char *return_path = 0;
 

          
M win32/stdlib_ex.h +1 -2
@@ 1,10 1,9 @@ 
 #include <stdlib.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-char *realpath(const char *path, char resolved_path[PATH_MAX]);
+char *realpath(const char *path, char *resolved_path);
 
 #ifdef __cplusplus
 }