Skip to content

Commit

Permalink
🔨 MA-42 Add VCPKG
Browse files Browse the repository at this point in the history
  • Loading branch information
cornking2020 committed Sep 20, 2024
1 parent 6e92461 commit e28c6ba
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 41 deletions.
18 changes: 7 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Objects.
.scons-cache/
*.os

# SConstruct
.DS_Store
.idea
.sconf_temp
.scons-cache/
.sconsign.dblite
.vs
.vscode
*.os
*.pyc

# MacOS
.DS_Store

# Editors
.vscode/
vcpkg_installed
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[submodule "godot-cpp"]
path = godot-cpp
url = https://github.com/godotengine/godot-cpp.git
branch = master
branch = 4.3
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@

GDExtension template that automatically builds into a self-contained addon for the Godot Asset Library.

### Getting started:
## Getting started

1. Clone this repository (or a new repository with this template) with submodules.
- `git clone --recurse-submodules https://github.com/nathanfranke/gdextension.git`
- `cd gdextension`
2. Update to the latest `godot-cpp`.
- `git submodule update --remote`
2. Build a debug binary for the current platform.
3. Install VCPKG <https://learn.microsoft.com/en-us/vcpkg/get_started/overview>
4. Modify the VCPKG dependence and install.
- `vcpkg install`
5. Build a debug binary for the current platform.
- `scons`
3. Import, edit, and play `project/` using Godot Engine 4+.
6. Import, edit, and play `project/` using Godot Engine 4+.
- `godot --path project/`
4. Check the output:
```
Hello GDScript!
Hello GDExtension Node!
Hello GDExtension Singleton!
```

### Repository structure:
7. Check the output:

```text
Hello GDScript!
Hello GDExtension Node!
Hello GDExtension Singleton!
```

## Repository structure

- `project/` - Godot project boilerplate.
- `addons/example/` - Files to be distributed to other projects.¹
- `demo/` - Scenes and scripts for internal testing. Not strictly necessary.
Expand All @@ -28,12 +34,14 @@ GDExtension template that automatically builds into a self-contained addon for t

¹ Before distributing as an addon, all binaries for all platforms must be built and copied to the `bin/` directory. This is done automatically by GitHub Actions.

### Make it your own:
## Make it your own

1. Rename `project/addons/example/` and `project/addons/example/example.gdextension`.
2. Replace `LICENSE`, `README.md`, and your code in `src/`.
3. Not required, but consider leaving a note about this template if you found it helpful!

### Distributing your extension on the Godot Asset Library with GitHub Actions:
## Distributing your extension on the Godot Asset Library with GitHub Actions

1. Go to Repository→Actions and download the latest artifact.
2. Test the artifact by extracting the addon into a project.
3. Create a new release on GitHub, uploading the artifact as an asset.
Expand Down
33 changes: 19 additions & 14 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ env = SConscript("godot-cpp/SConstruct")

# Add source files.
env.Append(CPPPATH=["src/"])

vcpkg_triplet = {
'windows': 'x64-windows',
'linux': 'x64-linux',
'macos': 'arm64-osx'
}[env["platform"]]

# Add vcpkg include paths.
env.Append(CPPPATH=[f"vcpkg_installed/{vcpkg_triplet}/include"])

# Add vcpkg library paths.
env.Append(LIBPATH=[f"vcpkg_installed/{vcpkg_triplet}/lib"])

# Add vcpkg libraries.
env.Append(LIBS=[lib.stem for lib in Path(
f"vcpkg_installed/{vcpkg_triplet}/lib").glob("*.a")])

sources = Glob("src/*.cpp")

# Find gdextension path even if the directory or extension is renamed (e.g. project/addons/example/example.gdextension).
Expand All @@ -28,24 +45,12 @@ project_name = Path(extension_path).stem
debug_or_release = "release" if env["target"] == "template_release" else "debug"
if env["platform"] == "macos":
library = env.SharedLibrary(
"{0}/bin/lib{1}.{2}.{3}.framework/{1}.{2}.{3}".format(
addon_path,
project_name,
env["platform"],
debug_or_release,
),
f"{addon_path}/bin/lib{project_name}.{env['platform']}.{debug_or_release}.framework/{project_name}.{env['platform']}.{debug_or_release}",
source=sources,
)
else:
library = env.SharedLibrary(
"{}/bin/lib{}.{}.{}.{}{}".format(
addon_path,
project_name,
env["platform"],
debug_or_release,
env["arch"],
env["SHLIBSUFFIX"],
),
f"{addon_path}/bin/lib{project_name}.{env['platform']}.{debug_or_release}.{env['arch']}{env['SHLIBSUFFIX']}",
source=sources,
)

Expand Down
2 changes: 1 addition & 1 deletion godot-cpp
Submodule godot-cpp updated 138 files
6 changes: 5 additions & 1 deletion project/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ config_version=5

config/name="project"
run/main_scene="res://demo/scene.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
config/features=PackedStringArray("4.3", "Forward Plus")

[dotnet]

project/assembly_name="project"
2 changes: 2 additions & 0 deletions src/my_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#include <fmt/core.h>

using namespace godot;

Expand All @@ -12,6 +13,7 @@ void MyNode::_bind_methods()

MyNode::MyNode()
{
fmt::print("MyNode created!\n");
}

MyNode::~MyNode()
Expand Down
2 changes: 2 additions & 0 deletions src/my_singleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#include <fmt/core.h>

using namespace godot;

Expand All @@ -19,6 +20,7 @@ MySingleton *MySingleton::get_singleton()

MySingleton::MySingleton()
{
fmt::print("MySingleton created!\n");
ERR_FAIL_COND(singleton != nullptr);
singleton = this;
}
Expand Down
1 change: 1 addition & 0 deletions vcpkg
Submodule vcpkg added at a39a74
14 changes: 14 additions & 0 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"default-registry": {
"kind": "git",
"baseline": "a39a74405f277773aba08018bb797cb4a6614d0c",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "artifact",
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
"name": "microsoft"
}
]
}
15 changes: 15 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg-schema-definitions.schema.json",
"name": "gdexample",
"version-string": "1.0.0",
"dependencies": [
{
"name": "fmt",
"version>=": "11.0.2"
},
{
"name": "sqlite3",
"version>=": "3.46.1"
}
]
}

0 comments on commit e28c6ba

Please sign in to comment.