Skip to content

Commit

Permalink
# This is a combination of 20 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

Parse gdextension_interface.h declarations using regex

# This is the commit message #2:

AsUninit trait to convert FFI pointers to their uninitialized versions

# This is the commit message godot-rust#3:

GodotFfi::from_sys_init() now uses uninitialized pointer types

# This is the commit message godot-rust#4:

Introduce GDExtensionUninitialized*Ptr, without changing semantics

# This is the commit message godot-rust#5:

Adjust init code to new get_proc_address mechanism

# This is the commit message godot-rust#6:

Make `trace` feature available in godot-ffi, fix interface access before initialization

# This is the commit message godot-rust#7:

Compatibility layer between Godot 4.0 and 4.1 (different GDExtension APIs)

# This is the commit message godot-rust#8:

Add GdextBuild to access build/runtime metadata

# This is the commit message godot-rust#9:

Detect 4.0 <-> 4.1 mismatches in both directions + missing `compatibility_minimum = 4.1`

# This is the commit message godot-rust#10:

Detect legacy/modern version of C header (also without `custom-godot` feature)

# This is the commit message godot-rust#11:

CI: add jobs that use patched 4.0.x versions

# This is the commit message godot-rust#12:

Remove several memory leaks by constructing into uninitialized pointers

# This is the commit message godot-rust#13:

CI: memcheck jobs for both 4.0.3 and nightly

# This is the commit message godot-rust#14:

Remove ToVariant, FromVariant, and VariantMetadata impls for pointers

This commit splits SignatureTuple into two separate traits:
PtrcallSignatureTuple and VarcallSignatureTuple. The latter is a child
of the former. PtrcallSignatureTuple is used for ptrcall and only
demands GodotFuncMarshall of its arguments. VarcallSignatureTuple is
used for varcall and additionally demands ToVariant, FromVariant, and
VariantMetadata of its arguments, so pointers cannot benefit from the
optimizations provided by varcall over ptrcall.

# This is the commit message godot-rust#15:

Adds FromVariant and ToVariant proc macros

# This is the commit message godot-rust#16:

godot-core: builtin: reimplement Plane functions/methods

# This is the commit message godot-rust#17:

impl GodotFfi for Option<T> when T is pointer sized and nullable godot-rust#240

Additionally FromVariant and ToVariant are also implemented for Option<Gd<T>>
to satisfy all the requirements for ffi and godot_api.

# This is the commit message godot-rust#18:

Fix UB in virtual method calls that take objects
Fix incorrect incrementing of refcount when calling in to godot
Fix refcount not being incremented when we receive a refcounted object in virtual methods

# This is the commit message godot-rust#19:

fix UB caused by preload weirdness

# This is the commit message godot-rust#20:

Implements swizzle and converts from/to tuples
  • Loading branch information
Bromeon authored and Hapenia-Lans committed May 26, 2023
1 parent 4107ee6 commit 2c41abc
Show file tree
Hide file tree
Showing 71 changed files with 3,086 additions and 510 deletions.
51 changes: 49 additions & 2 deletions .github/composite/godot-itest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ inputs:
default: 'false'
description: "Should the job check against latest gdextension_interface.h, and warn on difference"

godot-prebuilt-patch:
required: false
default: ''
description: "If specified, sets the branch name of the godot4-prebuilt crate to this value"

rust-toolchain:
required: false
default: 'stable'
Expand Down Expand Up @@ -71,14 +76,56 @@ runs:
rust: ${{ inputs.rust-toolchain }}
with-llvm: ${{ inputs.with-llvm }}

