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

package everything for modules #203

Merged
merged 6 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/build_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,3 @@ jobs:
path: |
${{ github.workspace }}/bin/**/*.universal
if-no-files-found: error

- name: Upload Artifact Static
uses: actions/upload-artifact@v4
with:
name: static-sandbox-macos-${{ matrix.arch }}-${{ matrix.precision }}
path: |
${{ github.workspace }}/bin/**/*.a
${{ github.workspace }}/ext/godot-cpp/**/*.a
if-no-files-found: error
39 changes: 39 additions & 0 deletions .github/workflows/build_macos_static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build MacOS Static
on:
workflow_dispatch:
workflow_call:

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- {arch: arm64, precision: single, extension: ""}
- {arch: arm64, precision: double, extension: ".double"}
- {arch: x86_64, precision: single, extension: ""}
- {arch: x86_64, precision: double, extension: ".double"}
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: 🔗 GDExtension Build
uses: godotengine/godot-cpp-template/.github/actions/build@main
with:
platform: macos
arch: ${{ matrix.arch }}
build-target-type: template_release
float-precision: ${{ matrix.precision }}

- name: Upload Artifact Static
uses: actions/upload-artifact@v4
with:
name: static-sandbox-macos-${{ matrix.arch }}-${{ matrix.precision }}
path: |
${{ github.workspace }}/bin/**/*.a
${{ github.workspace }}/ext/godot-cpp/**/*.a
if-no-files-found: error
22 changes: 22 additions & 0 deletions .github/workflows/build_module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Module Builds
on:
workflow_call:

jobs:
godot:
runs-on: "ubuntu-latest"
name: Copy module files

steps:
- uses: actions/checkout@v4
- name: Copy icons
run: |
rm -rf ./bin/addons/godot_sandbox/bin
mv ./bin/addons/godot_sandbox/ icons
- name: Upload
uses: actions/upload-artifact@v4
with:
name: static-sandbox-gdextension
path: |
module
if-no-files-found: error
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
pattern: static-sandbox-*
merge-multiple: true
path: static-sandbox
path: sandbox
name: static-sandbox
- name: Delete draft release(s)
uses: hugo19941994/delete-draft-releases@v1.0.0
Expand All @@ -32,14 +32,14 @@ jobs:
run: |
ls
zip -r "godot-sandbox.zip" godot-sandbox
zip -r "static-sandbox.zip" static-sandbox
zip -r "sandbox.zip" sandbox
- name: Release
uses: softprops/action-gh-release@v2
with:
name: Godot Sandbox Nightly
files: |
godot-sandbox.zip
static-sandbox.zip
sandbox.zip
generate_release_notes: true
draft: true
prerelease: true
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
build_linux:
needs: [lint]
uses: ./.github/workflows/build_linux.yml
build_macos_static:
needs: [lint]
uses: ./.github/workflows/build_macos_static.yml
build_macos:
needs: [lint]
uses: ./.github/workflows/build_macos.yml
Expand All @@ -37,6 +40,8 @@ jobs:
uses: ./.github/workflows/build_web.yml
build_godot:
uses: ./.github/workflows/build_godot.yml
build_module:
uses: ./.github/workflows/build_module.yml

docker_build:
uses: ./.github/workflows/build_docker.yml
Expand All @@ -50,7 +55,7 @@ jobs:
merge:
runs-on: ubuntu-latest
name: Merge
needs: [build_android, build_ios, build_linux, build_macos, build_windows, build_web, build_godot]
needs: [build_android, build_ios, build_linux, build_macos, build_macos_static, build_windows, build_web, build_godot, build_module]
steps:
- uses: actions/upload-artifact/merge@v4
with:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ Linting:

The script icon is built from the Godot icons. It's using the same font as the Godot Logo, which is Lilita One. The icons are then imported into Godot once in order to check the box `Scale With Editor` in the import panel.

## Module

If you want to build this as a module, simply download the `sandbox.zip` from releases, unzip it, and copy it to the modules folder in godot, build it:

```sh
scons module_sandbox_enabled=True disable_exceptions=False target=editor
```

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand Down
39 changes: 39 additions & 0 deletions module/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

Import("env")
Import("env_modules")

def get_sufix():
suffix = ".{}.{}".format(env["platform"], env["target"])
if env.dev_build:
suffix += ".dev"
if env["precision"] == "double":
suffix += ".double"
suffix += "." + env["arch"]
if not env["threads"]:
suffix += ".nothreads"
return suffix.replace("editor", "template_release")

# Libraries
if env["platform"] == "macos" or env["platform"] == "ios":
base_path = "#modules/sandbox/bin/addons/godot_sandbox/bin/libgodot_riscv{}.framework".format(get_sufix())
base_file = "libgodot_riscv{}".format(get_sufix())
else:
base_path = "#modules/sandbox/bin/addons/godot_sandbox/bin"
base_file = "libgodot_riscv{}".format(get_sufix())

env.Append(LIBS=[base_file])
env.Append(LIBPATH=[base_path])

# Godot-cpp
base_path = "#modules/sandbox/ext/godot-cpp/bin"
base_file = "libgodot-cpp{}".format(get_sufix())

env.Append(LIBS=[base_file])
env.Append(LIBPATH=[base_path])

# Sources
env_gdextension = env_modules.Clone()

env_gdextension.add_source_files(env.modules_sources, "*.cpp")
6 changes: 6 additions & 0 deletions module/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def can_build(env, platform):
return True


def configure(env):
pass
41 changes: 41 additions & 0 deletions module/gdextension_static_library_loader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "gdextension_static_library_loader.h"

#include "core/config/project_settings.h"
#include "core/io/dir_access.h"
#include "core/version.h"
#include "core/extension/gdextension.h"

Error GDExtensionStaticLibraryLoader::open_library(const String &p_path) {
library_path = p_path;
return OK;
}

Error GDExtensionStaticLibraryLoader::initialize(GDExtensionInterfaceGetProcAddress p_get_proc_address, const Ref<GDExtension> &p_extension, GDExtensionInitialization *r_initialization) {

GDExtensionInitializationFunction initialization_function = (GDExtensionInitializationFunction)entry_funcptr;
if (initialization_function == nullptr) {
}
GDExtensionBool ret = initialization_function(p_get_proc_address, p_extension.ptr(), r_initialization);

if (ret) {
return OK;
} else {
ERR_PRINT("GDExtension initialization function '" + library_path + "' returned an error.");
return FAILED;
}
}

void GDExtensionStaticLibraryLoader::close_library() {
}

bool GDExtensionStaticLibraryLoader::is_library_open() const {
return true;
}

bool GDExtensionStaticLibraryLoader::has_library_changed() const {
return false;
}

bool GDExtensionStaticLibraryLoader::library_exists() const {
return true;
}
32 changes: 32 additions & 0 deletions module/gdextension_static_library_loader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef GDEXTENSION_STATIC_LIBRARY_LOADER_H
#define GDEXTENSION_STATIC_LIBRARY_LOADER_H

#include <functional>

#include "core/extension/gdextension_loader.h"
#include "core/io/config_file.h"
#include "core/os/shared_object.h"

class GDExtensionStaticLibraryLoader : public GDExtensionLoader {
friend class GDExtensionManager;
friend class GDExtension;

private:
String resource_path;
void *entry_funcptr = nullptr;
String library_path;
Vector<SharedObject> library_dependencies;

HashMap<String, String> class_icon_paths;

public:
void set_entry_funcptr(void *p_entry_funcptr) { entry_funcptr = p_entry_funcptr; }
virtual Error open_library(const String &p_path) override;
virtual Error initialize(GDExtensionInterfaceGetProcAddress p_get_proc_address, const Ref<GDExtension> &p_extension, GDExtensionInitialization *r_initialization) override;
virtual void close_library() override;
virtual bool is_library_open() const override;
virtual bool has_library_changed() const override;
virtual bool library_exists() const override;
};

#endif // GDEXTENSION_STATIC_LIBRARY_LOADER_H
28 changes: 28 additions & 0 deletions module/register_types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "register_types.h"
#include "core/object/object.h"
#include "core/extension/gdextension_interface.h"
#include "core/extension/gdextension_manager.h"
#include "./gdextension_static_library_loader.h"
#include "core/object/ref_counted.h"

extern "C" {
GDExtensionBool riscv_library_init(
GDExtensionInterfaceGetProcAddress p_get_proc_address,
GDExtensionClassLibraryPtr p_library,
GDExtensionInitialization *r_initialization
);
}

void initialize_sandbox_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) {
return;
}

Ref<GDExtensionStaticLibraryLoader> loader;
loader.instantiate();
loader->set_entry_funcptr((void*)&riscv_library_init);
GDExtensionManager::get_singleton()->load_extension_with_loader("sandbox", loader);
}

void uninitialize_sandbox_module(ModuleInitializationLevel p_level) {
}
9 changes: 9 additions & 0 deletions module/register_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef SANDBOX_REGISTER_TYPES_H
#define SANDBOX_REGISTER_TYPES_H

#include "modules/register_module_types.h"

void initialize_sandbox_module(ModuleInitializationLevel p_level);
void uninitialize_sandbox_module(ModuleInitializationLevel p_level);

#endif // SANDBOX_REGISTER_TYPES_H