Преглед изворни кода

Fix Linux shared compilation when using GCC (#752)

There is a parsing issue when C++17 attributes `[[something]]` and GCC
attributes `__attribute(something)__` appears in a class specification.

This can be fixed by using C++17 attributes syntax for GCC attributes.
However, this isn't a drop-in replacement for every usage.
Jérôme Leclercq пре 1 година
родитељ
комит
b084d8f905
6 измењених фајлова са 36 додато и 4 уклоњено
  1. 20 0
      .github/workflows/build.yml
  2. 1 1
      Jolt/Core/Color.h
  3. 12 0
      Jolt/Core/Core.h
  4. 1 1
      Jolt/Core/Profiler.h
  5. 1 1
      Jolt/Geometry/OrientedBox.h
  6. 1 1
      Jolt/Physics/Body/Body.h

+ 20 - 0
.github/workflows/build.yml

@@ -74,6 +74,26 @@ jobs:
       working-directory: ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}}
       run: ctest --output-on-failure
 
+  linux-gcc-so:
+    runs-on: ubuntu-latest
+    name: Linux GCC Shared Library
+    strategy:
+        fail-fast: false
+        matrix:
+            build_type: [Debug, Release, Distribution]
+            clang_version: [g++]
+
+    steps:
+    - name: Checkout Code
+      uses: actions/checkout@v4
+    - name: Configure CMake
+      run: cmake -B ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=${{matrix.clang_version}} -DBUILD_SHARED_LIBS=Yes Build
+    - name: Build
+      run: cmake --build ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -j 2
+    - name: Test
+      working-directory: ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}}
+      run: ctest --output-on-failure
+
   msys2_mingw_gcc:
     runs-on: windows-latest
     defaults:

+ 1 - 1
Jolt/Core/Color.h

@@ -12,7 +12,7 @@ class Color;
 using ColorArg = Color;
 
 /// Class that holds an RGBA color with 8-bits per component
-class [[nodiscard]] JPH_EXPORT Color
+class [[nodiscard]] JPH_EXPORT_GCC_BUG_WORKAROUND Color
 {
 public:
 	/// Constructors

+ 12 - 0
Jolt/Core/Core.h

@@ -192,6 +192,10 @@
 			#define JPH_EXPORT __declspec(dllexport)
 		#else
 			#define JPH_EXPORT __attribute__ ((visibility ("default")))
+			#if defined(JPH_COMPILER_GCC)
+				// Prevents an issue with GCC attribute parsing (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69585)
+				#define JPH_EXPORT_GCC_BUG_WORKAROUND [[gnu::visibility("default")]]
+			#endif
 		#endif
 	#else
 		// When linking against Jolt, we must import these symbols
@@ -199,6 +203,10 @@
 			#define JPH_EXPORT __declspec(dllimport)
 		#else
 			#define JPH_EXPORT __attribute__ ((visibility ("default")))
+			#if defined(JPH_COMPILER_GCC)
+				// Prevents an issue with GCC attribute parsing (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69585)
+				#define JPH_EXPORT_GCC_BUG_WORKAROUND [[gnu::visibility("default")]]
+			#endif
 		#endif
 	#endif
 #else
@@ -206,6 +214,10 @@
 	#define JPH_EXPORT
 #endif
 
+#ifndef JPH_EXPORT_GCC_BUG_WORKAROUND
+	#define JPH_EXPORT_GCC_BUG_WORKAROUND JPH_EXPORT
+#endif
+
 // Macro used by the RTTI macros to not export a function
 #define JPH_NO_EXPORT
 

+ 1 - 1
Jolt/Core/Profiler.h

@@ -166,7 +166,7 @@ private:
 };
 
 // Class that contains the information of a single scoped measurement
-class alignas(16) JPH_EXPORT ProfileSample : public NonCopyable
+class alignas(16) JPH_EXPORT_GCC_BUG_WORKAROUND ProfileSample : public NonCopyable
 {
 public:
 	JPH_OVERRIDE_NEW_DELETE

+ 1 - 1
Jolt/Geometry/OrientedBox.h

@@ -14,7 +14,7 @@ JPH_NAMESPACE_BEGIN
 class AABox;
 
 /// Oriented box
-class [[nodiscard]] JPH_EXPORT OrientedBox
+class [[nodiscard]] JPH_EXPORT_GCC_BUG_WORKAROUND OrientedBox
 {
 public:
 	JPH_OVERRIDE_NEW_DELETE

+ 1 - 1
Jolt/Physics/Body/Body.h

@@ -31,7 +31,7 @@ class SoftBodyCreationSettings;
 /// The functions that get/set the position of the body all indicate if they are relative to the center of mass or to the original position in which the shape was created.
 ///
 /// The linear velocity is also velocity of the center of mass, to correct for this: \f$VelocityCOM = Velocity - AngularVelocity \times ShapeCOM\f$.
-class alignas(JPH_RVECTOR_ALIGNMENT) JPH_EXPORT Body : public NonCopyable
+class alignas(JPH_RVECTOR_ALIGNMENT) JPH_EXPORT_GCC_BUG_WORKAROUND Body : public NonCopyable
 {
 public:
 	JPH_OVERRIDE_NEW_DELETE