Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build using Zig toolchain from within Godot editor for Windows 11 #241

Open
fire opened this issue Dec 17, 2024 · 0 comments
Open

Build using Zig toolchain from within Godot editor for Windows 11 #241

fire opened this issue Dec 17, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@fire
Copy link
Collaborator

fire commented Dec 17, 2024

The Zig toolchain is an optional feature in godot-sandbox allowing you to build complex projects with dependencies from within the Godot editor.

  1. Install scoop install git cmake ninja zig

Require zig greater than or equal to 0.13 version. Zig 0.14 reduces binary size a lot.

  1. Make a cmake folder in the project root exactly res://cmake
  2. Add file res://cmake/.gdignore to ignore the contents.
  3. Add res://cmake/CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(example)

include(FetchContent)
FetchContent_Declare(
    godot-sandbox
    GIT_REPOSITORY https://github.com/libriscv/godot-sandbox.git
    GIT_TAG        main
    SOURCE_SUBDIR  "program/cpp/cmake"
)
FetchContent_MakeAvailable(godot-sandbox)

set(PROOT ${CMAKE_SOURCE_DIR}/..)

add_sandbox_program_at(player ${PROOT}/scenes/player.elf
    ${PROOT}/scenes/player/player.cpp
)
  1. Copy toolchain.cmake from Godot Sandbox Programs repo to res://cmake/toolchain.cmake

Also, copy the remaining scripts from the cmake folder into res://cmake/cmake so that you now have:
- res://cmake/cmake/zig-ar.cmd
- res://cmake/cmake/zig-ranlib.cmd

  1. Initialize CMake with the toolchain file as an argument. The toolchain file is only used to initialize CMake, which is the same on all platforms. You can put this code snippet in cmake\build.cmd:
set HERE=%cd%
mkdir .build
pushd .build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRIPPED=ON -DCMAKE_TOOLCHAIN_FILE=%HERE%\toolchain.cmake
cmake --build .
popd

The example CMake script looks for player.cpp and builds player.elf. It supports full C++ API and Godot run-time API.

  1. Hero wanted: Add an integration to setup/configure cmake automatically from godot-sandbox
    CMake is already automatically called once it has been configured from the Godot editor. Try saving a C++ file in the editor, and you will see that it only uses CMake instead of other methods.
@fwsGonzo fwsGonzo added the documentation Improvements or additions to documentation label Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants