Skip to content

Commit

Permalink
update for 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
matrixant committed Jul 19, 2023
1 parent 70ff8b2 commit c7c4d65
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 9 deletions.
22 changes: 22 additions & 0 deletions .github/actions/godot-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Setup Godot build cache
description: Setup Godot build cache.
inputs:
cache-name:
description: The cache base name (job name by default).
default: "${{github.job}}"
scons-cache:
description: The scons cache path.
default: "${{github.workspace}}/.scons-cache/"
runs:
using: "composite"
steps:
# Upload cache on completion and check it out now
- name: Load .scons_cache directory
uses: actions/cache@v3
with:
path: ${{inputs.scons-cache}}
key: ${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}
restore-keys: |
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}
130 changes: 130 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Action name
name: Deploy

# 触发条件,这里是新的 tag 被 push 时触发
on:
push:
tags:
# 正则匹配 tag 格式,如 v0.1.0
- "v[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:

permissions:
contents: write

# 实际工作
jobs:
build-and-upload:
name: Build and Upload
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
# 配置编译目标平台,这里是在 Ubuntu, MacOS, Windows 上分别编译
matrix:
include:
- name: Linux (GCC)
platform: linux
arch: x86_64
os: ubuntu-latest
cache-name: linux-x86_64

- name: Windows (MSVC)
platform: windows
arch: x86_64
os: windows-latest
cache-name: windows-x86_64-msvc
# 执行流程
steps:
# 克隆仓库代码
- name: Clone repository
uses: actions/checkout@v3
with:
submodules: recursive

# 获取发布版本号
- name: Get the release version from the tag
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

# 设置 Godot 缓存
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
with:
cache-name: ${{ matrix.cache-name }}
continue-on-error: true

# 安装依赖库
- name: Install dependencies
if: ${{ matrix.platform == 'linux' }}
run: |
sudo apt-get update -qq
sudo apt-get install -qqq build-essential pkg-config tree
# 安装 SCons
- name: Set up Python (for SCons)
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install scons
run: |
python -m pip install scons
# 构建二进制文件
- name: Build binary files (template_debug)
run: |
scons target=template_debug --sconstruct=gdextension_build/SConstruct
- name: Build binary files (template_release)
run: |
scons target=template_release --sconstruct=gdextension_build/SConstruct
# 打包上传二进制文件
- name: Archive files
shell: bash
run: |
addon_name="serialport"
addon_path="gdextension_build/example/addons/$addon_name"
archive_bin_dir="addons/serialport/bin"
mkdir -p "$addon_path/bin"
mkdir -p "$archive_bin_dir"
if [ "${{ matrix.platform }}" = "linux" ]; then
addon_file_debug="lib$addon_name.${{ matrix.platform }}.template_debug.${{ matrix.arch }}.so"
addon_file_release="lib$addon_name.${{ matrix.platform }}.template_release.${{ matrix.arch }}.so"
elif [ "${{ matrix.platform }}" = "windows" ]; then
addon_file_debug="$addon_name.${{ matrix.platform }}.template_debug.${{ matrix.arch }}.dll"
addon_file_release="$addon_name.${{ matrix.platform }}.template_release.${{ matrix.arch }}.dll"
fi
mv $addon_path/bin/$addon_file_debug $archive_bin_dir/$addon_file_debug
mv $addon_path/bin/$addon_file_release $archive_bin_dir/$addon_file_release
cat>$archive_bin_dir/../$addon_name.gdextension<<EOF
[configuration]
entry_symbol = "${addon_name}_lib_init"
compatibility_minimum = 4.1
[libraries]
${{ matrix.platform }}.debug.${{ matrix.arch }}= "bin/$addon_file_debug"
${{ matrix.platform }}.release.${{ matrix.arch }}= "bin/$addon_file_release"
EOF
archive_name="$addon_name-${{ env.VERSION }}-${{ matrix.platform }}"
if [ "${{ matrix.platform }}" = "linux" ]; then
tree addons
tar -czvf "$archive_name.tar.gz" "addons"
echo "ASSET=$archive_name.tar.gz" >> $GITHUB_ENV
elif [ "${{ matrix.platform }}" = "windows" ]; then
7z a "$archive_name.zip" "addons"
echo "ASSET=$archive_name.zip" >> $GITHUB_ENV
fi
- name: Release files
uses: softprops/action-gh-release@v1
with:
files: |
${{ env.ASSET }}
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "serial"]
path = serial
url = https://github.com/matrixant/serial.git
url = https://github.com/wjwwood/serial.git
[submodule "godot-cpp"]
path = godot-cpp
url = https://github.com/matrixant/godot-cpp.git
url = https://github.com/godotengine/godot-cpp.git
[submodule "gdextension_build/example"]
path = gdextension_build/example
url = https://github.com/matrixant/serial_port_example.git
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ git clone https://github.com/matrixant/serial_port.git --recursive
> cd godot
> scons target=editor
> ```
> * Simple API document included. (Only available when build as module)
> Or you want to build as plugin, switch to the `plugin` branch and update the submodules, then compile the plugin.
> ```bash
> cd serial_port
Expand All @@ -23,9 +25,8 @@ git clone https://github.com/matrixant/serial_port.git --recursive
> ```
> The plugin things will be build to `gdextension_build/example/addons/serialport` directory.

2. The `SerialPort` class will add to godot. You can new a SerialPort object and set it's 'port', 'baudrate', 'bytesize' and so on. Then open it and communicate with your serial device.
3. There is an example in [serial_port_example](https://github.com/matrixant/serial_port_example) repo.

> Simple API document included.
![example](https://github.com/raw/matrixant/serial_port_example/main/screen_shot_0.png)
12 changes: 11 additions & 1 deletion gdextension_build/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,24 @@ addon_name = "serialport"
addon_path = "gdextension_build/example/addons/{}".format(addon_name)
if env["platform"] == "macos":
library = env.SharedLibrary(
"{0}/bin/lib{1}.{2}.{3}.framework/lib{1}.{2}.{3}".format(
"{0}/bin/lib{1}.{2}.{3}.dylib".format(
addon_path,
addon_name,
env["platform"],
env["target"]
),
source=addon_sources,
)
elif env["platform"] == "windows":
library = env.SharedLibrary(
"{0}/bin/{1}{2}{3}".format(
addon_path,
addon_name,
env["suffix"],
env["SHLIBSUFFIX"]
),
source=addon_sources,
)
else:
library = env.SharedLibrary(
"{0}/bin/lib{1}{2}{3}".format(
Expand Down
2 changes: 1 addition & 1 deletion godot-cpp
Submodule godot-cpp updated 51 files
+71 −0 .github/ISSUE_TEMPLATE/bug_report.yml
+14 −0 .github/ISSUE_TEMPLATE/config.yml
+32 −0 .github/workflows/ci.yml
+1 −1 .gitignore
+2 −2 CMakeLists.txt
+8 −4 README.md
+55 −20 SConstruct
+130 −61 binding_generator.py
+7,969 −847 gdextension/extension_api.json
+1,877 −216 gdextension/gdextension_interface.h
+10 −21 include/godot_cpp/classes/ref.hpp
+81 −81 include/godot_cpp/classes/wrapped.hpp
+3 −3 include/godot_cpp/core/binder_common.hpp
+24 −10 include/godot_cpp/core/class_db.hpp
+5 −5 include/godot_cpp/core/engine_ptrcall.hpp
+1 −1 include/godot_cpp/core/memory.hpp
+2 −2 include/godot_cpp/core/method_bind.hpp
+3 −2 include/godot_cpp/core/method_ptrcall.hpp
+12 −6 include/godot_cpp/core/object.hpp
+2 −2 include/godot_cpp/core/type_info.hpp
+147 −7 include/godot_cpp/godot.hpp
+61 −0 src/classes/editor_plugin.cpp
+5 −5 src/classes/low_level.cpp
+3 −3 src/classes/wrapped.cpp
+19 −9 src/core/class_db.cpp
+4 −4 src/core/error_macros.cpp
+4 −4 src/core/memory.cpp
+1 −1 src/core/method_bind.cpp
+30 −0 src/core/object.cpp
+328 −15 src/godot.cpp
+25 −25 src/variant/char_string.cpp
+42 −42 src/variant/packed_arrays.cpp
+38 −37 src/variant/variant.cpp
+1 −4 test/README.md
+2 −2 test/SConstruct
+0 −80 test/demo/main.gd
+0 −0 test/project/bin/libgdexample.osx.template_debug.framework/Resources/Info.plist
+0 −0 test/project/bin/libgdexample.osx.template_release.framework/Resources/Info.plist
+1 −1 test/project/default_env.tres
+1 −0 test/project/example.gdextension
+ test/project/icon.png
+1 −1 test/project/icon.png.import
+121 −0 test/project/main.gd
+2 −2 test/project/main.tscn
+1 −1 test/project/project.godot
+59 −0 test/project/test_base.gd
+24 −0 test/run-tests.sh
+82 −31 test/src/example.cpp
+17 −1 test/src/example.h
+2 −2 test/src/register_types.cpp
+1 −1 tools/windows.py
6 changes: 3 additions & 3 deletions register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void uninitialize_serial_port_module(ModuleInitializationLevel p_level) {

extern "C" {
// Initialization.
GDExtensionBool GDE_EXPORT serial_port_library_init(const GDExtensionInterface *p_interface, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
GDExtensionBool GDE_EXPORT serialport_lib_init(const GDExtensionInterfaceGetProcAddress p_get_proc_addr, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
godot::GDExtensionBinding::InitObject init_obj(p_get_proc_addr, p_library, r_initialization);

init_obj.register_initializer(initialize_serial_port_module);
init_obj.register_terminator(uninitialize_serial_port_module);
Expand All @@ -64,4 +64,4 @@ GDExtensionBool GDE_EXPORT serial_port_library_init(const GDExtensionInterface *
}
} // extern "C"

#endif
#endif

0 comments on commit c7c4d65

Please sign in to comment.