You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/godot_docs/cmake.md
+42-10
Original file line number
Diff line number
Diff line change
@@ -10,32 +10,53 @@ This method requires a local RISC-V compiler installed on your system. If you do
10
10
11
11
CMake is completely optional. Normally, you can use Docker which compiles for you in the Godot editor.
12
12
13
-
## Setup & Installation
13
+
## Build using Zig
14
14
15
-
There is a [CMake project in the Godot Sandbox](https://github.com/libriscv/godot-sandbox/tree/main/program/cpp/cmake) repository that can be used to create ELFs with the API pre-included.
15
+
In order to build programs you will need to install: CMake, git, Zig
16
16
17
-
The easiest way to access it is to create a symlink to the cmake folder above in your project so that you can directly reference it in CMake:
17
+
[Download Zig](https://ziglang.org/download/) and add the extracted folder to PATH so that it becomes globally accessible. This means that typing `zig` from anywhere should work.
18
+
19
+
The easiest way to use CMake is to have a look at what [Godot Sandbox Programs](https://github.com/libriscv/godot-sandbox-programs) is doing. It has build scripts for Linux, macOS and Windows, and builds several projects for you.
20
+
21
+
Either fork the godot-sandbox-programs repository or copy it into a new one that you just created. Then go into the programs folder and remove everything except hello-world. Also edit `programs/CMakeLists.txt` to remove the other projects that you just deleted. You can rename hello-world, if you want.
22
+
23
+
Now you have two options:
24
+
1. If you commit changes and push them, Github Actions will build programs for you and upload them to a draft release. These are ready-to-use and will be very small.
25
+
2. You can build programs yourself using any of the root-level scripts. Linux/macOS: `./build.sh` Windows: `./build.cmd`
26
+
27
+
28
+
## Manual CMake setup
29
+
30
+
There is a [CMake project in the Godot Sandbox](https://github.com/libriscv/godot-sandbox/tree/main/program/cpp/cmake) repository that can be used to create ELFs with the API pre-included. This CMake script supports both RISC-V cross-compilers and Zig cross-compilation.
18
31
19
32
```cmake
20
33
cmake_minimum_required(VERSION 3.10)
21
34
project(example LANGUAGES CXX)
22
35
23
-
# Add the Godot Sandbox build functions
24
-
add_subdirectory(cmake)
36
+
# Fetch godot-sandbox repository (add_subdirectory is implicitly called)
Here `example`is a regular CMake target that you can use like normal. You can have as many programs as you want.
51
+
Here `example`becomes a program that you can load in the sandbox. You can add as many programs as you want.
32
52
33
53
In order to build this project, we will use a simple build script:
34
54
35
55
```sh
36
56
#!/bin/bash
37
57
38
58
# Change this to reflect your RISC-V toolchain
59
+
# You can also use a Zig toolchain here if you want
39
60
export CC="riscv64-linux-gnu-gcc-14"
40
61
export CXX="riscv64-linux-gnu-g++-14"
41
62
@@ -53,6 +74,19 @@ Remember to make the script executable:
53
74
chmod +x build.sh
54
75
```
55
76
77
+
### macOS
78
+
79
+
You can use Zig as a cross-compiler. Have a look at the first chapter.
80
+
81
+
The [macOS github action](https://github.com/libriscv/godot-sandbox-programs/blob/main/.github/workflows/zig-macos.yml) shows you how to build on macOS.
82
+
83
+
### Windows
84
+
85
+
You can use Zig as a cross-compiler. Have a look at the first chapter.
86
+
87
+
The [Windows github action](https://github.com/libriscv/godot-sandbox-programs/blob/main/.github/workflows/zig-windows.yml) shows you how to build on Windows.
88
+
89
+
56
90
### Ubuntu and Windows WSL2
57
91
58
92
On Linux and Windows WSL2 we can install a RISC-V compiler like so:
@@ -65,6 +99,8 @@ On some systems you may only have access to g++ version 12 or 13. Modify the `bu
65
99
66
100
### Windows MSYS2
67
101
102
+
MSYS2 has a RISC-V compiler that is not capable of compiling all kinds of programs. But it's enough to compile most C++.
You can find a working [MSYS2 build example here](https://github.com/libriscv/godot-sandbox-demo/tree/master/json_diff_sample/json_diff). For `unknown-elf`-type toolchains a toolchain file is needed.
77
113
78
114
79
-
### macOS
80
-
81
-
On macOS there are RISC-V toolchains in brew. Let us know which ones worked for you.
0 commit comments