Build, Configure and Export your project (original) (raw)

Basic usage

For example, the simplest example would be as follows:

config.nims

import gdext/buildconf

--path: src

let setting = BuildSettings( name: "MyExtension", )

configure(setting)

This will generate a MyExtension.gdextension file in the same directory as config.nims. We can build it as follows:

$ gdextwiz build PROJECT # to build for your system

$ gdextwiz run PROJECT # to build and execute project

$ gdextwiz build -d:platform=web -d:target=release # to make a release build for web platform

see also: gdextwiz

Dynamic .gdextension configuration

The path to the generated .gdextension can be set with the extpath property:

config.nims

import gdext/buildconf

--path: src

let setting = BuildSettings( name: "MyExtension", extpath: projectDir() & "/myextension.gdextension", )

configure(setting)

If you want to change the name or path of the generated DLL, do the following:

config.nims

import gdext/buildconf import std/[strformat, strutils]

--path: src

let setting = BuildSettings( name: "MyExtension", )

let bin = setting.name.toLowerAscii

configure(setting): [libraries] linux.debug = &"res://nim/lib/lib{bin}.so" if true: linux.release = &"res://nim/lib/lib{bin}.release.so" else: linux.release = &"res://nim/lib/release/lib{bin}.so"

The build system checks the platform, target, and arch in the BuildSettings and outputs binaries to the appropriate paths. In this example, if you build with gdextwiz build -d:platform=linux -d:target=release, res://nim/lib/libmyextension.release.so is automatically selected as the output destination.

There are three update methods for the .gdextension file. See the documentation for details.

Cross-platform build

By using the value of setting.platform, you can easily get a cross-platform build environment as well. For example, if you want to build for WebAssembly, you can do the following:

Note

The emcc backend is already built into the library, so there is no need to copy and paste this.

config.nims

import gdext/buildconf

--path: src

let setting = BuildSettings( name: "MyExtension", )

configure(setting)

case setting.platform of web: --cpu: wasm32 --cc: clang

when buildOS == "windows":
  --clang.exe: emcc.bat
  --clang.linkerexe: emcc.bat
else:
  --clang.exe: emcc
  --clang.linkerexe: emcc

--passC: "-s SIDE_MODULE=1 -s SUPPORT_LONGJMP='wasm'"
--passL: "-s SIDE_MODULE=1 -s SUPPORT_LONGJMP='wasm' -s WASM_BIGINT"

Export to web

Step by step

  1. Install emscripten following the guide
  2. Set up export templates following [exporting projects] (https://docs.godotengine.org/en/stable/tutorials/export/exporting_projects.html#exporting-projects)
  3. Build your extension: gdextwiz build -d:platform=web
  4. Check [Extensions Support] and [Thread Support] onimage
  5. Start HTTP server and have fun!Peek 2025-04-04 15-30