Skip to content

Commit d9529ef

Browse files
committed
Fix missing #
1 parent 3f9cde5 commit d9529ef

File tree

8 files changed

+36
-21
lines changed

8 files changed

+36
-21
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ jobs:
347347
CHATMSG_AUTHOR_EMAIL: ${{ github.event.head_commit.author.email }}
348348
CHATMSG_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
349349
CHATMSG_JOB_ID: ${{ matrix.label }}
350-
if: ${{ failure() && github.event_name == 'push' && env.GCHAT_API_URL != '' }}
350+
if: failure() && github.event_name == 'push' && env.GCHAT_API_URL != '' && github.ref_name == 'main'
351351
run: bash ./.github/workflows/build_steps.sh notify_team_chat
352352

353353
# This job quickly determines if MuJoCo Studio is broken.
@@ -406,7 +406,7 @@ jobs:
406406
CHATMSG_AUTHOR_EMAIL: ${{ github.event.head_commit.author.email }}
407407
CHATMSG_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
408408
CHATMSG_JOB_ID: ${{ matrix.label }}
409-
if: ${{ failure() && github.event_name == 'push' && env.GCHAT_API_URL != '' }}
409+
if: failure() && github.event_name == 'push' && env.GCHAT_API_URL != '' && github.ref_name == 'main'
410410
run: bash ./.github/workflows/build_steps.sh notify_team_chat
411411

412412

@@ -451,5 +451,5 @@ jobs:
451451
CHATMSG_AUTHOR_EMAIL: ${{ github.event.head_commit.author.email }}
452452
CHATMSG_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
453453
CHATMSG_JOB_ID: ${{ env.label }}
454-
if: ${{ failure() && github.event_name == 'push' && env.GCHAT_API_URL != '' }}
454+
if: failure() && github.event_name == 'push' && env.GCHAT_API_URL != '' && github.ref_name == 'main'
455455
run: bash ./.github/workflows/build_steps.sh notify_team_chat

include/mujoco/mjplugin.h

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,36 @@ struct mjSDF_ {
182182
};
183183
typedef struct mjSDF_ mjSDF;
184184

185-
#if defined(__has_attribute) && __has_attribute(constructor)
186-
#define mjPLUGIN_LIB_INIT \
187-
static void _mjplugin_init(void) __attribute__((constructor)); \
188-
static void _mjplugin_init(void)
185+
#if defined(__GNUC__) || defined(__clang__)
186+
// GCC and Clang (including clang-cl)
187+
#define mjPLUGIN_LIB_INIT(n) \
188+
static void _mj_init_##n(void) __attribute__((constructor)); \
189+
static void _mj_init_##n(void)
189190
#elif defined(_MSC_VER)
191+
#define m_STR(x) #x
192+
#define m_XSTR(x) m_STR(x)
193+
194+
// On x86, symbols are decorated with a leading underscore.
195+
// On x64, they are not.
196+
#ifdef _M_IX86
197+
#define LINKER_NAME "__mj_ptr_"
198+
#else
199+
#define LINKER_NAME "_mj_ptr_"
200+
#endif
201+
190202
#pragma section(".CRT$XCU", read)
191203

192-
#define mjPLUGIN_LIB_INIT \
193-
static void __cdecl _mj_init_##__COUNTER__(void); \
194-
/* The 'used' attribute for the linker */ \
195-
__declspec(allocate(".CRT$XCU")) \
196-
static void (__cdecl * _mj_ptr_##__COUNTER__)(void) = _mj_init_##__COUNTER__; \
197-
/* This pragma prevents the linker from optimizing this specific pointer away */ \
198-
__pragma(comment(linker, "/include:" "_mj_ptr_" #__COUNTER__)) \
199-
static void __cdecl _mj_init_##__COUNTER__(void)
204+
#define mjPLUGIN_LIB_INIT(n) \
205+
static void __cdecl _mj_init_##n(void); \
206+
/* We use extern "C" to prevent C++ name mangling */ \
207+
extern "C" __declspec(allocate(".CRT$XCU")) \
208+
void (__cdecl * _mj_ptr_##n)(void) = _mj_init_##n; \
209+
/* Force the linker to include the pointer symbol */ \
210+
__pragma(comment(linker, "/include:" LINKER_NAME #n)) \
211+
static void __cdecl _mj_init_##n(void)
212+
213+
#else
214+
#error "Unknown compiler: Plugin registration not supported."
200215
#endif
201216

202217
// function pointer type for mj_loadAllPluginLibraries callback

plugin/actuator/register.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
namespace mujoco::plugin::actuator {
1919

20-
mjPLUGIN_LIB_INIT { Pid::RegisterPlugin(); }
20+
mjPLUGIN_LIB_INIT(actuator) { Pid::RegisterPlugin(); }
2121

2222
} // namespace mujoco::plugin::actuator

plugin/elasticity/register.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace mujoco::plugin::elasticity {
1919

20-
mjPLUGIN_LIB_INIT {
20+
mjPLUGIN_LIB_INIT(elasticity) {
2121
Cable::RegisterPlugin();
2222
}
2323

plugin/obj_decoder/obj_decoder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int CanDecode(const mjResource* resource) {
114114

115115
} // namespace
116116

117-
mjPLUGIN_LIB_INIT {
117+
mjPLUGIN_LIB_INIT(obj_decoder) {
118118
mjpDecoder decoder;
119119
mjp_defaultDecoder(&decoder);
120120
decoder.content_type = "model/obj";

plugin/sensor/register.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace mujoco::plugin::sensor {
1919

20-
mjPLUGIN_LIB_INIT {
20+
mjPLUGIN_LIB_INIT(sensor) {
2121
TouchGrid::RegisterPlugin();
2222
}
2323

plugin/stl_decoder/stl_decoder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int CanDecode(const mjResource* resource) {
132132

133133
} // namespace
134134

135-
mjPLUGIN_LIB_INIT {
135+
mjPLUGIN_LIB_INIT(stl_decoder) {
136136
mjpDecoder decoder;
137137
mjp_defaultDecoder(&decoder);
138138
decoder.content_type = "model/stl";

plugin/usd_decoder/usd_decoder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,7 @@ int CanDecode(const mjResource* resource) {
24592459
} // namespace
24602460

24612461
// clang-format off
2462-
mjPLUGIN_LIB_INIT {
2462+
mjPLUGIN_LIB_INIT(usd_decoder) {
24632463
mjpDecoder decoder;
24642464
mjp_defaultDecoder(&decoder);
24652465
decoder.content_type = "model/usd";

0 commit comments

Comments
 (0)