Skip to content

Commit 1754288

Browse files
committed
WIP notes on the build system
1 parent 5058663 commit 1754288

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

doc/Cakelisp.org

+77
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,80 @@ See [[file:../src/GeneratorHelpers.hpp][GeneratorHelpers.hpp]]. All of these fun
319319
Additionally, the ~Expect~ functions are quick ways to validate your inputs. They will write an error if the expectation isn't met.
320320

321321
[[file:../src/Generators.cpp][Generators.cpp]] serves as a good reference to how generators are written. However, they are rather verbose because they don't use any macros and have extensive validation. Generators written in Cakelisp can be much more compact thanks to macros.
322+
* Build system
323+
Cakelisp's build system is powerful enough at this point to serve as a general-purpose C/C++ build system, even if you aren't using Cakelisp for any runtime code.
324+
325+
For example, Cakelisp itself consists of C++ code. [[file:../Bootstrap.cake][Bootstrap.cake]] builds Cakelisp, and serves as a good demonstration of the build system. I'll explain it here.
326+
327+
#+BEGIN_SRC lisp
328+
(skip-build)
329+
#+END_SRC
330+
This indicates the current module should not be built, nor be linked into the final executable. ~Bootstrap.cake~ doesn't contain any runtime code, so we omit it. Modules which contain only compile-time functions like macros should also ~skip-build~.
331+
332+
#+BEGIN_SRC lisp
333+
(set-cakelisp-option executable-output "bin/cakelisp")
334+
#+END_SRC
335+
This changes the location where the final executable is output. Note that if you don't have a ~(main)~ function defined, you can change this output to e.g. ~lib/libCakelisp.so~ to output a dynamic library (on Linux).
336+
337+
#+BEGIN_SRC lisp
338+
(add-c-search-directory module "src")
339+
#+END_SRC
340+
It is good practice to refer to files without any directories in the path. This helps future developers if they need to relocate files. In this case, we add ~src~ to the ~module~ search paths, which means only this module and its dependencies will have that search path.
341+
342+
If ~global~ is specified instead, all modules and build dependencies would include the search path. Generally, you should try to use ~module~ only, because it lessens the chances of unnecessary rebuilds due to command signature changes, and is one less directory for the compiler to search.
343+
344+
#+BEGIN_SRC lisp
345+
(add-cpp-build-dependency
346+
"Tokenizer.cpp"
347+
"Evaluator.cpp"
348+
"Utilities.cpp"
349+
"FileUtilities.cpp"
350+
"Converters.cpp"
351+
"Writer.cpp"
352+
"Generators.cpp"
353+
"GeneratorHelpers.cpp"
354+
"RunProcess.cpp"
355+
"OutputPreambles.cpp"
356+
"DynamicLoader.cpp"
357+
"ModuleManager.cpp"
358+
"Logging.cpp"
359+
"Main.cpp")
360+
#+END_SRC
361+
362+
#+BEGIN_SRC lisp
363+
(add-build-options "-DUNIX")
364+
#+END_SRC
365+
366+
#+BEGIN_SRC lisp
367+
(defun-comptime cakelisp-link-hook (manager (& ModuleManager)
368+
linkCommand (& ProcessCommand)
369+
linkTimeInputs (* ProcessCommandInput) numLinkTimeInputs int
370+
&return bool)
371+
(Log "Cakelisp: Adding link arguments\n")
372+
;; Dynamic loading
373+
(on-call (field linkCommand arguments) push_back
374+
(array ProcessCommandArgumentType_String
375+
"-ldl"))
376+
;; Expose Cakelisp symbols for compile-time function symbol resolution
377+
(on-call (field linkCommand arguments) push_back
378+
(array ProcessCommandArgumentType_String
379+
"-Wl,--export-dynamic"))
380+
(return true))
381+
382+
(add-compile-time-hook pre-link cakelisp-link-hook)
383+
#+END_SRC
384+
385+
#+BEGIN_SRC lisp
386+
;; Use separate build configuration in case other things build files from src/
387+
(add-build-config-label "Bootstrap")
388+
#+END_SRC
389+
390+
** Cache validity
391+
The C/C++ compilation time dominates the total time from ~.cake~ to executable. In order to minimize this, Cakelisp maintains a cache of previously built "artifacts" and reuses them when possible.
392+
393+
It is critical that the cache does not become stale. To the developer, a stale cache results in confusion, because the developer might have made a change but does not see the change reflected in the output. Cakelisp's build system errs on the side of caution at the cost of build time performance to ensure this doesn't occur.
394+
395+
The following things are checked before a cached artifact is used (not all are relevant to all types of artifacts):
396+
*** Command signature
397+
*** Modification time
398+
*** Includes modification times

0 commit comments

Comments
 (0)