- name: "Patch prebuilt version ({{ inputs.godot-prebuilt-patch }})"
if: inputs.godot-prebuilt-patch != ''
env:
VERSION: ${{ inputs.godot-prebuilt-patch }}
# sed -i'' needed for macOS compatibility, see https://stackoverflow.com/q/4247068
run: |
echo "Patch prebuilt version to $VERSION..."
# For newer versions, update the compatibility_minimum in .gdextension files to 4.1
# Once a 4.1.0 is released, we can invert this and set compatibility_minimum to 4.0 for older versions.
if [[ "$VERSION" == "4.1" ]]; then
echo "Update compatibility_minimum in .gdextension files..."
dirs=("itest" "examples")
for dir in "${dirs[@]}"; do
find "$dir" -type f -name "*.gdextension" -exec sed -i'.bak' 's/compatibility_minimum = 4\.0/compatibility_minimum = 4.1/' {} +
done
# Versions 4.0.x
else
# Patch only needed if version is not already set
if grep -E 'godot4-prebuilt = { .+ branch = "$VERSION" }' godot-bindings/Cargo.toml; then
echo "Already has version $version; no need for patch."
else
cat << HEREDOC >> Cargo.toml
[patch."https://github.com/godot-rust/godot4-prebuilt"]
godot4-prebuilt = { git = "https://github.com//godot-rust/godot4-prebuilt", branch = "$VERSION" }
HEREDOC
echo "Patched Cargo.toml for version $version."
fi
fi
shell: bash

# else
- name: "No patch selected"
if: inputs.godot-prebuilt-patch == ''
run: |
echo "No patch selected; use default godot4-prebuilt version."
shell: bash

- name: "Build gdext (itest)"
run: |
cargo build -p itest ${{ inputs.rust-extra-args }}
shell: bash
env:
RUSTFLAGS: ${{ inputs.rust-env-rustflags }}

# Note: no longer fails, as we expect header to be forward-compatible; instead issues a warning
# This step no longer fails if there's a diff, as we expect header to be forward-compatible; instead issues a warning
# However, still fails if patch cannot be applied (conflict).
# Step is only run in latest, not for compat 4.0.1 etc. -> no need to take into account different header versions.
- name: "Copy and compare GDExtension header"
if: inputs.godot-check-header == 'true'
run: |
Expand All @@ -96,7 +143,7 @@ runs:
echo "\`\`\`diff" >> $GITHUB_STEP_SUMMARY
git diff --no-index gdextension_interface_prebuilt.h gdextension_interface.h >> $GITHUB_STEP_SUMMARY || true
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "After manually updating file, run: \`git diff -R > tweak.patch\`." >> $GITHUB_STEP_SUMMARY
echo "After manually updating file, run: \`git diff -R > tweak2.patch && mv tweak2.patch tweak.patch\`." >> $GITHUB_STEP_SUMMARY
# Undo modifications
mv gdextension_interface_prebuilt.h gdextension_interface.h
Expand Down
68 changes: 62 additions & 6 deletions .github/workflows/full-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ jobs:
# Additionally, the 'linux (msrv *)' special case will then be listed next to the other 'linux' jobs.
# Note: Windows uses '--target x86_64-pc-windows-msvc' by default as Cargo argument.
include:
- name: macos
# macOS

- name: macos-4.0.3
os: macos-12
artifact-name: macos
godot-binary: godot.macos.editor.dev.x86_64
godot-prebuilt-patch: '4.0.3'

- name: macos-double
os: macos-12
Expand All @@ -142,10 +146,15 @@ jobs:
godot-binary: godot.macos.editor.dev.x86_64
rust-extra-args: --features godot/custom-godot
with-llvm: true
godot-prebuilt-patch: '4.1'

- name: windows
# Windows

- name: windows-4.0.3
os: windows-latest
artifact-name: windows
godot-binary: godot.windows.editor.dev.x86_64.exe
godot-prebuilt-patch: '4.0.3'

- name: windows-double
os: windows-latest
Expand All @@ -157,12 +166,35 @@ jobs:
artifact-name: windows
godot-binary: godot.windows.editor.dev.x86_64.exe
rust-extra-args: --features godot/custom-godot
godot-prebuilt-patch: '4.1'

# Linux

