From 94efe3d410f712fd1a730ed4e6b2ac90ffdc2fe7 Mon Sep 17 00:00:00 2001 From: Bastiaan Olij Date: Fri, 12 Nov 2021 21:03:29 +1100 Subject: [PATCH] Fixing compiler warnings around implicit type casting loosing precision --- .github/workflows/ci.yml | 20 ++++++++++++++++ include/godot_cpp/core/binder_common.hpp | 24 +++++++++---------- include/godot_cpp/core/math.hpp | 2 +- include/godot_cpp/core/method_bind.hpp | 18 +++++++------- include/godot_cpp/variant/aabb.hpp | 14 +++++------ include/godot_cpp/variant/color.hpp | 30 ++++++++++++------------ include/godot_cpp/variant/quaternion.hpp | 20 ++++++++-------- include/godot_cpp/variant/rect2.hpp | 4 ++-- include/godot_cpp/variant/vector2.hpp | 8 +++---- include/godot_cpp/variant/vector2i.hpp | 12 ++++++---- include/godot_cpp/variant/vector3.hpp | 10 ++++---- test/SConstruct | 22 +++++++++++++---- test/src/example.cpp | 2 +- 13 files changed, 111 insertions(+), 75 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bef4cfe3..a3c1ca61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,11 @@ jobs: run: | scons target=release generate_bindings=yes -j $(nproc) + - name: Build test project + run: | + cd test + scons target=release -j $(nproc) + - name: Upload artifact uses: actions/upload-artifact@v2 with: @@ -55,6 +60,11 @@ jobs: run: | scons target=release generate_bindings=yes -j $env:NUMBER_OF_PROCESSORS + - name: Build test project + run: | + cd test + scons target=release -j $env:NUMBER_OF_PROCESSORS + - name: Upload artifact uses: actions/upload-artifact@v2 with: @@ -89,6 +99,11 @@ jobs: gcc --version scons target=release generate_bindings=yes use_mingw=yes -j $env:NUMBER_OF_PROCESSORS + #- name: Build test project (TODO currently not supported, leaving uncommented as a reminder to fix this) + # run: | + # cd test + # scons target=release use_mingw=yes -j $env:NUMBER_OF_PROCESSORS + - name: Upload artifact uses: actions/upload-artifact@v2 with: @@ -118,6 +133,11 @@ jobs: run: | scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu) + - name: Build test project + run: | + cd test + scons target=release -j $(sysctl -n hw.logicalcpu) + static-checks: name: Static Checks (clang-format) runs-on: ubuntu-20.04 diff --git a/include/godot_cpp/core/binder_common.hpp b/include/godot_cpp/core/binder_common.hpp index eb4f5280..cabefb90 100644 --- a/include/godot_cpp/core/binder_common.hpp +++ b/include/godot_cpp/core/binder_common.hpp @@ -239,18 +239,18 @@ void call_with_variant_args_dv(T *p_instance, void (T::*p_method)(P...), const G #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = GDNATIVE_CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.argument = (int32_t)sizeof...(P); return; } #endif int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; - int32_t dvs = default_values.size(); + int32_t dvs = (int32_t)default_values.size(); #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = GDNATIVE_CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.argument = (int32_t)sizeof...(P); return; } #endif @@ -274,18 +274,18 @@ void call_with_variant_argsc_dv(T *p_instance, void (T::*p_method)(P...) const, #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = GDNATIVE_CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.argument = (int32_t)sizeof...(P); return; } #endif int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; - int32_t dvs = default_values.size(); + int32_t dvs = (int32_t)default_values.size(); #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = GDNATIVE_CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.argument = (int32_t)sizeof...(P); return; } #endif @@ -309,18 +309,18 @@ void call_with_variant_args_ret_dv(T *p_instance, R (T::*p_method)(P...), const #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = GDNATIVE_CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.argument = (int32_t)sizeof...(P); return; } #endif int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; - int32_t dvs = default_values.size(); + int32_t dvs = (int32_t)default_values.size(); #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = GDNATIVE_CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.argument = (int32_t)sizeof...(P); return; } #endif @@ -344,18 +344,18 @@ void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const, #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = GDNATIVE_CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.argument = (int32_t)sizeof...(P); return; } #endif int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; - int32_t dvs = default_values.size(); + int32_t dvs = (int32_t)default_values.size(); #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = GDNATIVE_CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.argument = (int32_t)sizeof...(P); return; } #endif diff --git a/include/godot_cpp/core/math.hpp b/include/godot_cpp/core/math.hpp index fb7178e0..7eb2394e 100644 --- a/include/godot_cpp/core/math.hpp +++ b/include/godot_cpp/core/math.hpp @@ -163,7 +163,7 @@ inline double sinc(double p_x) { } inline float sincn(float p_x) { - return sinc(Math_PI * p_x); + return (float)sinc(Math_PI * p_x); } inline double sincn(double p_x) { return sinc(Math_PI * p_x); diff --git a/include/godot_cpp/core/method_bind.hpp b/include/godot_cpp/core/method_bind.hpp index 176a53c8..b8f2bf23 100644 --- a/include/godot_cpp/core/method_bind.hpp +++ b/include/godot_cpp/core/method_bind.hpp @@ -71,10 +71,10 @@ protected: public: const char *get_name() const; void set_name(const char *p_name); - _FORCE_INLINE_ int get_default_argument_count() const { return default_arguments.size(); } + _FORCE_INLINE_ int get_default_argument_count() const { return (int)default_arguments.size(); } _FORCE_INLINE_ const std::vector &get_default_arguments() const { return default_arguments; } _FORCE_INLINE_ Variant has_default_argument(int p_arg) const { - int idx = p_arg - (argument_count - default_arguments.size()); + int idx = p_arg - (argument_count - (int)default_arguments.size()); if (idx < 0 || idx >= default_arguments.size()) { return false; @@ -83,7 +83,7 @@ public: } } _FORCE_INLINE_ Variant get_default_argument(int p_arg) const { - int idx = p_arg - (argument_count - default_arguments.size()); + int idx = p_arg - (argument_count - (int)default_arguments.size()); if (idx < 0 || idx >= default_arguments.size()) { return Variant(); @@ -159,7 +159,7 @@ public: } void set_method_info(const MethodInfo &p_info, bool p_return_nil_is_variant) { - set_argument_count(p_info.arguments.size()); + set_argument_count((int)p_info.arguments.size()); if (p_info.arguments.size()) { std::vector names; names.reserve(p_info.arguments.size()); @@ -175,7 +175,7 @@ public: if (p_return_nil_is_variant) { arguments.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; } - generate_argument_types(p_info.arguments.size()); + generate_argument_types((int)p_info.arguments.size()); } virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_return) const { @@ -252,7 +252,7 @@ public: virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeCallError &r_error) const { #ifdef TYPED_METHOD_BIND - call_with_variant_args_dv(static_cast(p_instance), method, p_args, p_argument_count, r_error, get_default_arguments()); + call_with_variant_args_dv(static_cast(p_instance), method, p_args, (int)p_argument_count, r_error, get_default_arguments()); #else call_with_variant_args_dv(reinterpret_cast(p_instance), method, p_args, p_argument_count, r_error, get_default_arguments()); #endif @@ -330,7 +330,7 @@ public: virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeCallError &r_error) const { #ifdef TYPED_METHOD_BIND - call_with_variant_argsc_dv(static_cast(p_instance), method, p_args, p_argument_count, r_error, get_default_arguments()); + call_with_variant_argsc_dv(static_cast(p_instance), method, p_args, (int)p_argument_count, r_error, get_default_arguments()); #else call_with_variant_argsc_dv(reinterpret_cast(p_instance), method, p_args, p_argument_count, r_error, get_default_arguments()); #endif @@ -414,7 +414,7 @@ public: virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeCallError &r_error) const { Variant ret; #ifdef TYPED_METHOD_BIND - call_with_variant_args_ret_dv(static_cast(p_instance), method, p_args, p_argument_count, ret, r_error, get_default_arguments()); + call_with_variant_args_ret_dv(static_cast(p_instance), method, p_args, (int)p_argument_count, ret, r_error, get_default_arguments()); #else call_with_variant_args_ret_dv((MB_T *)p_instance, method, p_args, p_argument_count, ret, r_error, get_default_arguments()); #endif @@ -499,7 +499,7 @@ public: virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeCallError &r_error) const { Variant ret; #ifdef TYPED_METHOD_BIND - call_with_variant_args_retc_dv(static_cast(p_instance), method, p_args, p_argument_count, ret, r_error, get_default_arguments()); + call_with_variant_args_retc_dv(static_cast(p_instance), method, p_args, (int)p_argument_count, ret, r_error, get_default_arguments()); #else call_with_variant_args_retc_dv((MB_T *)p_instance, method, p_args, p_argument_count, ret, r_error, get_default_arguments()); #endif diff --git a/include/godot_cpp/variant/aabb.hpp b/include/godot_cpp/variant/aabb.hpp index 1d46025a..f654aae1 100644 --- a/include/godot_cpp/variant/aabb.hpp +++ b/include/godot_cpp/variant/aabb.hpp @@ -336,7 +336,7 @@ inline void AABB::expand_to(const Vector3 &p_vector) { } void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const { - Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5); + Vector3 half_extents(size.x * (real_t)0.5, size.y * (real_t)0.5, size.z * (real_t)0.5); Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z); real_t length = p_plane.normal.abs().dot(half_extents); @@ -374,9 +374,9 @@ inline real_t AABB::get_shortest_axis_size() const { } bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const { - real_t divx = 1.0 / p_dir.x; - real_t divy = 1.0 / p_dir.y; - real_t divz = 1.0 / p_dir.z; + real_t divx = (real_t)1.0 / p_dir.x; + real_t divy = (real_t)1.0 / p_dir.y; + real_t divz = (real_t)1.0 / p_dir.z; Vector3 upbound = position + size; real_t tmin, tmax, tymin, tymax, tzmin, tzmax; @@ -426,9 +426,9 @@ void AABB::grow_by(real_t p_amount) { position.x -= p_amount; position.y -= p_amount; position.z -= p_amount; - size.x += 2.0 * p_amount; - size.y += 2.0 * p_amount; - size.z += 2.0 * p_amount; + size.x += (real_t)2.0 * p_amount; + size.y += (real_t)2.0 * p_amount; + size.z += (real_t)2.0 * p_amount; } void AABB::quantize(real_t p_unit) { diff --git a/include/godot_cpp/variant/color.hpp b/include/godot_cpp/variant/color.hpp index 7fe62944..d8948d12 100644 --- a/include/godot_cpp/variant/color.hpp +++ b/include/godot_cpp/variant/color.hpp @@ -157,7 +157,7 @@ public: inline Color blend(const Color &p_over) const { Color res; - float sa = 1.0 - p_over.a; + float sa = (real_t)1.0 - p_over.a; res.a = a * sa + p_over.a; if (res.a == 0) { return Color(0, 0, 0, 0); @@ -171,16 +171,16 @@ public: inline Color to_linear() const { return Color( - r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4), - g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4), - b < 0.04045 ? b * (1.0 / 12.92) : Math::pow((b + 0.055) * (1.0 / (1 + 0.055)), 2.4), + r < (real_t)0.04045 ? r * (real_t)(1.0 / 12.92) : Math::pow((r + (real_t)0.055) * (real_t)(1.0 / (1.0 + 0.055)), (real_t)2.4), + g < (real_t)0.04045 ? g * (real_t)(1.0 / 12.92) : Math::pow((g + (real_t)0.055) * (real_t)(1.0 / (1.0 + 0.055)), (real_t)2.4), + b < (real_t)0.04045 ? b * (real_t)(1.0 / 12.92) : Math::pow((b + (real_t)0.055) * (real_t)(1.0 / (1.0 + 0.055)), (real_t)2.4), a); } inline Color to_srgb() const { return Color( - r < 0.0031308 ? 12.92 * r : (1.0 + 0.055) * Math::pow(r, 1.0f / 2.4f) - 0.055, - g < 0.0031308 ? 12.92 * g : (1.0 + 0.055) * Math::pow(g, 1.0f / 2.4f) - 0.055, - b < 0.0031308 ? 12.92 * b : (1.0 + 0.055) * Math::pow(b, 1.0f / 2.4f) - 0.055, a); + r < (real_t)0.0031308 ? (real_t)12.92 * r : (real_t)(1.0 + 0.055) * Math::pow(r, (real_t)(1.0 / 2.4)) - (real_t)0.055, + g < (real_t)0.0031308 ? (real_t)12.92 * g : (real_t)(1.0 + 0.055) * Math::pow(g, (real_t)(1.0 / 2.4)) - (real_t)0.055, + b < (real_t)0.0031308 ? (real_t)12.92 * b : (real_t)(1.0 + 0.055) * Math::pow(b, (real_t)(1.0 / 2.4)) - (real_t)0.055, a); } static Color hex(uint32_t p_hex); @@ -202,14 +202,14 @@ public: operator String() const; // For the binder. - inline void set_r8(int32_t r8) { r = (Math::clamp(r8, 0, 255) / 255.0); } - inline int32_t get_r8() const { return int32_t(Math::clamp(r * 255.0, 0.0, 255.0)); } - inline void set_g8(int32_t g8) { g = (Math::clamp(g8, 0, 255) / 255.0); } - inline int32_t get_g8() const { return int32_t(Math::clamp(g * 255.0, 0.0, 255.0)); } - inline void set_b8(int32_t b8) { b = (Math::clamp(b8, 0, 255) / 255.0); } - inline int32_t get_b8() const { return int32_t(Math::clamp(b * 255.0, 0.0, 255.0)); } - inline void set_a8(int32_t a8) { a = (Math::clamp(a8, 0, 255) / 255.0); } - inline int32_t get_a8() const { return int32_t(Math::clamp(a * 255.0, 0.0, 255.0)); } + inline void set_r8(int32_t r8) { r = (Math::clamp(r8, 0, 255) / (real_t)255.0); } + inline int32_t get_r8() const { return int32_t(Math::clamp(r * (real_t)255.0, (real_t)0.0, (real_t)255.0)); } + inline void set_g8(int32_t g8) { g = (Math::clamp(g8, 0, 255) / (real_t)255.0); } + inline int32_t get_g8() const { return int32_t(Math::clamp(g * (real_t)255.0, (real_t)0.0, (real_t)255.0)); } + inline void set_b8(int32_t b8) { b = (Math::clamp(b8, 0, 255) / (real_t)255.0); } + inline int32_t get_b8() const { return int32_t(Math::clamp(b * (real_t)255.0, (real_t)0.0, (real_t)255.0)); } + inline void set_a8(int32_t a8) { a = (Math::clamp(a8, 0, 255) / (real_t)255.0); } + inline int32_t get_a8() const { return int32_t(Math::clamp(a * (real_t)255.0, (real_t)0.0, (real_t)255.0)); } inline void set_h(float p_h) { set_hsv(p_h, get_s(), get_v()); } inline void set_s(float p_s) { set_hsv(get_h(), p_s, get_v()); } diff --git a/include/godot_cpp/variant/quaternion.hpp b/include/godot_cpp/variant/quaternion.hpp index 012cfd0c..e87862cd 100644 --- a/include/godot_cpp/variant/quaternion.hpp +++ b/include/godot_cpp/variant/quaternion.hpp @@ -152,19 +152,19 @@ public: Vector3 c = v0.cross(v1); real_t d = v0.dot(v1); - if (d < -1.0 + CMP_EPSILON) { - x = 0; - y = 1; - z = 0; - w = 0; + if (d < (real_t)-1.0 + CMP_EPSILON) { + x = (real_t)0.0; + y = (real_t)1.0; + z = (real_t)0.0; + w = (real_t)0.0; } else { - real_t s = Math::sqrt((1.0 + d) * 2.0); - real_t rs = 1.0 / s; + real_t s = Math::sqrt(((real_t)1.0 + d) * (real_t)2.0); + real_t rs = (real_t)1.0 / s; x = c.x * rs; y = c.y * rs; z = c.z * rs; - w = s * 0.5; + w = s * (real_t)0.5; } } }; @@ -199,7 +199,7 @@ void Quaternion::operator*=(const real_t &s) { } void Quaternion::operator/=(const real_t &s) { - *this *= 1.0 / s; + *this *= (real_t)1.0 / s; } Quaternion Quaternion::operator+(const Quaternion &q2) const { @@ -222,7 +222,7 @@ Quaternion Quaternion::operator*(const real_t &s) const { } Quaternion Quaternion::operator/(const real_t &s) const { - return *this * (1.0 / s); + return *this * ((real_t)1.0 / s); } bool Quaternion::operator==(const Quaternion &p_quat) const { diff --git a/include/godot_cpp/variant/rect2.hpp b/include/godot_cpp/variant/rect2.hpp index a75406e9..e5a25ca5 100644 --- a/include/godot_cpp/variant/rect2.hpp +++ b/include/godot_cpp/variant/rect2.hpp @@ -37,7 +37,7 @@ namespace godot { -struct Transform2D; +class Transform2D; class Rect2 { public: @@ -290,7 +290,7 @@ public: //check ray box r /= l; - Vector2 ir(1.0 / r.x, 1.0 / r.y); + Vector2 ir((real_t)1.0 / r.x, (real_t)1.0 / r.y); // lb is the corner of AABB with minimal coordinates - left bottom, rt is maximal corner // r.org is origin of ray diff --git a/include/godot_cpp/variant/vector2.hpp b/include/godot_cpp/variant/vector2.hpp index 2c020ef8..f7ae8b06 100644 --- a/include/godot_cpp/variant/vector2.hpp +++ b/include/godot_cpp/variant/vector2.hpp @@ -164,19 +164,19 @@ inline Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec) const { } inline Vector2 operator*(float p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; + return p_vec * (real_t)p_scalar; } inline Vector2 operator*(double p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; + return p_vec * (real_t)p_scalar; } inline Vector2 operator*(int32_t p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; + return p_vec * (real_t)p_scalar; } inline Vector2 operator*(int64_t p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; + return p_vec * (real_t)p_scalar; } inline Vector2 Vector2::operator+(const Vector2 &p_v) const { diff --git a/include/godot_cpp/variant/vector2i.hpp b/include/godot_cpp/variant/vector2i.hpp index 3726c31a..a9758128 100644 --- a/include/godot_cpp/variant/vector2i.hpp +++ b/include/godot_cpp/variant/vector2i.hpp @@ -95,7 +95,7 @@ public: operator String() const; - operator Vector2() const { return Vector2(x, y); } + operator Vector2() const { return Vector2((real_t)x, (real_t)y); } inline Vector2i() {} inline Vector2i(const Vector2 &p_vec2) { @@ -113,15 +113,19 @@ inline Vector2i operator*(const int32_t &p_scalar, const Vector2i &p_vector) { } inline Vector2i operator*(const int64_t &p_scalar, const Vector2i &p_vector) { - return p_vector * p_scalar; + return p_vector * (int32_t)p_scalar; } inline Vector2i operator*(const float &p_scalar, const Vector2i &p_vector) { - return p_vector * p_scalar; + float x = (float)p_vector.x * p_scalar; + float y = (float)p_vector.y * p_scalar; + return Vector2i((int32_t)round(x), (int32_t)round(y)); } inline Vector2i operator*(const double &p_scalar, const Vector2i &p_vector) { - return p_vector * p_scalar; + double x = (double)p_vector.x * p_scalar; + double y = (double)p_vector.y * p_scalar; + return Vector2i((int32_t)round(x), (int32_t)round(y)); } typedef Vector2i Size2i; diff --git a/include/godot_cpp/variant/vector3.hpp b/include/godot_cpp/variant/vector3.hpp index 84200663..e435fb64 100644 --- a/include/godot_cpp/variant/vector3.hpp +++ b/include/godot_cpp/variant/vector3.hpp @@ -385,8 +385,8 @@ real_t Vector3::length_squared() const { void Vector3::normalize() { real_t lengthsq = length_squared(); - if (lengthsq == 0) { - x = y = z = 0; + if (lengthsq == (real_t)0.0) { + x = y = z = (real_t)0.0; } else { real_t length = Math::sqrt(lengthsq); x /= length; @@ -403,15 +403,15 @@ Vector3 Vector3::normalized() const { bool Vector3::is_normalized() const { // use length_squared() instead of length() to avoid sqrt(), makes it more stringent. - return Math::is_equal_approx(length_squared(), 1.0, UNIT_EPSILON); + return Math::is_equal_approx(length_squared(), (real_t)1.0, (real_t)UNIT_EPSILON); } Vector3 Vector3::inverse() const { - return Vector3(1.0 / x, 1.0 / y, 1.0 / z); + return Vector3((real_t)1.0 / x, (real_t)1.0 / y, (real_t)1.0 / z); } void Vector3::zero() { - x = y = z = 0; + x = y = z = (real_t)0.0; } // slide returns the component of the vector along the given plane, specified by its normal vector. diff --git a/test/SConstruct b/test/SConstruct index c03138c9..61a5a86b 100644 --- a/test/SConstruct +++ b/test/SConstruct @@ -38,12 +38,13 @@ opts.Add( host_platform, # We'll need to support these in due times # allowed_values=("linux", "freebsd", "osx", "windows", "android", "ios", "javascript"), - allowed_values=("linux", "windows"), + allowed_values=("linux", "windows", "osx"), ignorecase=2, ) ) opts.Add(EnumVariable("bits", "Target platform bits", "64", ("32", "64"))) opts.Add(BoolVariable("use_llvm", "Use the LLVM / Clang compiler", "no")) +opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "universal", ["universal", "x86_64", "arm64"])) opts.Add(PathVariable("target_path", "The path where the lib is installed.", default_target_path, PathVariable.PathAccept)) opts.Add(PathVariable("target_name", "The library name.", default_library_name, PathVariable.PathAccept)) @@ -90,14 +91,25 @@ if env["target"] == "debug": if env["platform"] == "osx": env["target_path"] += "osx/" cpp_library += ".osx" - env.Append(CCFLAGS=["-arch", "x86_64"]) + + if env["bits"] == "32": + raise ValueError("Only 64-bit builds are supported for the macOS target.") + + if env["macos_arch"] == "universal": + env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"]) + env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"]) + else: + env.Append(LINKFLAGS=["-arch", env["macos_arch"]]) + env.Append(CCFLAGS=["-arch", env["macos_arch"]]) + env.Append(CXXFLAGS=["-std=c++17"]) - env.Append(LINKFLAGS=["-arch", "x86_64"]) if env["target"] == "debug": env.Append(CCFLAGS=["-g", "-O2"]) else: env.Append(CCFLAGS=["-g", "-O3"]) + arch_suffix = env["macos_arch"] + elif env["platform"] in ("x11", "linux"): cpp_library += ".linux" env.Append(CCFLAGS=["-fPIC"]) @@ -107,6 +119,7 @@ elif env["platform"] in ("x11", "linux"): else: env.Append(CCFLAGS=["-g", "-O3"]) + arch_suffix = str(bits) elif env["platform"] == "windows": cpp_library += ".windows" # This makes sure to keep the session environment variables on windows, @@ -127,8 +140,7 @@ elif env["platform"] == "windows": if not(env["use_llvm"]): env.Append(CPPDEFINES=["TYPED_METHOD_BIND"]) -# determine our architecture suffix -arch_suffix = str(bits) + arch_suffix = str(bits) # suffix our godot-cpp library cpp_library += "." + env["target"] + "." + arch_suffix diff --git a/test/src/example.cpp b/test/src/example.cpp index 4d34d4c8..54cd1ae6 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -118,7 +118,7 @@ Ref Example::extended_ref_checks(Ref p_ref) const { } Variant Example::varargs_func(const Variant **args, GDNativeInt arg_count, GDNativeCallError &error) { - UtilityFunctions::print("Varargs called with ", String::num(arg_count), " arguments"); + UtilityFunctions::print("Varargs called with ", String::num((double)arg_count), " arguments"); return arg_count; }