| 1 | # Castle Game Engine build tool |
| 2 | |
| 3 | Build, package Castle Game Engine projects from the command-line. |
| 4 | |
| 5 | See the https://castle-engine.io/build_tool for documentation. |
| 6 | |
| 7 | - This tool is used by the GUI editor, https://castle-engine.io/editor |
| 8 | |
| 9 | - It is also useful in all environments when only command-line is available, e.g. in CI jobs (Jenkins, GitHub actions, GitLab CI -- see https://castle-engine.io/manual_automatic_builds.php ). |
| 10 | |
| 11 | - You can call it from own editors (e.g. to integrate [VS Code](https://castle-engine.io/vscode) or Emacs with CGE). |
| 12 | |
| 13 | - Or just use it directly from command-line, if you like to use CLI :) |
| 14 | |
| 15 | ## Building |
| 16 | |
| 17 | To compile the build tool, all you need is an FPC installed. |
| 18 | |
| 19 | - Unix: |
| 20 | |
| 21 | ``` |
| 22 | cd castle-engine/tools/build-tool/ # first enter the build tool directory |
| 23 | ./castle-engine_compile.sh |
| 24 | ``` |
| 25 | |
| 26 | - Windows (execute this in PowerShell): |
| 27 | |
| 28 | ``` |
| 29 | cd castle-engine/tools/build-tool/ # first enter the build tool directory |
| 30 | Set-ExecutionPolicy Bypass -Scope Process |
| 31 | ./castle-engine_compile.ps1 |
| 32 | ``` |
| 33 | |
| 34 | See https://castle-engine.io/compiling_from_source.php about compiling CGE. |
| 35 | |
| 36 | You can also compile the build tool using standard methods for CGE applications: |
| 37 | |
| 38 | - From [CGE editor](https://castle-engine.io/editor). Just use menu item _"Compile"_. |
| 39 | |
| 40 | - Use [CGE command-line build tool](https://castle-engine.io/build_tool) to "bootstrap" it. Run `castle-engine compile` in this directory. |
| 41 | |
| 42 | - Or use [Lazarus](https://www.lazarus-ide.org/). Open in Lazarus `castle-engine.lpi` file and compile / run from Lazarus. Make sure to first register [CGE Lazarus packages](https://castle-engine.io/lazarus). |
| 43 | |
| 44 | ## Delphi TODOs |
| 45 | |
| 46 | The build tool cannot be compiled with Delphi for now. |
| 47 | |
| 48 | It can only be compiled with FPC. Never the less, it can execute Delphi compiler to compile your projects (if instructed by `--compiler` option or `compiler` attribute in the [CastleEngineManifest.xml](https://castle-engine.io/project_manifest#_compiler_options_and_paths)). |
| 49 | |
| 50 | To make the build tool compile with Delphi, we miss: |
| 51 | |
| 52 | - `Process` unit, part of FPC, to run external programs with |
| 53 | nice cross-platform API. |
| 54 | |
| 55 | - Ability to enumerate *all* environment variables (not only query by name), |
| 56 | like FPC `GetEnvironmentVariableCount` and `GetEnvironmentString(Integer)`. |
| 57 | |
| 58 | - Understand the issue of `castleconf.inc` reporting problems with `CompilerVersion` |
| 59 | when trying to compile the build tool with Delphi. |
| 60 | In general `castleconf.inc` works with Delphi -- we include it in every CGE unit, |
| 61 | but it fails when trying to compile the build tool. |
| 62 | A temporary workaround is to comment out `{$if CompilerVersion < ...}` |
| 63 | checks when compiling build tool with Delphi. |
| 64 | |
| 65 | |
| 66 | ## Dev notes: CASTLE_STRICT_CLI symbol |
| 67 | |
| 68 | The `CASTLE_STRICT_CLI` symbol is used when building the CGE for build tool. It means we know this is only a command-line application and we avoid linking any unit that may (indirectly) reference OpenGL units, sound or the big X3D/transform/scenes units. |
| 69 | |
| 70 | - Major practical advantage is that it fixes build tool working in GitLab CI shared runner on Windows. See https://castle-engine.io/gitlab_ci https://gitlab.com/castle-engine/test-gitlab-ci/ . |
| 71 | |
| 72 | Such machines don't have OpenGL dynamic libraries, and GL unit initialization would fail. |
| 73 | |
| 74 | (Moreover it seems there are problems when X3DNodes is included in build tool on GitLab CI, build tool can fail without any error message. Never debugged it to the end, but it seemed *additional* issue on top of using GL. But it doesn't matter anymore, as this fix avoids using X3DNodes too.) |
| 75 | |
| 76 | - Minor advantage: It is good that we're aware of how build tool is (accidentally) using OpenGL (or other unwanted) units. In general it is most elegant if it doesn't -- since build tool should never need to initialize OpenGL context. So all units used by build tool should be independent from OpenGL. |
| 77 | |
| 78 | - Minor practical advantage: make build tool compilation even faster. |