Skip to content
V. Khmelevskiy edited this page Jun 8, 2021 · 2 revisions

Using with Docker

To build gentool docker image run this command, it will fetch base image, setup dependencies and produce ready to use docker image with minimal environment.

docker build -t gentool .

Example

This image is then can be used to run gentool in container, however because these images are run in isolation in order to access your computer files you need to mount folder to access it.

Let's for example clone imgui (assuming destination folder C:/cpp/imgui)

C:
mkdir cpp
cd cpp
git clone https://github.com/ocornut/imgui.git imgui

Now let's add gentool project file to imgui (here I assume cross compilation to Windows), notice that all paths are now relative to container

imgui.gentool.json:

{
    "$schema": "https://raw.githubusercontent.com/Superbelko/ohmygentool/master/config-schema.json",
    "version": 1,
    "input": {
        "std": "c++14",
        "paths": ["/imgui/imgui.h"],
        "includes": [
            "/imgui/imgui",
        ],
        "system": [],
        "defines": [],
		
		// list of clang flags to use, more info https://clang.llvm.org/docs/ClangCommandLineReference.html#compilation-flags
        "cflags": [ "fms-compatibility-version=19", "target x86_64-pc-win32" ]
    },
    "output": {
        "path": "/imgui/imgui_gen.d",
        "target": "dlang",
        "attr-nogc": false
    }
}

Now let's generate D bindings from it, assuming docker image is already built all we need is to mount imgui folder and specify gentool project to use.

Note that -v flag mounts local path to be available in path after colon (:) inside container, you can have multiple -v mounted locations as needed.

docker run -v "C:\cpp\imgui:/imgui" gentool /imgui/imgui.gentool.json

Now it should generate bindings and write it under C:\cpp\imgui\imgui_gen.d

Final note:

There are many factors that will impact final result, availability of headers, macro definitions, compiler flags...
If anything was incorrectly configured it may affect quality of produced output because now basically compiler has to guess what it supposed to do.

More info about cross compiling setup
https://stackoverflow.com/questions/23248989/clang-c-cross-compiler-generating-windows-executable-from-mac-os-x

Of cource on Windows it is just easier to get regular build without all this hassle.

Clone this wiki locally