Browse Source

Get TinyCC working on Windows

master
Macoy Madson 8 months ago
parent
commit
e8a8337e11
  1. 58
      src/TinyCCompiler.cake

58
src/TinyCCompiler.cake

@ -56,9 +56,65 @@ void test(void)
;;
(defun-comptime build-tiny-cc (manager (& ModuleManager) module (* Module) &return bool)
(var tinycc-build-dir (* (const char)) "cakelisp_cache/TinyCCBuildDir")
(comptime-cond
('Windows
(comptime-error "Need to add Windows support to TinyCC"))
(var tinycc-expect-file ([] 1024 char) (array 0))
(SafeSnprintf tinycc-expect-file (array-size tinycc-expect-file) "%s/libtcc.lib" tinycc-build-dir)
;; Add dependency
(call-on push_back (field manager environment additionalStaticLinkObjects) tinycc-expect-file)
(when (and (fileExists tinycc-expect-file)
(fileExists "libtcc.dll"))
(return true))
(makeDirectory tinycc-build-dir)
(var install-dir ([] 1024 char) (array 0))
(scope ;; Output must be absolute directory
(var absolute-output-path (* (const char))
(makeAbsolutePath_Allocated null tinycc-build-dir))
(unless absolute-output-path
(Logf "error: failed to make TinyCC output directory '%s'\n" tinycc-build-dir)
(return false))
(PrintfBuffer install-dir "%s" absolute-output-path)
(free (type-cast absolute-output-path (* void))))
;; TODO: Only works from a visual studio command prompt
(run-process-sequential-or
("C:\\Windows\\System32\\cmd.exe" "/C" "build-tcc.bat"
"-c" "cl" ;; Compile with MSVC
"-i" install-dir
:in-directory "Dependencies/TinyCC/win32")
(Log "failed to build TinyCC via build-tcc.bat\n")
(return false))
;; Create static library
(run-process-sequential-or
("lib.exe" "/def:libtcc/libtcc.def"
"/out:libtcc.lib"
"/machine:X64"
:in-directory tinycc-build-dir)
(Log "failed to create TinyCC static library via lib.exe\n")
(return false))
(var tinycc-dll ([] 1024 char) (array 0))
(SafeSnprintf tinycc-dll (array-size tinycc-dll) "%s/libtcc.dll" tinycc-build-dir)
(unless (copyBinaryFileTo tinycc-dll "libtcc.dll")
(Logf "error: failed to copy %s to project directory" tinycc-dll)
(return false))
;; TODO Static link tcc
(unless (and (fileExists tinycc-expect-file)
(fileExists "libtcc.dll"))
(Log
"error: TinyCC build sequence completed, but files are not where expected. Is there an issue
with the configuration?\n")
(return false)))
('Unix
(var tinycc-build-dir (* (const char)) "cakelisp_cache/TinyCCBuildDir")

Loading…
Cancel
Save