# Don't use latest Ubuntu (22.04) as it breaks lots of ecosystem compatibility.
# If ever moving to ubuntu-latest, need to manually install libtinfo5 for LLVM.
- name: linux
- name: linux-4.0.3
os: ubuntu-20.04
artifact-name: linux
godot-binary: godot.linuxbsd.editor.dev.x86_64
godot-check-header: false # disabled for now

- name: linux-4.0.2
os: ubuntu-20.04
artifact-name: linux
godot-binary: godot.linuxbsd.editor.dev.x86_64
godot-prebuilt-patch: '4.0.2'

- name: linux-4.0.1
os: ubuntu-20.04
artifact-name: linux
godot-binary: godot.linuxbsd.editor.dev.x86_64
godot-prebuilt-patch: '4.0.1'

- name: linux-4.0
os: ubuntu-20.04
artifact-name: linux
godot-binary: godot.linuxbsd.editor.dev.x86_64
godot-prebuilt-patch: '4.0'

- name: linux-double
os: ubuntu-20.04
Expand All @@ -180,27 +212,50 @@ jobs:
artifact-name: linux
godot-binary: godot.linuxbsd.editor.dev.x86_64
rust-extra-args: --features godot/custom-godot
godot-prebuilt-patch: '4.1'

# Special Godot binaries compiled with AddressSanitizer/LeakSanitizer to detect UB/leaks.
# Additionally, the Godot source is patched to make dlclose() a no-op, as unloading dynamic libraries loses stacktrace and
# cause false positives like println!. See https://github.com/google/sanitizers/issues/89.
# The gcc version can possibly be removed later, as it is slower and needs a larger artifact than the clang one.

# --disallow-focus: fail if #[itest(focus)] is encountered, to prevent running only a few tests for full CI
- name: linux-memcheck-gcc
- name: linux-memcheck-gcc-4.0.3
os: ubuntu-20.04
artifact-name: linux-memcheck-gcc
godot-binary: godot.linuxbsd.editor.dev.x86_64.san
godot-args: -- --disallow-focus
rust-toolchain: nightly
rust-env-rustflags: -Zrandomize-layout

- name: linux-memcheck-clang
- name: linux-memcheck-clang-4.0.3
os: ubuntu-20.04
artifact-name: linux-memcheck-clang
godot-binary: godot.linuxbsd.editor.dev.x86_64.llvm.san
godot-args: -- --disallow-focus
rust-toolchain: nightly
rust-env-rustflags: -Zrandomize-layout

- name: linux-memcheck-gcc-nightly
os: ubuntu-20.04
artifact-name: linux-memcheck-gcc
godot-binary: godot.linuxbsd.editor.dev.x86_64.san
godot-args: -- --disallow-focus
rust-toolchain: nightly
rust-env-rustflags: -Zrandomize-layout
rust-extra-args: --features godot/custom-godot
godot-prebuilt-patch: '4.1'

- name: linux-memcheck-clang-nightly
os: ubuntu-20.04
artifact-name: linux-memcheck-clang
godot-binary: godot.linuxbsd.editor.dev.x86_64.llvm.san
godot-args: -- --disallow-focus
rust-toolchain: nightly
rust-env-rustflags: -Zrandomize-layout
rust-extra-args: --features godot/custom-godot
godot-prebuilt-patch: '4.1'


steps:
- uses: actions/checkout@v3
Expand All @@ -211,11 +266,12 @@ jobs:
artifact-name: godot-${{ matrix.artifact-name || matrix.name }}
godot-binary: ${{ matrix.godot-binary }}
godot-args: ${{ matrix.godot-args }}
godot-prebuilt-patch: ${{ matrix.godot-prebuilt-patch }}
rust-extra-args: ${{ matrix.rust-extra-args }}
rust-toolchain: ${{ matrix.rust-toolchain || 'stable' }}
rust-env-rustflags: ${{ matrix.rust-env-rustflags }}
with-llvm: ${{ matrix.with-llvm }}
godot-check-header: ${{ matrix.name == 'linux' }}
godot-check-header: ${{ matrix.godot-check-header }}


license-guard:
Expand Down
1 change: 1 addition & 0 deletions examples/dodge-the-creeps/godot/DodgeTheCreeps.gdextension
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[configuration]
entry_symbol = "gdext_rust_init"
compatibility_minimum = 4.0

[libraries]
linux.debug.x86_64 = "res://../../../target/debug/libdodge_the_creeps.so"
Expand Down
2 changes: 1 addition & 1 deletion godot-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ custom-godot = ["dep:bindgen", "dep:regex", "dep:which"]
custom-godot-extheader = []

[dependencies]
godot4-prebuilt = { optional = true, git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.1" }
godot4-prebuilt = { optional = true, git = "https://github.com/godot-rust/godot4-prebuilt", branch = "4.0.3" }

# Version >= 1.5.5 for security: https://blog.rust-lang.org/2022/03/08/cve-2022-24713.html
# 'unicode-gencat' needed for \d, see: https://docs.rs/regex/1.5.5/regex/#unicode-features
Expand Down
41 changes: 33 additions & 8 deletions godot-bindings/res/tweak.patch
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
diff --git b/godot-ffi/src/gen/gdextension_interface.h a/godot-ffi/src/gen/gdextension_interface.h
index 0b7615f..6db266e 100644
index 4e4f300..e1cd5fb 100644
--- b/godot-ffi/src/gen/gdextension_interface.h
+++ a/godot-ffi/src/gen/gdextension_interface.h
@@ -139,22 +139,22 @@ typedef enum {

} GDExtensionVariantOperator;
@@ -155,27 +155,27 @@ typedef enum {
// - Some types have no destructor (see `extension_api.json`'s `has_destructor` field), for
// them it is always safe to skip the constructor for the return value if you are in a hurry ;-)

-typedef void *GDExtensionVariantPtr;
-typedef const void *GDExtensionConstVariantPtr;
-typedef void *GDExtensionUninitializedVariantPtr;
-typedef void *GDExtensionStringNamePtr;
-typedef const void *GDExtensionConstStringNamePtr;
-typedef void *GDExtensionUninitializedStringNamePtr;
-typedef void *GDExtensionStringPtr;
-typedef const void *GDExtensionConstStringPtr;
-typedef void *GDExtensionUninitializedStringPtr;
-typedef void *GDExtensionObjectPtr;
-typedef const void *GDExtensionConstObjectPtr;
-typedef void *GDExtensionUninitializedObjectPtr;
-typedef void *GDExtensionTypePtr;
-typedef const void *GDExtensionConstTypePtr;
-typedef void *GDExtensionUninitializedTypePtr;
-typedef const void *GDExtensionMethodBindPtr;
+typedef struct __GdextVariant *GDExtensionVariantPtr;
+typedef const struct __GdextVariant *GDExtensionConstVariantPtr;
+typedef struct __GdextUninitializedVariant *GDExtensionUninitializedVariantPtr;
+typedef struct __GdextStringName *GDExtensionStringNamePtr;
+typedef const struct __GdextStringName *GDExtensionConstStringNamePtr;
+typedef struct __GdextUninitializedStringName *GDExtensionUninitializedStringNamePtr;
+typedef struct __GdextString *GDExtensionStringPtr;
+typedef const struct __GdextString *GDExtensionConstStringPtr;
+typedef struct __GdextUninitializedString *GDExtensionUninitializedStringPtr;
+typedef struct __GdextObject *GDExtensionObjectPtr;
+typedef const struct __GdextObject *GDExtensionConstObjectPtr;
+typedef struct __GdextUninitializedObject *GDExtensionUninitializedObjectPtr;
+typedef struct __GdextType *GDExtensionTypePtr;
+typedef const struct __GdextType *GDExtensionConstTypePtr;
+typedef struct __GdextUninitializedType *GDExtensionUninitializedTypePtr;
+typedef const struct __GdextMethodBind *GDExtensionMethodBindPtr;
typedef int64_t GDExtensionInt;
typedef uint8_t GDExtensionBool;
Expand All @@ -38,7 +48,22 @@ index 0b7615f..6db266e 100644

/* VARIANT DATA I/O */

@@ -203,7 +203,7 @@ typedef struct {
@@ -195,11 +195,11 @@ typedef struct {
int32_t expected;
} GDExtensionCallError;

-typedef void (*GDExtensionVariantFromTypeConstructorFunc)(GDExtensionVariantPtr, GDExtensionTypePtr);
-typedef void (*GDExtensionTypeFromVariantConstructorFunc)(GDExtensionTypePtr, GDExtensionVariantPtr);
+typedef void (*GDExtensionVariantFromTypeConstructorFunc)(GDExtensionUninitializedVariantPtr, GDExtensionTypePtr);
+typedef void (*GDExtensionTypeFromVariantConstructorFunc)(GDExtensionUninitializedTypePtr, GDExtensionVariantPtr);
typedef void (*GDExtensionPtrOperatorEvaluator)(GDExtensionConstTypePtr p_left, GDExtensionConstTypePtr p_right, GDExtensionTypePtr r_result);
typedef void (*GDExtensionPtrBuiltInMethod)(GDExtensionTypePtr p_base, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_return, int p_argument_count);
-typedef void (*GDExtensionPtrConstructor)(GDExtensionTypePtr p_base, const GDExtensionConstTypePtr *p_args);
+typedef void (*GDExtensionPtrConstructor)(GDExtensionUninitializedTypePtr p_base, const GDExtensionConstTypePtr *p_args);
typedef void (*GDExtensionPtrDestructor)(GDExtensionTypePtr p_base);
typedef void (*GDExtensionPtrSetter)(GDExtensionTypePtr p_base, GDExtensionConstTypePtr p_value);
typedef void (*GDExtensionPtrGetter)(GDExtensionConstTypePtr p_base, GDExtensionTypePtr r_value);
@@ -224,7 +224,7 @@ typedef struct {

/* EXTENSION CLASSES */

Expand All @@ -47,7 +72,7 @@ index 0b7615f..6db266e 100644

typedef GDExtensionBool (*GDExtensionClassSet)(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value);
typedef GDExtensionBool (*GDExtensionClassGet)(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret);
@@ -266,7 +266,7 @@ typedef struct {
@@ -287,7 +287,7 @@ typedef struct {
void *class_userdata; // Per-class user data, later accessible in instance bindings.
} GDExtensionClassCreationInfo;

Expand All @@ -56,7 +81,7 @@ index 0b7615f..6db266e 100644

/* Method */

@@ -323,7 +323,7 @@ typedef struct {
@@ -345,7 +345,7 @@ typedef struct {

/* SCRIPT INSTANCE EXTENSION */

Expand All @@ -65,7 +90,7 @@ index 0b7615f..6db266e 100644

typedef GDExtensionBool (*GDExtensionScriptInstanceSet)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value);
typedef GDExtensionBool (*GDExtensionScriptInstanceGet)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret);
@@ -353,13 +353,13 @@ typedef GDExtensionBool (*GDExtensionScriptInstanceRefCountDecremented)(GDExtens
@@ -375,13 +375,13 @@ typedef GDExtensionBool (*GDExtensionScriptInstanceRefCountDecremented)(GDExtens
typedef GDExtensionObjectPtr (*GDExtensionScriptInstanceGetScript)(GDExtensionScriptInstanceDataPtr p_instance);
typedef GDExtensionBool (*GDExtensionScriptInstanceIsPlaceholder)(GDExtensionScriptInstanceDataPtr p_instance);

Expand Down
Loading

0 comments on commit 2c41abc

Please sign in to comment.